Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes
optionwidgets.Option Class Reference
Inheritance diagram for optionwidgets.Option:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def enable
def disable
def is_enabled
def get_current_value
def is_changed
def writeback
def checkConflicts
def on_change
def on_btnConflict_clicked

Public Attributes

 option
 ppd
 gui
 enabled
 tab_label
 btnConflict
 conflictIcon
 constraints
 conflicts
 conflict_message

Detailed Description

Definition at line 45 of file optionwidgets.py.


Constructor & Destructor Documentation

def optionwidgets.Option.__init__ (   self,
  option,
  ppd,
  gui,
  tab_label = None 
)

Reimplemented in optionwidgets.OptionPickMany, optionwidgets.OptionPickOne, and optionwidgets.OptionBool.

Definition at line 46 of file optionwidgets.py.

00046 
00047     def __init__(self, option, ppd, gui, tab_label=None):
00048         self.option = option
00049         self.ppd = ppd
00050         self.gui = gui
00051         self.enabled = True
00052         self.tab_label = tab_label
00053 
00054         vbox = gtk.VBox()
00055         
00056         self.btnConflict = gtk.Button()
00057         icon = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING,
00058                                         gtk.ICON_SIZE_SMALL_TOOLBAR)
00059         self.btnConflict.add(icon)
00060         self.btnConflict.set_no_show_all(True) #avoid the button taking
00061                                                # over control again
00062         vbox.add(self.btnConflict)    # vbox reserves space while button
00063         #vbox.set_size_request(32, 28) # is hidden
00064         self.conflictIcon = vbox
00065 
00066         self.btnConflict.connect("clicked", self.on_btnConflict_clicked)
00067         icon.show()
00068 
00069         self.constraints = [c for c in ppd.constraints
00070                             if (c.option1 == option.keyword or
00071                                 c.option2 == option.keyword)]
00072         #for c in self.constraints:
00073         #    if not c.choice1 or not c.choice2:
00074         #        print c.option1, repr(c.choice1), c.option2, repr(c.choice2)
00075         self.conflicts = set()
00076         self.conflict_message = ""


Member Function Documentation

def optionwidgets.Option.checkConflicts (   self,
  update_others = True 
)

Definition at line 98 of file optionwidgets.py.

00098 
00099     def checkConflicts(self, update_others=True):
00100         value = self.get_current_value()
00101         for constraint in self.constraints:
00102             if constraint.option1 == self.option.keyword:
00103                 option2 = self.gui.options.get(constraint.option2, None)
00104                 choice1 = constraint.choice1
00105                 choice2 = constraint.choice2
00106             else:
00107                 option2 = self.gui.options.get(constraint.option1, None)
00108                 choice1 = constraint.choice2
00109                 choice2 = constraint.choice1
00110 
00111             if option2 is None: continue
00112 
00113             def matches (constraint_choice, value):
00114                 if constraint_choice != '':
00115                     return constraint_choice == value
00116                 return value not in ['None', 'False', 'Off']
00117 
00118             if (matches (choice1, value) and
00119                 matches (choice2, option2.get_current_value())):
00120                 # conflict
00121                 self.conflicts.add(constraint)
00122                 if update_others:
00123                     option2.checkConflicts(update_others=False)
00124             elif constraint in self.conflicts:
00125                 # remove conflict
00126                 self.conflicts.remove(constraint)
00127                 option2.checkConflicts(update_others=False)
00128 
00129 
00130         tooltip = [_("Conflicts with:")]
00131         conflicting_options = dict()
00132         for c in self.conflicts:
00133             if c.option1 == self.option.keyword:
00134                 option = self.gui.options.get(c.option2)
00135             else:
00136                 option = self.gui.options.get(c.option1)
00137 
00138             conflicting_options[option.option.keyword] = option
00139 
00140         for option in conflicting_options.values ():
00141             opt = option.option.text
00142             val = option.get_current_value ()
00143             for choice in option.option.choices:
00144                 if choice['choice'] == val:
00145                     val = ppdippstr.ppd.get (choice['text'])
00146 
00147             tooltip.append ("%s: %s" % (opt, val))
00148             
00149         tooltip = "\n".join(tooltip)
00150 
00151         self.conflict_message = tooltip # XXX more verbose
00152             
00153         if self.conflicts:
00154             self.btnConflict.set_tooltip_text (tooltip)
00155             self.btnConflict.show()
00156         else:
00157             self.btnConflict.hide()
00158 
00159         self.gui.option_changed(self)
00160         return self.conflicts
            

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 81 of file optionwidgets.py.

00081 
00082     def disable(self):
00083         self.enable (False)

Here is the call graph for this function:

def optionwidgets.Option.enable (   self,
  enabled = True 
)

Definition at line 77 of file optionwidgets.py.

00077 
00078     def enable(self, enabled=True):
00079         self.selector.set_sensitive (enabled)
00080         self.enabled = enabled

Here is the caller graph for this function:

Reimplemented in optionwidgets.OptionPickOne, and optionwidgets.OptionBool.

Definition at line 87 of file optionwidgets.py.

00087 
00088     def get_current_value(self):
00089         raise NotImplemented

Here is the caller graph for this function:

Definition at line 90 of file optionwidgets.py.

00090 
00091     def is_changed(self):
00092         return self.get_current_value()!= self.option.defchoice
    

Here is the call graph for this function:

Definition at line 84 of file optionwidgets.py.

00084 
00085     def is_enabled(self):
00086         return self.enabled

def optionwidgets.Option.on_btnConflict_clicked (   self,
  button 
)

Definition at line 164 of file optionwidgets.py.

00164 
00165     def on_btnConflict_clicked(self, button):
00166         parent = self.btnConflict
00167         while parent != None and not isinstance (parent, gtk.Window):
00168             parent = parent.get_parent ()
00169 
00170         dialog = gtk.MessageDialog (parent,
00171                                     gtk.DIALOG_DESTROY_WITH_PARENT |
00172                                     gtk.DIALOG_MODAL,
00173                                     gtk.MESSAGE_WARNING,
00174                                     gtk.BUTTONS_CLOSE,
00175                                     self.conflict_message)
00176         dialog.run()
00177         dialog.destroy()
00178         
00179 # ---------------------------------------------------------------------------

def optionwidgets.Option.on_change (   self,
  widget 
)

Definition at line 161 of file optionwidgets.py.

00161 
00162     def on_change(self, widget):
00163         self.checkConflicts()

Here is the call graph for this function:

Definition at line 93 of file optionwidgets.py.

00093 
00094     def writeback(self):
00095         #print repr(self.option.keyword), repr(self.get_current_value())
00096         if self.enabled:
00097             self.ppd.markOption(self.option.keyword, self.get_current_value())

Here is the call graph for this function:


Member Data Documentation

Definition at line 55 of file optionwidgets.py.

Definition at line 75 of file optionwidgets.py.

Definition at line 63 of file optionwidgets.py.

Definition at line 74 of file optionwidgets.py.

Definition at line 68 of file optionwidgets.py.

Definition at line 50 of file optionwidgets.py.

Definition at line 49 of file optionwidgets.py.

Definition at line 47 of file optionwidgets.py.

Definition at line 48 of file optionwidgets.py.

Definition at line 51 of file optionwidgets.py.


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