[Skencil-commits] r794 - skencil/branches/skencil-0.6/src/Sketch/Base
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Feb 6 20:02:23 CET 2011
Author: bh
Date: 2011-02-06 20:02:22 +0100 (Sun, 06 Feb 2011)
New Revision: 794
Modified:
skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py
Log:
Fix code formatting.
Modified: skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py 2010-12-22 18:31:08 UTC (rev 793)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py 2011-02-06 19:02:22 UTC (rev 794)
@@ -37,42 +37,44 @@
font_style - list of font styles like 'bold' and 'italic'
font_size - font size integer value
"""
-
+
try:
tmpfile = NamedTemporaryFile()
command = "import gtk;w = gtk.Window();w.realize();"
command += "style=w.get_style(); print style.font_desc.to_string();"
- if os.system('python -c "%s" >%s 2>/dev/null' % (command, tmpfile.name)):
+ if os.system('python -c "%s" >%s 2>/dev/null'
+ % (command, tmpfile.name)):
raise Exception
-
+
font = tmpfile.readline().strip()
-
+
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
if not 'bold' in large_font[1]:
large_font[1].append('bold')
-
+
fixed_font = copy.deepcopy(normal_font)
fixed_font[0] = 'monospace'
except:
- small_font = normal_font = large_font = fixed_font = ['helvetica', '', '9']
-
+ small_font = normal_font = large_font = fixed_font = \
+ ['helvetica', '', '9']
+
return [small_font, normal_font, large_font, fixed_font]
-
-
+
+
def process_gtk_font_string(font):
"""
Converts Gtk font string to font description list
So Gtk string like: San Serif Bold Italic 10
will be: ['San\ Serif', ['bold','italic'], 10]
- Such form is much better for constructing of
+ Such form is much better for constructing of
Tk font description.
"""
-
+
font_style = []
vals = font.split()
font_size = int(vals[-1])
@@ -90,6 +92,7 @@
"""
Constructs tk font string from font list.
"""
+ print "tkfont_from_list", repr(font_list)
return '%s %d ' % (font_list[0], font_list[2]) + string.join(font_list[1])
def set_ui_fonts(widget, font_list):
@@ -106,7 +109,7 @@
SYSTEM_SCHEME = 'System'
BUILTIN_SCHEME = 'Built-in'
-
+
def gtk_to_tk_color(color):
"""
Converts gtk color representation to tk.
@@ -125,18 +128,18 @@
def saturated_color(color):
"""
- Returns saturated color value.
+ 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)
-
+
def middle_color(dark, light, factor=0.5):
"""
Calcs middle color value.
-
+
dark, light - tk color strings
- factor - resulted color shift
+ factor - resulted color shift
"""
dark = tkcolor_to_rgb(dark)
light = tkcolor_to_rgb(light)
@@ -148,21 +151,22 @@
def lighter_color(color, factor):
"""
Calcs lighted color value according factor.
-
+
color - tk color strings
- factor - resulted color shift
+ factor - resulted color shift
"""
return middle_color(color, saturated_color(color), factor)
-
+
class ColorScheme:
+
"""
The class represents UI color scheme.
Colors can be imported from system (SYSTEM_SCHEME)
or built-in values (BUILTIN_SCHEME).
"""
-
+
bg = '#d4d0c8'
fg = '#000000'
highlightbackground = '#f3f2ef'
@@ -170,43 +174,43 @@
disabledforeground = '#b0ada6'
selectbackground = '#002468'
selectforeground = '#ffffff'
-
+
menubackground = '#dedad2'
menuforeground = '#000000'
menuselectbackground = '#002468'
menuselectforeground = '#ffffff'
menudisabledforeground = '#b0ada6'
menubordercolor = '#7e7b77'
-
+
editfieldbackground = '#ffffff'
editfieldforeground = '#000000'
treelinescolor = '#000000'
-
+
d3_light = '#ffffff'
d3_dark = '#b0ada6'
-
+
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:
- return
+ return
else:
self.name = SYSTEM_SCHEME
try:
self.import_gtk_colors()
except:
scheme == BUILTIN_SCHEME
-
+
def import_gtk_colors(self):
"""
- Imports system gtk color scheme using pygtk binding.
+ Imports system gtk color scheme using pygtk binding.
"""
colors = {}
tmpfile = NamedTemporaryFile()
@@ -231,10 +235,11 @@
" style.bg[gtk.STATE_PRELIGHT].to_string()," + \
" style.bg[gtk.STATE_SELECTED].to_string()," + \
" style.bg[gtk.STATE_INSENSITIVE].to_string();"
-
- if os.system('python -c "%s" >%s 2>/dev/null' % (command, tmpfile.name)):
- raise Exception
+ if os.system('python -c "%s" >%s 2>/dev/null'
+ % (command, tmpfile.name)):
+ raise Exception
+
for type in ["base", "text", "fg", "bg"]:
line = tmpfile.readline().strip().split()
colors[type + ' normal'] = gtk_to_tk_color(line[0])
@@ -243,54 +248,55 @@
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):
"""
Maps gtk colors to ColorScheme fields.
"""
-
+
self.bg = gtk_colors['bg normal']
self.fg = gtk_colors['text normal']
-
+
self.highlightbackground = gtk_colors['bg active']
self.highlightcolor = gtk_colors['fg active']
self.disabledforeground = gtk_colors['fg insensitive']
self.selectbackground = gtk_colors['bg selected']
self.selectforeground = gtk_colors['text selected']
-
+
self.menubackground = lighter_color(self.bg, .25)
self.menuforeground = gtk_colors['fg normal']
self.menuselectbackground = gtk_colors['bg selected']
self.menuselectforeground = gtk_colors['fg selected']
self.menudisabledforeground = gtk_colors['text insensitive']
self.menubordercolor = gtk_colors['fg insensitive']
-
+
self.editfieldbackground = gtk_colors['base normal']
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 = middle_color(gtk_colors['bg active'],
gtk_colors['fg insensitive'])
-
+
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):
"""
Applies ColorScheme object values to tk defaults.
- """
+ """
widget.tk.call('tk_setPalette', color_scheme.bg)
-
+
cs = color_scheme
-
+
options = [
('*background', cs.bg),
('*foreground', cs.fg),
@@ -302,32 +308,33 @@
('*activeForeground', cs.fg),
('*Menu.activeBackground', cs.selectbackground),
('*Menu.activeForeground', cs.selectforeground),
-
+
('*Listbox.background', cs.editfieldbackground),
('*Listbox.foreground', cs.editfieldforeground),
('*Entry.background', cs.editfieldbackground),
('*Entry.foreground', cs.editfieldforeground),
-
+
('*tooltips*background', '#F6F6B9'),
('*tooltips.background', '#C2C24E'),
-
+
('*Menu.background', cs.menubackground),
('*Menu*background', cs.menubackground),
('*Menu.highlightColor', cs.menubordercolor),
-
+
('*canvas_frame.highlightColor', cs.normal_border),
('*canvas_frame.highlightBackground', cs.normal_border),
-
+
('*Darkline.background', cs.d3_dark),
('*Lightline.background', cs.d3_light),
]
-
+
for key, value in options:
widget.tk.call('option', 'add', key, value, 'interactive')
-
+
+
#module self testing
if __name__ == '__main__':
-
+
fonts = get_gtk_fonts()
for item in fonts:
print tkfont_from_list(item)
More information about the Skencil-commits
mailing list