diff options
author | florent <florent.pigout@gmail.com> | 2011-04-26 22:19:32 (GMT) |
---|---|---|
committer | florent <florent.pigout@gmail.com> | 2011-04-26 22:19:32 (GMT) |
commit | 05ac644c99c1ea7ea3b9ade7e6f799d955aec049 (patch) | |
tree | bb60f586c471b77d15793f0d31feaf9420083e04 | |
parent | 605067ba5279b06d0852dd6e70e6debd41cc4287 (diff) |
add forgotten file + small refactoring
-rw-r--r-- | activity.py | 8 | ||||
-rw-r--r-- | atoidejouer/story/keys.py | 3 | ||||
-rw-r--r-- | atoidejouer/tools/registry.py | 109 | ||||
-rw-r--r-- | atoidejouer/ui/toolbar.py | 2 |
4 files changed, 117 insertions, 5 deletions
diff --git a/activity.py b/activity.py index 488b0b3..518b1e3 100644 --- a/activity.py +++ b/activity.py @@ -146,9 +146,11 @@ class AToiDeJouerActivity(activity.Activity): self._toolbox = activity.ActivityToolbox(self) # add tool bars self.set_toolbox(self._toolbox) + # ... + _rate = 0.5 # sequence dict and list - self.graphic_keys = StoryKeys('graphics') - self.sound_keys = StoryKeys('sounds') + self.graphic_keys = StoryKeys('graphics', rate=_rate) + self.sound_keys = StoryKeys('sounds', rate=_rate) # keep thread & screen self._thread = None self._screens = dict() @@ -171,7 +173,7 @@ class AToiDeJouerActivity(activity.Activity): # .. self._toolbox.connect('current-toolbar-changed', _toolbar_changed, self) # do anim - self._thread = ThreadAnim(self) + self._thread = ThreadAnim(self, rate=_rate) def get_toolbox(self): return self._toolbox diff --git a/atoidejouer/story/keys.py b/atoidejouer/story/keys.py index 4bebb2e..7d8f9cf 100644 --- a/atoidejouer/story/keys.py +++ b/atoidejouer/story/keys.py @@ -20,9 +20,10 @@ logger = logging.getLogger('atoidejouer') class StoryKeys(object): - def __init__(self, type_): + def __init__(self, type_, rate=1.0): # keep type self._type = type_ + self.__rate = rate # .. self.clear() diff --git a/atoidejouer/tools/registry.py b/atoidejouer/tools/registry.py new file mode 100644 index 0000000..8947d4d --- /dev/null +++ b/atoidejouer/tools/registry.py @@ -0,0 +1,109 @@ + +# python import +import logging + +# get application logger +logger = logging.getLogger('atoidejouer') + +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 diff --git a/atoidejouer/ui/toolbar.py b/atoidejouer/ui/toolbar.py index 71a5f96..dcd72fa 100644 --- a/atoidejouer/ui/toolbar.py +++ b/atoidejouer/ui/toolbar.py @@ -596,7 +596,7 @@ class Toolbar(gtk.Toolbar): value = 0 else: # update value - _s.set_value(value) + _s.set_value(int(value)) # return _v to keep time value in thread return value |