From: Tero K. <te...@us...> - 2005-08-15 13:35:43
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26724 Modified Files: oevt_python.py openexvis.py visualizer.py Log Message: Better visualization. More things visualized. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- oevt_python.py 14 Aug 2005 22:46:59 -0000 1.3 +++ oevt_python.py 15 Aug 2005 13:35:35 -0000 1.4 @@ -49,18 +49,19 @@ # We return strings, since what the translator gives to the visualizer # should be language-independent. #print "DEBUG: data == ", data + # Remove the line number from the data. viscommands = str(data.pop(0)) + ';' # The visualization commands lastconst = None # Track the last loaded constant olderconst = None # Track the constant loaded before lastconst for op in data: - #print "DEBUG: opcode == ", opcode['opcode'] + #print "DEBUG: op == ", op if op['opcode'] == 'LOAD_CONST': # Loading a constant. viscommands += 'GET_CONSTANT:' + op['oparg2'] + ';' # Load the given constant to lastconst. olderconst = lastconst lastconst = op['oparg2'] - elif op['opcode'] == 'STORE_NAME': + elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': # TODO: I'm afraid this could be inadequate information to # pass forward. # Storing the last constant in the given variable. @@ -71,20 +72,28 @@ str(lastconst) + ';' elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' - elif op['opcode'] == 'LOAD_NAME': + elif op['opcode'] == 'LOAD_NAME' or op['opcode'] == 'LOAD_ATTR': # Loading the given variable. - viscommands += 'LOAD:' + op['oparg2'] + ':' + \ - str(self.variables[op['oparg2']]) + ';' - olderconst = lastconst - lastconst = self.variables[op['oparg2']] + try: + viscommands += 'LOAD:' + op['oparg2'] + ':' + \ + str(self.variables[op['oparg2']]) + ';' + olderconst = lastconst + lastconst = self.variables[op['oparg2']] + except KeyError, msg: + print "oevt_python.py: No such key: ", msg + # It can still be a valid operation, so do it like this. + # TODO: Think this over. + viscommands += 'LOAD:' + op['oparg2'] + ':' + '' + ';' elif op['opcode'] == 'COMPARE_OP': viscommands += 'COMPARE:' + op['oparg2'] + ':' + \ str(olderconst) + ':' + str(lastconst) + ';' elif op['opcode'] == 'INPLACE_ADD': + #print "DEBUG: older, last == ", olderconst, " ", lastconst viscommands += 'ADD:' + str(lastconst) + ':' + str(olderconst)\ + ';' + tmp = lastconst lastconst = int(lastconst) + int(olderconst) - olderconst = None + olderconst = tmp elif op['opcode'] == 'PRINT_ITEM': viscommands += 'OUTPUT:' + str(lastconst) + ';' elif op['opcode'] == 'PRINT_NEWLINE': Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- openexvis.py 15 Aug 2005 00:40:15 -0000 1.7 +++ openexvis.py 15 Aug 2005 13:35:35 -0000 1.8 @@ -68,13 +68,8 @@ self.vArea.set_size_request(200, 300) self.set_positions() - # Clear the area and create some initial text to place in them. + # Clear the area. self.clear_visualization_area() - self.struct_layout = self.vArea.create_pango_layout("There is no code.") - self.var_layout = self.vArea.create_pango_layout("Nothing to see " + \ - "here.") - self.const_layout = self.vArea.create_pango_layout("Constantly empty.") - self.eval_layout = self.vArea.create_pango_layout("Non-evaluation.") def init_code_area(self): """Initialize the code area.""" @@ -107,14 +102,14 @@ self.eval_split - self.gridh * 3) self.var_pos = (self.vis_split_x + self.gridw * 1, \ self.eval_split - self.gridh * 3) - self.bool_pos = (self.vis_split_x + self.gridw * 3, \ - self.eval_split + self.gridh * 3) self.eval_left_pos = (self.vis_split_x + self.gridw, \ self.eval_split + self.gridh * 1) self.eval_sign_pos = (self.vis_split_x + self.gridw * 4, \ self.eval_split + self.gridh * 1) self.eval_right_pos = (self.vis_split_x + self.gridw * 6, \ self.eval_split + self.gridh * 1) + self.eval_result_pos = (self.vis_split_x + self.gridw * 3, \ + self.eval_split + self.gridh * 3) def name_widgets(self): """Give all important UI widgets easy names.""" @@ -212,38 +207,57 @@ ei = self.oArea.get_buffer().get_end_iter() self.oArea.get_buffer().insert(ei, cmd[1]) elif cmd[0] == 'SHOW_CONSTANT': - # cmd[1] is the constant to show as string. - self.draw_show_constant(cmd[1]) - elif cmd[0] == 'SHOW_VARIABLE': - # cmd[1] is the variable name. - # cmd[2] is the variable value. - self.draw_show_variable(cmd[1], cmd[2]) + # cmd[1] is the constant to show. + if cmd[1] != 'None': + self.draw_show_constant(cmd[1]) + elif cmd[0] == 'SHOW_VARIABLES': + # cmd[1] is the variable list. + self.draw_show_variables(cmd[1]) elif cmd[0] == 'SHOW_STORING': # cmd[1] is a constant to store to last shown variable. - self.draw_show_storing(cmd[1]) + if cmd[1] != 'None': + self.draw_show_storing(cmd[1]) elif cmd[0] == 'SHOW_COMPARISON': # cmd[1] is the comparison sign (==,<,>) - # cmd[2] is the left side of comparison. - # cmd[3] is the right side of comparison. - self.draw_show_eval(cmd[2], cmd[1], cmd[3]) + # cmd[2] is the left side of the comparison. + # cmd[3] is the right side of the comparison. # Could there be an easier way to do the following? if cmd[1] == '==': if cmd[2] == cmd[3]: - self.draw_show_bool(True) + result = 'TRUE' else: - self.draw_show_bool(False) + result = 'FALSE' elif cmd[1] == '<': if cmd[2] < cmd[3]: - self.draw_show_bool(True) + result = 'TRUE' else: - self.draw_show_bool(False) + result = 'FALSE' elif cmd[1] == '>': if cmd[2] > cmd[3]: - self.draw_show_bool(True) + result = 'TRUE' else: - self.draw_show_bool(False) + result = 'FALSE' else: print "Unsupported comparison: ", cmd[1] + continue + self.draw_show_eval(cmd[2], cmd[1], cmd[3], result) + elif cmd[0] == 'SHOW_OPERATION': + # cmd[1] is the operation sign (+,-,*,/) + # cmd[2] is the left side of the operation. + # cmd[3] is the right side of the operation. + # Could there be an easier way to do the following? + if cmd[1] == '+': + result = cmd[2] + cmd[3] + elif cmd[1] == '-': + result = cmd[2] - cmd[3] + elif cmd[1] == '*': + result = cmd[2] * cmd[3] + elif cmd[1] == '/': + result = cmd[2] / cmd[3] + else: + print "Unsupported comparison: ", cmd[1] + continue + self.draw_show_eval(cmd[2], cmd[1], cmd[3], result) else: print "Visualizing ", cmd[0], " not supported." return True @@ -288,9 +302,9 @@ return moresteps # NOTE: To grok the following draw_show_* methods, see do_frame_pixmap. - def draw_show_eval(self, left, sign, right): + def draw_show_eval(self, left, sign, right, result): """Store an evaluation in the visualization pixmap.""" - # The left side of evaluation. + # The left side of the evaluation. lx = self.eval_left_pos[0] ly = self.eval_left_pos[1] lw = self.gridw * 3 @@ -300,46 +314,46 @@ sy = self.eval_sign_pos[1] sw = self.gridw * 2 stxt = self.vArea.create_pango_layout(sign) - # The right side of evaluation. + # The right side of the evaluation. rx = self.eval_right_pos[0] ry = self.eval_right_pos[1] rw = self.gridw * 3 rtxt = self.vArea.create_pango_layout(right) + # The result of the evaluation. + # The res_ex is a hack to make sure the evaluation stays on screen for + # a while. + res_x = self.eval_result_pos[0] + res_ex = self.eval_result_pos[0] + self.gridw * 2 + res_y = self.eval_result_pos[1] + res_w = self.gridw * 3 + if result == 'TRUE': + res_fg = self.bool_true_color + elif result == 'FALSE': + res_fg = self.bool_false_color + else: + res_fg = self.const_color + res_txt = self.vArea.create_pango_layout(result) # Height is same for all. h = self.gridh # Create the pixmaps to display the evaluation. self.do_frame_pixmap(self.var_color, lw, h, lx, lx, ly, ly, ltxt) self.do_frame_pixmap(self.const_color, sw, h, sx, sx, sy, sy, stxt) self.do_frame_pixmap(self.var_color, rw, h, rx, rx, ry, ry, rtxt) + self.do_frame_pixmap(res_fg, res_w, h, res_x, res_ex, res_y, res_y, \ + res_txt) - def draw_show_bool(self, bool): - """Store displaying a boolean in the visualization pixmap.""" - # TODO: ex and mod to x are for DEBUG purposes. Without them, - # currently, the boolean just flashes for a short time. A better - # solution is needed to keep it visible for a while. Should be done - # when revisiting the more general speed issues. - x = self.bool_pos[0] - self.gridw * 2 - ex = self.bool_pos[0] + self.gridw * 2 - y = self.bool_pos[1] - w = self.gridw * 2 - h = self.gridh - if bool: - fg = self.bool_true_color - text = 'TRUE' - else: - fg = self.bool_false_color - text = 'FALSE' - txt = self.vArea.create_pango_layout(text) - self.do_frame_pixmap(fg, w, h, x, ex, y, y, txt) - - def draw_show_variable(self, varname, varvalue): - """Store displaying a variable in the visualization pixmap.""" - x = self.var_pos[0] - y = self.var_pos[1] - w = self.gridw * 6 - h = self.gridh - txt = self.vArea.create_pango_layout(varname) - self.do_frame_pixmap(self.var_color, w, h, x, x, y, y, txt) + def draw_show_variables(self, cur_vars): + """Store displaying the variables in the visualization pixmap.""" + #print "DEBUG: cur_vars == ", cur_vars + pos = 0 + for v in cur_vars: + x = self.var_pos[0] + y = self.var_pos[1] - (self.gridh * pos) + w = self.gridw * 6 + h = self.gridh + txt = self.vArea.create_pango_layout(v[0]) + self.do_frame_pixmap(self.var_color, w, h, x, x, y, y, txt) + pos += 1 def draw_show_constant(self, constant): """Store displaying a constant in the visualization pixmap.""" @@ -396,7 +410,7 @@ self.cBuf.get_start_iter(), \ self.cBuf.get_end_iter()) # Highlight the line currently visualized. Note that the buffer starts - # counting from 0 but we want to highlight lines from 1 line further. + # counting from 0 but we want to highlight the line 1 line further. si = self.cBuf.get_iter_at_line(lineno-1) ei = si.copy() ei.forward_line() Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- visualizer.py 14 Aug 2005 22:46:59 -0000 1.4 +++ visualizer.py 15 Aug 2005 13:35:35 -0000 1.5 @@ -53,25 +53,42 @@ # should be documented well somewhere. Now they're not as they're still # evolving. cmd = [] + cur_vars = [] # TODO: Use to separate multiple vars. for item in data: c = item.split(':') #print "DEBUG: c == ", c if c[0] == 'GET_CONSTANT': + # c[1] is the constant to show. cmd.append(['SHOW_CONSTANT', c[1]]) elif c[0] == 'STORE_VARIABLE': + # c[1] is the variable name to store to. + # c[2] is the variable value. + # c[3] is the constant to store. # TODO: This, especially, requires some more thought. - cmd.append(['SHOW_VARIABLE', c[1], c[2]]) + cur_vars.append([c[1], c[2]]) + print "DEBUG: vis cur_vars == ", cur_vars + cmd.append(['SHOW_VARIABLES', cur_vars]) cmd.append(['SHOW_CONSTANT', c[3]]) cmd.append(['SHOW_STORING', c[3], c[1]]) elif c[0] == 'LOAD': - cmd.append(['SHOW_VARIABLE', c[1], c[2]]) + # c[1] is the variable name. + # c[2] is the variable value. + cur_vars.append([c[1], c[2]]) + print "DEBUG: vis cur_vars == ", cur_vars + cmd.append(['SHOW_VARIABLES', cur_vars]) elif c[0] == 'BEGIN_LOOP': cmd.append(['SHOW_LOOP']) elif c[0] == 'COMPARE': + # c[1] is the comparison sign. + # c[2] is the left side of the comparison. + # c[3] is the right side of the comparison. cmd.append(['SHOW_COMPARISON', c[1], c[2], c[3]]) elif c[0] == 'INPLACE_ADD': + # c[1] is the left side of the operation. + # c[2] is the right side of the operation. cmd.append(['SHOW_OPERATION', '+', c[1], c[2]]) elif c[0] == 'OUTPUT': + # c[1] is the string to output. cmd.append(['OUTPUT', c[1]]) elif c[0] == 'RETURN': cmd.append(['RETURN']) |