2 Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT, DND_TARGETS
25 class DrawingArea(gtk.DrawingArea):
27 DrawingArea is the gtk pixel map that graphical elements may draw themselves on.
28 The drawing area also responds to mouse and key events.
31 def __init__(self, flow_graph):
33 DrawingArea contructor.
34 Connect event handlers.
35 @param main_window the main_window containing all flow graphs
37 self.ctrl_mask = False
38 self._flow_graph = flow_graph
39 gtk.DrawingArea.__init__(self)
40 self.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
41 self.connect('realize', self._handle_window_realize)
42 self.connect('configure-event', self._handle_window_configure)
43 self.connect('expose-event', self._handle_window_expose)
44 self.connect('motion-notify-event', self._handle_mouse_motion)
45 self.connect('button-press-event', self._handle_mouse_button_press)
46 self.connect('button-release-event', self._handle_mouse_button_release)
48 gtk.gdk.BUTTON_PRESS_MASK | \
49 gtk.gdk.POINTER_MOTION_MASK | \
50 gtk.gdk.BUTTON_RELEASE_MASK | \
51 gtk.gdk.LEAVE_NOTIFY_MASK | \
52 gtk.gdk.ENTER_NOTIFY_MASK
55 self.drag_dest_set(gtk.DEST_DEFAULT_ALL, DND_TARGETS, gtk.gdk.ACTION_COPY)
56 self.connect('drag-data-received', self._handle_drag_data_received)
58 self._focus_flag = False
59 self.get_focus_flag = lambda: self._focus_flag
60 def _handle_focus_event(widget, event, focus_flag): self._focus_flag = focus_flag
61 self.connect('leave-notify-event', _handle_focus_event, False)
62 self.connect('enter-notify-event', _handle_focus_event, True)
64 def new_pixmap(self, width, height): return gtk.gdk.Pixmap(self.window, width, height, -1)
66 ##########################################################################
68 ##########################################################################
69 def _handle_drag_data_received(self, widget, drag_context, x, y, selection_data, info, time):
71 Handle a drag and drop by adding a block at the given coordinate.
73 self._flow_graph.add_new_block(selection_data.data, (x, y))
75 def _handle_mouse_button_press(self, widget, event):
77 Forward button click information to the flow graph.
79 self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK
80 self._flow_graph.handle_mouse_button_press(
81 left_click=(event.button == 1),
82 double_click=(event.type == gtk.gdk._2BUTTON_PRESS),
83 coordinate=(event.x, event.y),
86 def _handle_mouse_button_release(self, widget, event):
88 Forward button release information to the flow graph.
90 self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK
91 self._flow_graph.handle_mouse_button_release(
92 left_click=(event.button == 1),
93 coordinate=(event.x, event.y),
96 def _handle_mouse_motion(self, widget, event):
98 Forward mouse motion information to the flow graph.
100 self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK
101 self._flow_graph.handle_mouse_motion(
102 coordinate=(event.x, event.y),
105 def _handle_window_realize(self, widget):
107 Called when the window is realized.
108 Update the flowgraph, which calls new pixmap.
110 self._flow_graph.update()
112 def _handle_window_configure(self, widget, event):
114 Called when the window is resized.
115 Create a new pixmap for background buffer.
117 self._pixmap = self.new_pixmap(*self.get_size_request())
119 def _handle_window_expose(self, widget, event):
121 Called when window is exposed, or queue_draw is called.
122 Double buffering: draw to pixmap, then draw pixmap to window.
124 gc = self.window.new_gc()
125 self._flow_graph.draw(gc, self._pixmap)
126 self.window.draw_drawable(gc, self._pixmap, 0, 0, 0, 0, -1, -1)