[Skencil-commits] r793 - skencil/branches/skencil-0.6/src/Sketch/Base

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 22 19:31:08 CET 2010


Author: igor_n
Date: 2010-12-22 19:31:08 +0100 (Wed, 22 Dec 2010)
New Revision: 793

Modified:
   skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py
Log:
long string refactoring

Modified: skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py
===================================================================
--- skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py	2010-11-26 13:57:15 UTC (rev 792)
+++ skencil/branches/skencil-0.6/src/Sketch/Base/gtkutils.py	2010-12-22 18:31:08 UTC (rev 793)
@@ -40,7 +40,8 @@
     
     try:
         tmpfile = NamedTemporaryFile()
-        command = "import gtk;w = gtk.Window();w.realize();style=w.get_style(); print style.font_desc.to_string();"
+        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)):
             raise Exception
         
@@ -58,7 +59,7 @@
         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]
     
@@ -111,14 +112,16 @@
     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):
     """
@@ -269,48 +272,58 @@
         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.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.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)
+        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)
-                
-    widget.tk.call('option', 'add', '*background', color_scheme.bg, 'interactive')
-    widget.tk.call('option', 'add', '*foreground', color_scheme.fg, 'interactive')
-    widget.tk.call('option', 'add', '*selectForeground', color_scheme.selectforeground, 'interactive')
-    widget.tk.call('option', 'add', '*selectBackground', color_scheme.selectbackground, 'interactive')
-    widget.tk.call('option', 'add', '*highlightBackground', color_scheme.highlightbackground, 'interactive')
-    widget.tk.call('option', 'add', '*highlightColor', color_scheme.highlightcolor, 'interactive')
-    widget.tk.call('option', 'add', '*activeBackground', color_scheme.bg, 'interactive')
-    widget.tk.call('option', 'add', '*activeForeground', color_scheme.fg, 'interactive')
-    widget.tk.call('option', 'add', '*Menu.activeBackground', color_scheme.selectbackground, 'interactive')
-    widget.tk.call('option', 'add', '*Menu.activeForeground', color_scheme.selectforeground, 'interactive')
     
-    widget.tk.call('option', 'add', '*Listbox.background', color_scheme.editfieldbackground, 'interactive')
-    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', '*tooltips*background', '#F6F6B9', 'interactive')  
-    widget.tk.call('option', 'add', '*tooltips.background', '#C2C24E', 'interactive')
+    cs = color_scheme
     
-    widget.tk.call('option', 'add', '*Menu.background', color_scheme.menubackground, 'interactive')
-    widget.tk.call('option', 'add', '*Menu*background', color_scheme.menubackground, 'interactive')
-    widget.tk.call('option', 'add', '*Menu.highlightColor', color_scheme.menubordercolor, 'interactive')
+    options = [
+        ('*background', cs.bg),
+        ('*foreground', cs.fg),
+        ('*selectForeground', cs.selectforeground),
+        ('*selectBackground', cs.selectbackground),
+        ('*highlightBackground', cs.highlightbackground),
+        ('*highlightColor', cs.highlightcolor),
+        ('*activeBackground', cs.bg),
+        ('*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),
+        ]
     
-    widget.tk.call('option', 'add', '*canvas_frame.highlightColor', color_scheme.normal_border, 'interactive')
-    widget.tk.call('option', 'add', '*canvas_frame.highlightBackground', color_scheme.normal_border, 'interactive')
-     
-    widget.tk.call('option', 'add', '*Darkline.background', color_scheme.d3_dark, 'interactive')
-    widget.tk.call('option', 'add', '*Lightline.background', color_scheme.d3_light, 'interactive')
+    for key, value in options:
+        widget.tk.call('option', 'add', key, value, 'interactive')
    
 #module self testing
 if __name__ == '__main__':



More information about the Skencil-commits mailing list