def __init__(self, model, prop_name, prop_read=None, prop_write=None, value_error=None, spurious=False, prop_cast=True): """ Observe one property of one model instance for assignment (and nothing else). After you :meth:`connect_widget` those changes will be propagated to that widget, and vice versa. *prop_name* is a string. It may contain dots and will be resolved using Python attribute access on *model*. All objects traversed must be :class:`Model` instances. The last part of the string names a property. Examples:: >>> "age" observe("age") observe_model(model) >>> "child.age" observe("age") observe_model(model.child) .. versionchanged:: 1.99.2 Changes to intermediate models used to be ignored. *spurious* see superclass. *prop_read* is an optional callable. It will be passed the actual value of the model property and must return it in a format suitable for the widget. *prop_write* is the mirror image of *prop_read*. *prop_cast* denotes whether to attempt a cast of the widget value to the type of the previous property value, before passing the result to *prop_write*. You cannot disable this unless you define *prop_write*. *value_error* is an optional callable. It is used when the automatic cast or *prop_write* raise :exc:`ValueError`. It will be passed this adapter, the name of the property we observe (i.e. the last part of *prop_name*) and the value obtained from the widget. """ # 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)
def __init__(self): Observer.__init__(self) self.__observers = [] # keys are properties names, values are pairs (method, # kwargs|None) inside the observer. kwargs is the keyword # argument possibly specified when explicitly defining the # notification method in observers, and it is used to build # the NTInfo instance passed down when the notification method # is invoked. If kwargs is None (special case), the # notification method is "old style" (property_<name>_...) and # won't be receiving the property name. self.__value_notifications = {} self.__instance_notif_before = {} self.__instance_notif_after = {} self.__signal_notif = {} for key in self.get_properties(): self.register_property(key) # here OPs dependencies are reversed and pre-calculated self._calculate_logical_deps() # this stack is used to avoid spurious multiple notifications # which can happen otherwise when logical properties are # involved. self._notify_stack = []
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): self.logger = log.get_logger(type(self).__name__) self.logger.info("Initiate gtkmvc3 observer") # register self as observer of rafcon.gui.singleton.state_machine_manager_model Observer.__init__(self, rafcon.gui.singleton.state_machine_manager_model) self.state_machine_manager_model = rafcon.gui.singleton.state_machine_manager_model # register self as observer of already existing StateMachineModels in state_machines list for sm_id, sm_m in list( self.state_machine_manager_model.state_machines.items()): self.observe_model(sm_m)
def __init__(self, tree, column=0): """ Observe models stored in a list for assignment to their observable properties, and notify the container that the row has changed. *tree* is a :class:`Gtk.TreeModel` instance. *column* is an integer adressing the column of *tree* that contains :class:`gtkmvc3.Model` instances. """ Observer.__init__(self) self.column = column self.rows = weakref.WeakKeyDictionary() tree.foreach(self.on_changed) tree.connect('row-changed', self.on_changed)
def __init__(self, model, view, spurious=False, auto_adapt=False, handlers=""): """ Two positional and three 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. *handlers* denotes where signal connections are made. Possible values are "glade" (the default) and "class". In the latter case all controller methods with a name like `on_<widget>__<signal>` (e.g. :meth:`on_my_window__delete_event`, note the two underscores) are connected automatically. 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.handlers = handlers or self.handlers 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 GLib.idle_add(self._idle_register_view, view, priority=GLib.PRIORITY_HIGH)
def __init__(self, model, path, adapter): """ *model* is an instance. *path* is a list of strings, with the first naming a property of *model*. Its value must have a property named like the second string, and so on. *adapter* is an instance. Its widget will be updated every time a property in *path* changes. Currently this only covers assignment. """ self.model = model self.prop_name = path[0] self.path = path[1:] self.adapter = adapter self.next = None Observer.__init__(self) self.observe(self.update_widget, self.prop_name, assign=True) self.observe_model(model) self.create_next()
def __init__(self, model): Observer.__init__(self, model) return
def __init__(self, model): Observer.__init__(self) self.model = model self.observe_model(model) self.nested_action_already_in = []
def __init__(self, model): Observer.__init__(self) self.model = model self.observe_model(model) self.last_execution_change_at_state = None