1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 11:30:19 +01:00

* Updated pygtkmvc to 1.2.2.

This commit is contained in:
2008-11-10 13:56:42 +00:00
parent 920ad915d1
commit 0e22fead19
20 changed files with 221 additions and 66 deletions

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2005 by Roberto Cavada
#
@@ -18,13 +18,13 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
__all__ = ["model", "view", "controller", "observable", "observer"]
__all__ = ["model", "view", "controller", "observable", "observer", "support"]
__version = (1,2,1)
__version = (1,2,2)
from model import Model, TreeStoreModel, ListStoreModel, TextBufferModel
from model_mt import ModelMT

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2007 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
from gtkmvc.adapters.basic import Adapter, UserClassAdapter, RoUserClassAdapter
from gtkmvc.adapters.containers import StaticContainerAdapter

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2007 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
import types
@@ -142,7 +142,7 @@ class Adapter (Observer):
def update_model(self):
"""Forces the property to be updated from the value hold by
the widget. This method should be called directly by the
user in very unusual coditions."""
user in very unusual conditions."""
self._write_property(self._read_widget())
return
@@ -150,7 +150,7 @@ class Adapter (Observer):
"""Forces the widget to be updated from the property
value. This method should be called directly by the user
when the property is not observable, or in very unusual
coditions."""
conditions."""
self._write_widget(self._read_property())
return
@@ -218,8 +218,8 @@ class Adapter (Observer):
def _get_property(self):
"""Private method that returns the value currently stored
into the property"""
#return getattr(self.get_model(), self._prop_name)
return self._prop
return getattr(self.get_model(), self._prop_name)
#return self._prop # bug fix reported by A. Dentella
def _set_property(self, val):
"""Private method that sets the value currently of the property."""
@@ -308,8 +308,7 @@ class Adapter (Observer):
def _on_prop_changed(self):
"""Called by the observation code, when the value in the
observed property is changed"""
if self._itsme: return
self.update_widget()
if not self._itsme: self.update_widget()
return
pass # end of class Adapter

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2007 by Roberto Cavada
#
@@ -18,14 +18,14 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
import types
import gtk
from gtkmvc.adapters.basic import UserClassAdapter
from gtkmvc.adapters.basic import UserClassAdapter, Adapter
from gtkmvc.adapters.default import *
from gtkmvc.observer import Observer
@@ -49,7 +49,6 @@ class StaticContainerAdapter (UserClassAdapter):
dynamically. If the container grows up in length, no change will
occur in the view-side.
"""
def __init__(self, model, prop_name,
prop_read=None, prop_write=None, value_error=None):
@@ -59,7 +58,8 @@ class StaticContainerAdapter (UserClassAdapter):
prop_read, prop_write,
value_error)
prop = self._get_property()
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 +

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2005 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
from gtkmvc.observer import Observer

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2005 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
import support.metaclasses
from support.wrappers import ObsWrapperBase

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2006 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
from gtkmvc.model import Model

View File

@@ -1,5 +1,5 @@
# -------------------------------------------------------------------------
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (C) 2006 by Roberto Cavada
#
@@ -19,7 +19,7 @@
# Boston, MA 02110, USA.ridge, MA 02139, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author <cavada@irst.itc.it>.
# or email to the author <cavada@fbk.eu>.
# -------------------------------------------------------------------------

View File

@@ -1,5 +1,5 @@
# -------------------------------------------------------------------------
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (C) 2006 by Roberto Cavada
#
@@ -19,8 +19,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
# -------------------------------------------------------------------------

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2005 by Roberto Cavada
#
@@ -18,8 +18,9 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
__all__ = ["metaclass_base", "metaclasses", "wrappers", "decorators"]
__all__ = ["metaclass_base", "metaclasses", "wrappers", "decorators",
"factories"]

View File

@@ -1,5 +1,5 @@
# -------------------------------------------------------------------------
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (C) 2006 by Roberto Cavada
#
@@ -19,8 +19,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
# -------------------------------------------------------------------------

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2005 by Roberto Cavada
#
@@ -18,7 +18,7 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.

View File

@@ -0,0 +1,86 @@
# -------------------------------------------------------------------------
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (C) 2008 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 <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
# -------------------------------------------------------------------------
import new
from gtkmvc import Model
from noconflict import get_noconflict_metaclass
class ModelFactory (object):
"""This factory constructs classes for models. Use it to build
the classes to derive your own models"""
__memoized = {}
@staticmethod
def __fix_bases(base_classes, have_mt):
"""This function check whether base_classes contains a Model
instance. If not, choose the best fitting class for
model. Furthermore, it makes the list in a cannonical
ordering form in a way that ic can be used as memoization
key"""
fixed = list(base_classes)
contains_model = False
for b in fixed:
if isinstance(fixed, Model): contains_model = True; break
pass
# adds a model when user is lazy
if not contains_model:
if have_mt:
from gtkmvc.model_mt import ModelMT
fixed.insert(0, ModelMT)
else: fixed.insert(0, Model)
pass
class ModelFactoryWrap (object):
__metaclass__ = get_noconflict_metaclass(tuple(fixed), (), ())
def __init__(self, *args, **kwargs): pass
pass
fixed.append(ModelFactoryWrap)
fixed.sort()
return tuple(fixed)
@staticmethod
def make(base_classes=(), have_mt=False):
"""Use this static method to build a model class that
possibly derives from other classes. If have_mt is True,
then returned class will take into account multi-threading
issues when dealing with observable properties."""
good_bc = ModelFactory.__fix_bases(base_classes, have_mt)
print "Base classes are:", good_bc
key = "".join(map(str, good_bc))
if ModelFactory.__memoized.has_key(key):
return ModelFactory.__memoized[key]
cls = new.classobj('', good_bc, {'__module__': '__main__', '__doc__': None})
ModelFactory.__memoized[key] = cls
return cls
#__
#make = staticmethod(make)
pass # end of class

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2005 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
import new
@@ -59,7 +59,7 @@ class PropertyMeta (type):
Programmers can override basic behaviour for getters or setters simply by
defining their getters and setters (see at the names convention above).
The customized function can lie everywhere in the user classes hierarchy.
Every overrided function will not be generated by the metaclass.
Every overridden function will not be generated by the metaclass.
To supply your own methods is good for few methods, but can result in a
very unconfortable way for many methods. In this case you can extend
@@ -197,14 +197,14 @@ class PropertyMeta (type):
# Override these:
def get_getter_source(cls, getter_name, prop_name):
"""This must be overrided if you need a different implementation.
"""This must be overridden if you need a different implementation.
Simply the generated implementation returns the variable name
_prop_name"""
return "def %s(self): return self._prop_%s" % (getter_name, prop_name)
def get_setter_source(cls, setter_name, prop_name):
"""This must be overrided if you need a different implementation.
"""This must be overridden if you need a different implementation.
Simply the generated implementation sets the variable _prop_name"""
return "def %s(self, val): self._prop_%s = val" \
% (setter_name, prop_name)

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2005 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
from metaclass_base import PropertyMeta
import types

View File

@@ -0,0 +1,65 @@
# Author: Michele Simionato <michelesimionato@libero.it>
# Copyright (C) 2004 by Michele Simionato
# License: Python License (version not specified)
# Last Updated: 2nd of March 2007, 10:23 GMT
#
# Any serious user of metaclasses has been bitten at least once by
# the infamous metaclass/metatype conflict. This script contains a
# general recipe to solve the problem, as well as some theory and
# some examples.
import inspect, types, __builtin__
############## preliminary: two utility functions #####################
def skip_redundant(iterable, skipset=None):
"Redundant items are repeated items or items in the original skipset."
if skipset is None: skipset = set()
for item in iterable:
if item not in skipset:
skipset.add(item)
yield item
def remove_redundant(metaclasses):
skipset = set([types.ClassType])
for meta in metaclasses: # determines the metaclasses to be skipped
skipset.update(inspect.getmro(meta)[1:])
return tuple(skip_redundant(metaclasses, skipset))
##################################################################
## now the core of the module: two mutually recursive functions ##
##################################################################
memoized_metaclasses_map = {}
def get_noconflict_metaclass(bases, left_metas, right_metas):
"""Not intended to be used outside of this module, unless you know
what you are doing."""
# make tuple of needed metaclasses in specified priority order
metas = left_metas + tuple(map(type, bases)) + right_metas
needed_metas = remove_redundant(metas)
# return existing confict-solving meta, if any
if needed_metas in memoized_metaclasses_map:
return memoized_metaclasses_map[needed_metas]
# nope: compute, memoize and return needed conflict-solving meta
elif not needed_metas: # wee, a trivial case, happy us
meta = type
elif len(needed_metas) == 1: # another trivial case
meta = needed_metas[0]
# check for recursion, can happen i.e. for Zope ExtensionClasses
elif needed_metas == bases:
raise TypeError("Incompatible root metatypes", needed_metas)
else: # gotta work ...
metaname = '_' + ''.join([m.__name__ for m in needed_metas])
meta = classmaker()(metaname, needed_metas, {})
memoized_metaclasses_map[needed_metas] = meta
return meta
def classmaker(left_metas=(), right_metas=()):
def make_class(name, bases, adict):
metaclass = get_noconflict_metaclass(bases, left_metas, right_metas)
return metaclass(name, bases, adict)
return make_class

View File

@@ -0,0 +1,4 @@
class A (object):
a = 10
pass

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (c) 2007 by Roberto Cavada
#
@@ -18,8 +18,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.

View File

@@ -1,5 +1,5 @@
# -------------------------------------------------------------------------
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
#
# Copyright (C) 2006 by Roberto Cavada
#
@@ -19,8 +19,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
# -------------------------------------------------------------------------

View File

@@ -1,4 +1,4 @@
# Author: Roberto Cavada <cavada@irst.itc.it>
# Author: Roberto Cavada <cavada@fbk.eu>
# Modified by: Guillaume Libersat <glibersat AT linux62.org>
#
# Copyright (c) 2005 by Roberto Cavada
@@ -20,8 +20,8 @@
# Boston, MA 02110, USA.
#
# For more information on pygtkmvc see <http://pygtkmvc.sourceforge.net>
# or email to the author Roberto Cavada <cavada@irst.itc.it>.
# Please report bugs to <cavada@irst.itc.it>.
# or email to the author Roberto Cavada <cavada@fbk.eu>.
# Please report bugs to <cavada@fbk.eu>.
import gtk.glade