Exemple #1
0
    def __init__(self, model, prop_name,
                 prop_read=None, prop_write=None, value_error=None):

        UserClassAdapter.__init__(self, model, prop_name,
                                  lambda c,i: c.__getitem__(i),
                                  lambda c,v,i: c.__setitem__(i,v),
                                  prop_read, prop_write, 
                                  value_error)

        prop =  Adapter._get_property(self)
        #prop =  self._get_property() # bug fix reported by A. Dentella
        if not (hasattr(prop, "__getitem__") and
                hasattr(prop, "__setitem__")):
            raise TypeError("Property " + self._prop_name +
                            " is not a valid container")


        self._prop_is_map = isinstance(prop, types.DictType) or \
                            isinstance(prop, ObsMapWrapper)
        # contained widgets
        self._idx2wid = {}
        self._wid2idx = {}
        
        self._widgets = None
        return
Exemple #2
0
    def connect_widget(self, wid, getters=None, setters=None,
                       signals=None, arg=None):
        """
        Called when the widget is instantiated, and the adapter is
        ready to connect the widgets inside it (if a container) or
        each widget if wid is a list of widgets. getters and setters
        can be None, a function or a list or a map of
        functions. signals can be None, a signal name, or a list or
        a map of signal names. When maps are used, keys can be
        widgets or widget names. The length of the possible lists or
        maps must be lesser or equal to the number of widgets that
        will be connected.
        """

        if isinstance(wid, gtk.Container): self._widgets = wid.get_children()
        elif isinstance(wid, types.ListType) or isinstance(wid, types.TupleType): self._widgets = wid
        else: raise TypeError("widget must be either a gtk.Container or a list or tuple")

        # prepares the mappings:
        for idx, w in enumerate(self._widgets):
            if self._prop_is_map: idx=w.get_name()
            self._idx2wid[idx] = w
            self._wid2idx[w] = idx
            pass

        # prepares the lists for signals
        getters = self.__handle_par("getters", getters)
        setters = self.__handle_par("setters", setters)
        signals = self.__handle_par("signals", signals)
        
        for wi,ge,se,si in zip(self._widgets, getters, setters, signals):
            if type(ge) == types.MethodType: ge = ge.im_func
            if type(se) == types.MethodType: se = se.im_func
            UserClassAdapter.connect_widget(self, wi, ge, se, si, arg, False)
            pass

        self.update_widget()
        self._wid = wid
        return
Exemple #3
0
 def _write_widget(self, val, idx):
     sav = self._wid
     self._wid = self._get_widget_from_idx(idx)
     UserClassAdapter._write_widget(self, val)
     self._wid = sav
     return
Exemple #4
0
 def _read_widget(self, idx):
     sav = self._wid
     self._wid = self._get_widget_from_idx(idx)
     val = UserClassAdapter._read_widget(self)
     self._wid = sav
     return val