Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes | Static Public Attributes
options.OptionAlwaysShown Class Reference
Inheritance diagram for options.OptionAlwaysShown:
Inheritance graph
[legend]
Collaboration diagram for options.OptionAlwaysShown:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_default
def set_default
def reinit
def set_widget_value
def get_widget_value
def get_current_value
def is_changed
def reset
def changed

Public Attributes

 name
 widget
 button
 ipp_type
 combobox_map
 combobox_dict
 use_supported
 system_default
 original_value
 state

Static Public Attributes

int STATE_UNCHANGED = 0
int STATE_RESET = 1
int STATE_ADJUSTED = 2

Detailed Description

Definition at line 118 of file options.py.


Constructor & Destructor Documentation

def options.OptionAlwaysShown.__init__ (   self,
  name,
  ipp_type,
  system_default,
  widget,
  button,
  combobox_map = None,
  use_supported = False 
)

Definition at line 125 of file options.py.

00125 
00126                  widget, button, combobox_map = None, use_supported = False):
00127         self.name = name
00128         self.widget = widget
00129         self.button = button
00130         if ipp_type == bool:
00131             def bool_type (x):
00132                 if type (x) == str:
00133                     if x.lower () in ("false", "no", "off"):
00134                         return False
00135                     # Even the empty string is true.
00136                     return True
00137                 return bool (x)
00138             ipp_type = bool_type
00139         self.ipp_type = ipp_type
00140         self.set_default (system_default)
00141         self.combobox_map = combobox_map
00142 
00143         if (type(self.widget) == gtk.ComboBox and
00144             self.widget.get_model () == None):
00145             print "No ComboBox model for %s" % self.name
00146             model = gtk.ListStore (gobject.TYPE_STRING)
00147             self.widget.set_model (model)
00148 
00149         if combobox_map != None and ipp_type == int:
00150             model = self.widget.get_model ()
00151             i = 0
00152             dict = {}
00153             iter = model.get_iter_first ()
00154             while iter:
00155                 dict[combobox_map[i]] = model.get_value (iter, 0)
00156                 i += 1
00157                 iter = model.iter_next (iter)
00158             self.combobox_dict = dict
00159         self.use_supported = use_supported
00160         self.reinit (None)


Member Function Documentation

Reimplemented in options.OptionAlwaysShownSpecial.

Definition at line 302 of file options.py.

00302 
00303     def changed(self):
00304         self.state = self.STATE_ADJUSTED
00305         self.button.set_sensitive (True)

Reimplemented from options.OptionInterface.

Definition at line 272 of file options.py.

00272 
00273     def get_current_value(self):
00274         return self.get_widget_value ()

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from options.OptionInterface.

Definition at line 161 of file options.py.

00161 
00162     def get_default(self):
00163         return self.system_default

Definition at line 246 of file options.py.

00246 
00247     def get_widget_value(self):
00248         t = type(self.widget)
00249         if t == gtk.SpinButton:
00250             # Ideally we would use self.widget.get_value() here, but
00251             # it doesn't work if the value has been typed in and then
00252             # the Apply button immediately clicked.  To handle this,
00253             # we use self.widget.get_text() and fall back to
00254             # get_value() if the result cannot be interpreted as the
00255             # type we expect.
00256             try:
00257                 return self.ipp_type (self.widget.get_text ())
00258             except ValueError:
00259                 # Can't convert result of get_text() to ipp_type.
00260                 return self.ipp_type (self.widget.get_value ())
00261         elif t == gtk.ComboBox:
00262             if self.combobox_map:
00263                 return self.combobox_map[self.widget.get_active()]
00264             if self.ipp_type == str or self.ipp_type == IPPResolution:
00265                 return self.widget.get_active_text ()
00266             return self.ipp_type (self.widget.get_active ())
00267         elif t == gtk.CheckButton:
00268             return self.ipp_type (self.widget.get_active ())
00269 
00270         print t
00271         raise NotImplemented

Here is the caller graph for this function:

Reimplemented from options.OptionInterface.

Definition at line 275 of file options.py.

00275 
00276     def is_changed(self):
00277         if self.original_value != None:
00278             # There was a value set previously.
00279             if self.state == self.STATE_RESET:
00280                 # It's been removed.
00281                 return True
00282             if self.state == self.STATE_ADJUSTED:
00283                 if self.get_current_value () != self.original_value:
00284                     return True
00285                 return False
00286 
00287             # The value is the same as before, and not reset.
00288             return False
00289 
00290         # There was no original value set.
00291         if self.state == self.STATE_ADJUSTED:
00292             # It's been adjusted.
00293             return True
00294 
00295         # It's been left alone, or possible adjusted and then reset.
00296         return False

Here is the call graph for this function:

def options.OptionAlwaysShown.reinit (   self,
  original_value,
  supported = None 
)
Set the original value of the option and the supported choices.
The special value None for original_value resets the option to the
system default.

Reimplemented in options.OptionAlwaysShownSpecial.

Definition at line 170 of file options.py.

00170 
00171     def reinit(self, original_value, supported=None):
00172         """Set the original value of the option and the supported choices.
00173         The special value None for original_value resets the option to the
00174         system default."""
00175         if (supported != None and
00176             self.use_supported):
00177             if (type(self.widget) == gtk.ComboBox and
00178                 (self.ipp_type == str or self.ipp_type == IPPResolution)):
00179                 model = self.widget.get_model ()
00180                 model.clear ()
00181                 translations = ppdippstr.job_options.get (self.name)
00182                 if translations:
00183                     self.combobox_map = []
00184                     self.combobox_dict = dict()
00185                     i = 0
00186 
00187                 for each in supported:
00188                     txt = each
00189                     if self.ipp_type != str:
00190                         txt = str (self.ipp_type (each))
00191 
00192                     if translations:
00193                         self.combobox_map.append (txt)
00194                         text = translations.get (txt)
00195                         self.combobox_dict[each] = text
00196                         i += 1
00197                     else:
00198                         text = txt
00199 
00200                     iter = model.append ()
00201                     model.set_value (iter, 0, text)
00202             elif (type(self.widget) == gtk.ComboBox and
00203                   self.ipp_type == int and
00204                   self.combobox_map != None):
00205                 model = self.widget.get_model ()
00206                 model.clear ()
00207                 for each in supported:
00208                     iter = model.append ()
00209                     model.set_value (iter, 0, self.combobox_dict[each])
00210 
00211         if original_value != None:
00212             self.original_value = self.ipp_type (original_value)
00213             self.set_widget_value (self.original_value)
00214             self.button.set_sensitive (True)
00215         else:
00216             self.original_value = None
00217             self.set_widget_value (self.system_default)
00218             self.button.set_sensitive (False)
00219         self.state = self.STATE_UNCHANGED

Reimplemented in options.OptionAlwaysShownSpecial.

Definition at line 297 of file options.py.

00297 
00298     def reset(self):
00299         self.set_widget_value (self.system_default)
00300         self.state = self.STATE_RESET
00301         self.button.set_sensitive (False)

Here is the call graph for this function:

def options.OptionAlwaysShown.set_default (   self,
  system_default 
)

Definition at line 164 of file options.py.

00164 
00165     def set_default(self, system_default):
00166         # For the media option, the system default depends on the printer's
00167         # PageSize setting.  This method allows the main module to tell us
00168         # what that is.
00169         self.system_default = self.ipp_type (system_default)

def options.OptionAlwaysShown.set_widget_value (   self,
  ipp_value 
)

Definition at line 220 of file options.py.

00220 
00221     def set_widget_value(self, ipp_value):
00222         t = type(self.widget)
00223         if t == gtk.SpinButton:
00224             return self.widget.set_value (ipp_value)
00225         elif t == gtk.ComboBox:
00226             if ((self.ipp_type == str or self.ipp_type == IPPResolution)
00227                 and self.combobox_map == None):
00228                 model = self.widget.get_model ()
00229                 iter = model.get_iter_first ()
00230                 while (iter != None and
00231                        self.ipp_type (model.get_value (iter, 0)) != ipp_value):
00232                     iter = model.iter_next (iter)
00233                 if iter:
00234                     self.widget.set_active_iter (iter)
00235             else:
00236                 # It's an int.
00237                 if self.combobox_map:
00238                     index = self.combobox_map.index (ipp_value)
00239                 else:
00240                     index = ipp_value
00241                 return self.widget.set_active (index)
00242         elif t == gtk.CheckButton:
00243             return self.widget.set_active (ipp_value)
00244         else:
00245             raise NotImplemented

Here is the caller graph for this function:


Member Data Documentation

Definition at line 128 of file options.py.

Definition at line 157 of file options.py.

Definition at line 140 of file options.py.

Definition at line 138 of file options.py.

Definition at line 126 of file options.py.

Definition at line 211 of file options.py.

Definition at line 218 of file options.py.

Definition at line 122 of file options.py.

Definition at line 121 of file options.py.

Definition at line 120 of file options.py.

Definition at line 168 of file options.py.

Definition at line 158 of file options.py.

Definition at line 127 of file options.py.


The documentation for this class was generated from the following file: