@@ -17,17 +17,25 @@ def fread_lines(file_path_and_name):
17
17
return content
18
18
19
19
20
- class KRLModuleSrcFileParser (parser_instructions .KRLGenericParser ):
20
+ class KRLModuleSrcFileParser (parser_instructions .KRLGenericParser , gui . HBox ):
21
21
file_path_name = '' # the str path and file
22
-
23
22
def __init__ (self , file_path_name ):
24
23
# read all instructions, parse and collect definitions
24
+ self .krl_procedures_and_functions_list = []
25
25
self .indent_comments = False
26
26
self .file_path_name = file_path_name
27
27
permissible_instructions = ['procedure begin' , 'function begin' ]
28
28
permissible_instructions_dictionary = {k :v for k ,v in parser_instructions .instructions_defs .items () if k in permissible_instructions }
29
29
parser_instructions .KRLGenericParser .__init__ (self , permissible_instructions_dictionary )
30
+
31
+ gui .HBox .__init__ (self )
32
+ self .append (gui .ListView (), 'list' )
33
+ self .children ['list' ].onselection .do (self .on_proc_list_selected )
30
34
35
+ def on_proc_list_selected (self , widget , selected_key ):
36
+ self .append (widget .children [selected_key ].node , 'proc_to_view' )
37
+ widget .children [selected_key ].node .draw ()
38
+
31
39
def parse_single_instruction (self , code_line_original , code_line , instruction_name , match_groups , file_lines ):
32
40
translation_result_tmp = []
33
41
@@ -41,7 +49,10 @@ def parse_single_instruction(self, code_line_original, code_line, instruction_na
41
49
translation_result_tmp .append ( "def " + procedure_name + "(" + ", " .join (param_names ) + "):" )
42
50
43
51
node = parser_instructions .KRLProcedureParser ( procedure_name , param_names )
44
- self .append (node )
52
+ #self.append(node)
53
+ li = gui .ListItem (node .name )
54
+ li .node = node
55
+ self .children ['list' ].append (li )
45
56
_translation_result_tmp , file_lines = node .parse (file_lines )
46
57
if len (_translation_result_tmp ):
47
58
translation_result_tmp .extend (_translation_result_tmp )
@@ -57,7 +68,9 @@ def parse_single_instruction(self, code_line_original, code_line, instruction_na
57
68
translation_result_tmp .append ( "def " + procedure_name + "(" + ", " .join (param_names ) + "): #function returns %s" % return_value_type_name )
58
69
59
70
node = parser_instructions .KRLFunctionParser ( procedure_name , param_names , return_value_type_name )
60
- self .append (node )
71
+ li = gui .ListItem (node .name )
72
+ li .node = node
73
+ self .children ['list' ].append (li )
61
74
_translation_result_tmp , file_lines = node .parse (file_lines )
62
75
if len (_translation_result_tmp ):
63
76
translation_result_tmp .extend (_translation_result_tmp )
@@ -68,53 +81,6 @@ def parse_single_instruction(self, code_line_original, code_line, instruction_na
68
81
69
82
return translation_result_tmp , file_lines
70
83
71
- def recalc_size_and_arrange_children (self ):
72
- #remove all drawings prior to redraw it
73
- for k in self .drawings_keys :
74
- self .remove_child (self .children [k ])
75
- self .drawings_keys = []
76
-
77
- w = max ( len (self .box_text_content ) * self .text_letter_width , 200 )
78
- h = self .box_height
79
-
80
- w_max = w
81
- #estimate self width
82
- for k in self ._render_children_list :
83
- v = self .children [k ]
84
- v .draw ()
85
- w_max = max (w_max , float (v .attr_width ))
86
-
87
- gap_between_elements = 70
88
- #set position for children
89
- for k in self ._render_children_list :
90
- v = self .children [k ]
91
- v .set_position (- float (v .attr_width )/ 2 , h + gap_between_elements )
92
- h = h + float (v .attr_height ) + gap_between_elements
93
-
94
- gui ._MixinSvgSize .set_size (self , w_max + self .margins * 2 , h + self .margins * 2 )
95
-
96
- self .set_viewbox (- w_max / 2 - self .margins , - self .margins , w_max + self .margins * 2 , h + self .margins * 2 )
97
-
98
- return w_max + self .margins * 2 , h + self .margins * 2
99
-
100
- #overloads FlowInstruction.draw§()
101
- def draw (self ):
102
- self .box_height = 50
103
- w , h = self .recalc_size_and_arrange_children ()
104
-
105
- #central box
106
- self .drawings_keys .append ( self .append (gui .SvgRectangle (- w / 2 , 0 , w , h ), 'box' ) )
107
-
108
- #text
109
- txt = gui .SvgText (0 , self .box_height / 2 , self .box_text_content )
110
- txt .attributes ['text-anchor' ] = 'middle'
111
- txt .attributes ['dominant-baseline' ] = 'middle' #'central'
112
- self .drawings_keys .append ( self .append (txt , 'text' ) )
113
-
114
- self .children ['box' ].set_stroke (1 , 'black' )
115
- self .children ['box' ].set_fill ('transparent' )
116
-
117
-
118
84
119
85
class KRLModuleDatFileParser (parser_instructions .KRLGenericParser ):
120
86
file_path_name = '' # the str path and file
@@ -130,53 +96,14 @@ def __init__(self, file_path_name):
130
96
permissible_instructions_dictionary = {k :v for k ,v in parser_instructions .instructions_defs .items () if k in permissible_instructions }
131
97
self .permissible_instructions_dictionary .update (permissible_instructions_dictionary )
132
98
133
- def parse_single_instruction (self , code_line_original , code_line , instruction_name , match_groups , file_lines ):
134
- translation_result_tmp = []
135
99
136
- if instruction_name == 'dat begin' :
137
- return translation_result_tmp , file_lines
138
-
139
- if instruction_name == 'dat end' :
140
- return translation_result_tmp , file_lines
141
-
142
- _translation_result_tmp , file_lines = parser_instructions .KRLGenericParser .parse_single_instruction (self , code_line_original , code_line , instruction_name , match_groups , file_lines )
143
- if len (_translation_result_tmp ):
144
- translation_result_tmp .extend (_translation_result_tmp )
145
-
146
- return translation_result_tmp , file_lines
147
-
148
- #overloads FlowInstruction.draw§()
149
- def draw (self ):
150
- self .box_height = 50
151
- w , h = self .recalc_size_and_arrange_children ()
152
-
153
- title_box_width = max ( len (self .box_text_content ) * self .text_letter_width , 200 )
154
-
155
- self .drawings_keys .append ( self .append (gui .SvgRectangle (- w / 2 , 0 , title_box_width , self .box_height ), 'title' ) )
156
- #central box
157
- self .drawings_keys .append ( self .append (gui .SvgRectangle (- w / 2 , self .box_height , w , h ), 'box' ) )
158
-
159
- #text
160
- txt = gui .SvgText (- w / 2 + title_box_width / 2 , self .box_height / 2 , self .box_text_content )
161
- #txt.attr_textLength = w-w*0.1
162
- #txt.attr_lengthAdjust = 'spacingAndGlyphs' # 'spacing'
163
- txt .attributes ['text-anchor' ] = 'middle'
164
- txt .attributes ['dominant-baseline' ] = 'middle' #'central'
165
- self .drawings_keys .append ( self .append (txt , 'text' ) )
166
-
167
- self .children ['title' ].set_stroke (1 , 'black' )
168
- self .children ['title' ].set_fill ('lightyellow' )
169
-
170
- self .children ['box' ].set_stroke (1 , 'black' )
171
- self .children ['box' ].set_fill ('transparent' )
172
-
173
-
174
- class KRLModule (flow_chart_graphics .FlowInstruction ):
100
+ class KRLModule (gui .VBox ):
175
101
name = ''
176
102
module_dat = None # KRLDat instance
177
103
module_src = None # KRLSrc instance
178
- def __init__ (self , module_name , dat_path_and_file = '' , src_path_and_file = '' , imports_to_prepend = '' ):
179
- flow_chart_graphics .FlowInstruction .__init__ (self )
104
+ def __init__ (self , module_name , dat_path_and_file = '' , src_path_and_file = '' , imports_to_prepend = '' , * args , ** kwargs ):
105
+ super (KRLModule , self ).__init__ (* args , ** kwargs )
106
+ self .append (gui .Label ("MODULE: %s" % module_name ))
180
107
self .name = module_name
181
108
if len (dat_path_and_file ):
182
109
self .module_dat = KRLModuleDatFileParser (dat_path_and_file )
@@ -195,7 +122,6 @@ def __init__(self, module_name, dat_path_and_file = '', src_path_and_file = '',
195
122
if len (src_path_and_file ):
196
123
has_dat = not (self .module_dat is None )
197
124
self .module_src = KRLModuleSrcFileParser (src_path_and_file )
198
- self .module_src .box_text_content = "SRC %s" % module_name
199
125
self .append (self .module_src )
200
126
file_lines = fread_lines (src_path_and_file )
201
127
translation_result , file_lines = self .module_src .parse (file_lines )
@@ -204,53 +130,7 @@ def __init__(self, module_name, dat_path_and_file = '', src_path_and_file = '',
204
130
f .write (imports_to_prepend )
205
131
for l in translation_result :
206
132
f .write (l + '\n ' )
207
- self .box_text_content = self .name
208
- self .draw ()
209
-
210
- def recalc_size_and_arrange_children (self ):
211
- #remove all drawings prior to redraw it
212
- for k in self .drawings_keys :
213
- self .remove_child (self .children [k ])
214
- self .drawings_keys = []
215
-
216
- w = max ( len (self .box_text_content ) * self .text_letter_width , 200 )
217
- h = self .box_height
218
-
219
- w_max = w
220
- #estimate self width
221
- for k in self ._render_children_list :
222
- v = self .children [k ]
223
- v .draw ()
224
- w_max = max (w_max , float (v .attr_width ))
225
-
226
- #set position for children
227
- for k in self ._render_children_list :
228
- v = self .children [k ]
229
- v .set_position (- float (v .attr_width )/ 2 , h )
230
- h = h + float (v .attr_height )
231
-
232
- gui ._MixinSvgSize .set_size (self , w_max + self .margins * 2 , h + self .margins * 2 )
233
-
234
- self .set_viewbox (- w_max / 2 - self .margins , - self .margins , w_max + self .margins * 2 , h + self .margins * 2 )
235
-
236
- return w_max + self .margins * 2 , h + self .margins * 2
237
-
238
- #overloads FlowInstruction.draw§()
239
- def draw (self ):
240
- self .box_height = 50
241
- w , h = self .recalc_size_and_arrange_children ()
242
-
243
- #central box
244
- self .drawings_keys .append ( self .append (gui .SvgRectangle (- w / 2 , 0 , w , h ), 'box' ) )
245
-
246
- #text
247
- txt = gui .SvgText (0 , self .box_height / 2 , self .box_text_content )
248
- txt .attributes ['text-anchor' ] = 'middle'
249
- txt .attributes ['dominant-baseline' ] = 'middle' #'central'
250
- self .drawings_keys .append ( self .append (txt , 'text' ) )
251
-
252
- self .children ['box' ].set_stroke (1 , 'black' )
253
- self .children ['box' ].set_fill ('transparent' )
254
133
134
+
255
135
256
136
0 commit comments