From: Tero K. <te...@us...> - 2005-08-16 23:14:45
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30280 Modified Files: oevt_python.py openexvis.py visualizer.py Log Message: Improved visualization of evaluations further. Several small fixes. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- oevt_python.py 16 Aug 2005 19:37:57 -0000 1.9 +++ oevt_python.py 16 Aug 2005 23:14:37 -0000 1.10 @@ -62,10 +62,15 @@ if op['opcode'] == 'LOAD_CONST': # Loading a constant. - viscommands += 'GET_CONSTANT:' + op['oparg2'] + ';' + if op['oparg2'][:13] == '<code object ': + split = op['oparg2'].split(' ') + const = split[2] + else: + const = op['oparg2'] + viscommands += 'GET_CONSTANT:' + const + ';' # Load the given constant to lastval. olderval = lastval - lastval = ['None', op['oparg2']] + lastval = ['None', const] elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': # Storing the last constant in the given variable. @@ -75,7 +80,7 @@ else: v = [lastval[1], ''] self.variables[op['oparg2']] = v - #print "DEBUG: variables == ", self.variables + print "DEBUG: variables == ", self.variables viscommands += 'STORE_VARIABLE:' + op['oparg2'] + ':' + \ str(v[0]) + ':' + str(v[1]) + ':' + lastval[0] + ';' @@ -161,7 +166,14 @@ globals_ = {"__name__" : "__main__"} locals_ = globals_ # The variables we need to track during the visualization. - self.variables = {} - statement = compile(code, "", 'exec') + # Key is the variable name. + # Value is a list of two items, where the first is the current value of + # the variable and second is the previous value of the variable. + self.variables = {'__name__' : ['__main__', '']} + try: + statement = compile(code, "", 'exec') + except: + # TODO: Think of a good way to handle this. + return False self.run(statement, globals=globals_, locals=locals_) Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- openexvis.py 16 Aug 2005 19:37:57 -0000 1.18 +++ openexvis.py 16 Aug 2005 23:14:37 -0000 1.19 @@ -60,7 +60,7 @@ self.colormap = self.vDraw.get_colormap() self.object_bg_color = self.colormap.alloc_color('#000000') self.static_const_color = self.colormap.alloc_color('#DDAA88') - self.const_color = self.colormap.alloc_color('#FFCCAA') + self.moving_const_color = self.colormap.alloc_color('#FFCCAA') self.var_color = self.colormap.alloc_color('#CCFFAA') self.bool_true_color = self.colormap.alloc_color('#33FF33') self.bool_false_color = self.colormap.alloc_color('#FF5555') @@ -108,8 +108,10 @@ 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) + self.eval_equals_sign_pos = (self.vis_split_x + self.gridw * 2, \ + self.eval_split + self.gridh * 4) + self.eval_result_pos = (self.vis_split_x + self.gridw * 4, \ + self.eval_split + self.gridh * 4) def name_widgets(self): """Give all important UI widgets easy names.""" @@ -180,11 +182,11 @@ if not elem[0] == 'oev_non_animation': # Update the visualization area. self.animate_element(elem) + self.vis_drawn.append(elem) else: if elem[1] == 'output': ei = self.oArea.get_buffer().get_end_iter() self.oArea.get_buffer().insert(ei, elem[2]) - self.vis_drawn.append(elem) if self.do_steps: while self.do_steps and not self.step_fwd: # Loop until we are told to step forward or to start running @@ -205,12 +207,14 @@ #print "DEBUG: cmd == ", cmd if cmd[0] == 'OUTPUT': # cmd[1] is the string to output. - # cmd[2] is the variable name of the string, None if the value is - # is a constant or '' for a newline. + # cmd[2] is the variable name of the string, None if the value + # is a constant or '' for a newline. self.draw_show_output(cmd[1], cmd[2]) + elif cmd[0] == 'SHOW_CONSTANTS': # cmd[1] is the constant list. self.draw_show_constants(cmd[1]) + elif cmd[0] == 'SHOW_VARIABLES': # cmd[1] is the variable dictionary, where: # key is the variable name to store to and @@ -220,6 +224,7 @@ for key, value in cmd[1].iteritems(): self.cur_vars[key] = value self.draw_show_variables(True) + elif cmd[0] == 'SHOW_STORING': # cmd[1] is a constant to store to a variable. # cmd[2] is the variable to store to. @@ -227,6 +232,7 @@ if cmd[1] == 'None': continue self.draw_show_storing(cmd[1], cmd[2], cmd[3]) + elif cmd[0] == 'SHOW_COMPARISON': # cmd[1] is the comparison sign (==,<,>) # cmd[2] is the variable on the left side of the comparison or @@ -235,8 +241,6 @@ # cmd[4] is the variable on the right side of the comparison or # None if the value is a constant. # cmd[5] is the value of the right side of the comparison. - - # Could there be an easier way to do the following? if cmd[1] == '==': if cmd[3] == cmd[5]: result = 'TRUE' @@ -264,6 +268,7 @@ else: right = 'const_' + str(cmd[5]) self.draw_show_eval(left, cmd[1], right, result) + elif cmd[0] == 'SHOW_OPERATION': # cmd[1] is the operation sign (+,-,*,/) # cmd[2] is the variable on the left side of the operation or @@ -272,8 +277,6 @@ # cmd[4] is the variable on the right side of the operation or # None if the value is a constant. # cmd[5] is the value of the right side of the operation. - - # Could there be an easier way to do the following? if cmd[1] == '+': result = cmd[3] + cmd[5] elif cmd[1] == '-': @@ -294,6 +297,7 @@ else: right = 'const_' + str(cmd[5]) self.draw_show_eval(left, cmd[1], right, str(result)) + else: if cmd[0]: print "Visualizing ", cmd[0], " not supported." @@ -365,6 +369,8 @@ def draw_show_output(self, output, source): """Store drawing an output to self.vis_steps.""" + if source == 'None': + source = output if self.vis_pixmaps.has_key('result_' + source): pmname = 'result_' + source elif self.vis_pixmaps.has_key('const_' + source): @@ -393,19 +399,25 @@ sx = self.eval_sign_pos[0] sy = self.eval_sign_pos[1] sw = self.gridw * 1 - # Height is same for both + # The equals sign. + eqx = self.eval_equals_sign_pos[0] + eqy = self.eval_equals_sign_pos[1] + eqw = self.gridw * 1 + # Height is same for all. h = self.gridh 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_fg = self.moving_const_color self.create_element_pixmap('result_' + result, res_x, res_y, \ res_fg, res_w, h, result) self.create_element_pixmap(sign, sx, sy, \ - self.const_color, sw, h, sign) - # Names to use the correct pixmaps. + self.static_const_color, sw, h, sign) + self.create_element_pixmap('eval_equals_sign', eqx, eqy, \ + self.static_const_color, eqw, h, '=') + # To use the correct pixmaps. result = 'result_' + result # Create the animation. self.draw_show_variables(False) @@ -415,6 +427,9 @@ self.eval_sign_pos[0], self.eval_sign_pos[1]]) self.vis_steps.append([right, \ self.eval_right_pos[0], self.eval_right_pos[1]]) + self.vis_steps.append(['eval_equals_sign', \ + self.eval_equals_sign_pos[0], self.eval_equals_sign_pos[1]]) + self.draw_delay(2) self.vis_steps.append([result, \ self.eval_result_pos[0], self.eval_result_pos[1]]) self.draw_delay(5) @@ -475,7 +490,7 @@ if source == 'None': pmname = 'move_const_' + const self.create_element_pixmap(pmname, startx, starty,\ - self.const_color, w, h, const) + self.moving_const_color, w, h, const) elif source == 'eval_result': pmname = 'result_' + const else: Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- visualizer.py 16 Aug 2005 19:37:57 -0000 1.11 +++ visualizer.py 16 Aug 2005 23:14:37 -0000 1.12 @@ -58,7 +58,9 @@ for item in data: c = item.split(':') #print "DEBUG: c == ", c - if c[0] == 'GET_CONSTANT': + if c[0] == '': + continue + elif c[0] == 'GET_CONSTANT': # c[1] is the constant to show. cur_consts.append(c[1]) cmd.append(['SHOW_CONSTANTS', cur_consts]) |