Syntax highlighting for examples.#1124
Conversation
|
Hi @dargor, Thanks for the PR, this issue you're addressing is something I've found a bit annoying myself. It appears the CI pipelines are failing for all python3 builds Funny enough, this was not an issue for Python2 runs. You can see more info on the CI runs here: https://dev.azure.com/pyqtgraph/pyqtgraph/_build/results?buildId=571&view=results |
b62009a to
adba81a
Compare
|
Sorry for that, this should fix it. |
|
No need to apologize, that's what we have CI for. The failures you're seeing are unrelated to your PR. |
|
Closing and Reopening to trigger a run with the new CI system |
|
I'm going to throw a screenshot of what this looks like on my machine: Unfortunately in dark mode (on macOS), the class names (and @dargor do you have ideas on how you can handle light/dark mode compatibility? |
|
Sure but I run only Linux, so is there a way I can set this "dark mode" on my system to fix this ? How is this detected on MacOS anyway, I will need to know the current mode to set colors appropriately ? |
|
@dargor Hmm...not sure how to test dark mode on linux, you might need to run KDE as a desktop environment with the dark-breeze theme (or some other dark theme), and even then I'm not sure. It's been a while since I used linux from a desktop environment. On macOS, Qt detects the dark mode automatically from the OS (even as I change the OS setting, the app changes with it). There is an open issue for implementing dark mode on Windows. You should know that conda-based distributions of Python have had issues detecting dark mode on macOS (this one took me forever to debug). I do have to manipulate some colors in my Qt app based on light/dark mode, while I'm not saying this is the best solution, what I did was class App(QApplication):
def __init__(self, args: List[str]) -> None:
super().__init__(args)
self.colors: Union[
Type[LightThemeColors], Type[DarkThemeColors]
] = DarkThemeColors
self.paletteChanged.connect(self.onPaletteChange)
self.onPaletteChange(self.palette())
...
@Slot(QPalette)
def onPaletteChange(self, palette: QPalette) -> None:
if palette.base().color() == "#FFFFFF":
self.colors = LightThemeColors
else:
self.colors = DarkThemeColors
return Noneand.... class LightThemeColors(Enum):
# Mateiral colors with shade 900
Red = "#B71C1C"
Pink = "#FCE4EC" # (default accent)
Purple = "#4A148C"
DeepPurple = "#311B92"
Indigo = "#1A237E" # (default primary)
Blue = "#0D47A1"
LightBlue = "#01579B"
Cyan = "#006064"
Teal = "#004D40"
Green = "#1B5E20"
LightGreen = "#33691E"
Lime = "#827717"
Yellow = "#F57F17"
Amber = "#FF6F00"
Orange = "#E65100"
DeepOrange = "#BF360C"
Brown = "#3E2723"
Grey = "#212121"
BlueGrey = "#263238"
class DarkThemeColors(Enum):
Red = "#F44336"
Pink = "#F48FB1" # (default accent)
Purple = "#CE93D8"
DeepPurple = "#B39DDB"
Indigo = "#9FA8DA" # (default primary)
Blue = "#90CAF9"
LightBlue = "#81D4FA"
Cyan = "#80DEEA"
Teal = "#80CBC4"
Green = "#A5D6A7"
LightGreen = "#C5E1A5"
Lime = "#E6EE9C"
Yellow = "#FFF59D"
Amber = "#FFE082"
Orange = "#FFCC80"
DeepOrange = "#FFAB91"
Brown = "#BCAAA4"
Grey = "#EEEEEE"
BlueGrey = "#B0BEC5"Hope that helps! |
|
Also, if you want to iterate, I'll be happy to test and send screenshots back to you to show you how things look on macOS dark mode.... |
|
I managed to simulate the black mode by modifying some attributes of the QPlainTextEdit widget, so here is a diff based on your code and colors :) Hope it works with the dynamic modification of colors, though. |
|
Woah, this looks nice! (while I had all the colors defined, in my application I only used a small handful of them, so I really had no idea what it was going to look like). It indeed does not intercept the change of light to dark status, I feel like that may be a bit outside the scope of this PR... I'll see if I can intercept that change of status and update accordingly, but even if I can't intercept that system change, this PR has a 👍 from me. I'm going to try and solicit some input from the other maintainers as well. |
|
LGTM, thanks for the PR @dargor Merging! |



Allow bad eyesighted people like me to read and play with examples.
Tested and working with both
PyQt5andPySide2, on Python3.6and3.7.Based on https://github.com/art1415926535/PyQt5-syntax-highlighting