summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorjblum2009-05-14 21:18:28 +0000
committerjblum2009-05-14 21:18:28 +0000
commit65446f553650a464fabf2bc4edf66a044e67b338 (patch)
tree705fc594b264cdf01549ee7f386ecaf967bf84e5 /grc
parent30e9c0d1d47f1e4200afd6abf955271609dbbdc3 (diff)
downloadgnuradio-65446f553650a464fabf2bc4edf66a044e67b338.tar.gz
gnuradio-65446f553650a464fabf2bc4edf66a044e67b338.tar.bz2
gnuradio-65446f553650a464fabf2bc4edf66a044e67b338.zip
Create one drawing area per flowgraph/notebook page.
Previously, there was one global drawing area, and empty notebook pages. This has the advantage of saving the scroll position though mutiple scroll windows, rendering the flow graph only when the notebook page is realized, and proper use + appearance of the gtk notebook git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11030 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc')
-rw-r--r--grc/src/gui/ActionHandler.py6
-rw-r--r--grc/src/gui/DrawingArea.py33
-rw-r--r--grc/src/gui/MainWindow.py26
-rw-r--r--grc/src/gui/NotebookPage.py15
4 files changed, 45 insertions, 35 deletions
diff --git a/grc/src/gui/ActionHandler.py b/grc/src/gui/ActionHandler.py
index f5f349d4a..06e998b31 100644
--- a/grc/src/gui/ActionHandler.py
+++ b/grc/src/gui/ActionHandler.py
@@ -61,7 +61,7 @@ class ActionHandler:
self.main_window.connect('key-press-event', self._handle_key_press)
self.get_page = self.main_window.get_page
self.get_flow_graph = self.main_window.get_flow_graph
- self.get_focus_flag = self.main_window.drawing_area.get_focus_flag
+ self.get_focus_flag = self.main_window.get_focus_flag
#setup the messages
Messages.register_messenger(self.main_window.add_report_line)
Messages.send_init()
@@ -170,8 +170,8 @@ class ActionHandler:
# Cut/Copy/Paste
##################################################
elif state == Actions.BLOCK_CUT:
- self.handle_states(BLOCK_COPY)
- self.handle_states(ELEMENT_DELETE)
+ self.handle_states(Actions.BLOCK_COPY)
+ self.handle_states(Actions.ELEMENT_DELETE)
elif state == Actions.BLOCK_COPY:
self.clipboard = self.get_flow_graph().copy_to_clipboard()
elif state == Actions.BLOCK_PASTE:
diff --git a/grc/src/gui/DrawingArea.py b/grc/src/gui/DrawingArea.py
index 22edb9093..6f90049c5 100644
--- a/grc/src/gui/DrawingArea.py
+++ b/grc/src/gui/DrawingArea.py
@@ -28,18 +28,17 @@ class DrawingArea(gtk.DrawingArea):
The drawing area also responds to mouse and key events.
"""
- def __init__(self, main_window):
+ def __init__(self, flow_graph):
"""
DrawingArea contructor.
Connect event handlers.
@param main_window the main_window containing all flow graphs
"""
self.ctrl_mask = False
- self._main_window = main_window
- #inject drawing area into main_window
- self._main_window.drawing_area = self
+ self._flow_graph = flow_graph
gtk.DrawingArea.__init__(self)
self.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
+ self.connect('realize', self._handle_window_realize)
self.connect('configure-event', self._handle_window_configure)
self.connect('expose-event', self._handle_window_expose)
self.connect('motion-notify-event', self._handle_mouse_motion)
@@ -58,8 +57,9 @@ class DrawingArea(gtk.DrawingArea):
#setup the focus flag
self._focus_flag = False
self.get_focus_flag = lambda: self._focus_flag
- self.connect('leave-notify-event', self._handle_focus_event, False)
- self.connect('enter-notify-event', self._handle_focus_event, True)
+ def _handle_focus_event(widget, event, focus_flag): self._focus_flag = focus_flag
+ self.connect('leave-notify-event', _handle_focus_event, False)
+ self.connect('enter-notify-event', _handle_focus_event, True)
def new_pixmap(self, width, height): return gtk.gdk.Pixmap(self.window, width, height, -1)
@@ -70,18 +70,14 @@ class DrawingArea(gtk.DrawingArea):
"""
Handle a drag and drop by adding a block at the given coordinate.
"""
- self._main_window.get_flow_graph().add_new_block(selection_data.data, (x, y))
-
- def _handle_focus_event(self, widget, event, focus_flag):
- """Record the focus state of the flow graph window."""
- self._focus_flag = focus_flag
+ self._flow_graph.add_new_block(selection_data.data, (x, y))
def _handle_mouse_button_press(self, widget, event):
"""
Forward button click information to the flow graph.
"""
self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK
- self._main_window.get_flow_graph().handle_mouse_button_press(
+ self._flow_graph.handle_mouse_button_press(
left_click=(event.button == 1),
double_click=(event.type == gtk.gdk._2BUTTON_PRESS),
coordinate=(event.x, event.y),
@@ -92,7 +88,7 @@ class DrawingArea(gtk.DrawingArea):
Forward button release information to the flow graph.
"""
self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK
- self._main_window.get_flow_graph().handle_mouse_button_release(
+ self._flow_graph.handle_mouse_button_release(
left_click=(event.button == 1),
coordinate=(event.x, event.y),
)
@@ -102,10 +98,17 @@ class DrawingArea(gtk.DrawingArea):
Forward mouse motion information to the flow graph.
"""
self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK
- self._main_window.get_flow_graph().handle_mouse_motion(
+ self._flow_graph.handle_mouse_motion(
coordinate=(event.x, event.y),
)
+ def _handle_window_realize(self, widget):
+ """
+ Called when the window is realized.
+ Update the flowgraph, which calls new pixmap.
+ """
+ self._flow_graph.update()
+
def _handle_window_configure(self, widget, event):
"""
Called when the window is resized.
@@ -119,5 +122,5 @@ class DrawingArea(gtk.DrawingArea):
Double buffering: draw to pixmap, then draw pixmap to window.
"""
gc = self.window.new_gc()
- self._main_window.get_flow_graph().draw(gc, self._pixmap)
+ self._flow_graph.draw(gc, self._pixmap)
self.window.draw_drawable(gc, self._pixmap, 0, 0, 0, 0, -1, -1)
diff --git a/grc/src/gui/MainWindow.py b/grc/src/gui/MainWindow.py
index ffb696a45..2106b8ea1 100644
--- a/grc/src/gui/MainWindow.py
+++ b/grc/src/gui/MainWindow.py
@@ -18,7 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
from Constants import \
- MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT, \
NEW_FLOGRAPH_TITLE, DEFAULT_REPORTS_WINDOW_WIDTH
from Actions import \
APPLICATION_QUIT, FLOW_GRAPH_KILL, \
@@ -29,7 +28,6 @@ import gtk
import Bars
from BlockTreeWindow import BlockTreeWindow
from Dialogs import TextDisplay, MessageDialogHelper
-from DrawingArea import DrawingArea
from NotebookPage import NotebookPage
import Preferences
import Messages
@@ -59,12 +57,6 @@ class MainWindow(gtk.Window):
vbox.pack_start(Bars.MenuBar(), False)
vbox.pack_start(Bars.Toolbar(), False)
vbox.pack_start(self.hpaned)
- #setup scrolled window
- self.scrolled_window = gtk.ScrolledWindow()
- self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
- self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.drawing_area = DrawingArea(self)
- self.scrolled_window.add_with_viewport(self.drawing_area)
#create the notebook
self.notebook = gtk.Notebook()
self.page_to_be_closed = None
@@ -73,11 +65,9 @@ class MainWindow(gtk.Window):
self.notebook.set_scrollable(True) #scroll arrows for page tabs
self.notebook.connect('switch-page', self._handle_page_change)
#setup containers
- flow_graph_box = gtk.VBox(False, 0)
self.flow_graph_vpaned = gtk.VPaned()
- flow_graph_box.pack_start(self.notebook, False, False, 0)
- flow_graph_box.pack_start(self.scrolled_window)
- self.flow_graph_vpaned.pack1(flow_graph_box)
+ #flow_graph_box.pack_start(self.scrolled_window)
+ self.flow_graph_vpaned.pack1(self.notebook)
self.hpaned.pack1(self.flow_graph_vpaned)
self.hpaned.pack2(BlockTreeWindow(platform, self.get_flow_graph), False) #dont allow resize
#create the reports window
@@ -155,8 +145,6 @@ class MainWindow(gtk.Window):
try: #try to load from file
if file_path: Messages.send_start_load(file_path)
flow_graph = self._platform.get_new_flow_graph()
- #inject drawing area and handle states into flow graph
- flow_graph.drawing_area = self.drawing_area
flow_graph.handle_states = self.handle_states
page = NotebookPage(
self,
@@ -252,8 +240,7 @@ class MainWindow(gtk.Window):
)
)
#show/hide notebook tabs
- if len(self._get_pages()) > 1: self.notebook.show()
- else: self.notebook.hide()
+ self.notebook.set_show_tabs(len(self._get_pages()) > 1)
def get_page(self):
"""
@@ -269,6 +256,13 @@ class MainWindow(gtk.Window):
"""
return self.get_page().get_flow_graph()
+ def get_focus_flag(self):
+ """
+ Get the focus flag from the current page.
+ @return the focus flag
+ """
+ return self.get_page().get_drawing_area().get_focus_flag()
+
############################################################
# Helpers
############################################################
diff --git a/grc/src/gui/NotebookPage.py b/grc/src/gui/NotebookPage.py
index 50a1216f9..0d6a4a87c 100644
--- a/grc/src/gui/NotebookPage.py
+++ b/grc/src/gui/NotebookPage.py
@@ -24,6 +24,8 @@ import gtk
from .. utils import ParseXML
from StateCache import StateCache
from .. platforms.base.Constants import FLOW_GRAPH_DTD
+from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT
+from DrawingArea import DrawingArea
import os
############################################################
@@ -56,7 +58,6 @@ class NotebookPage(gtk.HBox):
self.set_saved(True)
#import the data to the flow graph
self.get_flow_graph().import_data(initial_state)
- self.get_flow_graph().update()
#initialize page gui
gtk.HBox.__init__(self, False, 0)
self.show()
@@ -81,6 +82,18 @@ class NotebookPage(gtk.HBox):
button.set_size_request(w+6, h+6)
self.tab.pack_start(button, False)
self.tab.show_all()
+ #setup scroll window and drawing area
+ self.scrolled_window = gtk.ScrolledWindow()
+ self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
+ self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ self.drawing_area = DrawingArea(self.get_flow_graph())
+ self.scrolled_window.add_with_viewport(self.get_drawing_area())
+ self.pack_start(self.scrolled_window)
+ #inject drawing area and handle states into flow graph
+ self.get_flow_graph().drawing_area = self.get_drawing_area()
+ self.show_all()
+
+ def get_drawing_area(self): return self.drawing_area
def get_generator(self):
"""