Skip to content

Syntax highlighting for examples.#1124

Merged
j9ac9k merged 3 commits intopyqtgraph:developfrom
dargor:color_examples
Mar 8, 2020
Merged

Syntax highlighting for examples.#1124
j9ac9k merged 3 commits intopyqtgraph:developfrom
dargor:color_examples

Conversation

@dargor
Copy link
Copy Markdown
Contributor

@dargor dargor commented Feb 9, 2020

Allow bad eyesighted people like me to read and play with examples.

Tested and working with both PyQt5 and PySide2, on Python 3.6 and 3.7.

Based on https://github.com/art1415926535/PyQt5-syntax-highlighting

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 11, 2020

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

=================================== ERRORS ====================================
_________________ ERROR collecting examples/test_examples.py __________________
ImportError while importing test module 'D:\a\1\s\examples\test_examples.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
examples\__init__.py:1: in <module>
    from .__main__ import run
examples\__main__.py:14: in <module>
    import syntax
E   ModuleNotFoundError: No module named 'syntax'

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

@dargor
Copy link
Copy Markdown
Contributor Author

dargor commented Feb 11, 2020

Sorry for that, this should fix it.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 11, 2020

No need to apologize, that's what we have CI for. The failures you're seeing are unrelated to your PR.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 6, 2020

Closing and Reopening to trigger a run with the new CI system

@j9ac9k j9ac9k closed this Mar 6, 2020
@j9ac9k j9ac9k reopened this Mar 6, 2020
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 6, 2020

I'm going to throw a screenshot of what this looks like on my machine:

image

Unfortunately in dark mode (on macOS), the class names (and self) are really hard to see:

image

@dargor do you have ideas on how you can handle light/dark mode compatibility?

@dargor
Copy link
Copy Markdown
Contributor Author

dargor commented Mar 6, 2020

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 ?

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 6, 2020

@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 None

and....

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!

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 6, 2020

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....

@dargor
Copy link
Copy Markdown
Contributor Author

dargor commented Mar 7, 2020

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.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 8, 2020

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).

image

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.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 8, 2020

LGTM, thanks for the PR @dargor Merging!

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.

2 participants