From 2d0fecacda6cb305238a5107a0445fc673b912fb Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 13 May 2003 16:06:26 +0000 Subject: [PATCH] Loading files now adds the namespaces. git-svn-id: http://dom-editor.googlecode.com/svn/branches/Gtk2@483 ef21e15d-ca94-4315-9c45-0d95b1b2e117 --- Dome/Display.py | 540 ----------------------------------------------------- Dome/Display2.py | 9 +- Dome/Model.py | 32 +++- Dome/Namespaces.py | 39 +++- Dome/View.py | 10 +- 5 files changed, 73 insertions(+), 557 deletions(-) delete mode 100644 Dome/Display.py diff --git a/Dome/Display.py b/Dome/Display.py deleted file mode 100644 index e6acf56..0000000 --- a/Dome/Display.py +++ /dev/null @@ -1,540 +0,0 @@ -from rox import g, TRUE, FALSE -from gnome import canvas -from xml.dom import Node -from constants import * -import rox - -watch_cursor = g.gdk.Cursor(g.gdk.WATCH) -no_cursor = g.gdk.Cursor(g.gdk.TCROSS) - -def set_busy(widget, busy = TRUE): - w = widget.window - if not w: - return - if busy: - w.set_cursor(watch_cursor) - else: - w.set_cursor(no_cursor) - -def wrap(str, width): - ret = '' - while len(str) > width: - i = str[:width].rfind(' ') - if i == -1: - i = width - ret = ret + str[:i + 1] + '\n' - str = str[i + 1:] - return ret + str - -cramped_indent = 16 -normal_indent = 24 - -import __main__ -default_font = __main__.default_font - -class Display(canvas.Canvas): - def __init__(self, window, view): - canvas.Canvas.__init__(self) - self.view = None - self.parent_window = window - self.root_group = None - self.update_timeout = 0 - self.update_nodes = {} # Set of nodes to update on update_timeout - self.current_attrib = None # Canvas group - self.node_to_group = {} - - self.visible = 1 - - s = self.get_style().copy() - s.bg[g.STATE_NORMAL] = g.gdk.color_parse('old lace') - self.set_style(s) - - self.connect('size-allocate', self.size_allocate) - self.connect('destroy', self.destroyed) - self.connect('button-press-event', self.bg_event) - - self.set_view(view) - - rox.app_options.add_notify(self.options_changed) - - def size_allocate(self, canvas, size): - x, y, width, height = self.get_allocation() - chains = self.parent_window.list.chains - if self.visible: - if width < 40: - self.visible = 0 - chains.set_active(0) - print "hide" - else: - if width > 40: - self.visible = 1 - self.update_all() - chains.set_active(1) - print "show" - - def set_view(self, view): - if self.view: - self.view.remove_display(self) - self.view = view - self.view.add_display(self) - self.update_all() - - def set_bounds(self): - m = 8 - - (x, y, w, h) = self.get_allocation() - w -= m * 2 + 1 - h -= m * 2 + 1 - - #self.update_now() # GnomeCanvas bug? - min_x, min_y, max_x, max_y = self.root().get_bounds() - if max_x - min_x < w: - max_x = min_x + w - if max_y - min_y < h: - max_y = min_y + h - self.set_scroll_region(min_x - m, min_y - m, max_x + m, max_y + m) - self.root().move(0, 0) # Magic! - - def update_record_state(self): - self.parent_window.update_title() - - def update_all(self, node = None): - if not node: - node = self.view.model.doc.documentElement - - if node == self.view.root: - self.update_nodes = {node: None} - elif node not in self.update_nodes: - # Note: we don't eliminate duplicates (parent and child) nodes - # here because it takes *ages* - self.update_nodes[node] = None - - if self.update_timeout or not self.visible: - return # Going to update anyway... - - if self.view.running(): - self.update_timeout = g.timeout_add(2000, self.update_callback) - else: - self.update_timeout = g.timeout_add(10, self.update_callback) - - def do_update_now(self): - # Update now, if we need to - if self.update_timeout: - g.timeout_remove(self.update_timeout) - self.update_callback() - #self.update_timeout = g.timeout_add(10, self.update_callback) - - def update_callback(self): - print "update_callback" - self.update_timeout = 0 - #print "Update...", self.update_nodes - set_busy(self) - try: - for node in self.update_nodes: - root = self.view.root - if node is not root and self.view.has_ancestor(node, root): - # The root is OK - the change is inside... - try: - group = self.node_to_group[node] - #if group.flags() & DESTROYED: - # print "(group destroyed)" - # raise Exception('Group destroyed') - except: - # Modified node not created yet. - # Don't worry, updating the parent later - # will fix it... - print "(node missing)" - pass - else: - # Can't delete all children, so create a new group - # instead. - parent = group.get_property('parent') - x = group.get_property('x') - y = group.get_property('y') - gr = parent.add(canvas.CanvasGroup, x = x, y = y) - group.destroy() - group.attrib_to_group = None - self.node_to_group[node] = gr - gr.connect('event', self.node_event, node) - - self.create_tree(node, gr, cramped = group.cramped) - self.auto_highlight(node, rec = 1) - self.child_group_resized(node) - else: - # Need to rebuild everything... - if self.root_group: - self.root_group.destroy() - self.node_to_group = {} - self.root_group = self.root().add(canvas.CanvasGroup, x = 0, y = 0) - group = self.root_group - node = self.view.root - group.connect('event', self.node_event, node) - print "creating tree..." - self.create_tree(node, group) - print "highlighting..." - self.auto_highlight(node, rec = 1) - print "done" - self.move_from() - self.set_bounds() - if self.view.current_nodes: - self.scroll_to_show(self.view.current_nodes[0]) - finally: - set_busy(self, FALSE) - self.update_nodes = {} - #print "