From e3a1e19e87dbb3df413015bfc714283bc8602999 Mon Sep 17 00:00:00 2001 From: Gary Bressler Date: Mon, 12 Apr 2010 11:58:37 -0400 Subject: Minor fixes --- unit_trace/viz/viewer.py | 61 +++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'unit_trace/viz/viewer.py') diff --git a/unit_trace/viz/viewer.py b/unit_trace/viz/viewer.py index 4d1fb7f..5e707b8 100644 --- a/unit_trace/viz/viewer.py +++ b/unit_trace/viz/viewer.py @@ -116,19 +116,21 @@ class GraphArea(gtk.DrawingArea): def get_schedule(self): return self.renderer.get_schedule() - + def zoom_in(self): scale = self.scale + GraphArea.ZOOM_INCR if scale > GraphArea.MAX_ZOOM_IN: scale = GraphArea.MAX_ZOOM_IN self.set_scale(scale) - + self.config_scrollbars(self.cur_x, self.cur_y, self.scale) + def zoom_out(self): scale = self.scale - GraphArea.ZOOM_INCR if scale < GraphArea.MIN_ZOOM_OUT: scale = GraphArea.MIN_ZOOM_OUT self.set_scale(scale) - + self.config_scrollbars(self.cur_x, self.cur_y, self.scale) + def set_scale(self, scale): if scale == self.scale: return @@ -136,6 +138,22 @@ class GraphArea(gtk.DrawingArea): self.scale = scale self._dirty(0, 0, self.width, self.height) + def set_hvalue(self, value): + if self.horizontal is None: + return + + value = max(value, self.horizontal.get_lower()) + value = min(value, self.horizontal.get_upper() - self.horizontal.get_page_size()) + self.horizontal.set_value(value) + + def set_vvalue(self, value): + if self.vertical is None: + return + + value = max(value, self.vertical.get_lower()) + value = min(value, self.vertical.get_upper() - self.vertical.get_page_size()) + self.vertical.set_value(value) + def set_scroll_adjustments(self, widget, horizontal, vertical, data=None): graph = self.renderer.get_graph() width = graph.get_width() @@ -143,7 +161,7 @@ class GraphArea(gtk.DrawingArea): self.horizontal = horizontal self.vertical = vertical - self.config_scrollbars(self.cur_x, self.cur_y) + self.config_scrollbars(self.cur_x, self.cur_y, self.scale) if self.horizontal is not None: self.horizontal.connect('value-changed', self.horizontal_value_changed) @@ -167,22 +185,26 @@ class GraphArea(gtk.DrawingArea): def size_allocate(self, widget, allocation): self.width = allocation.width self.height = allocation.height - self.config_scrollbars(self.cur_x, self.cur_y) + self.config_scrollbars(self.cur_x, self.cur_y, self.scale) - def config_scrollbars(self, hvalue, vvalue): + def config_scrollbars(self, hvalue, vvalue, scale): graph = self.renderer.get_graph() width = graph.get_width() height = graph.get_height() if self.horizontal is not None: - self.horizontal.set_all(hvalue, 0.0, width + self.width, - graph.get_attrs().maj_sep * GraphArea.HORIZ_STEP_SCROLL_FACTOR, - graph.get_attrs().maj_sep * GraphArea.HORIZ_PAGE_SCROLL_FACTOR, self.width) + self.horizontal.set_all(0.0, 0.0, width, + graph.get_attrs().maj_sep * GraphArea.HORIZ_STEP_SCROLL_FACTOR / scale, + graph.get_attrs().maj_sep * GraphArea.HORIZ_PAGE_SCROLL_FACTOR / scale, + self.width / scale) + self.set_hvalue(hvalue) if self.vertical is not None: - self.vertical.set_all(vvalue, 0.0, height + self.height, - graph.get_attrs().y_item_size * GraphArea.VERT_STEP_SCROLL_FACTOR, - graph.get_attrs().y_item_size * GraphArea.VERT_PAGE_SCROLL_FACTOR, self.height) - + self.vertical.set_all(0.0, 0.0, height, + graph.get_attrs().y_item_size * GraphArea.VERT_STEP_SCROLL_FACTOR / scale, + graph.get_attrs().y_item_size * GraphArea.VERT_PAGE_SCROLL_FACTOR / scale, + self.height / scale) + self.set_vvalue(vvalue) + def refresh_events(self, sender, new, old, replace): """Even if the selected areas change on one graph, they change everywhere, and different events might be in different regions on @@ -485,16 +507,10 @@ class GraphWindow(gtk.ScrolledWindow): return True def set_hvalue(self, value): - if self.get_hadjustment() is None: - return - - self.get_hadjustment().set_value(value) + self.get_graph_area().set_hvalue(value) def set_vvalue(self, value): - if self.get_vadjustment() is None: - return - - self.get_vadjustment().set_value(value) + self.get_graph_area().set_vvalue(value) def _scroll_direction(self, keystr): hadj = self.get_hadjustment() @@ -721,9 +737,6 @@ class MainWindow(gtk.Window): garea = self.notebook.get_nth_page(i).get_graph_area() # Center as much as possible pos = garea.get_graph().get_time_xpos(time) - garea.get_width() / 2.0 - pos = max(0, pos) - pos = min(garea.get_graph().get_width(), pos) - self.notebook.get_nth_page(i).set_hvalue(pos) else: err_dialog = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, -- cgit v1.2.2