1
1
import yaml
2
2
import copy
3
3
import math
4
+ import pprint
4
5
import string
5
6
6
7
from gestalt .Datasheet import *
@@ -15,6 +16,7 @@ def __init__(self, classname, name=None, node=None, layout={}, loc=None):
15
16
self .classname = classname
16
17
self .name = name
17
18
self .location = loc
19
+ self .debug = False
18
20
19
21
self .properties = {}
20
22
self .properties ["attrs" ] = {}
@@ -25,6 +27,7 @@ def __init__(self, classname, name=None, node=None, layout={}, loc=None):
25
27
if node :
26
28
self .name = node .name
27
29
self .location = node .location
30
+ self .debug = node .debug
28
31
29
32
for typ in ( "attrs" , "internal" ):
30
33
for key ,val in node .properties [typ ].items ():
@@ -41,6 +44,10 @@ def __init__(self, classname, name=None, node=None, layout={}, loc=None):
41
44
42
45
self .setDefault (Rect , "geometry" , "0x0x0x0" )
43
46
47
+ def log (self , info ):
48
+ if self .debug :
49
+ print (str (self .name ) + ": " + info + "\n " )
50
+
44
51
45
52
def setDefault (self , datatype , key , default , internal = False ):
46
53
which = "internal" if internal else "attrs"
@@ -60,6 +67,8 @@ def makeInternal(self, datatype, key, default=None):
60
67
def updateProperties (self , macros = {}):
61
68
if len (macros ) == 0 : return
62
69
70
+ self .log ("Updating macros\n " + pprint .pformat (macros ))
71
+
63
72
for attr in self .properties ["internal" ].values ():
64
73
attr .apply (macros )
65
74
@@ -87,11 +96,15 @@ def setProperty(self, key, input, internal=False):
87
96
to_assign = input .copy ()
88
97
else :
89
98
to_assign = copy .deepcopy (input )
90
-
99
+
100
+ if isinstance (to_assign , DataType ):
101
+ self .log ("Setting Property " + key + " from " + str (self .properties [which ].get (key )) + " to " + str (to_assign .value ))
102
+ else :
103
+ self .log ("Setting Property " + key + " from " + str (self .properties [which ].get (key )) + " to " + pprint .pformat (to_assign ))
91
104
self .properties [which ][key ] = to_assign
92
105
93
106
94
- def setProperties (self , layout = {"internal" : {}, "attrs" : {}}):
107
+ def setProperties (self , layout = {"internal" : {}, "attrs" : {}}):
95
108
for key , val in layout ["internal" ].items ():
96
109
self .setProperty (key , val , internal = True )
97
110
@@ -139,20 +152,24 @@ def position(self, *args, x=None, y=None):
139
152
out_y = args [0 ]["y" ]
140
153
141
154
if out_x is not None :
155
+ self .log ("Setting x to " + str (out_x ))
142
156
self ["geometry" ]["x" ] = out_x
143
157
144
158
if out_y is not None :
159
+ self .log ("Setting y to " + str (out_y ))
145
160
self ["geometry" ]["y" ] = out_y
146
161
147
162
return self
148
163
149
164
150
165
def apply (self , generator , data = {}):
151
166
gen_func = getattr (generator , "generate" + self .classname , None )
152
-
167
+
153
168
if gen_func :
169
+ self .log ("Generating " + self .classname )
154
170
return gen_func (self , macros = data )
155
171
else :
172
+ self .log ("Generating generic widget" )
156
173
return generator .generateWidget (self , macros = data )
157
174
158
175
def __deepcopy__ (self , memo ):
@@ -162,6 +179,7 @@ def __deepcopy__(self, memo):
162
179
output .classname = self .classname
163
180
output .name = self .name
164
181
output .location = self .location
182
+ output .debug = self .debug
165
183
166
184
output .properties = {}
167
185
output .properties ["attrs" ] = copy .copy (self .properties ["attrs" ])
@@ -202,7 +220,9 @@ def __init__(self, classname, name=None, node=None, layout={}, loc=None):
202
220
self .setDefault (Number , "border-width" , 0 )
203
221
204
222
205
- def append (self , child , keep_original = False ):
223
+ def append (self , child , keep_original = False ):
224
+ self .log ("Adding child node " + child .__repr__ ())
225
+
206
226
if not keep_original :
207
227
self .children .append (copy .deepcopy (child ))
208
228
else :
@@ -242,6 +262,7 @@ def place(self, child, x=None, y=None, keep_original=False):
242
262
243
263
244
264
def apply (self , generator , data = {}):
265
+ self .log ("Generating group node" )
245
266
output = generator .generateGroup (self , macros = data )
246
267
margins = self .getProperty ("margins" , internal = True ).val ()
247
268
@@ -285,6 +306,7 @@ def __init__(self, name=None, layout={}, loc=None):
285
306
self .setDefault (Font , "font" , "-Liberation Sans - Regular - 12" )
286
307
287
308
def apply (self , generator , data = {}):
309
+ self .log ("Generating Tabbed Group" )
288
310
output = generator .generateTabbedGroup (self , macros = data )
289
311
290
312
tk_root = tk .Tk ()
0 commit comments