This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Change colorscheme from a script

Tags: None
(comma "," separated)
User avatar
spleen
Registered Member
Posts
15
Karma
0
OS

Change colorscheme from a script

Sun Apr 26, 2015 2:57 pm
Hi all!

I'm looking for help with changing color palette from a script.
i've tried by writing directly on kdeglobals:

Code: Select all
kwriteconfig --file kdeglobals --group General --key ColorScheme MYCOLORSNAME


And from kcmshell4 colors i can see that the colorscheme is highlighted as current, but has not been applied...
After some searches i found this old thread: viewtopic.php?f=17&t=102884&hilit=notifyChange
I then tried with the code from the last post there:
Code: Select all
#!/usr/bin/env python

from PyKDE4.kdeui import KGlobalSettings
from PyKDE4.kdecore import KConfig, KConfigGroup

scheme = KConfig('/full/path/to/MYCOLORSNAME')
kdeglobals = KConfig('kdeglobals')
for groupName in scheme.groupList():
      group = scheme.group('General')
      global_group = kdeglobals.group('General')
      for (k, v) in group.entryMap().items():
                global_group.writeEntry(k, v)
               
kdeglobals.sync()
kGlobalSettings = KGlobalSettings.self()
KGlobalSettings.emitChange(KGlobalSettings.PaletteChanged)

With the very same effect as using kwriteconfig. The colorscheme is written into kdeglobals, but the change is not picked, despite the KGlobalSettings.emitChange.
Most probably i'm doing it wrong.

Since i consider myself a real noob™ i would like to ask your help with this.
I garantuee you'll have my eternal gratitude (in form of a comment within the script itself) :D


User avatar
spleen
Registered Member
Posts
15
Karma
0
OS
Stupid me, it works actually. Because of autocompletion i didn't realize that i was trying to call KGlobalSettings istance with an uppercase :|

Code: Select all
#!/usr/bin/env python

from PyKDE4.kdeui import KGlobalSettings
from PyKDE4.kdecore import KConfig, KConfigGroup

scheme = KConfig('/path/to/my/colorscheme.colors')
kdeglobals = KConfig('kdeglobals')
for groupName in scheme.groupList():
            group = scheme.group(groupName)
            global_group = kdeglobals.group(groupName)
            for (k, v) in group.entryMap().items():
                global_group.writeEntry(k, v)
               
kdeglobals.sync()
kGlobalSettings = KGlobalSettings.self()
kGlobalSettings.emitChange(KGlobalSettings.PaletteChanged)


I'm not sure...But probably i owe myself a beer now....


User avatar
Heiko Tietze
Registered Member
Posts
593
Karma
0
OS
Would be great to have a plasmoid for stuff like this. Missing the theme switcher too.
User avatar
spleen
Registered Member
Posts
15
Karma
0
OS
Heiko Tietze wrote:Would be great to have a plasmoid for stuff like this. Missing the theme switcher too.


Or, a service for Color abstraction.
Like: Extracting colors from current wallpaper(on any wallpaper changed event) → generate a colorscheme → apply the generated colorscheme on the fly.
And since Plasma supports colorschemes in its themes, this could be a really nice automation, visually.

I suppose i could post about this on the VDG section, if there's an interest.




Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]