Package screenlets :: Package options
[hide private]
[frames] | no frames]

Source Code for Package screenlets.options

  1  # This application is released under the GNU General Public License 
  2  # v3 (or, at your option, any later version). You can find the full 
  3  # text of the license under http://www.gnu.org/licenses/gpl.txt. 
  4  # By using, editing and/or distributing this software you agree to 
  5  # the terms and conditions of this license. 
  6  # Thank you for using free software! 
  7   
  8  # Options-system (c) RYX (aka Rico Pfaus) 2007 <ryx@ryxperience.com> 
  9  # Heavily Refactored by Martin Owens (c) 2009 
 10  # 
 11  # INFO: 
 12  # - a dynamic Options-system that allows very easy creation of 
 13  #   objects with embedded configuration-system. 
 14  #   NOTE: The Dialog is not very nice yet - it is not good OOP-practice 
 15  #   because too big functions and bad class-layout ... but it works 
 16  #   for now ... :) 
 17  # 
 18  # TODO: 
 19  # - option-widgets for all option-types (e.g. ListOptionWidget, ColorOptionWidget) 
 20  # - OptionGroup-class instead of (or behind) add_options_group 
 21  # - TimeOption, DateOption 
 22  # - FileOption needs filter/limit-attribute 
 23  # - allow options to disable/enable other options 
 24  # - support for EditableOptions-subclasses as options 
 25  # - separate OptionEditorWidget from Editor-Dialog 
 26  # - place ui-code into screenlets.options.ui-module 
 27  # - create own widgets for each Option-subclass 
 28  # 
 29   
 30  import screenlets 
 31   
 32  import os 
 33  import gtk, gobject 
 34   
 35  # translation stuff 
 36  import gettext 
 37  gettext.textdomain('screenlets') 
 38  gettext.bindtextdomain('screenlets', screenlets.INSTALL_PREFIX +  '/share/locale') 
 39   
40 -def _(s):
41 return gettext.gettext(s)
42 43 from boolean_option import BoolOption 44 from string_option import StringOption 45 from number_option import IntOption, FloatOption 46 from list_option import ListOption 47 from account_option import AccountOption 48 from font_option import FontOption 49 from file_option import FileOption, DirectoryOption, ImageOption 50 from colour_option import ColorOption, ColorsOption 51 from time_option import TimeOption 52 from base import EditableOptions, OptionsDialog, create_option_from_node 53 54 # ------ ONLY FOR TESTING ------------------: 55 if __name__ == "__main__": 56 57 import os 58 59 # this is only for testing - should be a Screenlet
60 - class TestObject (EditableOptions):
61 62 testlist = ['test1', 'test2', 3, 5, 'Noch ein Test'] 63 pop3_account = ('Username', '') 64 65 # TEST 66 pin_x = 100 67 pin_y = 6 68 text_x = 19 69 text_y = 35 70 font_name = 'Sans 12' 71 rgba_color = (0.0, 0.0, 1.0, 1.0) 72 text_prefix = '<b>' 73 text_suffix = '</b>' 74 note_text = "" # hidden option because val has its own editing-dialog 75 random_pin_pos = True 76 opt1 = 'testval 1' 77 opt2 = 'testval 2' 78 filename2 = '' 79 filename = '' 80 dirname = '' 81 font = 'Sans 12' 82 color = (0.1, 0.5, 0.9, 0.9) 83 name = 'a name' 84 name2 = 'another name' 85 combo_test = 'el2' 86 flt = 0.5 87 x = 10 88 y = 25 89 width = 30 90 height = 50 91 is_sticky = False 92 is_widget = False 93 time = (12, 32, 49) # a time-value (tuple with ints) 94
95 - def __init__ (self):
96 EditableOptions.__init__(self) 97 # Add group 98 self.add_options_group('General', 99 'The general options for this Object ...') 100 self.add_options_group('Window', 101 'The Window-related options for this Object ...') 102 self.add_options_group('Test', 'A Test-group ...') 103 # Add editable options 104 self.add_option(ListOption('Test', 'testlist', default=self.testlist, 105 label='ListOption-Test', desc='Testing a ListOption-type ...')) 106 self.add_option(StringOption('Window', 'name', default='TESTNAME', 107 label='Testname', desc='The name/id of this Screenlet-instance ...'), 108 realtime=False) 109 self.add_option(AccountOption('Test', 'pop3_account', 110 default=self.pop3_account, label='Username/Password', 111 desc='Enter username/password here ...')) 112 self.add_option(StringOption('Window', 'name2', default='TESTNAME2', 113 label='String2', desc='Another string-test ...')) 114 self.add_option(StringOption('Test', 'combo_test', default="el1", 115 label='Combo', desc='A StringOption for a drop-down-list.', 116 choices=['el1', 'el2', 'element 3'])) 117 self.add_option(FloatOption('General', 'flt', default=30.4, 118 label='A Float', desc='Testing a FLOAT-type ...', 119 min=0, max=gtk.gdk.screen_width(), increment=0.01, digits=4)) 120 self.add_option(IntOption('General', 'x', default=30, 121 label='X-Position', desc='The X-position of this Screenlet ...', 122 min=0, max=gtk.gdk.screen_width())) 123 self.add_option(IntOption('General', 'y', default=30, 124 label='Y-Position', desc='The Y-position of this Screenlet ...', 125 min=0, max=gtk.gdk.screen_height())) 126 self.add_option(IntOption('Test', 'width', default=300, 127 label='Width', desc='The width of this Screenlet ...', 128 min=100, max=1000, increment=12)) 129 self.add_option(IntOption('Test', 'height', default=150, 130 label='Height', desc='The height of this Screenlet ...', 131 min=100, max=1000)) 132 self.add_option(BoolOption('General', 'is_sticky', default=True, 133 label='Stick to Desktop', desc='Show this Screenlet always ...')) 134 self.add_option(BoolOption('General', 'is_widget', default=False, 135 label='Treat as Widget', desc='Treat this Screenlet as a "Widget" ...')) 136 self.add_option(FontOption('Test', 'font', default='Sans 14', 137 label='Font', desc='The font for whatever ...')) 138 self.add_option(ColorOption('Test', 'color', default=(1, 0.35, 0.35, 0.7), 139 label='Color', desc='The color for whatever ...')) 140 self.add_option(ColorsOption('Test', 'rainbows', default=[(1, 0.35, 0.35, 0.7), (0.1, 0.8, 0.2, 0.2), (1, 0.35, 0.6, 0.7)], 141 label='Multi-Colours', desc='The colors for whatever ...')) 142 self.add_option(ColorsOption('Test', 'rainbow2', default=(1, 0.35, 0.35, 0.7), 143 label='Colours-Up', desc='The colors for whatever ...')) 144 self.add_option(FileOption('Test', 'filename', default=os.environ['HOME'], 145 label='Filename-Test', desc='Testing a FileOption-type ...', 146 patterns=[ ( 'Python Files', ['*.py', '*.pyc'] ) ])) 147 self.add_option(ImageOption('Test', 'filename2', default=os.environ['HOME'], 148 label='Image-Test', desc='Testing the ImageOption-type ...')) 149 self.add_option(DirectoryOption('Test', 'dirname', default=os.environ['HOME'], 150 label='Directory-Test', desc='Testing a FileOption-type ...')) 151 self.add_option(TimeOption('Test','time', default=self.time, 152 label='TimeOption-Test', desc='Testing a TimeOption-type ...')) 153 # TEST 154 self.disable_option('width') 155 self.disable_option('height')
156 # TEST: load options from file 157 #self.add_options_from_file('/home/ryx/Desktop/python/screenlets/screenlets-0.0.9/src/share/screenlets/Notes/options.xml') 158
159 - def __setattr__(self, name, value):
160 self.__dict__[name] = value 161 print name + "=" + str(value)
162
163 - def get_short_name(self):
164 return self.__class__.__name__[:-6]
165 166 167 # this is only for testing - should be a Screenlet
168 - class TestChildObject (TestObject):
169 170 uses_theme = True 171 theme_name = 'test' 172
173 - def __init__ (self):
174 TestObject.__init__(self) 175 self.add_option(StringOption('Test', 'anothertest', default='ksjhsjgd', 176 label='Another Test', desc='An attribute in the subclass ...')) 177 self.add_option(StringOption('Test', 'theme_name', default=self.theme_name, 178 label='Theme', desc='The theme for this Screenelt ...', 179 choices=['test1', 'test2', 'mytheme', 'blue', 'test']))
180 181 # TEST: load/save 182 # TEST: option-editing 183 to = TestChildObject() 184 #print to.export_options_as_list() 185 se = OptionsDialog(500, 380)#, treeview=True) 186 #img = gtk.image_new_from_stock(gtk.STOCK_ABOUT, 5) 187 img = gtk.Image() 188 img.set_from_file('../share/screenlets/Notes/icon.svg') 189 se.set_info('TestOptions', 190 'A test for an extended options-dialog with embedded about-info.' + 191 ' Can be used for the Screenlets to have all in one ...\nNOTE:' + 192 '<span color="red"> ONLY A TEST!</span>', 193 '(c) RYX 2007', version='v0.0.1', icon=img) 194 se.show_options_for_object(to) 195 resp = se.run() 196 if resp == gtk.RESPONSE_OK: 197 print "OK" 198 else: 199 print "Cancelled." 200 se.destroy() 201 print to.export_options_as_list() 202