Bugfix: Handle example search failure due to bad regex#2121
Bugfix: Handle example search failure due to bad regex#2121j9ac9k merged 3 commits intopyqtgraph:masterfrom
Conversation
pyqtgraph/examples/ExampleApp.py
Outdated
| background = pg.mkColor(colors.Red) | ||
| background.setAlpha(100) | ||
| validRegex = False | ||
| self.ui.exampleFilter.setStyleSheet(f'background: {pg.mkColor(background).name(QtGui.QColor.HexArgb)}') |
There was a problem hiding this comment.
QtGui.QColor.NameFormat.HexArgb?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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')There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()})a82679e to
cf6f6cf
Compare
|
Ugh, this PR is 9-10 months old..this is embarrassing. Thanks for the PR @ntjess LGTM, merging. |

This fixes an error message when the user is halfway through typing a regex and a
re.erroris 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
setPalettedirectly.