You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(32) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: Tero K. <te...@us...> - 2005-08-26 17:15:42
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30403 Modified Files: oevt_python.py openexvis.py visualizer.py Log Message: Fix some problems found in pre-release testing. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- oevt_python.py 26 Aug 2005 16:10:37 -0000 1.14 +++ oevt_python.py 26 Aug 2005 17:15:34 -0000 1.15 @@ -60,6 +60,7 @@ # oev_class == the value is a class name # oev_function == the value is a function name # oev_tuple == the value is a tuple + # oev_result == the value is a result from an evaluation # oev_temp == the value is something just to fill the stack # # The second item is the actual value. @@ -168,10 +169,35 @@ elif op['opcode'] == 'COMPARE_OP': r_name, r_value = lastvals.pop() l_name, l_value = lastvals.pop() - viscommands += 'COMPARE:' + op['oparg2'] + ':' + \ + try: + r_value = int(r_value) + l_value = int(l_value) + except ValueError: + pass + sign = op['oparg2'] + if sign == '==': + if (l_value == r_value): + result = 'TRUE' + else: + result = 'FALSE' + elif sign == '<': + if (l_value < r_value): + result = 'TRUE' + else: + result = 'FALSE' + elif sign == '>': + if (l_value > r_value): + result = 'TRUE' + else: + result = 'FALSE' + else: + print "Unsupported comparison operation: ", sign + continue + viscommands += 'COMPARE:' + sign + ':' + \ str(l_name) + ':' + str(l_value) + ':' + \ - str(r_name) + ':' + str(r_value) + ';' - lastvals.append(['oev_temp', 'comparison_result']) + str(r_name) + ':' + str(r_value) + ':' + \ + result + ';' + lastvals.append(['oev_result', result]) elif op['opcode'] == 'INPLACE_ADD': r_name, r_value = lastvals.pop() @@ -180,7 +206,7 @@ str(l_name) + ':' + str(l_value) + ':' + \ str(r_name) + ':' + str(r_value) + ';' sum = int(l_value) + int(r_value) - lastvals.append(['eval_result', sum]) + lastvals.append(['oev_result', sum]) elif op['opcode'] == 'BUILD_TUPLE': if int(op['oparg1']) < 1: @@ -212,9 +238,9 @@ if lastvals: lastvals.pop() - - elif op['opcode'] == 'POP_BLOCK': - viscommands += 'EXIT_BLOCK' +# TODO: Hmm, this didn't work when a typo was fixed. +# elif op['opcode'] == 'POP_BLOCK': +# viscommands += 'EXIT_BLOCK;' elif op['opcode'] == 'PRINT_ITEM': name, output = lastvals.pop() Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- openexvis.py 26 Aug 2005 16:31:51 -0000 1.25 +++ openexvis.py 26 Aug 2005 17:15:34 -0000 1.26 @@ -203,9 +203,9 @@ elif elem[1] == 'structure': direction = elem[2] if direction == 'UP': - #print "DEBUG: About to pop from structure, which is ",\ - #self.structure - self.structure.pop() + #print "DEBUG: About to pop from ", self.structure + if self.structure: + self.structure.pop() elif direction == 'DOWN': pass @@ -271,24 +271,7 @@ # 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. - if cmd[1] == '==': - if cmd[3] == cmd[5]: - result = 'TRUE' - else: - result = 'FALSE' - elif cmd[1] == '<': - if cmd[3] < cmd[5]: - result = 'TRUE' - else: - result = 'FALSE' - elif cmd[1] == '>': - if cmd[3] > cmd[5]: - result = 'TRUE' - else: - result = 'FALSE' - else: - print "Unsupported comparison operation: ", cmd[1] - continue + # cmd[6] is the comparison result. if cmd[2] != 'None': left = str(cmd[2]) + '_value' else: @@ -297,7 +280,7 @@ right = str(cmd[4]) + '_value' else: right = 'const_' + str(cmd[5]) - self.draw_show_eval(left, cmd[1], right, result) + self.draw_show_eval(left, cmd[1], right, cmd[6]) elif cmd[0] == 'SHOW_OPERATION': # cmd[1] is the operation sign (+,-,*,/) @@ -592,7 +575,7 @@ pmname = 'move_const_' + const self.create_element_pixmap(pmname, startx, starty,\ self.moving_const_color, w, h, const) - elif source == 'eval_result': + elif source == 'oev_result': pmname = 'result_' + const else: # The source should be another variable. Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- visualizer.py 26 Aug 2005 16:10:37 -0000 1.14 +++ visualizer.py 26 Aug 2005 17:15:34 -0000 1.15 @@ -102,7 +102,9 @@ # c[4] is the variable on the right side of the comparison or # None if the value is a constant. # c[5] is the value of the right side of the comparison. - cmd.append(['SHOW_COMPARISON', c[1], c[2], c[3], c[4], c[5]]) + # cmd[6] is the comparison result. + cmd.append(['SHOW_COMPARISON', c[1], \ + c[2], c[3], c[4], c[5], c[6]]) elif c[0] == 'SHOW_INT_OPERATION': # c[1] is the sign of the operation. # c[2] is the variable on the left side of the operation or |
From: Tero K. <te...@us...> - 2005-08-26 16:32:02
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18234 Modified Files: ChangeLog TODO openexvis.py Log Message: Prepare for 0.3.0-pre1 Index: TODO =================================================================== RCS file: /cvsroot/openexvis/openexvis/TODO,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TODO 15 Aug 2005 14:33:28 -0000 1.2 +++ TODO 26 Aug 2005 16:31:51 -0000 1.3 @@ -3,11 +3,12 @@ For 0.3.0: - * Improve the visualization - + Visualize mathematical operations correctly - + Improve visualization of evaluation in general - + Move correct constants to correct variables - + Implement visualizing the structure - + Try to improve the animation speed control further + * Improve the visualization (DONE) + + Visualize mathematical operations correctly (DONE) + + Improve visualization of evaluation in general (DONE) + + Move correct constants to correct variables (DONE) + + Implement visualizing the structure (DONE) + + Try to improve the animation speed control further (POSTPONED - needs + more general optimization to have more effect, at least on my machine) * Include some more test files and make sure they're visualized correctly Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- openexvis.py 26 Aug 2005 16:10:37 -0000 1.24 +++ openexvis.py 26 Aug 2005 16:31:51 -0000 1.25 @@ -23,7 +23,7 @@ def __init__(self): visualizer.OevVisualizer.__init__(self) - self.version = "0.3.0-pre" + self.version = "0.3.0-pre1" self.structure = [] # Build the UI Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- ChangeLog 26 Aug 2005 16:10:37 -0000 1.17 +++ ChangeLog 26 Aug 2005 16:31:51 -0000 1.18 @@ -3,6 +3,10 @@ CVS + + +0.3.0-pre1 + * Internal restructuring * Improve the animation a lot * Exceptions while visualizing now cause visualization to stop and provide some |
From: Tero K. <te...@us...> - 2005-08-26 16:10:46
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13128 Modified Files: ChangeLog oevt_python.py openexvis.py visualizer.py Log Message: Finally the structure is visualized tolerably, but the code certainly isn't prettier after these changes. Several other fixes here and there as well. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- oevt_python.py 18 Aug 2005 15:11:39 -0000 1.13 +++ oevt_python.py 26 Aug 2005 16:10:37 -0000 1.14 @@ -48,87 +48,130 @@ def to_oevdata(self, data): # We return strings, since what the translator gives to the visualizer # should be language-independent. + # print '\n\n' + '*' * 80 # DEBUG clarity #print "DEBUG: data == ", data # Remove the line number from the data and store it at the beginning of # the visualization commands. viscommands = str(data.pop(0)) + ';' - # In the following, the first list item tells the variable name. - # If the first item is None, it means the value is a constant. If it's - # oev_function, the value is a function name. + # In lastvals, the first list item tells the value type. + # If the first item is + # None == the value is a constant # TODO: change to oev_const + # oev_code == the value is a code object's name + # oev_class == the value is a class name + # oev_function == the value is a function name + # oev_tuple == the value is a tuple + # oev_temp == the value is something just to fill the stack + # # The second item is the actual value. lastvals = [] # Last loaded values for op in data: - #print "DEBUG: lastvals == ", lastvals + #print "\nDEBUG: lastvals == ", lastvals #print "DEBUG: variables == ", self.variables - #print "DEBUG: op == ", op + #print "DEBUG: functions == ", self.structure + #print "\nDEBUG: op == ", op if op['opcode'] == 'LOAD_CONST': # Loading a constant. if op['oparg2'][:13] == '<code object ': split = op['oparg2'].split(' ') - const = split[2] + const_value = split[2] + const_type = 'oev_code' else: - const = op['oparg2'] - if const[0] == "'" and const[-1] == "'": - const = const[1:-1] - viscommands += 'GET_CONSTANT:' + const + ';' + const_value = op['oparg2'] + const_type = 'None' + if const_value[0] == "'" and const_value[-1] == "'": + const_value = const_value[1:-1] + viscommands += 'LOAD_CONSTANT:' + const_value + ';' # Load the given constant to lastval. - lastvals.append(['None', const]) + lastvals.append([const_type, const_value]) + + elif op['opcode'] == 'LOAD_NAME' or op['opcode'] == 'LOAD_ATTR' \ + or op['opcode'] == 'LOAD_GLOBAL': + # Loading the given variable. + var = op['oparg2'] + v = self.variables[var] + if v[1] == '': + # The variable value hasn't changed after creation. Send + # the current value as the old value so a value is drawn + # during visualization. + v[1] = v[0] + viscommands += 'LOAD:' + var + ':' + str(v[0]) + \ + ':' + str(v[1]) + ';' + lastvals.append([var, v[0]]) + + elif op['opcode'] == 'LOAD_FAST': + varname = op['oparg2'] + if self.fast.has_key(varname): + lastvals.append(self.fast[varname]) + + elif op['opcode'] == 'LOAD_LOCALS': + lastvals.append(['oev_temp', 'locals']) elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR' \ or op['opcode'] == 'STORE_GLOBAL': # Storing the last constant in the given variable. var = op['oparg2'] - const_name, const_value = lastvals.pop() - if const_name == 'oev_function': - self.variables[const_value] = const_value - viscommands += 'SHOW_FUNCTION:' + const_value + ';' + const_type, const_value = lastvals.pop() + if const_type == 'oev_class' or const_type == 'oev_function': + self.variables[const_value] = [const_value, ''] continue if self.variables.has_key(var): - tmp = self.variables[var] - v = [const_value, tmp[0]] + class_type = self.variables[var] + v = [const_value, class_type[0]] else: v = [const_value, ''] self.variables[var] = v viscommands += 'STORE_VARIABLE:' + var + ':' + \ - str(v[0]) + ':' + str(v[1]) + ':' + const_name + ';' + str(v[0]) + ':' + str(v[1]) + ':' + const_type + ';' + + elif op['opcode'] == 'STORE_FAST': + storename = op['oparg2'] + vartype, varname = lastvals.pop() + if self.structure.has_key(varname): + vartype = self.structure[varname] + self.fast[storename] = [vartype, varname] elif op['opcode'] == 'MAKE_FUNCTION': - tmp, name = lastvals.pop() - lastvals.append(['oev_function', name]) + # TODO: Handle argument of MAKE_FUNCTION (pop function's + # default parameters from the stack). + old_type, function_name = lastvals.pop() + self.structure[function_name] = 'oev_function' + viscommands += 'SHOW_FUNCTION_CREATION:' + function_name + ';' + lastvals.append(['oev_function', function_name]) elif op['opcode'] == 'CALL_FUNCTION': - func, name = lastvals.pop() - if func == 'oev_function': - viscommands += 'CREATE_FUNCTION:' + name + ';' + # TODO: Handle argument of CALL_FUNCTION (pop function's + # arguments from the stack). + temp, function_name = lastvals.pop() + if self.structure.has_key(function_name): + function_type = self.structure[function_name] + viscommands += 'SHOW_FUNCTION_CALL:' + function_name + \ + ':' + function_type + ';' + if function_type == 'oev_class': + # XXX A hack to keep structure tracking in order. + viscommands += \ + 'SHOW_FUNCTION_CALL:__init__:oev_function;' else: - print "Expected a function for CALL_FUNCTION!" + print "Expected a function for CALL_FUNCTION! Got :", \ + func, " ", function_name + lastvals.append([temp, function_name]) + + elif op['opcode'] == 'BUILD_CLASS': + bases_type, bases_tuple = lastvals.pop() + old_type, class_name = lastvals.pop() + self.structure[class_name] = 'oev_class' + lastvals.append(['oev_class', class_name]) elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' - elif op['opcode'] == 'LOAD_NAME' or op['opcode'] == 'LOAD_ATTR' \ - or op['opcode'] == 'LOAD_GLOBAL': - # Loading the given variable. - var = op['oparg2'] - try: - v = self.variables[var] - viscommands += 'LOAD:' + var + ':' + str(v[0]) + \ - ':' + str(v[1]) + ';' - lastvals.append([var, v[0]]) - 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:' + var + ':' + '' +':' + \ - '' + ';' - elif op['opcode'] == 'COMPARE_OP': r_name, r_value = lastvals.pop() l_name, l_value = lastvals.pop() viscommands += 'COMPARE:' + op['oparg2'] + ':' + \ str(l_name) + ':' + str(l_value) + ':' + \ str(r_name) + ':' + str(r_value) + ';' + lastvals.append(['oev_temp', 'comparison_result']) elif op['opcode'] == 'INPLACE_ADD': r_name, r_value = lastvals.pop() @@ -141,8 +184,8 @@ elif op['opcode'] == 'BUILD_TUPLE': if int(op['oparg1']) < 1: - # XXX I'm not sure what to do, but this works reasonably - # well. + # XXX This probably isn't the right thing to do, but + # pushing empty tuples on the stack creates a mess. continue tail = [] t = () @@ -152,13 +195,27 @@ for i in loops: item = tail.pop(), t = t + item - lastvals.append(t) + lastvals.append(['oev_tuple', t]) elif op['opcode'] == 'UNPACK_SEQUENCE': sequence = lastvals.pop() for i in range(int(op['oparg1'])): lastvals.append(sequence[-(i+1)]) + elif op['opcode'] == 'POP_TOP': + # TODO: How each bytecode actually affects the stack is still + # unclear to me, so we can't just pop always or we might pop + # from an empty stack. The problem with this approach, of + # course, is that we might pop something that shouldn't be + # popped. The right way to fix this is to make sure every + # bytecode affects our stack as it should. + if lastvals: + lastvals.pop() + + + elif op['opcode'] == 'POP_BLOCK': + viscommands += 'EXIT_BLOCK' + elif op['opcode'] == 'PRINT_ITEM': name, output = lastvals.pop() viscommands += 'OUTPUT:' + str(output) + ':' + \ @@ -168,29 +225,15 @@ viscommands += 'OUTPUT:\n:'';' elif op['opcode'] == 'RETURN_VALUE': + lastvals.pop() viscommands += 'RETURN;' - #elif opcode['opcode'] == : - # pass - #elif opcode['opcode'] == : - # pass - #elif opcode['opcode'] == : - # pass - - elif op['opcode'] == 'JUMP_IF_FALSE': - # Not visualized in visualization area. - pass - elif op['opcode'] == 'JUMP_ABSOLUTE': - # Not visualized in visualization area. - pass - elif op['opcode'] == 'POP_TOP': - # XXX Needed? - pass - elif op['opcode'] == 'POP_BLOCK': - # XXX Needed? - pass else: print "Not supported in translator yet: ", op + if lastvals: + remain_type, remain_value = lastvals.pop() + if remain_type == 'oev_class': + viscommands += 'DUMMY_MOVE_DOWN' #print "DEBUG: vc == ", viscommands return viscommands @@ -212,6 +255,12 @@ # 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__', '']} + # The structure elements we need to track. + # Key is the element name. + # Value is the element type. + self.structure = {} + # A dictionary for STORE_FAST and LOAD_FAST. + self.fast = {} try: statement = compile(code, "", 'exec') except: Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- openexvis.py 20 Aug 2005 19:46:45 -0000 1.23 +++ openexvis.py 26 Aug 2005 16:10:37 -0000 1.24 @@ -1,6 +1,10 @@ #!/usr/bin/env python -"""OpenExVis GTK user interface.""" +""" +openexvis.py +OpenExVis GTK user interface. +Copyright (C) 2005 Tero Kuusela +""" import gtk import gtk.glade @@ -10,6 +14,7 @@ import pango import sys import time +import traceback import visualizer @@ -20,6 +25,7 @@ visualizer.OevVisualizer.__init__(self) self.version = "0.3.0-pre" + self.structure = [] # Build the UI self.build_gui() @@ -64,6 +70,7 @@ 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') + self.struct_color = self.colormap.alloc_color('#FFFFCC') # Make sure the visualization area doesn't get too small. self.vArea.set_size_request(200, 300) self.set_positions() @@ -160,6 +167,11 @@ self.pixmap.draw_layout(self.gc, 10, self.const_split + 5, const_title) self.pixmap.draw_layout(self.gc, self.vis_split_x + 10, \ self.eval_split + 5, eval_title) + if self.structure: + for name in self.structure: + data = self.vis_permanent_pixmaps[name[0]] + self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ + data[1], data[2], -1, -1) def draw_step(self, lineno, viscommands): """Draw one visualization step.""" @@ -168,6 +180,8 @@ self.vis_pixmaps = {} # Mark the line we're visualizing on the code area. vis_code = self.mark_line(lineno) + # Create the animation pixmaps. + self.update_pixmaps(vis_code, viscommands) # If the line is marked, we should skip it. Note that the buffer counts # from 0 but the user visually sees a line one further. line_iter = self.cBuf.get_iter_at_line(lineno-1) @@ -176,8 +190,7 @@ line_markers = self.cBuf.get_markers_in_region(line_iter, end_iter) if line_markers: return True - # Create the animation pixmaps. - self.update_pixmaps(vis_code, viscommands) + # Animate the visualization step. for elem in self.vis_steps: if not elem[0] == 'oev_non_animation': # Update the visualization area. @@ -187,10 +200,15 @@ if elem[1] == 'output': ei = self.oArea.get_buffer().get_end_iter() self.oArea.get_buffer().insert(ei, elem[2]) - elif elem[1] == 'function': - self.vis_permanents.append([elem[2], \ - self.gridw, self.gridh]) - self.refresh() + elif elem[1] == 'structure': + direction = elem[2] + if direction == 'UP': + #print "DEBUG: About to pop from structure, which is ",\ + #self.structure + self.structure.pop() + elif direction == 'DOWN': + pass + 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 @@ -204,11 +222,11 @@ def update_pixmaps(self, vis_code, visinfo): """Update the pixmaps to draw on the visualization area.""" self.oevWindow.queue_draw() - #print "\nDEBUG: The data:\n", visinfo + #print "\nDEBUG: visinfo == ", visinfo self.clear_visualization_area() self.cur_vars = {} for cmd in visinfo: - #print "DEBUG: cmd == ", cmd + #print "\nDEBUG: 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 @@ -237,9 +255,13 @@ continue self.draw_show_storing(cmd[1], cmd[2], cmd[3]) - elif cmd[0] == 'SHOW_FUNCTION': + elif cmd[0] == 'SHOW_CREATE_FUNCTION': # cmd[1] is the function name. - self.draw_show_function(cmd[1]) + self.draw_show_create_function(cmd[1]) + + elif cmd[0] == 'SHOW_CALL_FUNCTION': + # cmd[1] is the function name. + self.draw_show_call_function(cmd[1]) elif cmd[0] == 'SHOW_COMPARISON': # cmd[1] is the comparison sign (==,<,>) @@ -306,6 +328,23 @@ right = 'const_' + str(cmd[5]) self.draw_show_eval(left, cmd[1], right, str(result)) + elif cmd[0] == 'SHOW_LOOP': + self.loop_name_counter = self.loop_name_counter + 1 + self.draw_show_loop(str(self.loop_name_counter)) + + elif cmd[0] == 'MOVE_IN_STRUCTURE': + # cmd[1] is the direction to move to, either UP or DOWN. + if cmd[1] == 'UP': + self.struct_level -= 1 + self.vis_steps.append(['oev_non_animation', \ + 'structure', 'UP']) + elif cmd[1] == 'DOWN': + self.struct_level += 1 + self.vis_steps.append(['oev_non_animation', \ + 'structure', 'DOWN']) + + elif cmd[0] == 'SHOW_DUMMY_STRUCTURE': + self.draw_show_dummy_structure() else: if cmd[0]: print "Visualizing ", cmd[0], " not supported." @@ -354,12 +393,17 @@ # This makes things a bit slower but makes sure we don't erase # other elements on our way. self.clear_visualization_area() - self.draw_non_moving() + for name in self.vis_drawn: + data = self.vis_pixmaps[name[0]] + self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ + data[1], data[2], -1, -1) # Draw the element. self.pixmap.draw_drawable(self.gc, pm[0], 0, 0, pm[1], pm[2], \ -1, -1) self.refresh() # Higher speed setting gives higher speed like this. + # TODO: We are way too slow, even without sleeping here the + # visualization isn't very fast. time.sleep((11-self.speed) * 0.05) # NOTE: To grok the following draw_show_* methods, see do_frame_pixmap. @@ -371,30 +415,56 @@ self.vis_steps.append(['oev_delay_pm', self.vis_split_x, \ self.gridh * steps]) - def draw_non_moving(self): - """Draw the visualized objects not currently moving.""" - for name in self.vis_permanents: - data = self.vis_permanent_pixmaps[name[0]] - self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ - data[1], data[2], -1, -1) - for name in self.vis_drawn: - data = self.vis_pixmaps[name[0]] - self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ - data[1], data[2], -1, -1) + def draw_show_dummy_structure(self): + """Add an invisible element to the structure.""" + if not self.vis_pixmaps.has_key('oev_dummy_structure'): + self.create_element_pixmap('oev_dummy_structure', \ + self.vis_split_x, 0, self.object_bg_color, 1, 1, \ + '', permanent = True) + self.structure.append(['oev_dummy_structure', self.vis_split_x, 0]) - def draw_show_function(self, function): + def draw_show_loop(self, name): + """Add a loop to the structure.""" + name = 'oev_loop' + name + x = self.gridw * self.struct_level + y = self.gridh * self.struct_level + color = self.struct_color + w = self.vis_split_x - (x + self.gridw) + h = self.const_split - (y + self.gridh) + txt = 'Looping...' + self.create_element_pixmap(name, x, y, color, w, h, txt, \ + permanent = True) + #print "DEBUG: Appending to structure in d_s_l" + self.structure.append([name, \ + self.gridw * self.struct_level, \ + self.gridh * self.struct_level]) + self.draw_delay(5) + + def draw_show_create_function(self, function): """Store displaying a function to self.vis_steps.""" name = 'oev_function_' + function - x = self.gridw - y = self.gridh - color = self.static_const_color - w = self.vis_split_x - self.gridw - h = self.const_split - self.gridh + x = self.gridw * self.struct_level + y = self.gridh * self.struct_level + color = self.struct_color + w = self.vis_split_x - (x + self.gridw) + h = self.const_split - (y + self.gridh) txt = function self.create_element_pixmap(name, x, y, color, w, h, txt, \ permanent = True) - self.vis_steps.append(['const_' + function, self.gridw, self.gridh]) - self.vis_steps.append(['oev_non_animation', 'function', name]) + self.vis_steps.append(['const_' + function, x, y]) + #print "DEBUG: Appending to structure in d_cr_f" + self.structure.append([name, \ + self.gridw * self.struct_level, \ + self.gridh * self.struct_level]) + self.draw_delay(5) + + def draw_show_call_function(self, function): + """Store displaying a function to self.vis_steps.""" + name = 'oev_function_' + function + #print "DEBUG: Appending to structure in d_ca_f" + self.structure.append([name, \ + self.gridw * self.struct_level, \ + self.gridh * self.struct_level]) self.draw_delay(5) def draw_show_output(self, output, source): @@ -526,7 +596,7 @@ pmname = 'result_' + const else: # The source should be another variable. - pmname = source + pmname = source + '_value' self.vis_steps.append([pmname, endx, endy]) def create_element_pixmap(self, name, x, y, fgc, w, h, txt, \ @@ -602,6 +672,7 @@ except: print "Failed to load file ", filename return False + self.structure = [] # To clear the structure area. self.clear_visualization_area() self.oArea.get_buffer().set_text('') self.cBuf.set_text(code) @@ -625,13 +696,26 @@ return self.cBuf.get_text(si, ei) def do_visualization(self): + # Clear the output area. self.oArea.get_buffer().set_text('') - self.vis_permanents = [] + # Visualization run -specific variables. + self.structure = [] self.vis_permanent_pixmaps = {} + self.struct_level = 0 + self.loop_name_counter = 1 # Make sure the UI only calls visualize() once for one # visualization. self.cArea.set_sensitive(False) - self.visualize(self.get_code()) + try: + self.visualize(self.get_code()) + except: + version = sys.version_info + if version[0] >= 2 and version [1] >= 4: + err = traceback.format_exc() + else: + err = '' + traceback.print_exc() + self.draw_step(1, [['OUTPUT', 'Exception occurred!\n' + err, '']]) self.cArea.set_sensitive(True) Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- visualizer.py 18 Aug 2005 15:11:39 -0000 1.13 +++ visualizer.py 26 Aug 2005 16:10:37 -0000 1.14 @@ -1,9 +1,11 @@ -"""The OpenExVis visualizer. +""" +The OpenExVis visualizer. Transfers the visualization data it receives from an OpenExVis translator into visualization commands used by the UI to show the visualization. OpenExVis user interfaces should inherit the visualizer. +Copyright (C) 2005 Tero Kuusela """ # TODO: Is inheritance the correct solution? @@ -57,10 +59,10 @@ cur_consts = [] for item in data: c = item.split(':') - #print "DEBUG: c == ", c + #print "\nDEBUG: c == ", c if c[0] == '': continue - elif c[0] == 'GET_CONSTANT': + elif c[0] == 'LOAD_CONSTANT': # c[1] is the constant to show. cur_consts.append(c[1]) cmd.append(['SHOW_CONSTANTS', cur_consts]) @@ -79,13 +81,18 @@ if not cur_vars.has_key(c[1]): cur_vars[c[1]] = [c[2], c[3]] cmd.append(['SHOW_VARIABLES', cur_vars]) - elif c[0] == 'SHOW_FUNCTION': + elif c[0] == 'SHOW_FUNCTION_CREATION': # c[1] is the function name. - cmd.append(['SHOW_FUNCTION', c[1]]) - elif c[0] == 'CREATE_FUNCTION': + cmd.append(['MOVE_IN_STRUCTURE', 'DOWN']) + cmd.append(['SHOW_CREATE_FUNCTION', c[1]]) + cmd.append(['MOVE_IN_STRUCTURE', 'UP']) + elif c[0] == 'SHOW_FUNCTION_CALL': # c[1] is the function name. - cmd.append(['SHOW_FUNCTION', c[1]]) + # c[2] is the function type (oev_function or oev_class) + cmd.append(['MOVE_IN_STRUCTURE', 'DOWN']) + cmd.append(['SHOW_CALL_FUNCTION', c[1]]) elif c[0] == 'BEGIN_LOOP': + cmd.append(['MOVE_IN_STRUCTURE', 'DOWN']) cmd.append(['SHOW_LOOP']) elif c[0] == 'COMPARE': # c[1] is the sign of the comparison. @@ -106,14 +113,23 @@ # c[5] is the value of the right side of the operation. cmd.append(['SHOW_OPERATION', c[1], c[2], int(c[3]), \ c[4], int(c[5])]) + elif c[0] == 'OUTPUT': # c[1] is the string to output. # c[2] is the variable name of the string, None if the value is # is a constant or '' for a newline. - # TODO: Think if this newline system is reasonable. cmd.append(['OUTPUT', c[1], c[2]]) + + elif c[0] == 'EXIT_BLOCK': + cmd.append(['MOVE_IN_STRUCTURE', 'UP']) + elif c[0] == 'RETURN': - cmd.append(['RETURN']) + cmd.append(['MOVE_IN_STRUCTURE', 'UP']) + + elif c[0] == 'DUMMY_MOVE_DOWN': + cmd.append(['MOVE_IN_STRUCTURE', 'DOWN']) + cmd.append(['SHOW_DUMMY_STRUCTURE']) + else: print "No drawing command for ", c[0], ". Whole list was: ", c return cmd Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- ChangeLog 18 Aug 2005 15:11:39 -0000 1.16 +++ ChangeLog 26 Aug 2005 16:10:37 -0000 1.17 @@ -5,12 +5,13 @@ * Internal restructuring * Improve the animation a lot - * First step to support visualizing the structure of a program - * Support new byte codes in Python translator - + BUILD_TUPLE - + UNPACK_SEQUENCE - + MAKE_FUNCTION - + CALL_FUNCTION + * Exceptions while visualizing now cause visualization to stop and provide some + information to the output area. OpenExVis still becomes unusable, though, + will look into that. + * Support visualizing the structure of a program to some extent + * Support some new byte codes in Python translator + * When storing from one variable to another, now move the variable value in + the visualization instead of its name * Constants to move now leave from the position of the corresponding static constant * Moving items to output is now visualized |
From: Tero K. <te...@us...> - 2005-08-20 19:46:53
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6114 Modified Files: openexvis.py Log Message: Further work towards visualizing the program structure. Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- openexvis.py 18 Aug 2005 15:11:39 -0000 1.22 +++ openexvis.py 20 Aug 2005 19:46:45 -0000 1.23 @@ -187,6 +187,10 @@ if elem[1] == 'output': ei = self.oArea.get_buffer().get_end_iter() self.oArea.get_buffer().insert(ei, elem[2]) + elif elem[1] == 'function': + self.vis_permanents.append([elem[2], \ + self.gridw, self.gridh]) + self.refresh() 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 @@ -349,12 +353,8 @@ more_for_element = False # This makes things a bit slower but makes sure we don't erase # other elements on our way. - pmw, pmh = pm[0].get_size() self.clear_visualization_area() - for name in self.vis_drawn: - data = self.vis_pixmaps[name[0]] - self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ - data[1], data[2], -1, -1) + self.draw_non_moving() # Draw the element. self.pixmap.draw_drawable(self.gc, pm[0], 0, 0, pm[1], pm[2], \ -1, -1) @@ -371,9 +371,30 @@ self.vis_steps.append(['oev_delay_pm', self.vis_split_x, \ self.gridh * steps]) + def draw_non_moving(self): + """Draw the visualized objects not currently moving.""" + for name in self.vis_permanents: + data = self.vis_permanent_pixmaps[name[0]] + self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ + data[1], data[2], -1, -1) + for name in self.vis_drawn: + data = self.vis_pixmaps[name[0]] + self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ + data[1], data[2], -1, -1) + def draw_show_function(self, function): """Store displaying a function to self.vis_steps.""" + name = 'oev_function_' + function + x = self.gridw + y = self.gridh + color = self.static_const_color + w = self.vis_split_x - self.gridw + h = self.const_split - self.gridh + txt = function + self.create_element_pixmap(name, x, y, color, w, h, txt, \ + permanent = True) self.vis_steps.append(['const_' + function, self.gridw, self.gridh]) + self.vis_steps.append(['oev_non_animation', 'function', name]) self.draw_delay(5) def draw_show_output(self, output, source): @@ -508,7 +529,8 @@ pmname = source self.vis_steps.append([pmname, endx, endy]) - def create_element_pixmap(self, name, x, y, fgc, w, h, txt): + def create_element_pixmap(self, name, x, y, fgc, w, h, txt, \ + permanent = False): """Build a pixmap for an element of a visualization.""" gc = self.vDraw.new_gc() pm = gtk.gdk.Pixmap(self.vDraw, w, h) @@ -519,7 +541,8 @@ layout = self.vArea.create_pango_layout(txt) pm.draw_layout(self.gc, 2, 2, layout) self.vis_pixmaps[name] = [pm, x, y] - return pm + if permanent: + self.vis_permanent_pixmaps[name] = [pm, x, y] def refresh(self): """Refresh the OpenExVis window.""" @@ -603,6 +626,8 @@ def do_visualization(self): self.oArea.get_buffer().set_text('') + self.vis_permanents = [] + self.vis_permanent_pixmaps = {} # Make sure the UI only calls visualize() once for one # visualization. self.cArea.set_sensitive(False) |
From: Tero K. <te...@us...> - 2005-08-19 00:13:27
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8769 Modified Files: ChangeLog oevt_python.py openexvis.py visualizer.py Log Message: First steps towards supporting visualization of program structure. Some fixes. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- oevt_python.py 17 Aug 2005 00:28:45 -0000 1.12 +++ oevt_python.py 18 Aug 2005 15:11:39 -0000 1.13 @@ -52,12 +52,15 @@ # Remove the line number from the data and store it at the beginning of # the visualization commands. viscommands = str(data.pop(0)) + ';' - # In the following, the first list item tells the variable name. If the - # first item is None, it means the value is a constant. The second item - # is the actual value. + # In the following, the first list item tells the variable name. + # If the first item is None, it means the value is a constant. If it's + # oev_function, the value is a function name. + # The second item is the actual value. lastvals = [] # Last loaded values for op in data: - print "DEBUG: op == ", op + #print "DEBUG: lastvals == ", lastvals + #print "DEBUG: variables == ", self.variables + #print "DEBUG: op == ", op if op['opcode'] == 'LOAD_CONST': # Loading a constant. @@ -66,24 +69,41 @@ const = split[2] else: const = op['oparg2'] + if const[0] == "'" and const[-1] == "'": + const = const[1:-1] viscommands += 'GET_CONSTANT:' + const + ';' # Load the given constant to lastval. lastvals.append(['None', const]) - elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': + elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR' \ + or op['opcode'] == 'STORE_GLOBAL': # Storing the last constant in the given variable. var = op['oparg2'] const_name, const_value = lastvals.pop() + if const_name == 'oev_function': + self.variables[const_value] = const_value + viscommands += 'SHOW_FUNCTION:' + const_value + ';' + continue if self.variables.has_key(var): tmp = self.variables[var] v = [const_value, tmp[0]] else: v = [const_value, ''] self.variables[var] = v - print "DEBUG: variables == ", self.variables viscommands += 'STORE_VARIABLE:' + var + ':' + \ str(v[0]) + ':' + str(v[1]) + ':' + const_name + ';' + elif op['opcode'] == 'MAKE_FUNCTION': + tmp, name = lastvals.pop() + lastvals.append(['oev_function', name]) + + elif op['opcode'] == 'CALL_FUNCTION': + func, name = lastvals.pop() + if func == 'oev_function': + viscommands += 'CREATE_FUNCTION:' + name + ';' + else: + print "Expected a function for CALL_FUNCTION!" + elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' @@ -120,12 +140,24 @@ lastvals.append(['eval_result', sum]) elif op['opcode'] == 'BUILD_TUPLE': + if int(op['oparg1']) < 1: + # XXX I'm not sure what to do, but this works reasonably + # well. + continue tail = [] + t = () loops = range(int(op['oparg1'])) for i in loops: - tail.insert(0, lastvals.pop()) + tail.append(lastvals.pop()) for i in loops: - lastvals.append(tail.pop()) + item = tail.pop(), + t = t + item + lastvals.append(t) + + elif op['opcode'] == 'UNPACK_SEQUENCE': + sequence = lastvals.pop() + for i in range(int(op['oparg1'])): + lastvals.append(sequence[-(i+1)]) elif op['opcode'] == 'PRINT_ITEM': name, output = lastvals.pop() Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- openexvis.py 17 Aug 2005 00:39:43 -0000 1.21 +++ openexvis.py 18 Aug 2005 15:11:39 -0000 1.22 @@ -233,6 +233,10 @@ continue self.draw_show_storing(cmd[1], cmd[2], cmd[3]) + elif cmd[0] == 'SHOW_FUNCTION': + # cmd[1] is the function name. + self.draw_show_function(cmd[1]) + elif cmd[0] == 'SHOW_COMPARISON': # cmd[1] is the comparison sign (==,<,>) # cmd[2] is the variable on the left side of the comparison or @@ -367,6 +371,11 @@ self.vis_steps.append(['oev_delay_pm', self.vis_split_x, \ self.gridh * steps]) + def draw_show_function(self, function): + """Store displaying a function to self.vis_steps.""" + self.vis_steps.append(['const_' + function, self.gridw, self.gridh]) + self.draw_delay(5) + def draw_show_output(self, output, source): """Store drawing an output to self.vis_steps.""" if source == 'None': Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- visualizer.py 16 Aug 2005 23:14:37 -0000 1.12 +++ visualizer.py 18 Aug 2005 15:11:39 -0000 1.13 @@ -79,25 +79,31 @@ if not cur_vars.has_key(c[1]): cur_vars[c[1]] = [c[2], c[3]] cmd.append(['SHOW_VARIABLES', cur_vars]) + elif c[0] == 'SHOW_FUNCTION': + # c[1] is the function name. + cmd.append(['SHOW_FUNCTION', c[1]]) + elif c[0] == 'CREATE_FUNCTION': + # c[1] is the function name. + cmd.append(['SHOW_FUNCTION', c[1]]) elif c[0] == 'BEGIN_LOOP': cmd.append(['SHOW_LOOP']) elif c[0] == 'COMPARE': # c[1] is the sign of the comparison. - # cmd[2] is the variable on the left side of the comparison or + # c[2] is the variable on the left side of the comparison or # None if the value is a constant. - # cmd[3] is the value of the left side of the comparison. - # cmd[4] is the variable on the right side of the comparison or + # c[3] is the value of the left side of the comparison. + # c[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. + # c[5] is the value of the right side of the comparison. cmd.append(['SHOW_COMPARISON', c[1], c[2], c[3], c[4], c[5]]) elif c[0] == 'SHOW_INT_OPERATION': # c[1] is the sign of the operation. - # cmd[2] is the variable on the left side of the operation or + # c[2] is the variable on the left side of the operation or # None if the value is a constant. - # cmd[3] is the value of the left side of the operation. - # cmd[4] is the variable on the right side of the operation or + # c[3] is the value of the left side of the operation. + # c[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. + # c[5] is the value of the right side of the operation. cmd.append(['SHOW_OPERATION', c[1], c[2], int(c[3]), \ c[4], int(c[5])]) elif c[0] == 'OUTPUT': Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- ChangeLog 17 Aug 2005 00:39:43 -0000 1.15 +++ ChangeLog 18 Aug 2005 15:11:39 -0000 1.16 @@ -5,9 +5,14 @@ * Internal restructuring * Improve the animation a lot + * First step to support visualizing the structure of a program + * Support new byte codes in Python translator + + BUILD_TUPLE + + UNPACK_SEQUENCE + + MAKE_FUNCTION + + CALL_FUNCTION * Constants to move now leave from the position of the corresponding static constant - * Support BUILD_TUPLE in Python translator * Moving items to output is now visualized * Storing to variable from evaluation result now better visualized * Draw elements in more intelligent order |
From: Tero K. <te...@us...> - 2005-08-17 00:39:51
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14333 Modified Files: ChangeLog openexvis.py Log Message: Constants now leave from their corresponding static constant. Update changelog for previous commit as well. Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- openexvis.py 17 Aug 2005 00:06:01 -0000 1.20 +++ openexvis.py 17 Aug 2005 00:39:43 -0000 1.21 @@ -481,13 +481,14 @@ def draw_show_storing(self, const, var, source): """Store a constant moved to a variable in the visualization pixmap.""" - startx = self.const_start[0] - starty = self.const_start[1] endx = self.vis_pixmaps[var + '_value'][1] endy = self.vis_pixmaps[var + '_value'][2] w = self.gridw * 2 h = self.gridh if source == 'None': + staticpm = 'const_' + const + startx = self.vis_pixmaps[staticpm][1] + starty = self.vis_pixmaps[staticpm][2] pmname = 'move_const_' + const self.create_element_pixmap(pmname, startx, starty,\ self.moving_const_color, w, h, const) Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- ChangeLog 16 Aug 2005 19:37:57 -0000 1.14 +++ ChangeLog 17 Aug 2005 00:39:43 -0000 1.15 @@ -5,6 +5,9 @@ * Internal restructuring * Improve the animation a lot + * Constants to move now leave from the position of the corresponding static + constant + * Support BUILD_TUPLE in Python translator * Moving items to output is now visualized * Storing to variable from evaluation result now better visualized * Draw elements in more intelligent order |
From: Tero K. <te...@us...> - 2005-08-17 00:28:54
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11947 Modified Files: oevt_python.py Log Message: Support BUILD_TUPLE. Now a,b,c=1,2,3 puts the values to correct variables in the visualization. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- oevt_python.py 17 Aug 2005 00:06:01 -0000 1.11 +++ oevt_python.py 17 Aug 2005 00:28:45 -0000 1.12 @@ -119,10 +119,13 @@ sum = int(l_value) + int(r_value) lastvals.append(['eval_result', sum]) - #elif op['opcode'] == 'BUILD_TUPLE': - # last = lastvals.pop() - # tupled = lastvals.pop(), last - # lastvals.append(tupled) + elif op['opcode'] == 'BUILD_TUPLE': + tail = [] + loops = range(int(op['oparg1'])) + for i in loops: + tail.insert(0, lastvals.pop()) + for i in loops: + lastvals.append(tail.pop()) elif op['opcode'] == 'PRINT_ITEM': name, output = lastvals.pop() |
From: Tero K. <te...@us...> - 2005-08-17 00:06:17
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7368 Modified Files: oevt_python.py openexvis.py Log Message: Ugh. Using a stack to track the values in memory should've been obvious from the start. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- oevt_python.py 16 Aug 2005 23:14:37 -0000 1.10 +++ oevt_python.py 17 Aug 2005 00:06:01 -0000 1.11 @@ -55,10 +55,9 @@ # In the following, the first list item tells the variable name. If the # first item is None, it means the value is a constant. The second item # is the actual value. - lastval = ['None', 'None'] # Last loaded value - olderval = ['None', 'None'] # Value loaded before lastval + lastvals = [] # Last loaded values for op in data: - #print "DEBUG: op == ", op + print "DEBUG: op == ", op if op['opcode'] == 'LOAD_CONST': # Loading a constant. @@ -69,58 +68,66 @@ const = op['oparg2'] viscommands += 'GET_CONSTANT:' + const + ';' # Load the given constant to lastval. - olderval = lastval - lastval = ['None', const] + lastvals.append(['None', const]) elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': # Storing the last constant in the given variable. - if self.variables.has_key(op['oparg2']): - tmp = self.variables[op['oparg2']] - v = [lastval[1], tmp[0]] + var = op['oparg2'] + const_name, const_value = lastvals.pop() + if self.variables.has_key(var): + tmp = self.variables[var] + v = [const_value, tmp[0]] else: - v = [lastval[1], ''] - self.variables[op['oparg2']] = v + v = [const_value, ''] + self.variables[var] = v print "DEBUG: variables == ", self.variables - viscommands += 'STORE_VARIABLE:' + op['oparg2'] + ':' + \ - str(v[0]) + ':' + str(v[1]) + ':' + lastval[0] + ';' + viscommands += 'STORE_VARIABLE:' + var + ':' + \ + str(v[0]) + ':' + str(v[1]) + ':' + const_name + ';' elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' - elif op['opcode'] == 'LOAD_NAME' or op['opcode'] == 'LOAD_ATTR': + elif op['opcode'] == 'LOAD_NAME' or op['opcode'] == 'LOAD_ATTR' \ + or op['opcode'] == 'LOAD_GLOBAL': # Loading the given variable. + var = op['oparg2'] try: - # op['oparg2'] is the variable name. - v = self.variables[op['oparg2']] - viscommands += 'LOAD:' + op['oparg2'] + ':' + str(v[0]) + \ + v = self.variables[var] + viscommands += 'LOAD:' + var + ':' + str(v[0]) + \ ':' + str(v[1]) + ';' - olderval = lastval - lastval = [op['oparg2'], v[0]] + lastvals.append([var, v[0]]) 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'] + ':' + '' +':' + \ + viscommands += 'LOAD:' + var + ':' + '' +':' + \ '' + ';' elif op['opcode'] == 'COMPARE_OP': + r_name, r_value = lastvals.pop() + l_name, l_value = lastvals.pop() viscommands += 'COMPARE:' + op['oparg2'] + ':' + \ - str(olderval[0]) + ':' + str(olderval[1]) + ':' + \ - str(lastval[0]) + ':' + str(lastval[1]) + ';' + str(l_name) + ':' + str(l_value) + ':' + \ + str(r_name) + ':' + str(r_value) + ';' elif op['opcode'] == 'INPLACE_ADD': - #print "DEBUG: older, last == ", olderval, " ", lastval + r_name, r_value = lastvals.pop() + l_name, l_value = lastvals.pop() viscommands += 'SHOW_INT_OPERATION:+:' + \ - str(olderval[0]) + ':' + str(olderval[1]) + ':' + \ - str(lastval[0]) + ':' + str(lastval[1]) + ';' - tmp = lastval - lastval[0] = 'eval_result' - lastval[1] = int(lastval[1]) + int(olderval[1]) - olderval = tmp + str(l_name) + ':' + str(l_value) + ':' + \ + str(r_name) + ':' + str(r_value) + ';' + sum = int(l_value) + int(r_value) + lastvals.append(['eval_result', sum]) + + #elif op['opcode'] == 'BUILD_TUPLE': + # last = lastvals.pop() + # tupled = lastvals.pop(), last + # lastvals.append(tupled) elif op['opcode'] == 'PRINT_ITEM': - viscommands += 'OUTPUT:' + str(lastval[1]) + ':' + \ - str(lastval[0]) +';' + name, output = lastvals.pop() + viscommands += 'OUTPUT:' + str(output) + ':' + \ + str(name) +';' elif op['opcode'] == 'PRINT_NEWLINE': viscommands += 'OUTPUT:\n:'';' Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- openexvis.py 16 Aug 2005 23:14:37 -0000 1.19 +++ openexvis.py 17 Aug 2005 00:06:01 -0000 1.20 @@ -495,7 +495,7 @@ pmname = 'result_' + const else: # The source should be another variable. - source == source + pmname = source self.vis_steps.append([pmname, endx, endy]) def create_element_pixmap(self, name, x, y, fgc, w, h, txt): |
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]) |
From: Tero K. <te...@us...> - 2005-08-16 19:38:05
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14590 Modified Files: ChangeLog oevt_python.py openexvis.py visualizer.py Log Message: Visualize producing output. Some small fixes. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- oevt_python.py 15 Aug 2005 23:36:15 -0000 1.8 +++ oevt_python.py 16 Aug 2005 19:37:57 -0000 1.9 @@ -55,8 +55,8 @@ # In the following, the first list item tells the variable name. If the # first item is None, it means the value is a constant. The second item # is the actual value. - lastval = [None, None] # Last loaded value - olderval = [None, None] # Value loaded before lastval + lastval = ['None', 'None'] # Last loaded value + olderval = ['None', 'None'] # Value loaded before lastval for op in data: #print "DEBUG: op == ", op @@ -65,7 +65,7 @@ viscommands += 'GET_CONSTANT:' + op['oparg2'] + ';' # Load the given constant to lastval. olderval = lastval - lastval = [None, op['oparg2']] + lastval = ['None', op['oparg2']] elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': # Storing the last constant in the given variable. @@ -77,7 +77,7 @@ self.variables[op['oparg2']] = v #print "DEBUG: variables == ", self.variables viscommands += 'STORE_VARIABLE:' + op['oparg2'] + ':' + \ - str(v[0]) + ':' + str(v[1]) + ';' + str(v[0]) + ':' + str(v[1]) + ':' + lastval[0] + ';' elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' @@ -109,15 +109,16 @@ str(olderval[0]) + ':' + str(olderval[1]) + ':' + \ str(lastval[0]) + ':' + str(lastval[1]) + ';' tmp = lastval - lastval[0] = None + lastval[0] = 'eval_result' lastval[1] = int(lastval[1]) + int(olderval[1]) olderval = tmp elif op['opcode'] == 'PRINT_ITEM': - viscommands += 'OUTPUT:' + str(lastval[1]) + ';' + viscommands += 'OUTPUT:' + str(lastval[1]) + ':' + \ + str(lastval[0]) +';' elif op['opcode'] == 'PRINT_NEWLINE': - viscommands += 'OUTPUT:\n;' + viscommands += 'OUTPUT:\n:'';' elif op['opcode'] == 'RETURN_VALUE': viscommands += 'RETURN;' Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- openexvis.py 16 Aug 2005 17:24:46 -0000 1.17 +++ openexvis.py 16 Aug 2005 19:37:57 -0000 1.18 @@ -132,7 +132,8 @@ """Clear the visualization area.""" # The image we store is a pixmap. Here we draw the visualization area # on it. - self.pixmap = gtk.gdk.Pixmap(self.vDraw, self.vis_width, self.vis_height) + self.pixmap = gtk.gdk.Pixmap(self.vDraw, self.vis_width, \ + self.vis_height) # Fill the background with white. self.pixmap.draw_rectangle(self.vArea.get_style().white_gc, True, 0, \ 0, self.vis_width, self.vis_height) @@ -176,8 +177,13 @@ # Create the animation pixmaps. self.update_pixmaps(vis_code, viscommands) for elem in self.vis_steps: - # Update the visualization area. - self.animate_element(elem) + if not elem[0] == 'oev_non_animation': + # Update the visualization area. + self.animate_element(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: @@ -199,24 +205,28 @@ #print "DEBUG: cmd == ", cmd if cmd[0] == 'OUTPUT': # cmd[1] is the string to output. - ei = self.oArea.get_buffer().get_end_iter() - self.oArea.get_buffer().insert(ei, cmd[1]) + # cmd[2] is the variable name of the string, None if the value is + # 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 list, where: - # [0] is the variable name to store to. - # [1] is the variable's new value. - # [2] is the variable's old value. - for v in cmd[1]: - self.cur_vars[v[0]] = [v[1], v[2]] + # cmd[1] is the variable dictionary, where: + # key is the variable name to store to and + # value is the variable's value list, where: + # value_list[0] is the variable's new value. + # value_list[1] is the variable's old value. + 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. - if cmd[1] != 'None': - self.draw_show_storing(cmd[1], cmd[2]) + # cmd[3] is the source to store from. + 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 @@ -325,6 +335,10 @@ elif pm[2] > elem[2]: pm[2] -= self.gridh more_for_element = True + if pm[1] < 0 or pm[1] > self.vis_width or \ + pm[2] < 0 or pm[2] > self.vis_height: + # We have moved outside the screen. + more_for_element = False # This makes things a bit slower but makes sure we don't erase # other elements on our way. pmw, pmh = pm[0].get_size() @@ -349,6 +363,25 @@ self.vis_steps.append(['oev_delay_pm', self.vis_split_x, \ self.gridh * steps]) + def draw_show_output(self, output, source): + """Store drawing an output to self.vis_steps.""" + if self.vis_pixmaps.has_key('result_' + source): + pmname = 'result_' + source + elif self.vis_pixmaps.has_key('const_' + source): + pmname = 'const_' + source + elif self.vis_pixmaps.has_key('move_const_' + source): + pmname = 'move_const_' + source + elif self.vis_pixmaps.has_key(source + '_value'): + self.draw_show_variables(False) + pmname = source + '_value' + else: + pmname = None + if pmname: + endx = self.eval_result_pos[0] + endy = self.vis_height + self.gridh + self.vis_steps.append([pmname, endx, endy]) + self.vis_steps.append(['oev_non_animation', 'output', output]) + def draw_show_eval(self, left, sign, right, result): """Store the steps to draw an evaluation to self.vis_steps.""" # Create a pixmap for the result and the sign. @@ -431,7 +464,7 @@ self.vis_steps.append([pmname, x, y]) pos += 1 - def draw_show_storing(self, const, var): + def draw_show_storing(self, const, var, source): """Store a constant moved to a variable in the visualization pixmap.""" startx = self.const_start[0] starty = self.const_start[1] @@ -439,9 +472,15 @@ endy = self.vis_pixmaps[var + '_value'][2] w = self.gridw * 2 h = self.gridh - pmname = 'move_const_' + const - self.create_element_pixmap(pmname, startx, starty,\ - self.const_color, w, h, const) + if source == 'None': + pmname = 'move_const_' + const + self.create_element_pixmap(pmname, startx, starty,\ + self.const_color, w, h, const) + elif source == 'eval_result': + pmname = 'result_' + const + else: + # The source should be another variable. + source == source self.vis_steps.append([pmname, endx, endy]) def create_element_pixmap(self, name, x, y, fgc, w, h, txt): Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- visualizer.py 15 Aug 2005 23:36:15 -0000 1.10 +++ visualizer.py 16 Aug 2005 19:37:57 -0000 1.11 @@ -53,7 +53,7 @@ # should be documented well somewhere. Now they're not as they're still # evolving. cmd = [] - cur_vars = [] + cur_vars = {} cur_consts = [] for item in data: c = item.split(':') @@ -66,14 +66,16 @@ # c[1] is the variable name to store to. # c[2] is the variable's new value. # c[3] is the variable's old value. - cur_vars.append([c[1], c[2], c[3]]) + # c[4] is the source to store from. + cur_vars[c[1]] = [c[2], c[3]] cmd.append(['SHOW_VARIABLES', cur_vars]) - cmd.append(['SHOW_STORING', c[2], c[1]]) + cmd.append(['SHOW_STORING', c[2], c[1], c[4]]) elif c[0] == 'LOAD': # c[1] is the variable name. # c[2] is the variable value. # c[3] is the variable's old value - cur_vars.append([c[1], c[2], c[3]]) + if not cur_vars.has_key(c[1]): + cur_vars[c[1]] = [c[2], c[3]] cmd.append(['SHOW_VARIABLES', cur_vars]) elif c[0] == 'BEGIN_LOOP': cmd.append(['SHOW_LOOP']) @@ -98,7 +100,10 @@ c[4], int(c[5])]) elif c[0] == 'OUTPUT': # c[1] is the string to output. - cmd.append(['OUTPUT', c[1]]) + # c[2] is the variable name of the string, None if the value is + # is a constant or '' for a newline. + # TODO: Think if this newline system is reasonable. + cmd.append(['OUTPUT', c[1], c[2]]) elif c[0] == 'RETURN': cmd.append(['RETURN']) else: Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- ChangeLog 16 Aug 2005 14:14:57 -0000 1.13 +++ ChangeLog 16 Aug 2005 19:37:57 -0000 1.14 @@ -5,6 +5,8 @@ * Internal restructuring * Improve the animation a lot + * Moving items to output is now visualized + * Storing to variable from evaluation result now better visualized * Draw elements in more intelligent order * Correct variable values shown when visualizing an evaluation * The screen is now cleaned up when a new file is loaded |
From: Tero K. <te...@us...> - 2005-08-16 17:25:00
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11037 Modified Files: openexvis.py Log Message: Add ability to place delays in the animation. Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- openexvis.py 16 Aug 2005 14:14:57 -0000 1.16 +++ openexvis.py 16 Aug 2005 17:24:46 -0000 1.17 @@ -341,19 +341,25 @@ time.sleep((11-self.speed) * 0.05) # NOTE: To grok the following draw_show_* methods, see do_frame_pixmap. + def draw_delay(self, steps): + """Add a delay to the animation.""" + if not self.vis_pixmaps.has_key('oev_delay_pm'): + self.create_element_pixmap('oev_delay_pm', self.vis_split_x, 0, \ + self.object_bg_color, 1, 1, '') + self.vis_steps.append(['oev_delay_pm', self.vis_split_x, \ + self.gridh * steps]) + def draw_show_eval(self, left, sign, right, result): """Store the steps to draw an evaluation to self.vis_steps.""" # Create a pixmap for the result and the sign. # The result. res_x = self.eval_result_pos[0] - res_ex = self.eval_result_pos[0] + self.gridw * 2 # Hack to delay a bit res_y = self.eval_result_pos[1] res_w = self.gridw * 2 # The sign. sx = self.eval_sign_pos[0] sy = self.eval_sign_pos[1] sw = self.gridw * 1 - stxt = self.vArea.create_pango_layout(sign) # Height is same for both h = self.gridh if result == 'TRUE': @@ -362,11 +368,10 @@ res_fg = self.bool_false_color else: res_fg = self.const_color - res_txt = self.vArea.create_pango_layout(result) self.create_element_pixmap('result_' + result, res_x, res_y, \ - res_fg, res_w, h, res_txt) + res_fg, res_w, h, result) self.create_element_pixmap(sign, sx, sy, \ - self.const_color, sw, h, stxt) + self.const_color, sw, h, sign) # Names to use the correct pixmaps. result = 'result_' + result # Create the animation. @@ -379,6 +384,7 @@ self.eval_right_pos[0], self.eval_right_pos[1]]) self.vis_steps.append([result, \ self.eval_result_pos[0], self.eval_result_pos[1]]) + self.draw_delay(5) def draw_show_variables(self, old): """Store displaying the variables to self.vis_steps.""" @@ -394,15 +400,15 @@ vy = self.var_value_pos[1] - (self.gridh * pos) vw = self.gridw * 2 if old: - vtxt = self.vArea.create_pango_layout(value[1]) + vtxt = value[1] else: - vtxt = self.vArea.create_pango_layout(value[0]) + vtxt = value[0] # Height is same for both h = self.gridh pm1 = name pm2 = name + '_value' self.create_element_pixmap(pm1, nx, ny, \ - self.var_color, nw, h, ntxt) + self.var_color, nw, h, name) self.create_element_pixmap(pm2, vx, vy, \ self.var_color, vw, h, vtxt) self.vis_steps.append([pm1, nx, ny]) @@ -419,10 +425,9 @@ y = self.const_start[1] + (self.gridh * pos) w = self.gridw * 2 h = self.gridh - txt = self.vArea.create_pango_layout(const) pmname = 'const_' + const self.create_element_pixmap(pmname, x, y, \ - self.static_const_color, w, h, txt) + self.static_const_color, w, h, const) self.vis_steps.append([pmname, x, y]) pos += 1 @@ -434,10 +439,9 @@ endy = self.vis_pixmaps[var + '_value'][2] w = self.gridw * 2 h = self.gridh - txt = self.vArea.create_pango_layout(const) pmname = 'move_const_' + const self.create_element_pixmap(pmname, startx, starty,\ - self.const_color, w, h, txt) + self.const_color, w, h, const) self.vis_steps.append([pmname, endx, endy]) def create_element_pixmap(self, name, x, y, fgc, w, h, txt): @@ -448,7 +452,8 @@ pm.draw_rectangle(gc, True, 0, 0, w, h) gc.set_foreground(fgc) pm.draw_rectangle(gc, True, 1, 1, w - 2, h - 2) - pm.draw_layout(self.gc, 2, 2, txt) + layout = self.vArea.create_pango_layout(txt) + pm.draw_layout(self.gc, 2, 2, layout) self.vis_pixmaps[name] = [pm, x, y] return pm |
From: Tero K. <te...@us...> - 2005-08-16 14:15:05
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28646 Modified Files: ChangeLog openexvis.py Log Message: Don't draw all the pixmaps when animating, just those that should be shown at the moment. Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- openexvis.py 16 Aug 2005 14:01:16 -0000 1.15 +++ openexvis.py 16 Aug 2005 14:14:57 -0000 1.16 @@ -161,6 +161,7 @@ def draw_step(self, lineno, viscommands): """Draw one visualization step.""" self.vis_steps = [] + self.vis_drawn = [] self.vis_pixmaps = {} # Mark the line we're visualizing on the code area. vis_code = self.mark_line(lineno) @@ -177,6 +178,7 @@ for elem in self.vis_steps: # Update the visualization area. self.animate_element(elem) + 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 @@ -327,7 +329,8 @@ # other elements on our way. pmw, pmh = pm[0].get_size() self.clear_visualization_area() - for name, data in self.vis_pixmaps.iteritems(): + for name in self.vis_drawn: + data = self.vis_pixmaps[name[0]] self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ data[1], data[2], -1, -1) # Draw the element. Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- ChangeLog 16 Aug 2005 14:01:16 -0000 1.12 +++ ChangeLog 16 Aug 2005 14:14:57 -0000 1.13 @@ -5,6 +5,7 @@ * Internal restructuring * Improve the animation a lot + * Draw elements in more intelligent order * Correct variable values shown when visualizing an evaluation * The screen is now cleaned up when a new file is loaded * The output area is cleared when beginning a new visualization |
From: Tero K. <te...@us...> - 2005-08-16 14:01:27
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23924 Modified Files: ChangeLog openexvis.py Log Message: Some box size adjustments. Correct variable value shown in evaluations. Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- openexvis.py 15 Aug 2005 23:36:15 -0000 1.14 +++ openexvis.py 16 Aug 2005 14:01:16 -0000 1.15 @@ -192,6 +192,7 @@ self.oevWindow.queue_draw() #print "\nDEBUG: The data:\n", visinfo self.clear_visualization_area() + self.cur_vars = {} for cmd in visinfo: #print "DEBUG: cmd == ", cmd if cmd[0] == 'OUTPUT': @@ -202,8 +203,13 @@ # cmd[1] is the constant list. self.draw_show_constants(cmd[1]) elif cmd[0] == 'SHOW_VARIABLES': - # cmd[1] is the variable list. - self.draw_show_variables(cmd[1]) + # cmd[1] is the variable list, where: + # [0] is the variable name to store to. + # [1] is the variable's new value. + # [2] is the variable's old value. + for v in cmd[1]: + self.cur_vars[v[0]] = [v[1], v[2]] + 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. @@ -333,16 +339,17 @@ # NOTE: To grok the following draw_show_* methods, see do_frame_pixmap. def draw_show_eval(self, left, sign, right, result): + """Store the steps to draw an evaluation to self.vis_steps.""" # Create a pixmap for the result and the sign. # The result. res_x = self.eval_result_pos[0] res_ex = self.eval_result_pos[0] + self.gridw * 2 # Hack to delay a bit res_y = self.eval_result_pos[1] - res_w = self.gridw * 3 + res_w = self.gridw * 2 # The sign. sx = self.eval_sign_pos[0] sy = self.eval_sign_pos[1] - sw = self.gridw * 2 + sw = self.gridw * 1 stxt = self.vArea.create_pango_layout(sign) # Height is same for both h = self.gridh @@ -360,6 +367,7 @@ # Names to use the correct pixmaps. result = 'result_' + result # Create the animation. + self.draw_show_variables(False) self.vis_steps.append([left, \ self.eval_left_pos[0], self.eval_left_pos[1]]) self.vis_steps.append([sign, \ @@ -369,24 +377,27 @@ self.vis_steps.append([result, \ self.eval_result_pos[0], self.eval_result_pos[1]]) - def draw_show_variables(self, cur_vars): - """Store displaying the variables in the visualization pixmap.""" + def draw_show_variables(self, old): + """Store displaying the variables to self.vis_steps.""" pos = 0 - for v in cur_vars: + for name, value in self.cur_vars.iteritems(): # Variable name. nx = self.var_name_pos[0] ny = self.var_name_pos[1] - (self.gridh * pos) - nw = self.gridw * 5 - ntxt = self.vArea.create_pango_layout(v[0]) + nw = self.gridw * 4 + ntxt = self.vArea.create_pango_layout(name) # Variable value. vx = self.var_value_pos[0] vy = self.var_value_pos[1] - (self.gridh * pos) vw = self.gridw * 2 - vtxt = self.vArea.create_pango_layout(v[2]) + if old: + vtxt = self.vArea.create_pango_layout(value[1]) + else: + vtxt = self.vArea.create_pango_layout(value[0]) # Height is same for both h = self.gridh - pm1 = v[0] - pm2 = v[0] + '_value' + pm1 = name + pm2 = name + '_value' self.create_element_pixmap(pm1, nx, ny, \ self.var_color, nw, h, ntxt) self.create_element_pixmap(pm2, vx, vy, \ Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- ChangeLog 15 Aug 2005 23:36:15 -0000 1.11 +++ ChangeLog 16 Aug 2005 14:01:16 -0000 1.12 @@ -5,6 +5,7 @@ * Internal restructuring * Improve the animation a lot + * Correct variable values shown when visualizing an evaluation * The screen is now cleaned up when a new file is loaded * The output area is cleared when beginning a new visualization * Fix showing integer calculation result |
From: Tero K. <te...@us...> - 2005-08-15 23:36:25
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13582 Modified Files: ChangeLog oevt_python.py openexvis.py visualizer.py Log Message: Further visualization improvements. Visualization area now cleared when a file is loaded. Output area likewise and also when starting a new visualization. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- oevt_python.py 15 Aug 2005 20:36:04 -0000 1.7 +++ oevt_python.py 15 Aug 2005 23:36:15 -0000 1.8 @@ -49,67 +49,86 @@ # 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 + # Remove the line number from the data and store it at the beginning of + # the visualization commands. + viscommands = str(data.pop(0)) + ';' + # In the following, the first list item tells the variable name. If the + # first item is None, it means the value is a constant. The second item + # is the actual value. + lastval = [None, None] # Last loaded value + olderval = [None, None] # Value loaded before lastval for op in data: #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'] + # Load the given constant to lastval. + olderval = lastval + lastval = [None, op['oparg2']] + elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': # Storing the last constant in the given variable. if self.variables.has_key(op['oparg2']): tmp = self.variables[op['oparg2']] - v = [lastconst, tmp[0]] + v = [lastval[1], tmp[0]] else: - v = [lastconst, ''] + v = [lastval[1], ''] self.variables[op['oparg2']] = v #print "DEBUG: variables == ", self.variables viscommands += 'STORE_VARIABLE:' + op['oparg2'] + ':' + \ str(v[0]) + ':' + str(v[1]) + ';' + elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' + elif op['opcode'] == 'LOAD_NAME' or op['opcode'] == 'LOAD_ATTR': # Loading the given variable. try: + # op['oparg2'] is the variable name. v = self.variables[op['oparg2']] viscommands += 'LOAD:' + op['oparg2'] + ':' + str(v[0]) + \ ':' + str(v[1]) + ';' - olderconst = lastconst - lastconst = v[0] + olderval = lastval + lastval = [op['oparg2'], v[0]] 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) + ';' + str(olderval[0]) + ':' + str(olderval[1]) + ':' + \ + str(lastval[0]) + ':' + str(lastval[1]) + ';' + elif op['opcode'] == 'INPLACE_ADD': - #print "DEBUG: older, last == ", olderconst, " ", lastconst - viscommands += 'SHOW_INT_OPERATION:+:' + str(lastconst) + \ - ':' + str(olderconst) + ';' - tmp = lastconst - lastconst = int(lastconst) + int(olderconst) - olderconst = tmp + #print "DEBUG: older, last == ", olderval, " ", lastval + viscommands += 'SHOW_INT_OPERATION:+:' + \ + str(olderval[0]) + ':' + str(olderval[1]) + ':' + \ + str(lastval[0]) + ':' + str(lastval[1]) + ';' + tmp = lastval + lastval[0] = None + lastval[1] = int(lastval[1]) + int(olderval[1]) + olderval = tmp + elif op['opcode'] == 'PRINT_ITEM': - viscommands += 'OUTPUT:' + str(lastconst) + ';' + viscommands += 'OUTPUT:' + str(lastval[1]) + ';' + elif op['opcode'] == 'PRINT_NEWLINE': viscommands += 'OUTPUT:\n;' + elif op['opcode'] == 'RETURN_VALUE': viscommands += 'RETURN;' + #elif opcode['opcode'] == : # pass #elif opcode['opcode'] == : # pass #elif opcode['opcode'] == : # pass + elif op['opcode'] == 'JUMP_IF_FALSE': # Not visualized in visualization area. pass @@ -123,7 +142,7 @@ # XXX Needed? pass else: - pass + print "Not supported in translator yet: ", op #print "DEBUG: vc == ", viscommands return viscommands Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- openexvis.py 15 Aug 2005 20:36:04 -0000 1.13 +++ openexvis.py 15 Aug 2005 23:36:15 -0000 1.14 @@ -96,7 +96,7 @@ self.const_split = self.gridh * 9 self.eval_split = self.gridh * 12 # Some important locations for drawing the visualization. - self.const_start = (self.vis_split_x - self.gridw * 3, \ + self.const_start = (self.vis_split_x - self.gridw * 4, \ self.const_split + self.gridh * 1) self.var_name_pos = (self.vis_split_x + self.gridw * 1, \ self.eval_split - self.gridh * 3) @@ -160,7 +160,8 @@ def draw_step(self, lineno, viscommands): """Draw one visualization step.""" - self.vis_pixmaps = [] + self.vis_steps = [] + self.vis_pixmaps = {} # Mark the line we're visualizing on the code area. vis_code = self.mark_line(lineno) # If the line is marked, we should skip it. Note that the buffer counts @@ -173,7 +174,7 @@ return True # Create the animation pixmaps. self.update_pixmaps(vis_code, viscommands) - for elem in self.vis_pixmaps: + for elem in self.vis_steps: # Update the visualization area. self.animate_element(elem) if self.do_steps: @@ -210,62 +211,89 @@ self.draw_show_storing(cmd[1], cmd[2]) elif cmd[0] == 'SHOW_COMPARISON': # cmd[1] is the comparison sign (==,<,>) - # cmd[2] is the left side of the comparison. - # cmd[3] is the right side of the comparison. + # cmd[2] is the variable on the left side of the comparison or + # None if the value is a constant. + # cmd[3] is the value of the left side of the comparison. + # 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[2] == cmd[3]: + if cmd[3] == cmd[5]: result = 'TRUE' else: result = 'FALSE' elif cmd[1] == '<': - if cmd[2] < cmd[3]: + if cmd[3] < cmd[5]: result = 'TRUE' else: result = 'FALSE' elif cmd[1] == '>': - if cmd[2] > cmd[3]: + if cmd[3] > cmd[5]: result = 'TRUE' else: result = 'FALSE' else: - print "Unsupported comparison: ", cmd[1] + print "Unsupported comparison operation: ", cmd[1] continue - self.draw_show_eval(cmd[2], cmd[1], cmd[3], result) + if cmd[2] != 'None': + left = str(cmd[2]) + '_value' + else: + left = 'const_' + str(cmd[3]) + if cmd[4] != 'None': + right = str(cmd[4]) + '_value' + 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 left side of the operation. - # cmd[3] is the right side of the operation. + # cmd[2] is the variable on the left side of the operation or + # None if the value is a constant. + # cmd[3] is the value of the left side of the operation. + # 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[2] + cmd[3] + result = cmd[3] + cmd[5] elif cmd[1] == '-': - result = cmd[2] - cmd[3] + result = cmd[3] - cmd[5] elif cmd[1] == '*': - result = cmd[2] * cmd[3] + result = cmd[3] * cmd[5] elif cmd[1] == '/': - result = cmd[2] / cmd[3] + result = cmd[3] / cmd[5] else: - print "Unsupported comparison: ", cmd[1] + print "Unsupported operation: ", cmd[1] continue - self.draw_show_eval(str(cmd[2]), cmd[1], str(cmd[3]), \ - str(result)) + if cmd[2] != 'None': + left = str(cmd[2]) + '_value' + else: + left = 'const_' + str(cmd[3]) + if cmd[4] != 'None': + right = str(cmd[4]) + '_value' + else: + right = 'const_' + str(cmd[5]) + self.draw_show_eval(left, cmd[1], right, str(result)) else: - print "Visualizing ", cmd[0], " not supported." + if cmd[0]: + print "Visualizing ", cmd[0], " not supported." return True def animate_element(self, elem): """Draw one animation frame. - Parameter elem is self.vispixmaps[i], where: - i[0] is current x, i[1] is x to move to - i[2] is current y, i[3] is y to move to - i[4] is the pixmap to draw on main pixmap + Parameter elem is self.vis_steps[i], where: + i[0] is the pixmap name + i[1] is the x coordinate to move to + i[2] is the y coordinate to move to """ # This is now so that horizontal movement always comes before vertical. # It might not be desireable in all cases. Figure that out when such a # situation arises. + pm = self.vis_pixmaps[elem[0]] more_for_element = True while more_for_element: while gtk.events_pending(): @@ -275,55 +303,49 @@ gtk.main_iteration() more_for_element = False # Move the element if needed. - prevx = elem[0] - prevy = elem[2] - if elem[0] < elem[1]: - elem[0] += self.gridw + prevx = pm[1] + prevy = pm[2] + if pm[1] < elem[1]: + pm[1] += self.gridw more_for_element = True - elif elem[0] > elem[1]: - elem[0] -= self.gridw + elif pm[1] > elem[1]: + pm[1] -= self.gridw more_for_element = True - elif elem[2] < elem[3]: - elem[2] += self.gridh + elif pm[2] < elem[2]: + pm[2] += self.gridh more_for_element = True - elif elem[2] > elem[3]: - elem[2] -= self.gridh + elif pm[2] > elem[2]: + pm[2] -= self.gridh more_for_element = True - # Clear the last position of the element. - pmw, pmh = elem[4].get_size() - self.pixmap.draw_rectangle(self.vArea.get_style().white_gc, True, \ - prevx, prevy, pmw, pmh) + # This makes things a bit slower but makes sure we don't erase + # other elements on our way. + pmw, pmh = pm[0].get_size() + self.clear_visualization_area() + for name, data in self.vis_pixmaps.iteritems(): + self.pixmap.draw_drawable(self.gc, data[0], 0, 0, \ + data[1], data[2], -1, -1) # Draw the element. - self.pixmap.draw_drawable(self.gc, elem[4], 0, 0, elem[0], elem[2], -1, -1) - self.refresh_screen() + self.pixmap.draw_drawable(self.gc, pm[0], 0, 0, pm[1], pm[2], \ + -1, -1) + self.refresh() # Higher speed setting gives higher speed like this. time.sleep((11-self.speed) * 0.05) # NOTE: To grok the following draw_show_* methods, see do_frame_pixmap. def draw_show_eval(self, left, sign, right, result): - """Store an evaluation in the visualization pixmap.""" - # The left side of the evaluation. - lx = self.eval_left_pos[0] - ly = self.eval_left_pos[1] - lw = self.gridw * 3 - ltxt = self.vArea.create_pango_layout(left) + # Create a pixmap for the result and the sign. + # The result. + res_x = self.eval_result_pos[0] + res_ex = self.eval_result_pos[0] + self.gridw * 2 # Hack to delay a bit + res_y = self.eval_result_pos[1] + res_w = self.gridw * 3 # The sign. sx = self.eval_sign_pos[0] sy = self.eval_sign_pos[1] sw = self.gridw * 2 stxt = self.vArea.create_pango_layout(sign) - # 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 + # Height is same for both + h = self.gridh if result == 'TRUE': res_fg = self.bool_true_color elif result == 'FALSE': @@ -331,17 +353,21 @@ 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. - pm1 = self.create_element_pixmap(self.var_color, lw, h, ltxt) - pm2 = self.create_element_pixmap(self.const_color, sw, h, stxt) - pm3 = self.create_element_pixmap(self.var_color, rw, h, rtxt) - pm4 = self.create_element_pixmap(res_fg, res_w, h, res_txt) - self.vis_pixmaps.append([lx, lx, ly, ly, pm1]) - self.vis_pixmaps.append([sx, sx, sy, sy, pm2]) - self.vis_pixmaps.append([rx, rx, ry, ry, pm3]) - self.vis_pixmaps.append([res_x, res_x, res_y, res_y, pm4]) + self.create_element_pixmap('result_' + result, res_x, res_y, \ + res_fg, res_w, h, res_txt) + self.create_element_pixmap(sign, sx, sy, \ + self.const_color, sw, h, stxt) + # Names to use the correct pixmaps. + result = 'result_' + result + # Create the animation. + self.vis_steps.append([left, \ + self.eval_left_pos[0], self.eval_left_pos[1]]) + self.vis_steps.append([sign, \ + 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([result, \ + self.eval_result_pos[0], self.eval_result_pos[1]]) def draw_show_variables(self, cur_vars): """Store displaying the variables in the visualization pixmap.""" @@ -359,43 +385,48 @@ vtxt = self.vArea.create_pango_layout(v[2]) # Height is same for both h = self.gridh - pm1 = self.create_element_pixmap(self.var_color, nw, h, ntxt) - pm2 = self.create_element_pixmap(self.var_color, vw, h, vtxt) - self.vis_pixmaps.append([nx, nx, ny, ny, pm1]) - self.vis_pixmaps.append([vx, vx, vy, vy, pm2]) + pm1 = v[0] + pm2 = v[0] + '_value' + self.create_element_pixmap(pm1, nx, ny, \ + self.var_color, nw, h, ntxt) + self.create_element_pixmap(pm2, vx, vy, \ + self.var_color, vw, h, vtxt) + self.vis_steps.append([pm1, nx, ny]) + self.vis_steps.append([pm2, vx, vy]) pos += 1 def draw_show_constants(self, cur_consts): """Store displaying the constants in the visualization pixmap.""" pos = 0 - for c in cur_consts: - print "DEBUG: c == ", c - if c == 'None': + for const in cur_consts: + if const == 'None': continue - # We draw the static constants one column left from where moving - # ones start. - x = self.const_start[0] - self.gridw + x = self.const_start[0] y = self.const_start[1] + (self.gridh * pos) w = self.gridw * 2 h = self.gridh - txt = self.vArea.create_pango_layout(c[:8]) - pm = self.create_element_pixmap(self.static_const_color, w, h, txt) - self.vis_pixmaps.append([x, x, y, y, pm]) + txt = self.vArea.create_pango_layout(const) + pmname = 'const_' + const + self.create_element_pixmap(pmname, x, y, \ + self.static_const_color, w, h, txt) + self.vis_steps.append([pmname, x, y]) pos += 1 def draw_show_storing(self, const, var): """Store a constant moved to a variable in the visualization pixmap.""" startx = self.const_start[0] starty = self.const_start[1] - endx = self.var_value_pos[0] - endy = self.var_value_pos[1] + endx = self.vis_pixmaps[var + '_value'][1] + endy = self.vis_pixmaps[var + '_value'][2] w = self.gridw * 2 h = self.gridh - txt = self.vArea.create_pango_layout(const[:8]) - pm = self.create_element_pixmap(self.const_color, w, h, txt) - self.vis_pixmaps.append([startx, endx, starty, endy, pm]) + txt = self.vArea.create_pango_layout(const) + pmname = 'move_const_' + const + self.create_element_pixmap(pmname, startx, starty,\ + self.const_color, w, h, txt) + self.vis_steps.append([pmname, endx, endy]) - def create_element_pixmap(self, fgc, w, h, txt): + def create_element_pixmap(self, name, x, y, fgc, w, h, txt): """Build a pixmap for an element of a visualization.""" gc = self.vDraw.new_gc() pm = gtk.gdk.Pixmap(self.vDraw, w, h) @@ -404,9 +435,10 @@ gc.set_foreground(fgc) pm.draw_rectangle(gc, True, 1, 1, w - 2, h - 2) pm.draw_layout(self.gc, 2, 2, txt) + self.vis_pixmaps[name] = [pm, x, y] return pm - def refresh_screen(self): + def refresh(self): """Refresh the OpenExVis window.""" w = self.oevWindow.window w.invalidate_rect(self.oevWindow.allocation, True) @@ -464,11 +496,14 @@ except: print "Failed to load file ", filename return False + self.clear_visualization_area() + self.oArea.get_buffer().set_text('') self.cBuf.set_text(code) self.cBuf.set_data('filename', path) self.cBuf.end_not_undoable_action() self.cBuf.set_modified(False) self.cBuf.place_cursor(self.cBuf.get_start_iter()) + self.refresh() print "Loaded ", filename def save_file(self, filename): @@ -484,6 +519,7 @@ return self.cBuf.get_text(si, ei) def do_visualization(self): + self.oArea.get_buffer().set_text('') # Make sure the UI only calls visualize() once for one # visualization. self.cArea.set_sensitive(False) Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- visualizer.py 15 Aug 2005 20:36:04 -0000 1.9 +++ visualizer.py 15 Aug 2005 23:36:15 -0000 1.10 @@ -79,14 +79,23 @@ cmd.append(['SHOW_LOOP']) elif c[0] == 'COMPARE': # c[1] is the sign of the comparison. - # 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]]) + # cmd[2] is the variable on the left side of the comparison or + # None if the value is a constant. + # cmd[3] is the value of the left side of the comparison. + # 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. + cmd.append(['SHOW_COMPARISON', c[1], c[2], c[3], c[4], c[5]]) elif c[0] == 'SHOW_INT_OPERATION': # c[1] is the sign of the operation. - # c[2] is the left side of the operation. - # c[3] is the right side of the operation. - cmd.append(['SHOW_OPERATION', c[1], int(c[2]), int(c[3])]) + # cmd[2] is the variable on the left side of the operation or + # None if the value is a constant. + # cmd[3] is the value of the left side of the operation. + # 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. + cmd.append(['SHOW_OPERATION', c[1], c[2], int(c[3]), \ + c[4], int(c[5])]) elif c[0] == 'OUTPUT': # c[1] is the string to output. cmd.append(['OUTPUT', c[1]]) Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- ChangeLog 15 Aug 2005 20:36:04 -0000 1.10 +++ ChangeLog 15 Aug 2005 23:36:15 -0000 1.11 @@ -4,7 +4,9 @@ CVS * Internal restructuring - * Improve the animation + * Improve the animation a lot + * The screen is now cleaned up when a new file is loaded + * The output area is cleared when beginning a new visualization * Fix showing integer calculation result * When storing to a variable, the old value is now shown and new value moved on top of it |
From: Tero K. <te...@us...> - 2005-08-15 20:36:14
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv735 Modified Files: ChangeLog oevt_python.py openexvis.py visualizer.py Log Message: Improve animation. Small fix to displaying interger calculation results. Restructure some code for future purposes. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- oevt_python.py 15 Aug 2005 18:34:16 -0000 1.6 +++ oevt_python.py 15 Aug 2005 20:36:04 -0000 1.7 @@ -93,8 +93,8 @@ str(olderconst) + ':' + str(lastconst) + ';' elif op['opcode'] == 'INPLACE_ADD': #print "DEBUG: older, last == ", olderconst, " ", lastconst - viscommands += 'ADD:' + str(lastconst) + ':' + str(olderconst)\ - + ';' + viscommands += 'SHOW_INT_OPERATION:+:' + str(lastconst) + \ + ':' + str(olderconst) + ';' tmp = lastconst lastconst = int(lastconst) + int(olderconst) olderconst = tmp Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- openexvis.py 15 Aug 2005 18:34:16 -0000 1.12 +++ openexvis.py 15 Aug 2005 20:36:04 -0000 1.13 @@ -173,15 +173,9 @@ return True # Create the animation pixmaps. self.update_pixmaps(vis_code, viscommands) - moresteps = True - while moresteps: - while not self.speed: - # We are paused. - gtk.main_iteration() - while gtk.events_pending(): - gtk.main_iteration() + for elem in self.vis_pixmaps: # Update the visualization area. - moresteps = self.draw_anim_frame() + self.animate_element(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 @@ -210,9 +204,10 @@ # 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. + # cmd[1] is a constant to store to a variable. + # cmd[2] is the variable to store to. if cmd[1] != 'None': - self.draw_show_storing(cmd[1]) + self.draw_show_storing(cmd[1], cmd[2]) elif cmd[0] == 'SHOW_COMPARISON': # cmd[1] is the comparison sign (==,<,>) # cmd[2] is the left side of the comparison. @@ -253,15 +248,16 @@ else: print "Unsupported comparison: ", cmd[1] continue - self.draw_show_eval(cmd[2], cmd[1], cmd[3], result) + self.draw_show_eval(str(cmd[2]), cmd[1], str(cmd[3]), \ + str(result)) else: print "Visualizing ", cmd[0], " not supported." return True - def draw_anim_frame(self): + def animate_element(self, elem): """Draw one animation frame. - In self.vispixmaps[i]: + Parameter elem is self.vispixmaps[i], where: i[0] is current x, i[1] is x to move to i[2] is current y, i[3] is y to move to i[4] is the pixmap to draw on main pixmap @@ -270,34 +266,38 @@ # This is now so that horizontal movement always comes before vertical. # It might not be desireable in all cases. Figure that out when such a # situation arises. - moresteps = False - for i in self.vis_pixmaps: - #print "DEBUG: vispixmaps[i] ", i + more_for_element = True + while more_for_element: + while gtk.events_pending(): + gtk.main_iteration() + while not self.speed: + # We are paused. + gtk.main_iteration() + more_for_element = False # Move the element if needed. - prevx = i[0] - prevy = i[2] - if i[0] < i[1]: - i[0] += self.gridw - moresteps = True - elif i[0] > i[1]: - i[0] -= self.gridw - moresteps = True - elif i[2] < i[3]: - i[2] += self.gridh - moresteps = True - elif i[2] > i[3]: - i[2] -= self.gridh - moresteps = True + prevx = elem[0] + prevy = elem[2] + if elem[0] < elem[1]: + elem[0] += self.gridw + more_for_element = True + elif elem[0] > elem[1]: + elem[0] -= self.gridw + more_for_element = True + elif elem[2] < elem[3]: + elem[2] += self.gridh + more_for_element = True + elif elem[2] > elem[3]: + elem[2] -= self.gridh + more_for_element = True # Clear the last position of the element. - pmw, pmh = i[4].get_size() + pmw, pmh = elem[4].get_size() self.pixmap.draw_rectangle(self.vArea.get_style().white_gc, True, \ prevx, prevy, pmw, pmh) # Draw the element. - self.pixmap.draw_drawable(self.gc, i[4], 0, 0, i[0], i[2], -1, -1) + self.pixmap.draw_drawable(self.gc, elem[4], 0, 0, elem[0], elem[2], -1, -1) self.refresh_screen() # Higher speed setting gives higher speed like this. time.sleep((11-self.speed) * 0.05) - return moresteps # NOTE: To grok the following draw_show_* methods, see do_frame_pixmap. def draw_show_eval(self, left, sign, right, result): @@ -334,11 +334,14 @@ # 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) + pm1 = self.create_element_pixmap(self.var_color, lw, h, ltxt) + pm2 = self.create_element_pixmap(self.const_color, sw, h, stxt) + pm3 = self.create_element_pixmap(self.var_color, rw, h, rtxt) + pm4 = self.create_element_pixmap(res_fg, res_w, h, res_txt) + self.vis_pixmaps.append([lx, lx, ly, ly, pm1]) + self.vis_pixmaps.append([sx, sx, sy, sy, pm2]) + self.vis_pixmaps.append([rx, rx, ry, ry, pm3]) + self.vis_pixmaps.append([res_x, res_x, res_y, res_y, pm4]) def draw_show_variables(self, cur_vars): """Store displaying the variables in the visualization pixmap.""" @@ -356,8 +359,10 @@ vtxt = self.vArea.create_pango_layout(v[2]) # Height is same for both h = self.gridh - self.do_frame_pixmap(self.var_color, nw, h, nx, nx, ny, ny, ntxt) - self.do_frame_pixmap(self.var_color, vw, h, vx, vx, vy, vy, vtxt) + pm1 = self.create_element_pixmap(self.var_color, nw, h, ntxt) + pm2 = self.create_element_pixmap(self.var_color, vw, h, vtxt) + self.vis_pixmaps.append([nx, nx, ny, ny, pm1]) + self.vis_pixmaps.append([vx, vx, vy, vy, pm2]) pos += 1 def draw_show_constants(self, cur_consts): @@ -374,10 +379,11 @@ w = self.gridw * 2 h = self.gridh txt = self.vArea.create_pango_layout(c[:8]) - self.do_frame_pixmap(self.static_const_color, w, h, x, x, y, y, txt) + pm = self.create_element_pixmap(self.static_const_color, w, h, txt) + self.vis_pixmaps.append([x, x, y, y, pm]) pos += 1 - def draw_show_storing(self, constant): + def draw_show_storing(self, const, var): """Store a constant moved to a variable in the visualization pixmap.""" startx = self.const_start[0] starty = self.const_start[1] @@ -385,17 +391,12 @@ endy = self.var_value_pos[1] w = self.gridw * 2 h = self.gridh - txt = self.vArea.create_pango_layout(constant[:8]) - self.do_frame_pixmap(self.const_color, w, h, startx, endx, \ - starty, endy, txt) - - def do_frame_pixmap(self, fgc, w, h, startx, endx, starty, endy, txt): - """Build a pixmap for an element of an animation frame. + txt = self.vArea.create_pango_layout(const[:8]) + pm = self.create_element_pixmap(self.const_color, w, h, txt) + self.vis_pixmaps.append([startx, endx, starty, endy, pm]) - This method gathers together everything needed from one item for the - draw_anim_frame() method from a pixmap and stores it in the - visualization pixmap list. - """ + def create_element_pixmap(self, fgc, w, h, txt): + """Build a pixmap for an element of a visualization.""" gc = self.vDraw.new_gc() pm = gtk.gdk.Pixmap(self.vDraw, w, h) gc.set_foreground(self.object_bg_color) @@ -403,7 +404,7 @@ gc.set_foreground(fgc) pm.draw_rectangle(gc, True, 1, 1, w - 2, h - 2) pm.draw_layout(self.gc, 2, 2, txt) - self.vis_pixmaps.append([startx, endx, starty, endy, pm]) + return pm def refresh_screen(self): """Refresh the OpenExVis window.""" @@ -612,7 +613,7 @@ d.set_website("http://openexvis.sourceforge.net/") d.set_authors(["Tero Kuusela"]) d.set_comments("OpenExVis is a tool to visualize program execution.\n"\ - + "It is mostly meant for educational purposes.") + + "It is mainly meant for educational purposes.") d.show() def on_visualizationArea_size_allocate(self, obj, event): @@ -637,7 +638,6 @@ int(event_x), int(event_y)) line_iter, line_top = self.cArea.get_line_at_y(y) lineno = line_iter.get_line() - print "About to set line marker at ", lineno end_iter = line_iter.copy() end_iter.forward_to_line_end() line_markers = self.cBuf.get_markers_in_region(line_iter, end_iter) Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- visualizer.py 15 Aug 2005 18:34:16 -0000 1.8 +++ visualizer.py 15 Aug 2005 20:36:04 -0000 1.9 @@ -61,7 +61,6 @@ if c[0] == 'GET_CONSTANT': # c[1] is the constant to show. cur_consts.append(c[1]) - print "DEBUG: cur_consts == ", cur_consts cmd.append(['SHOW_CONSTANTS', cur_consts]) elif c[0] == 'STORE_VARIABLE': # c[1] is the variable name to store to. @@ -79,14 +78,15 @@ elif c[0] == 'BEGIN_LOOP': cmd.append(['SHOW_LOOP']) elif c[0] == 'COMPARE': - # c[1] is the comparison sign. + # c[1] is the sign of the comparison. # 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] == 'SHOW_INT_OPERATION': + # c[1] is the sign of the operation. + # c[2] is the left side of the operation. + # c[3] is the right side of the operation. + cmd.append(['SHOW_OPERATION', c[1], int(c[2]), int(c[3])]) elif c[0] == 'OUTPUT': # c[1] is the string to output. cmd.append(['OUTPUT', c[1]]) Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- ChangeLog 15 Aug 2005 18:34:16 -0000 1.9 +++ ChangeLog 15 Aug 2005 20:36:04 -0000 1.10 @@ -3,6 +3,9 @@ CVS + * Internal restructuring + * Improve the animation + * Fix showing integer calculation result * When storing to a variable, the old value is now shown and new value moved on top of it * Visualization objects have a black border |
From: Tero K. <te...@us...> - 2005-08-15 18:34:25
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1648 Modified Files: ChangeLog oevt_python.py openexvis.py visualizer.py Log Message: Move the new value of a variable on top of the old one, which is now shown. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- oevt_python.py 15 Aug 2005 14:12:09 -0000 1.5 +++ oevt_python.py 15 Aug 2005 18:34:16 -0000 1.6 @@ -63,25 +63,31 @@ lastconst = op['oparg2'] elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': # Storing the last constant in the given variable. - self.variables[op['oparg2']] = lastconst + if self.variables.has_key(op['oparg2']): + tmp = self.variables[op['oparg2']] + v = [lastconst, tmp[0]] + else: + v = [lastconst, ''] + self.variables[op['oparg2']] = v #print "DEBUG: variables == ", self.variables viscommands += 'STORE_VARIABLE:' + op['oparg2'] + ':' + \ - str(self.variables[op['oparg2']]) + ':' + \ - str(lastconst) + ';' + str(v[0]) + ':' + str(v[1]) + ';' elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' elif op['opcode'] == 'LOAD_NAME' or op['opcode'] == 'LOAD_ATTR': # Loading the given variable. try: - viscommands += 'LOAD:' + op['oparg2'] + ':' + \ - str(self.variables[op['oparg2']]) + ';' + v = self.variables[op['oparg2']] + viscommands += 'LOAD:' + op['oparg2'] + ':' + str(v[0]) + \ + ':' + str(v[1]) + ';' olderconst = lastconst - lastconst = self.variables[op['oparg2']] + lastconst = v[0] 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'] + ':' + '' + ';' + viscommands += 'LOAD:' + op['oparg2'] + ':' + '' +':' + \ + '' + ';' elif op['opcode'] == 'COMPARE_OP': viscommands += 'COMPARE:' + op['oparg2'] + ':' + \ str(olderconst) + ':' + str(lastconst) + ';' Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- openexvis.py 15 Aug 2005 17:00:32 -0000 1.11 +++ openexvis.py 15 Aug 2005 18:34:16 -0000 1.12 @@ -98,9 +98,9 @@ # Some important locations for drawing the visualization. self.const_start = (self.vis_split_x - self.gridw * 3, \ self.const_split + self.gridh * 1) - self.const_end = (self.vis_split_x + self.gridw * 8, \ + self.var_name_pos = (self.vis_split_x + self.gridw * 1, \ self.eval_split - self.gridh * 3) - self.var_pos = (self.vis_split_x + self.gridw * 1, \ + self.var_value_pos = (self.vis_split_x + self.gridw * 8, \ self.eval_split - self.gridh * 3) self.eval_left_pos = (self.vis_split_x + self.gridw, \ self.eval_split + self.gridh * 1) @@ -171,7 +171,7 @@ line_markers = self.cBuf.get_markers_in_region(line_iter, end_iter) if line_markers: return True - # Update the visualization area. + # Create the animation pixmaps. self.update_pixmaps(vis_code, viscommands) moresteps = True while moresteps: @@ -180,6 +180,7 @@ gtk.main_iteration() while gtk.events_pending(): gtk.main_iteration() + # Update the visualization area. moresteps = self.draw_anim_frame() if self.do_steps: while self.do_steps and not self.step_fwd: @@ -343,12 +344,20 @@ """Store displaying the variables in the visualization pixmap.""" pos = 0 for v in cur_vars: - x = self.var_pos[0] - y = self.var_pos[1] - (self.gridh * pos) - w = self.gridw * 6 + # Variable name. + nx = self.var_name_pos[0] + ny = self.var_name_pos[1] - (self.gridh * pos) + nw = self.gridw * 5 + ntxt = self.vArea.create_pango_layout(v[0]) + # Variable value. + vx = self.var_value_pos[0] + vy = self.var_value_pos[1] - (self.gridh * pos) + vw = self.gridw * 2 + vtxt = self.vArea.create_pango_layout(v[2]) + # Height is same for both 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) + self.do_frame_pixmap(self.var_color, nw, h, nx, nx, ny, ny, ntxt) + self.do_frame_pixmap(self.var_color, vw, h, vx, vx, vy, vy, vtxt) pos += 1 def draw_show_constants(self, cur_consts): @@ -372,8 +381,8 @@ """Store a constant moved to a variable in the visualization pixmap.""" startx = self.const_start[0] starty = self.const_start[1] - endx = self.const_end[0] - endy = self.const_end[1] + endx = self.var_value_pos[0] + endy = self.var_value_pos[1] w = self.gridw * 2 h = self.gridh txt = self.vArea.create_pango_layout(constant[:8]) Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- visualizer.py 15 Aug 2005 14:17:25 -0000 1.7 +++ visualizer.py 15 Aug 2005 18:34:16 -0000 1.8 @@ -65,15 +65,16 @@ cmd.append(['SHOW_CONSTANTS', cur_consts]) 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. - cur_vars.append([c[1], c[2]]) + # c[2] is the variable's new value. + # c[3] is the variable's old value. + cur_vars.append([c[1], c[2], c[3]]) cmd.append(['SHOW_VARIABLES', cur_vars]) - cmd.append(['SHOW_STORING', c[3], c[1]]) + cmd.append(['SHOW_STORING', c[2], c[1]]) elif c[0] == 'LOAD': # c[1] is the variable name. # c[2] is the variable value. - cur_vars.append([c[1], c[2]]) + # c[3] is the variable's old value + cur_vars.append([c[1], c[2], c[3]]) cmd.append(['SHOW_VARIABLES', cur_vars]) elif c[0] == 'BEGIN_LOOP': cmd.append(['SHOW_LOOP']) Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ChangeLog 15 Aug 2005 17:00:32 -0000 1.8 +++ ChangeLog 15 Aug 2005 18:34:16 -0000 1.9 @@ -3,6 +3,8 @@ CVS + * When storing to a variable, the old value is now shown and new value moved on + top of it * Visualization objects have a black border 0.2.0 |
From: Tero K. <te...@us...> - 2005-08-15 17:00:43
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8446 Modified Files: ChangeLog openexvis.py Log Message: Visualization objects have a black border to make things look clearer. Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- openexvis.py 15 Aug 2005 14:33:28 -0000 1.10 +++ openexvis.py 15 Aug 2005 17:00:32 -0000 1.11 @@ -18,7 +18,7 @@ def __init__(self): visualizer.OevVisualizer.__init__(self) - self.version = "0.2.0" + self.version = "0.3.0-pre" # Build the UI self.build_gui() @@ -58,7 +58,7 @@ # Create the colors for different elements. They must be allocated # colors. self.colormap = self.vDraw.get_colormap() - self.color_white = self.colormap.alloc_color('#FFFFFF') + 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.var_color = self.colormap.alloc_color('#CCFFAA') @@ -84,7 +84,7 @@ def set_positions(self): """Set some important positions in the visualization area.""" self.vis_width, self.vis_height = self.vDraw.get_size() - # We divide the visualization area to a 20x20 grid. + # We divide the visualization area to a grid. self.gridw = self.vis_width/20 self.gridh = self.vis_height/20 while self.gridw > 50: @@ -389,7 +389,7 @@ """ gc = self.vDraw.new_gc() pm = gtk.gdk.Pixmap(self.vDraw, w, h) - gc.set_foreground(self.color_white) + gc.set_foreground(self.object_bg_color) pm.draw_rectangle(gc, True, 0, 0, w, h) gc.set_foreground(fgc) pm.draw_rectangle(gc, True, 1, 1, w - 2, h - 2) Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- ChangeLog 15 Aug 2005 14:33:28 -0000 1.7 +++ ChangeLog 15 Aug 2005 17:00:32 -0000 1.8 @@ -3,6 +3,8 @@ CVS + * Visualization objects have a black border + 0.2.0 * Lines can now be marked to be skipped while visualizing |
From: Tero K. <te...@us...> - 2005-08-15 14:33:37
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8036 Modified Files: ChangeLog README TODO openexvis.py Log Message: Prepare for 0.2.0 release. Index: README =================================================================== RCS file: /cvsroot/openexvis/openexvis/README,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- README 8 Aug 2005 21:30:39 -0000 1.1.1.1 +++ README 15 Aug 2005 14:33:28 -0000 1.2 @@ -18,18 +18,26 @@ $ python openexvis.py -When the program is running, load a Python source code file and click "Run" to -see the visualization. +Optionally, you can give OpenExVis a file to open as an argument, like this: -In this version of OpenExVis, the visualization is not functional yet and -instead the program only shows some text while executing a program. +$ ./openexvis.py filename.py + +When the program is running, load a Python source code file if none is loaded +and click "Run" to see the visualization. To see it one step at a time, use the +"Step" button. When stepping, a new click on the "Step" button proceeds one step +further and a click on the "Run" button switches to running continuously. + +You can mark some lines to not be visualized by clicking on the line number. +When an icon is shown next to the line number, that line is not visualized. To +remove a mark, click on the line number again. NOTE: This version of OpenExVis is alpha software and thus lacks several planned features. The program can crash at surprising places and otherwise behave in -weird ways. The code is probably full of bugs. If you find a bug, please let the -developers know! +weird ways. The visualization shown by the program can be incorrect or +misleading at times. The code is probably full of bugs. If you find a bug, please +let the developers know! You can find more information about OpenExVis and contacting the developers at our home page: http://openexvis.sourceforge.net/ Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- openexvis.py 15 Aug 2005 14:12:09 -0000 1.9 +++ openexvis.py 15 Aug 2005 14:33:28 -0000 1.10 @@ -18,7 +18,7 @@ def __init__(self): visualizer.OevVisualizer.__init__(self) - self.version = "0.2.0-pre" + self.version = "0.2.0" # Build the UI self.build_gui() Index: TODO =================================================================== RCS file: /cvsroot/openexvis/openexvis/TODO,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- TODO 8 Aug 2005 21:30:39 -0000 1.1.1.1 +++ TODO 15 Aug 2005 14:33:28 -0000 1.2 @@ -1,9 +1,13 @@ OpenExVis TODO ============== -For 0.2.0: +For 0.3.0: + + * Improve the visualization + + Visualize mathematical operations correctly + + Improve visualization of evaluation in general + + Move correct constants to correct variables + + Implement visualizing the structure + + Try to improve the animation speed control further + * Include some more test files and make sure they're visualized correctly - * Graphical presentation of target program's execution - * Step button behaviour - * Showing the output of target program during execution - * Ability to mark some areas of the code to be skipped during visualization Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ChangeLog 15 Aug 2005 00:40:15 -0000 1.6 +++ ChangeLog 15 Aug 2005 14:33:28 -0000 1.7 @@ -3,6 +3,8 @@ CVS +0.2.0 + * Lines can now be marked to be skipped while visualizing * Major changes to the code handling visualization data * Major changes to visualization area |
From: Tero K. <te...@us...> - 2005-08-15 14:17:34
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4796 Modified Files: visualizer.py Log Message: Remove some now useless code. Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- visualizer.py 15 Aug 2005 14:12:09 -0000 1.6 +++ visualizer.py 15 Aug 2005 14:17:25 -0000 1.7 @@ -67,11 +67,8 @@ # 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. cur_vars.append([c[1], c[2]]) - #cur_consts.append(c[3]) cmd.append(['SHOW_VARIABLES', cur_vars]) - #cmd.append(['SHOW_CONSTANTS', cur_consts]) cmd.append(['SHOW_STORING', c[3], c[1]]) elif c[0] == 'LOAD': # c[1] is the variable name. |
From: Tero K. <te...@us...> - 2005-08-15 14:12:18
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3545 Modified Files: oevt_python.py openexvis.py visualizer.py Log Message: Smoother animation. Constant visualization improved. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- oevt_python.py 15 Aug 2005 13:35:35 -0000 1.4 +++ oevt_python.py 15 Aug 2005 14:12:09 -0000 1.5 @@ -62,8 +62,6 @@ olderconst = lastconst lastconst = op['oparg2'] 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. self.variables[op['oparg2']] = lastconst #print "DEBUG: variables == ", self.variables Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- openexvis.py 15 Aug 2005 13:35:35 -0000 1.8 +++ openexvis.py 15 Aug 2005 14:12:09 -0000 1.9 @@ -181,10 +181,6 @@ while gtk.events_pending(): gtk.main_iteration() moresteps = self.draw_anim_frame() - # Higher speed setting gives higher speed like this. - # TODO: This should be improved so slowest and fastest differ more. - # FIXME: Also, this seems to cause a lot of speed alteration. - time.sleep((11-self.speed)/100) 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 @@ -206,10 +202,9 @@ # cmd[1] is the string to output. 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. - if cmd[1] != 'None': - self.draw_show_constant(cmd[1]) + 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 list. self.draw_show_variables(cmd[1]) @@ -299,6 +294,8 @@ # Draw the element. self.pixmap.draw_drawable(self.gc, i[4], 0, 0, i[0], i[2], -1, -1) self.refresh_screen() + # Higher speed setting gives higher speed like this. + time.sleep((11-self.speed) * 0.05) return moresteps # NOTE: To grok the following draw_show_* methods, see do_frame_pixmap. @@ -344,7 +341,6 @@ 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] @@ -355,14 +351,22 @@ 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.""" - x = self.const_start[0] - y = self.const_start[1] - w = self.gridw * 2 - h = self.gridh - txt = self.vArea.create_pango_layout(constant[:8]) - self.do_frame_pixmap(self.static_const_color, w, h, x, x, y, y, txt) + def draw_show_constants(self, cur_consts): + """Store displaying the constants in the visualization pixmap.""" + pos = 0 + for c in cur_consts: + print "DEBUG: c == ", c + if c == 'None': + continue + # We draw the static constants one column left from where moving + # ones start. + x = self.const_start[0] - self.gridw + y = self.const_start[1] + (self.gridh * pos) + w = self.gridw * 2 + h = self.gridh + txt = self.vArea.create_pango_layout(c[:8]) + self.do_frame_pixmap(self.static_const_color, w, h, x, x, y, y, txt) + pos += 1 def draw_show_storing(self, constant): """Store a constant moved to a variable in the visualization pixmap.""" Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- visualizer.py 15 Aug 2005 13:35:35 -0000 1.5 +++ visualizer.py 15 Aug 2005 14:12:09 -0000 1.6 @@ -53,28 +53,30 @@ # should be documented well somewhere. Now they're not as they're still # evolving. cmd = [] - cur_vars = [] # TODO: Use to separate multiple vars. + cur_vars = [] + cur_consts = [] 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]]) + cur_consts.append(c[1]) + print "DEBUG: cur_consts == ", cur_consts + cmd.append(['SHOW_CONSTANTS', cur_consts]) 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. cur_vars.append([c[1], c[2]]) - print "DEBUG: vis cur_vars == ", cur_vars + #cur_consts.append(c[3]) cmd.append(['SHOW_VARIABLES', cur_vars]) - cmd.append(['SHOW_CONSTANT', c[3]]) + #cmd.append(['SHOW_CONSTANTS', cur_consts]) cmd.append(['SHOW_STORING', c[3], c[1]]) elif c[0] == 'LOAD': # 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']) @@ -92,6 +94,8 @@ cmd.append(['OUTPUT', c[1]]) elif c[0] == 'RETURN': cmd.append(['RETURN']) + else: + print "No drawing command for ", c[0], ". Whole list was: ", c return cmd def visualize(self, code): |
From: Tero K. <te...@us...> - 2005-08-15 13:37:05
|
Update of /cvsroot/openexvis/openexvis/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26997/images Added Files: skip_line_marker.xpm Log Message: Add the image needed to draw the markers. Forgot this yesterday. --- NEW FILE: skip_line_marker.xpm --- /* XPM */ static char * skip_line_marker_xpm[] = { "14 14 8 1", " c None", ". c #000000", "+ c #092208", "@ c #298126", "# c #3AB436", "$ c #40C63C", "% c #40C83C", "& c #41C93D", " ", " ", " ", " .... ", " +@##@+ ", " .@$%%$@. ", " .#%&&%#. ", " .#%&&%#. ", " .@$%%$@. ", " +@##@+ ", " .... ", " ", " ", " "}; |
From: Tero K. <te...@us...> - 2005-08-15 13:35:58
|
Update of /cvsroot/openexvis/openexvis/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26784/images Log Message: Directory /cvsroot/openexvis/openexvis/images added to the repository |
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']) |
From: Tero K. <te...@us...> - 2005-08-15 00:40:30
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29186 Modified Files: ChangeLog openexvis.py Log Message: Lines can now be marked to be skipped while visualizing. Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- openexvis.py 14 Aug 2005 22:46:59 -0000 1.6 +++ openexvis.py 15 Aug 2005 00:40:15 -0000 1.7 @@ -47,8 +47,7 @@ self.oevWindow.maximize() # Set up the code area. - self.clear_code_buffer() - self.cArea.set_show_line_numbers(True) + self.init_code_area() # Set up the visualization area. self.init_visualization_area() @@ -77,6 +76,16 @@ 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.""" + self.clear_code_buffer() + self.cArea.set_show_line_numbers(True) + # Markers are used to tell the visualizer which lines to not visualize. + self.cArea.set_show_line_markers(True) + marker_image = \ + gtk.gdk.pixbuf_new_from_file('./images/skip_line_marker.xpm') + self.cArea.set_marker_pixbuf('SKIP_LINE_MARKER', marker_image) + def set_positions(self): """Set some important positions in the visualization area.""" self.vis_width, self.vis_height = self.vDraw.get_size() @@ -159,6 +168,14 @@ self.vis_pixmaps = [] # Mark the line we're visualizing on the code area. vis_code = self.mark_line(lineno) + # If the line is marked, we should skip it. Note that the buffer counts + # from 0 but the user visually sees a line one further. + line_iter = self.cBuf.get_iter_at_line(lineno-1) + end_iter = line_iter.copy() + end_iter.forward_to_line_end() + line_markers = self.cBuf.get_markers_in_region(line_iter, end_iter) + if line_markers: + return True # Update the visualization area. self.update_pixmaps(vis_code, viscommands) moresteps = True @@ -378,7 +395,8 @@ self.cBuf.remove_tag_by_name('visualize', \ self.cBuf.get_start_iter(), \ self.cBuf.get_end_iter()) - # Highlight the line currently visualized. + # Highlight the line currently visualized. Note that the buffer starts + # counting from 0 but we want to highlight lines from 1 line further. si = self.cBuf.get_iter_at_line(lineno-1) ei = si.copy() ei.forward_line() @@ -579,9 +597,29 @@ """Draw the visualization area contents.""" x , y, width, height = event.area # The image is a pixmap we build behind the scenes. - self.vDraw.draw_drawable(self.vArea.get_style().fg_gc[gtk.STATE_NORMAL],\ + self.vDraw.draw_drawable( \ + self.vArea.get_style().fg_gc[gtk.STATE_NORMAL],\ self.pixmap, x, y, x, y, width, height) + def on_codeArea_button_press_event(self, obj, event): + """Update the markers.""" + if obj.get_window_type(event.window) == gtk.TEXT_WINDOW_LEFT: + # We have a click over the left border. + event_x, event_y = event.get_coords() + x, y = self.cArea.window_to_buffer_coords(gtk.TEXT_WINDOW_LEFT, \ + int(event_x), int(event_y)) + line_iter, line_top = self.cArea.get_line_at_y(y) + lineno = line_iter.get_line() + print "About to set line marker at ", lineno + end_iter = line_iter.copy() + end_iter.forward_to_line_end() + line_markers = self.cBuf.get_markers_in_region(line_iter, end_iter) + if not line_markers: + self.cBuf.create_marker(None, 'SKIP_LINE_MARKER', line_iter) + else: + for m in line_markers: + self.cBuf.delete_marker(m) + def main(): oev = OevGUI() Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ChangeLog 12 Aug 2005 23:01:44 -0000 1.5 +++ ChangeLog 15 Aug 2005 00:40:15 -0000 1.6 @@ -3,6 +3,7 @@ CVS + * Lines can now be marked to be skipped while visualizing * Major changes to the code handling visualization data * Major changes to visualization area * Code area is now insensitive while visualizing |
From: Tero K. <te...@us...> - 2005-08-15 00:40:30
|
Update of /cvsroot/openexvis/openexvis/gui_openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29186/gui_openexvis Modified Files: gui_openexvis.glade Log Message: Lines can now be marked to be skipped while visualizing. Index: gui_openexvis.glade =================================================================== RCS file: /cvsroot/openexvis/openexvis/gui_openexvis/gui_openexvis.glade,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- gui_openexvis.glade 12 Aug 2005 23:01:46 -0000 1.2 +++ gui_openexvis.glade 15 Aug 2005 00:40:15 -0000 1.3 @@ -606,6 +606,7 @@ <property name="right_margin">0</property> <property name="indent">0</property> <property name="text" translatable="yes"></property> + <signal name="button_press_event" handler="on_codeArea_button_press_event" last_modification_time="Sun, 14 Aug 2005 23:30:48 GMT"/> </widget> </child> </widget> |