def menu_item_cb (view, action, widget): print 'Action:', action, gtk.item_factory_path_from_widget(widget), view view.canvas.push_undo (None) if action == FILE_NEW: canvas = dia.Canvas() canvas.set_property ('allow_undo', 1) view = dia.CanvasView(canvas=canvas, aa=1) display_canvas_view (view) elif action == FILE_CLOSE: view.get_toplevel().destroy() elif action == FILE_QUIT: view.get_toplevel().destroy() gtk.main_quit() elif action == EDIT_UNDO: view.canvas.pop_undo() elif action == EDIT_REDO: view.canvas.pop_redo() elif action == EDIT_SELECT_ALL: view.select_rectangle ( [ -100000, -100000, 100000, 100000 ] ) elif action == EDIT_DEL_FOCUSED: if view.focus_item: item = view.focus_item.item # If the item is a composite item, remove the parent item instead while (item.flags & dia.COMPOSITE) != 0: item = item.parent item.parent.remove (item) elif action == EDIT_DEL_SELECTED: pass # need wrapper elif action == EDIT_GC: pass elif action == VIEW_ZOOM_IN: view.set_zoom (view.get_zoom() + 0.1) elif action == VIEW_ZOOM_OUT: view.set_zoom (view.get_zoom() - 0.1) elif action == VIEW_ZOOM_100: view.set_zoom (1.0) elif action == VIEW_SNAP_TO_GRID: snap = view.canvas.get_property ('snap_to_grid') view.canvas.set_property ('snap_to_grid', not snap) elif action == OBJECT_ADD_LINE: tool = PlacementTool (dia.CanvasLine, color=dia.color(220, 0, 0)) view.set_tool (tool) tool.signal_id = tool.connect ('button_release_event', unset_tool, view) elif action == OBJECT_ADD_BOX: tool = PlacementTool (dia.CanvasBox, width=0.0, height=0.0) view.set_tool (tool) tool.signal_id = tool.connect ('button_release_event', unset_tool, view) else: print 'This item is not yet implemented.'
def main(argv): rect = (0, 0, 1000, 1000) canvas = dia.Canvas() box = dia.CanvasBox() box.set(parent=canvas.root, width=100, height=100)#, color=0x999900FF) box.move (50, 50) box.connect('connect', connect_cb) line = dia.CanvasLine() line.set(parent=canvas.root, add_point=(100, 100), color=dia.color(0, 200, 0)) line.set(add_point=(300, 300)) my_box = MyBox() canvas.root.add(my_box) my_box2 = MyBox2() canvas.root.add(my_box2) my_box2.move(100,100) del my_box2 canvas.update_now() canvas.set_property ('allow_undo', 1) canvas.set_property ('static_extents', 1) ext = canvas.get_property ('extents') ext = (-100.0, -100, 200, 200) canvas.set_property ('extents', ext) ext = canvas.get_property ('extents') view = dia.CanvasView (canvas=canvas, aa=1) tool = PlacementTool (dia.CanvasLine) view.set_tool (tool) del tool view.set_tool (None) display_canvas_view(view) gtk.main()