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
17
18
19 config = {'main.use_notebook':1, 'main.shadow.colour':(131, 129, 131), 'main.shadow.width':10}
20
21
23 "Wrapper for global objects needed by GNUMmed GUI clients"
24
25
26
27
28
29
30
31
32 __objects = {}
33 __keycounter=0
34
35
38
39
59
60
61
63 "allows to retrieve a gnumed gui element; see addobject() regarding the key parameter"
64 return GuiBroker.__objects[key]
65
68
69
70
72 " returns a list of all keys; see documentation for the dictionary data type"
73 return list(GuiBroker.__objects)
74
75
76
78 "returns a list of all values; see documentation for the dictionary data type"
79 return GuiBroker.__objects.values()
80
81
82
84 "returns a list of all key:value pairs; see documentation for the dictionary data type"
85 return GuiBroker.__objects.items()
86
87
88
90 "Allows retrieving the value via value = instance[key]"
91 return self.getobject(key)
92
93
94
96 "Allows access in the style of instance[key]=value"
97 return self.addobject(object, key)
98
99
100 if __name__ == "__main__":
101
102 import sys
103
104 if len(sys.argv) < 2:
105 sys.exit()
106
107 if sys.argv[1] != 'test':
108 sys.exit()
109
110
111 print('>>> gmGuiBroker.GuiBroker test')
112 test = GuiBroker()
113
114 print('>>> test.addobject("something", 3)')
115 var = test.addobject("something", 3)
116 print(var, "\n")
117
118 print('>>> test.addobject("something else without a specified key")')
119 var = test.addobject("something else without a specified key")
120 print(var, "\n")
121
122 print('>>> test.addobject(test)')
123 testreference = test.addobject(test)
124 print(testreference, "\n")
125
126 print('>>> test.addobject(100, "hundred)')
127 var = test.addobject(100, "hundred")
128 print(var, "\n")
129
130 print(">>> test.keylist()")
131 var = test.keylist()
132 print(var, "\n")
133
134 print(">>> test.valuelist()")
135 var = test.valuelist()
136 print(var, "\n")
137
138 print(">>> test.itemlist()")
139 var = test.itemlist()
140 print(var, "\n")
141
142 print(">>> test[3]")
143 var = test[3]
144 print(var, "\n")
145
146 print(">>> test[testreference].getobject('hundred')")
147 var = test[testreference].getobject('hundred')
148 print(var, "\n")
149
150 print(">>> var = test[testreference]")
151 var = test[testreference]
152 print(var, "\n")
153
154 print(">>> var = var['hundred']")
155 var = var['hundred']
156 print(var, "\n")
157
158 print('>>> try: test.addobject["duplicate key", 3]')
159 print('>>> except KeyError: print("Duplicate keys not allowed!"')
160 try: test["duplicate key", 3]
161 except KeyError: print("Duplicate keys not allowed!")
162
163 print(">>> test['key']='value'")
164 test['key']='value'
165 print(test['key'])
166