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, see <http://www.gnu.org/licenses/>. 
17  #  
18  """ 
19  String options, these classes will display a text box. 
20  """ 
21   
22  import gtk 
23   
24  from screenlets.options import _ 
25  from base import Option 
26   
27 -class StringOption(Option):
28 """An Option for string options.""" 29 choices = None 30 password = False 31
32 - def on_import(self, strvalue):
33 """When a string is imported from the config.""" 34 return strvalue.replace("\\n", "\n")
35
36 - def on_export(self, value):
37 """When a string is exported to the config.""" 38 return str(value).replace("\n", "\\n")
39
40 - def generate_widget(self, value):
41 """Generate a textbox for a string options""" 42 if self.choices: 43 # if a list of values is defined, show combobox 44 self.widget = gtk.combo_box_new_text() 45 p = -1 46 i = 0 47 for s in self.choices: 48 self.widget.append_text(s) 49 if s==value: 50 p = i 51 i+=1 52 self.widget.set_active(p) 53 else: 54 self.widget = gtk.Entry() 55 # if it is a password, set text to be invisible 56 if self.password: 57 self.widget.set_visibility(False) 58 59 self.set_value(value) 60 if self.realtime: 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( self.widget.get_active_text() ) 78 else: 79 self.set_value( self.widget.get_text() ) 80 super(StringOption, self).has_changed()
81