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

Source Code for Package screenlets.options

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