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

Source Code for Module screenlets.options.string_option

 1  #  
 2  # Copyright (C) 2009 Martin Owens (DoctorMO) <doctormo@gmail.com> 
 3  # Changed by Guido Tabbernuk 2011 
 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, write to the Free Software 
17  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18  #  
19  """ 
20  String options, these classes will display a text box. 
21  """ 
22   
23  import gtk 
24   
25  from screenlets.options import _ 
26  from base import Option 
27   
28 -class StringOption(Option):
29 """An Option for string options.""" 30 choices = None 31 password = False 32
33 - def on_import(self, strvalue):
34 """When a string is imported from the config.""" 35 return strvalue.replace("\\n", "\n")
36
37 - def on_export(self, value):
38 """When a string is exported to the config.""" 39 return str(value).replace("\n", "\\n")
40
41 - def generate_widget(self, value):
42 """Generate a textbox for a string options""" 43 if self.choices: 44 # if a list of values is defined, show combobox 45 self.widget = gtk.combo_box_new_text() 46 p = -1 47 i = 0 48 for s in self.choices: 49 self.widget.append_text(s) 50 if s==value: 51 p = i 52 i+=1 53 self.widget.set_active(p) 54 else: 55 self.widget = gtk.Entry() 56 # if it is a password, set text to be invisible 57 if self.password: 58 self.widget.set_visibility(False) 59 60 self.set_value(value) 61 self.widget.connect("changed", self.has_changed) 62 #self.widget.set_size_request(180, 28) 63 return self.widget
64
65 - def set_value(self, value):
66 """Set the string value as required.""" 67 self.value = value 68 if self.choices: 69 # TODO self.widget.set_active(p) 70 pass 71 else: 72 self.widget.set_text(value)
73
74 - def has_changed(self, widget):
75 """Executed when the widget event kicks off.""" 76 if self.choices: 77 self.set_value( widget.get_active_text() ) 78 else: 79 self.set_value( widget.get_text() ) 80 super(StringOption, self).has_changed()
81