May-25-2017, 02:40 PM
Hello,
On ArchLinux, I'm trying to get the Colors of the current GTK3 theme, but without opening a gtk window.
All I want the script to do is get the colors (and possibly other style attributes), choose a few, and print them to a file. no gui stuff.
I'm confident I can handle the selection & printing to file, but how to get at the colors in the first place?
I need this for gtk3 (and i assume that i also have to use python3 for this).
I have a working draft for gtk2:
any help appreciated, thanks.
o.
On ArchLinux, I'm trying to get the Colors of the current GTK3 theme, but without opening a gtk window.
All I want the script to do is get the colors (and possibly other style attributes), choose a few, and print them to a file. no gui stuff.
I'm confident I can handle the selection & printing to file, but how to get at the colors in the first place?
I need this for gtk3 (and i assume that i also have to use python3 for this).
I have a working draft for gtk2:
#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- import gtk sep="============================================" w = gtk.Window() w.realize() style=w.get_style() print '''A style contains the graphics information needed by a widget to draw itself in its various states: STATE_NORMAL # The state during normal operation. STATE_ACTIVE # The widget is currently active, such as a button pushed STATE_PRELIGHT # The mouse pointer is over the widget. STATE_SELECTED # The widget is selected STATE_INSENSITIVE # The widget is disabled A style contains the following attributes: ''' l=[gtk.STATE_NORMAL,gtk.STATE_ACTIVE,gtk.STATE_PRELIGHT,gtk.STATE_SELECTED,gtk.STATE_INSENSITIVE] print sep,"\nbase - a list of 5 colors" for i in l: print "\t",style.base[i].to_string(),i print sep,"\ntext - a list of 5 colors" for i in l: print "\t",style.text[i].to_string(),i print sep,"\nfg - a list of 5 foreground colors - one for each state" for i in l: print "\t",style.fg[i].to_string(),i print sep,"\nbg - a list of 5 background colors" for i in l: print "\t",style.bg[i].to_string(),i print sep,"\nlight - a list of 5 colors - created during set_style() method" for i in l: print "\t",style.light[i].to_string(),i print sep,"\ndark - a list of 5 colors - created during set_style() method" for i in l: print "\t",style.dark[i].to_string(),i print sep,"\nmid - a list of 5 colors - created during set_style() method" for i in l: print "\t",style.mid[i].to_string(),i print sep,"\ntext_aa - a list of 5 colors halfway between text/base" for i in l: print "\t",style.text_aa[i].to_string(),iand here's what i came up with for gtk3 (after hours of trawling the web and trying out things):
#!/usr/bin/env python # -*- coding: utf-8 -*- import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk win = Gtk.Window() #~ win.connect("delete-event", Gtk.main_quit) #~ win.show_all() #~ Gtk.main() style_context = win.get_style_context() print(style_context) print(style_context.lookup_color('bg_color')) # if this worked i'd still need to get a list of valid attributesand it gives me this:
Output:<Gtk.StyleContext object at 0x7f82975d0090 (GtkStyleContext at 0x130f320)>
(False, color=Gdk.RGBA(red=0.000000, green=0.000000, blue=0.000000, alpha=0.000000))
the first one is too low-level for me (ram addresses?!), the second clearly shows that i'm not getting what i'm looking for.any help appreciated, thanks.
o.