[Skencil-commits] r747 - skencil/branches/skencil-0.6/src/Sketch/Base
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Oct 8 20:07:56 CEST 2010
Author: igor_n
Date: 2010-10-08 20:07:55 +0200 (Fri, 08 Oct 2010)
New Revision: 747
Modified:
skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py
Log:
code is reformatted and mapping for border colors is added
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py 2010-10-08 17:53:57 UTC (rev 746)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py 2010-10-08 18:07:55 UTC (rev 747)
@@ -38,25 +38,25 @@
font_size - font size integer value
"""
- tmpfile=NamedTemporaryFile()
+ tmpfile = NamedTemporaryFile()
command = "import gtk;w = gtk.Window();w.realize();style=w.get_style(); print style.font_desc.to_string();"
- os.system('python -c "%s" >%s 2>/dev/null'%(command, tmpfile.name))
+ os.system('python -c "%s" >%s 2>/dev/null' % (command, tmpfile.name))
- font=tmpfile.readline().strip()
+ font = tmpfile.readline().strip()
- normal_font=process_gtk_font_string(font)
- small_font=copy.deepcopy(normal_font)
- small_font[2]-=1
+ normal_font = process_gtk_font_string(font)
+ small_font = copy.deepcopy(normal_font)
+ small_font[2] -= 1
- large_font=copy.deepcopy(normal_font)
- large_font[2]+=2
+ large_font = copy.deepcopy(normal_font)
+ large_font[2] += 2
if not 'bold' in large_font[1]:
large_font[1].append('bold')
- fixed_font=copy.deepcopy(normal_font)
- fixed_font[0]='monospace'
+ fixed_font = copy.deepcopy(normal_font)
+ fixed_font[0] = 'monospace'
- return [small_font,normal_font,large_font,fixed_font]
+ return [small_font, normal_font, large_font, fixed_font]
def process_gtk_font_string(font):
@@ -68,9 +68,9 @@
Tk font description.
"""
- font_style=[]
- vals=font.split()
- font_size=int(vals[-1])
+ font_style = []
+ vals = font.split()
+ font_size = int(vals[-1])
vals.remove(vals[-1])
if 'Bold' in vals:
vals.remove('Bold')
@@ -78,28 +78,28 @@
if 'Italic' in vals:
vals.remove('Italic')
font_style.append('italic')
- font_family=string.join(vals,'\ ')
- return [font_family,font_style,font_size]
+ font_family = string.join(vals, '\ ')
+ return [font_family, font_style, font_size]
def tkfont_from_list(font_list):
"""
Constructs tk font string from font list.
"""
- return '%s %d '%(font_list[0],font_list[2]) + string.join(font_list[1])
+ return '%s %d ' % (font_list[0], font_list[2]) + string.join(font_list[1])
def set_ui_fonts(widget, font_list):
"""
Applies font list to tk defaults.
"""
- widget.tk.call('option', 'add', '*font', tkfont_from_list(font_list[1]) )
+ widget.tk.call('option', 'add', '*font', tkfont_from_list(font_list[1]))
##################################################
# Colors routines
##################################################
-SYSTEM_SCHEME='System'
-BUILTIN_SCHEME='Built-in'
+SYSTEM_SCHEME = 'System'
+BUILTIN_SCHEME = 'Built-in'
def gtk_to_tk_color(color):
@@ -107,22 +107,22 @@
Converts gtk color representation to tk.
For example: #0000ffff0000 will be converted to #00ff00
"""
- return color[0]+color[1]+color[2]+color[5]+color[6]+color[9]+color[10]
+ return color[0] + color[1] + color[2] + color[5] + color[6] + color[9] + color[10]
def tkcolor_to_rgb(tkcolor):
"""
Converts tk color string as tuple of integer values.
For example: #ff00ff => (255,0,255)
"""
- return (int(tkcolor[1:3], 0x10),int(tkcolor[3:5], 0x10),int(tkcolor[5:], 0x10))
+ return (int(tkcolor[1:3], 0x10), int(tkcolor[3:5], 0x10), int(tkcolor[5:], 0x10))
def saturated_color(color):
"""
Returns saturated color value.
"""
- r,g,b=tkcolor_to_rgb(color)
- delta=255-max(r,g,b)
- return '#%02X%02X%02X'%(r+delta,g+delta,b+delta)
+ r, g, b = tkcolor_to_rgb(color)
+ delta = 255 - max(r, g, b)
+ return '#%02X%02X%02X' % (r + delta, g + delta, b + delta)
def middle_color(dark, light, factor=0.5):
"""
@@ -131,12 +131,12 @@
dark, light - tk color strings
factor - resulted color shift
"""
- dark=tkcolor_to_rgb(dark)
- light=tkcolor_to_rgb(light)
- r=dark[0]+(light[0]-dark[0])*factor
- g=dark[1]+(light[1]-dark[1])*factor
- b=dark[2]+(light[2]-dark[2])*factor
- return '#%02X%02X%02X'%(r,g,b)
+ dark = tkcolor_to_rgb(dark)
+ light = tkcolor_to_rgb(light)
+ r = dark[0] + (light[0] - dark[0]) * factor
+ g = dark[1] + (light[1] - dark[1]) * factor
+ b = dark[2] + (light[2] - dark[2]) * factor
+ return '#%02X%02X%02X' % (r, g, b)
def lighter_color(color, factor):
"""
@@ -156,79 +156,86 @@
or built-in values (BUILTIN_SCHEME).
"""
- bg ='#d4d0c8'
- foreground ='#000000'
- highlightbackground ='#f3f2ef'
- highlightcolor ='#b0ada5'
- disabledforeground ='#b0ada6'
- selectbackground ='#002468'
- selectforeground ='#ffffff'
+ bg = '#d4d0c8'
+ foreground = '#000000'
+ highlightbackground = '#f3f2ef'
+ highlightcolor = '#b0ada5'
+ disabledforeground = '#b0ada6'
+ selectbackground = '#002468'
+ selectforeground = '#ffffff'
- menubackground='#dedad2'
- menuforeground='#000000'
- menuselectbackground='#002468'
- menuselectforeground='#ffffff'
- menudisabledforeground='#b0ada6'
- menubordercolor='#7e7b77'
+ menubackground = '#dedad2'
+ menuforeground = '#000000'
+ menuselectbackground = '#002468'
+ menuselectforeground = '#ffffff'
+ menudisabledforeground = '#b0ada6'
+ menubordercolor = '#7e7b77'
- editfieldbackground='#ffffff'
- editfieldforeground='#000000'
- treelinescolor='#000000'
+ editfieldbackground = '#ffffff'
+ editfieldforeground = '#000000'
+ treelinescolor = '#000000'
- evencolor='#f0f0f0'
+ d3_light = '#ffffff'
+ d3_dark = '#b0ada6'
- name=BUILTIN_SCHEME
+ light_border = '#b0ada6'
+ normal_border = '#b0ada6'
+ dark_border = '#b0ada6'
+ evencolor = '#f0f0f0'
+
+ name = BUILTIN_SCHEME
+
def __init__(self, scheme=SYSTEM_SCHEME):
- self.name=scheme
- if scheme==BUILTIN_SCHEME:
+ self.name = scheme
+ if scheme == BUILTIN_SCHEME:
return
else:
- self.name=SYSTEM_SCHEME
+ self.name = SYSTEM_SCHEME
self.import_gtk_colors()
def import_gtk_colors(self):
"""
Imports system gtk color scheme using pygtk binding.
"""
- colors={}
- tmpfile=NamedTemporaryFile()
- command="import gtk;w = gtk.Window();w.realize();style=w.get_style();"
- command+="print style.base[gtk.STATE_NORMAL].to_string(),"+ \
- " style.base[gtk.STATE_ACTIVE].to_string(),"+ \
- " style.base[gtk.STATE_PRELIGHT].to_string(),"+ \
- " style.base[gtk.STATE_SELECTED].to_string(),"+ \
+ colors = {}
+ tmpfile = NamedTemporaryFile()
+ command = "import gtk;w = gtk.Window();w.realize();style=w.get_style();"
+ command += "print style.base[gtk.STATE_NORMAL].to_string()," + \
+ " style.base[gtk.STATE_ACTIVE].to_string()," + \
+ " style.base[gtk.STATE_PRELIGHT].to_string()," + \
+ " style.base[gtk.STATE_SELECTED].to_string()," + \
" style.base[gtk.STATE_INSENSITIVE].to_string();"
- command+="print style.text[gtk.STATE_NORMAL].to_string(),"+ \
- " style.text[gtk.STATE_ACTIVE].to_string(),"+ \
- " style.text[gtk.STATE_PRELIGHT].to_string(),"+ \
- " style.text[gtk.STATE_SELECTED].to_string(),"+ \
+ command += "print style.text[gtk.STATE_NORMAL].to_string()," + \
+ " style.text[gtk.STATE_ACTIVE].to_string()," + \
+ " style.text[gtk.STATE_PRELIGHT].to_string()," + \
+ " style.text[gtk.STATE_SELECTED].to_string()," + \
" style.text[gtk.STATE_INSENSITIVE].to_string();"
- command+="print style.fg[gtk.STATE_NORMAL].to_string(),"+ \
- " style.fg[gtk.STATE_ACTIVE].to_string(),"+ \
- " style.fg[gtk.STATE_PRELIGHT].to_string(),"+ \
- " style.fg[gtk.STATE_SELECTED].to_string(),"+ \
+ command += "print style.fg[gtk.STATE_NORMAL].to_string()," + \
+ " style.fg[gtk.STATE_ACTIVE].to_string()," + \
+ " style.fg[gtk.STATE_PRELIGHT].to_string()," + \
+ " style.fg[gtk.STATE_SELECTED].to_string()," + \
" style.fg[gtk.STATE_INSENSITIVE].to_string();"
- command+="print style.bg[gtk.STATE_NORMAL].to_string(),"+ \
- " style.bg[gtk.STATE_ACTIVE].to_string(),"+ \
- " style.bg[gtk.STATE_PRELIGHT].to_string(),"+ \
- " style.bg[gtk.STATE_SELECTED].to_string(),"+ \
+ command += "print style.bg[gtk.STATE_NORMAL].to_string()," + \
+ " style.bg[gtk.STATE_ACTIVE].to_string()," + \
+ " style.bg[gtk.STATE_PRELIGHT].to_string()," + \
+ " style.bg[gtk.STATE_SELECTED].to_string()," + \
" style.bg[gtk.STATE_INSENSITIVE].to_string();"
- os.system('python -c "%s" >%s 2>/dev/null'%(command, tmpfile.name))
+ os.system('python -c "%s" >%s 2>/dev/null' % (command, tmpfile.name))
- for type in ["base","text","fg","bg"]:
- line=tmpfile.readline().strip().split()
- colors[type+' normal']=gtk_to_tk_color(line[0])
- colors[type+' active']=gtk_to_tk_color(line[1])
- colors[type+' prelight']=gtk_to_tk_color(line[2])
- colors[type+' selected']=gtk_to_tk_color(line[3])
- colors[type+' insensitive']=gtk_to_tk_color(line[4])
+ for type in ["base", "text", "fg", "bg"]:
+ line = tmpfile.readline().strip().split()
+ colors[type + ' normal'] = gtk_to_tk_color(line[0])
+ colors[type + ' active'] = gtk_to_tk_color(line[1])
+ colors[type + ' prelight'] = gtk_to_tk_color(line[2])
+ colors[type + ' selected'] = gtk_to_tk_color(line[3])
+ colors[type + ' insensitive'] = gtk_to_tk_color(line[4])
tmpfile.close()
self.map_gtk_colors(colors)
- def map_gtk_colors(self,gtk_colors):
+ def map_gtk_colors(self, gtk_colors):
"""
Maps gtk colors to ColorScheme fields.
"""
@@ -253,6 +260,13 @@
self.editfieldforeground = gtk_colors['text normal']
self.treelinescolor = gtk_colors['text normal']
+ self.d3_light = middle_color('#ffffff', gtk_colors['bg normal'])
+ self.d3_dark = gtk_colors['bg active']
+
+ self.light_border = gtk_colors['bg active']
+ self.normal_border = middle_color(gtk_colors['bg active'], gtk_colors['fg insensitive'])
+ self.dark_border = gtk_colors['fg insensitive']
+
self.evencolor = middle_color(self.bg, self.editfieldbackground, 0.7)
def set_ui_colors(widget, color_scheme):
@@ -276,9 +290,7 @@
widget.tk.call('option', 'add', '*Listbox.foreground', color_scheme.editfieldforeground, 'interactive')
widget.tk.call('option', 'add', '*Entry.background', color_scheme.editfieldbackground, 'interactive')
widget.tk.call('option', 'add', '*Entry.foreground', color_scheme.editfieldforeground, 'interactive')
-
-# widget.tk.call('option', 'add', '*highlightThickness', '0', 'interactive')
-
+
widget.tk.call('option', 'add', '*tooltips*background', '#F6F6B9', 'interactive')
widget.tk.call('option', 'add', '*tooltips.background', '#C2C24E', 'interactive')
@@ -286,19 +298,15 @@
widget.tk.call('option', 'add', '*Menu*background', color_scheme.menubackground, 'interactive')
widget.tk.call('option', 'add', '*Menu.highlightColor', color_scheme.menubordercolor, 'interactive')
-#*Menu.highlightBackground: blue
-#*tooltips*background: #F6F6B9
-#*tooltips.background: black
-
#module self testing
if __name__ == '__main__':
- fonts=get_gtk_fonts()
+ fonts = get_gtk_fonts()
for item in fonts:
print tkfont_from_list(item)
- print tkfont_from_list(['San\ Serif', ['bold','italic'], 10])
- scheme=ColorScheme()
+ print tkfont_from_list(['San\ Serif', ['bold', 'italic'], 10])
+ scheme = ColorScheme()
print scheme.bg
print scheme.foreground
print scheme.selectbackground
- print scheme.selectforeground
\ No newline at end of file
+ print scheme.selectforeground
More information about the Skencil-commits
mailing list