corpnewt / ProperTree

Cross platform GUI plist editor written in python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Make the Propertree app automatically change it's color scheme according to the system theme.

chadify opened this issue · comments

I've built the ProperTree app from buildapp-select.command and found the consistent theme quite appealing. There's one problem, I've to manually switch the theme from dark to light and vice versa when the system appearance changes.

Can you incorporate the auto theme changing in the next build of the Mac app?

Thank You.

If you leverage python 3.10.2 (only 3.10 version I've tested) from python.org, the windows will change to match the OS theme already.

On macOS 10.14+, and Windows (I'm not sure of the version range), ProperTree will query the system's light/dark mode selection, and update the treeview theme accordingly. This happens on a 10 second loop, and has been a part of the code for awhile. Note that changing the colors manually will override this behavior.

Relevant code (link) follows:

    def get_dark(self):
        if os.name=="nt":
            # Get the registry entry to tell us if we're in dark/light mode
            p = subprocess.Popen(["reg","query","HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize","/v","AppsUseLightTheme"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            c = p.communicate()
            return c[0].decode("utf-8", "ignore").strip().lower().split(" ")[-1] in ("","0x0")
        elif str(sys.platform) != "darwin":
            return True # Default to dark mode on Linux platforms
        # Get the macOS version - and see if dark mode is a thing
        p = subprocess.Popen(["sw_vers","-productVersion"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        c = p.communicate()
        p_vers = c[0].decode("utf-8", "ignore").strip().lower()
        if p_vers < "10.14.0": return True # Default to dark on anything prior to 
        # At this point - we have an OS that supports dark mode, let's check our value
        p = subprocess.Popen(["defaults","read","-g","AppleInterfaceStyle"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        c = p.communicate()
        return c[0].decode("utf-8", "ignore").strip().lower() == "dark"

AFAIK there is no universal way to determine light/dark mode on Linux - so ProperTree will always assume dark mode there by default.

-CorpNewt

Ok. It works.