1
2
3
4 __doc__ = """GNUmed GUI element brokerage
5
6 This module provides wrappers for the equivalent of global
7 variables needed for a gnumed GUI client interface
8
9 @author: Dr. Horst Herb
10 @version: 0.2
11 @copyright: GPL v2 or later
12 """
13
14 __author__ = "H.Herb <hherb@gnumed.net>, H.Berger <Hilmar.Berger@gmx.de>"
15
16 if __name__ == '__main__':
17 _ = lambda x:x
18
19
20
21
22 config = {'main.use_notebook':1, 'main.shadow.colour':(131, 129, 131), 'main.shadow.width':10}
23
24
26 "Wrapper for global objects needed by GNUMmed GUI clients"
27
28
29
30
31
32
33
34
35 __objects = {}
36 __keycounter=0
37
38
41
42
62
63
64
66 "allows to retrieve a gnumed gui element; see addobject() regarding the key parameter"
67 return GuiBroker.__objects[key]
68
71
72
73
75 " returns a list of all keys; see documentation for the dictionary data type"
76 return GuiBroker.__objects.keys()
77
78
79
81 "returns a list of all values; see documentation for the dictionary data type"
82 return GuiBroker.__objects.values()
83
84
85
87 "returns a list of all key:value pairs; see documentation for the dictionary data type"
88 return GuiBroker.__objects.items()
89
90
91
93 "Allows retrieving the value via value = instance[key]"
94 return self.getobject(key)
95
96
97
99 "Allows access in the style of instance[key]=value"
100 return self.addobject(object, key)
101
102
103 if __name__ == "__main__":
104
105 import sys
106
107 if len(sys.argv) < 2:
108 sys.exit()
109
110 if sys.argv[1] != 'test':
111 sys.exit()
112
113
114 print('>>> gmGuiBroker.GuiBroker test')
115 test = GuiBroker()
116
117 print('>>> test.addobject("something", 3)')
118 var = test.addobject("something", 3)
119 print(var, "\n")
120
121 print('>>> test.addobject("something else without a specified key")')
122 var = test.addobject("something else without a specified key")
123 print(var, "\n")
124
125 print('>>> test.addobject(test)')
126 testreference = test.addobject(test)
127 print(testreference, "\n")
128
129 print('>>> test.addobject(100, "hundred)')
130 var = test.addobject(100, "hundred")
131 print(var, "\n")
132
133 print(">>> test.keylist()")
134 var = test.keylist()
135 print(var, "\n")
136
137 print(">>> test.valuelist()")
138 var = test.valuelist()
139 print(var, "\n")
140
141 print(">>> test.itemlist()")
142 var = test.itemlist()
143 print(var, "\n")
144
145 print(">>> test[3]")
146 var = test[3]
147 print(var, "\n")
148
149 print(">>> test[testreference].getobject('hundred')")
150 var = test[testreference].getobject('hundred')
151 print(var, "\n")
152
153 print(">>> var = test[testreference]")
154 var = test[testreference]
155 print(var, "\n")
156
157 print(">>> var = var['hundred']")
158 var = var['hundred']
159 print(var, "\n")
160
161 print('>>> try: test.addobject["duplicate key", 3]')
162 print('>>> except KeyError: print("Duplicate keys not allowed!"')
163 try: test["duplicate key", 3]
164 except KeyError: print("Duplicate keys not allowed!")
165
166 print(">>> test['key']='value'")
167 test['key']='value'
168 print(test['key'])
169