Skip to content

Bugfix: Handle example search failure due to bad regex#2121

Merged
j9ac9k merged 3 commits intopyqtgraph:masterfrom
ntjess:fix-example-regex
Sep 1, 2022
Merged

Bugfix: Handle example search failure due to bad regex#2121
j9ac9k merged 3 commits intopyqtgraph:masterfrom
ntjess:fix-example-regex

Conversation

@ntjess
Copy link
Copy Markdown
Contributor

@ntjess ntjess commented Nov 24, 2021

This fixes an error message when the user is halfway through typing a regex and a re.error is raised. The filter box turns red to indicate an issue and no search is performed until the issue is resolved.

Hoping @NilsNemitz can get the palette working instead of manhandling the stylesheet... I had no luck calling setPalette directly.

background = pg.mkColor(colors.Red)
background.setAlpha(100)
validRegex = False
self.ui.exampleFilter.setStyleSheet(f'background: {pg.mkColor(background).name(QtGui.QColor.HexArgb)}')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QtGui.QColor.NameFormat.HexArgb?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work to just set

try:
    re.compile(text)
    self.ui.exampleFilter.setStyleSheet('')
except:
    colors = DarkThemeColors if app.property('darkMode') else LightThemeColors
    qcol = QtGui.QColor(colors.Red)
    qcol.setAlpha(100)
    hexcol = qcol.name(QtGui.QColor.NameFormat.HexArgb)
    self.ui.exampleFilter.setStyleSheet(f'background: {hexcol})
    return

?
Going through mkColor twice just to prefix #64 to the string seems like the long way around.

And I think clearing the stylesheet should revert to the original colors, without explicitly setting one. Did not test, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NilsNemitz beat me to it, but yeah, get the colors via accessing DarkThemeColors or LightThemeColors based on the darkMode property.

Since the colors come in string form, I don't think we should even convert to qcolor.

colors = DarkThemeColors if app.property('darkMode') else LightThemeColors
red = colors.Red
self.ui.exampleFilter.setStyleSheet(f'background : {red}00')

Copy link
Copy Markdown
Contributor

@NilsNemitz NilsNemitz Nov 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qt's stylesheet seems to be AARRGGBB, though. Not sure if
self.ui.exampleFilter.setStyleSheet(f'background : #64{red[1:]}')
is more readable than the detour through QColor.
:)

Actually, alpha through hex codes seems to be unspecified:
https://doc.qt.io/qt-5/stylesheet-reference.html
background : rgba(r, g, b, a) seems to be the documented way to do this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, rgba() is likely far more readable

colors = DarkThemeColors if app.property('darkMode') else LightThemeColors
error_color = pg.mkColor(colors.Red)
self.ui.exampleFilter.setStyleSheet(f'background : rgba({error_color.red()}, {error_color.green()}, {error_color.blue(), {error_color.alpha()})

@ntjess
Copy link
Copy Markdown
Contributor Author

ntjess commented Dec 10, 2021

image
Does anyone else's error box change color with an annoying white outline?

@ntjess ntjess force-pushed the fix-example-regex branch from a82679e to cf6f6cf Compare August 31, 2022 01:55
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Sep 1, 2022

Ugh, this PR is 9-10 months old..this is embarrassing. Thanks for the PR @ntjess LGTM, merging.

@j9ac9k j9ac9k merged commit 4365d4f into pyqtgraph:master Sep 1, 2022
@ntjess ntjess deleted the fix-example-regex branch September 1, 2022 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants