From: <jU...@us...> - 2008-07-08 16:49:04
|
Revision: 565 http://fclient.svn.sourceforge.net/fclient/?rev=565&view=rev Author: jUrner Date: 2008-07-08 09:47:26 -0700 (Tue, 08 Jul 2008) Log Message: ----------- experimental ..add a global object registry Modified Paths: -------------- trunk/fclient/src/fclient/config.py Modified: trunk/fclient/src/fclient/config.py =================================================================== --- trunk/fclient/src/fclient/config.py 2008-07-08 15:58:43 UTC (rev 564) +++ trunk/fclient/src/fclient/config.py 2008-07-08 16:47:26 UTC (rev 565) @@ -5,6 +5,7 @@ import atexit import os +import weakref from PyQt4 import QtCore from .lib import fcp2 @@ -16,7 +17,37 @@ FclientAppName = 'fclient' SettingsDir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'settings') + #********************************************************************************** +# looks like QObject.findChild() does not always work. docs mention troubles +# with MSVC 6 where you should use qFindChild(). can not test this. so keep +# a dict for lookups... +#********************************************************************************** +IdViewWidget = 'ViewWidget' +IdViewLoggerWidget = 'ViewLoggerWidget' +IdViewConnectionWidget = 'ViewConnectionWidget' + + +class ObjectRegistry(weakref.WeakValueDictionary): + """global object registry + + use the registry to register and retrieve ui objects previously registerd by their object ids (Id*). + ObjectRegistry is actually a WeakValueDictionary. so use as a dict + """ + + def register(self, obj): + """regisdters an object in the registry + @param obj: (QObject) object to register + @note: QObject.objectName() is taken as id. ids have to be unique throughout the runtime of the gui + """ + ido = str(obj.objectName()) + if ido in self: + raise ValueError('ui object already registered: %s' % ido) + self[ido] = obj + + +ObjectRegistry = ObjectRegistry() +#********************************************************************************** # #********************************************************************************** class ConfigSettings(settingsbase.SettingsBase): @@ -67,8 +98,12 @@ #********************************************************************************** class Config(object): + _UiObjRegistry = weakref.WeakValueDictionary() + + def __init__(self, parent): - + + self.fcpClient = fcp2.Client() # global fcp client self.settings = Settings() # global settings class self.configSettings = ConfigSettings() # settings of the config @@ -79,15 +114,12 @@ atexit.register(self.close) - def close(self): self.settings.dumpSettings(None, self.configSettings) - +#********************************************************************************** +# +#********************************************************************************** + - -s = Config(None) - - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |