Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/atoidejouerbeta/tools/registry.py
diff options
context:
space:
mode:
Diffstat (limited to 'atoidejouerbeta/tools/registry.py')
-rw-r--r--atoidejouerbeta/tools/registry.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/atoidejouerbeta/tools/registry.py b/atoidejouerbeta/tools/registry.py
new file mode 100644
index 0000000..937f7c1
--- /dev/null
+++ b/atoidejouerbeta/tools/registry.py
@@ -0,0 +1,109 @@
+
+# python import
+import logging
+
+# get application logger
+logger = logging.getLogger('atoidejouerbeta')
+
+class PixRegistry(object):
+
+ class __Singleton:
+ """Our singleton object.
+ """
+
+ def __init__(self):
+ """Create the new singleton with the application config.
+
+ :param config: SafeConfigParser object for all the application
+ :see: `ConfigParser.SafeConfigParser`
+ """
+ # ensure config
+ self.__dict = dict()
+
+ def __key(self, path, width, height):
+ return '%s|%sx%s' % (path, width, height)
+
+ def get_pix(self, path, width, height):
+ # get key
+ _k = self.__key(path, width, height)
+ # ..
+ if _k in self.__dict:
+ return self.__dict[_k]
+ else:
+ return None
+
+ def set_pix(self, path, width, height, pixbuf):
+ # get key
+ _k = self.__key(path, width, height)
+ # clear previous
+ if _k in self.__dict:
+ _p = self.__dict[_k]
+ _p.destroy()
+ else:
+ pass
+ # ...
+ self.__dict[_k] = pixbuf
+
+ # singleton instance
+ instance = None
+
+ def __new__(c, force=False):
+ """Singleton new init.
+ """
+ # if doesn't already initialized
+ if not PixRegistry.instance \
+ or force is True:
+ # create a new instance
+ PixRegistry.instance = PixRegistry.__Singleton()
+ else:
+ pass
+ # return the manager object
+ return PixRegistry.instance
+
+
+class InfoRegistry(object):
+
+ class __Singleton:
+ """Our singleton object.
+ """
+
+ def __init__(self):
+ """Create the new singleton with the application config.
+
+ :param config: SafeConfigParser object for all the application
+ :see: `ConfigParser.SafeConfigParser`
+ """
+ # ensure config
+ self.__dict = dict()
+
+ def get_info(self, path):
+ # ..
+ if path in self.__dict:
+ return self.__dict[path]
+ else:
+ return None
+
+ def set_info(self, path, info):
+ # clear previous
+ if path in self.__dict:
+ del self.__dict[path]
+ else:
+ pass
+ # ...
+ self.__dict[path] = info
+
+ # singleton instance
+ instance = None
+
+ def __new__(c, force=False):
+ """Singleton new init.
+ """
+ # if doesn't already initialized
+ if not InfoRegistry.instance \
+ or force is True:
+ # create a new instance
+ InfoRegistry.instance = InfoRegistry.__Singleton()
+ else:
+ pass
+ # return the manager object
+ return InfoRegistry.instance