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
96
97
98
99
100
101
102
103
104
105
106
107
108
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
|