def __init__(self, model, prop_name, prop_read=None, prop_write=None, value_error=None, spurious=False, prop_cast=True): """ Creates a new adapter that handles setting of value of a model single model property when a corresponding widgets set is changed and viceversa when the property is also observable. This class handles only assignments to properties. For other kinds of setting (e.g. user-defined classes used as observable properties, containers, etc.) use other types of Adapters derived from this class. prop_name is the model's property name (as a string). It is possible to use a dotted notation to identify a property contained into a hierarchy of models. For example 'a.b.c' identifies property 'c' into model 'b' inside model 'a', where model 'a' is an attribute of given top level model. Last name must be an observable or non-observable attribute, and previous names (if specified) must all refer to instances of class Model. First name from the left must be the name of a model instance inside the given model. prop_{write,read} are two optional functions that apply custom modifications to the value of the property before setting and reading it. Both take a value and must return a transformed value whose type must be compatible with the type of the property. value_error can be a function (or a method) to be called when a ValueError exception occurs while trying to set a wrong value for the property inside the model. The function will receive: the adapter, the property name and the value coming from the widget that offended the model. spurious controls if the adapter should receive spurious changes from the model (see spuriousness in class Observer for further information). """ # registration is delayed, as we need to create possible # listener before: Observer.__init__(self, spurious=spurious) self._prop_name = prop_name self._prop_cast = prop_cast self._prop_read = prop_read self._prop_write = prop_write self._value_error = value_error self._wid = None self._wid_info = {} # this flag is set when self is changing the property or the # widget, in order to avoid infinite looping. self._itsme = False self._connect_model(model) return
def __init__(self, graphical_editor_v, state_machine_m, *args): GtkView.__init__(self, *args) Observer.__init__(self) self._selection = state_machine_m.selection self.value_cache = ValueCache() self.observe_model(self._selection) self.observe_model(state_machine_m.root_state) self._bounding_box_painter = BoundingBoxPainter(self) self._graphical_editor = ref(graphical_editor_v)
def __init__(self, model, view=None, spurious=False, auto_adapt=False): Observer.__init__(self, model, spurious) self.model = model self.view = None self.__adapters = [] # set of properties explicitly adapted by the user: self.__user_props = set() self.__auto_adapt = auto_adapt if view: gobject.idle_add(self._idle_register_view, view, priority=gobject.PRIORITY_HIGH) return
def __init__(self, model, view, spurious=False, auto_adapt=False): """ Two positional and two optional keyword arguments. *model* will have the new instance registered as an observer. It is made available as an attribute. *view* may contain signal connections loaded from XML. The handler methods have to exist in this class. *spurious* denotes whether notifications in this class will be called if a property of *model* is set to the same value it already has. *auto_adapt* denotes whether to call :meth:`adapt` with no arguments as part of the view registration process. View registration consists of connecting signal handlers, :meth:`register_view` and :meth:`register_adapters`, and is scheduled with the GTK main loop. It happens as soon as possible but after the constructor returns. When it starts *view* is available as an attribute. """ # In 1.99.0 the third parameter was optional. Now the interpreter will # raise if it isn't given. if view in (True, False): raise NotImplementedError("This version of GTKMVC does not" " support the 1.2 API") Observer.__init__(self, model, spurious) self.model = model self.view = None self.__adapters = [] # set of properties explicitly adapted by the user: self.__user_props = set() self.__auto_adapt = auto_adapt gobject.idle_add(self._idle_register_view, view, priority=gobject.PRIORITY_HIGH) return