Home | Trees | Indices | Help |
|
---|
|
1 # 2 # Copyright (C) 2009 Martin Owens (DoctorMO) <doctormo@gmail.com> 3 # 4 # This program is free software; you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation; either version 3 of the License, or 7 # (at your option) any later version. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program; if not, write to the Free Software 16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 # 18 """ 19 Color options, these classes will display a text box. 20 """ 21 22 import gtk 23 24 from screenlets.options import _ 25 from base import Option 2628 """An Option for color options."""89 9030 """Import (r, g, b, a) from comma-separated string.""" 31 # strip braces and spaces 32 strvalue = strvalue.lstrip('(') 33 strvalue = strvalue.rstrip(')') 34 strvalue = strvalue.strip() 35 # split value on commas 36 tmpval = strvalue.split(',') 37 outval = [] 38 for f in tmpval: 39 # create list and again remove spaces 40 outval.append(float(f.strip())) 41 return outval4244 """Export r, g, b, a to comma-separated string.""" 45 l = len(value) 46 outval = '' 47 for i in xrange(l): 48 if type(value[i]) == float: 49 outval += "%0.5f" % value[i] 50 else: 51 outval += str(value[i]) 52 if i < l-1: 53 outval += ',' 54 return outval5557 """Generate a textbox for a color options""" 58 self.widget = self.get_box_from_colour( value ) 59 self.set_value(value) 60 return self.widget61 6567 """Executed when the widget event kicks off.""" 68 self.value = self.get_colour_from_box(self.widget) 69 super(ColorOption, self).has_changed()7072 """Turn a colour array into a colour widget""" 73 result = gtk.ColorButton(gtk.gdk.Color( 74 int(colour[0]*65535), int(colour[1]*65535), int(colour[2]*65535))) 75 result.set_use_alpha(True) 76 result.set_alpha(int(colour[3]*65535)) 77 result.connect("color-set", self.has_changed) 78 return result7992 """Allow a list of colours to be created"""14994 """Importing multiple colours""" 95 result = [] 96 for col in value.split(';'): 97 if col: 98 result.append(super(ColorsOption, self).on_import(col)) 99 return result100102 """Exporting multiple colours""" 103 result = "" 104 for col in value: 105 result += super(ColorsOption, self).on_export(col)+';' 106 return result107109 """Generate a textbox for a color options""" 110 self.widget = gtk.HBox() 111 if type(value[0]) in [int, float]: 112 value = [value] 113 for col in value: 114 self.add_colour_box(self.widget, col, False) 115 116 but = gtk.Button('Add', gtk.STOCK_ADD) 117 but.show() 118 but.connect("clicked", self.add_colour_box) 119 self.widget.pack_end(but) 120 121 self.set_value(value) 122 return self.widget123125 """Remove a colour box from the array when right clicked""" 126 if event.button == 3: 127 if len(self.widget.get_children()) > 2: 128 self.widget.remove(widget) 129 self.has_changed(widget)130132 """Add a new box for colours""" 133 if not col: 134 col = self.value[-1] 135 new_box = self.get_box_from_colour( col ) 136 new_box.connect("button_press_event", self.del_colour_box) 137 self.widget.pack_start(new_box, padding=1) 138 new_box.show() 139 if update: 140 self.has_changed(widget)141143 """The colour widgets have changed!""" 144 self.value = [] 145 for c in self.widget.get_children(): 146 if type(c) == gtk.ColorButton: 147 self.value.append(self.get_colour_from_box( c )) 148 super(ColorOption, self).has_changed()
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Jun 6 10:56:41 2011 | http://epydoc.sourceforge.net |