Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark theme #6

Open
JStika opened this issue Apr 13, 2024 · 5 comments
Open

Dark theme #6

JStika opened this issue Apr 13, 2024 · 5 comments

Comments

@JStika
Copy link

JStika commented Apr 13, 2024

Hi,

can you help me, please?
In main code I'm using for "mainWindow" style as:
QApplication.setStyle(QStyleFactory.create("Fusion"))

How can be automaticaly used Toast Preset *_DARK without set it?

@Crackvignoule
Copy link

Hi, my code might help you:

def show_toast(self, preset, title, text):
        preset_mapping = {
            "success": (ToastPreset.SUCCESS, ToastPreset.SUCCESS_DARK),
            "warning": (ToastPreset.WARNING, ToastPreset.WARNING_DARK),
            "error": (ToastPreset.ERROR, ToastPreset.ERROR_DARK),
            "info": (ToastPreset.INFORMATION, ToastPreset.INFORMATION_DARK),
        }

        current_theme = self.model.theme
        is_dark_theme = current_theme == "dark"

        toast = Toast(self.view)
        toast.setDuration(3000)
        toast.setTitle(title)
        toast.setText(text)

        # Select the appropriate preset based on the theme
        selected_preset = preset_mapping[preset.lower()][is_dark_theme]
        toast.applyPreset(selected_preset)

        toast.show()

@JStika
Copy link
Author

JStika commented Oct 11, 2024

Hi,

[PySidde6 v6.7.3, OS LinuxMint] QMainWindow has no model.theme.

Damage. Your code didn't help me.
I tried the darktheme autodetect module but it doesn't work.

@Crackvignoule
Copy link

Hi,

[PySidde6 v6.7.3, OS LinuxMint] QMainWindow has no model.theme.

Damage. Your code didn't help me. I tried the darktheme autodetect module but it doesn't work.

Its normal, model.theme is specific go my app, I created this variable to store the current theme, I didnt meant to just copy paste my code.

@mtriedl
Copy link

mtriedl commented Oct 23, 2024

If you're using macOS, then you can check if OS dark mode is set using the func below. If you're using windows or prefer a pypi package, then check out darkdetect.

   import subprocess
    
   def is_dark_mode() -> bool:
        """
        Determines whether the system is currently in dark mode.

        The method executes a shell command to read the global AppleInterfaceStyle setting and interprets the output to ascertain if dark mode is enabled.

        Returns:
            bool: True if dark mode is active, False otherwise.
        """
        cmd = 'defaults read -g AppleInterfaceStyle'
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
        return bool(p.communicate()[0])

You could pair this with @Crackvignoule code snippet and replace:

    current_theme = self.model.theme
    is_dark_theme = current_theme == "dark"

with this:

    is_dark_theme =  is_dark_mode()

@JStika
Copy link
Author

JStika commented Oct 24, 2024

Hi,
I wrote I'm using OS LinuxMint, there darkdetect module doesnt work.

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

No branches or pull requests

3 participants