/usr/share/doc/python-gtkmvc-doc/examples/observable/value.py is in python-gtkmvc-doc 1.99.1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | # Author: Roberto Cavada <roboogle@gmail.com>
#
# Copyright (c) 2006 by Roberto Cavada
#
# pygtkmvc is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# pygtkmvc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <roboogle@gmail.com>.
# Please report bugs to <roboogle@gmail.com>.
# ----------------------------------------------------------------------
# In this example the use of observable properties is shown.
# The example does not need a view and a controller, as only
# the model side (and an observer) is used.
# ----------------------------------------------------------------------
import _importer
from gtkmvc import Model
from gtkmvc import Observer
# ----------------------------------------------------------------------
class MyModel (Model):
internal = 0
# external_spec here is a property that is not stored internally, but
# handled by a pair of methods (a getter and a setter)
# external_gen instead does not have a specific pair of getter/setter, but
# its values are got and set by a general methods pair.
__observables__ = ["internal", "external_spec", "external_gen"]
@Model.getter
def get_external_spec(self): return "some value for external_spec"
@Model.setter
def set_external_spec(self, val):
print "specific setter has been called"
return
@Model.getter("external_gen")
def get__value(self, name): return "some value for generic " + name
@Model.setter("external_gen")
def set__value(self, name, value):
print "generic setter for %s has been called" % name
return
pass
# ----------------------------------------------------------------------
class MyObserver (Observer):
"""Since version 1.0.0, base class 'Observer' is provided to
create observers that are not necessarily derived from Controller"""
# notifications
@Observer.observe("internal", assign=True)
@Observer.observe("external_spec", assign=True)
@Observer.observe("external_gen", assign=True)
def value_change(self, model, prop_name, info):
print prop_name, "changed!"
return
pass
# Look at what happens to the observer
if __name__ == "__main__":
m = MyModel()
c = MyObserver(m)
m.internal = 20
m.external_spec = "a new value"
m.external_gen = "a new value"
a = m.external_gen
print a
pass
|