summaryrefslogtreecommitdiff
path: root/grc/gui/DrawingArea.py
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2016-04-18 18:11:52 +0200
committerSeth Hitefield <sdhitefield@gmail.com>2016-05-24 13:02:23 -0400
commit5352dfd80fd238256da7bbd5efd15c154f3f5a14 (patch)
tree2221b54d0b7f7b42bd7f6e3fa521a6c9e8ded401 /grc/gui/DrawingArea.py
parente66cfa31ff52b95a9c3df27c8a1f3b02bef6db3d (diff)
gtk3: add flowgraph draw code and other gtk3 fixes (WIP)
Diffstat (limited to 'grc/gui/DrawingArea.py')
-rw-r--r--grc/gui/DrawingArea.py57
1 files changed, 12 insertions, 45 deletions
diff --git a/grc/gui/DrawingArea.py b/grc/gui/DrawingArea.py
index f91fb2a3de..2bce21fa6d 100644
--- a/grc/gui/DrawingArea.py
+++ b/grc/gui/DrawingArea.py
@@ -48,8 +48,7 @@ class DrawingArea(Gtk.DrawingArea):
GObject.GObject.__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('draw', self.draw)
self.connect('motion-notify-event', self._handle_mouse_motion)
self.connect('button-press-event', self._handle_mouse_button_press)
self.connect('button-release-event', self._handle_mouse_button_release)
@@ -59,35 +58,22 @@ class DrawingArea(Gtk.DrawingArea):
Gdk.EventMask.POINTER_MOTION_MASK | \
Gdk.EventMask.BUTTON_RELEASE_MASK | \
Gdk.EventMask.LEAVE_NOTIFY_MASK | \
- Gdk.EventMask.ENTER_NOTIFY_MASK | \
- Gdk.EventMask.FOCUS_CHANGE_MASK
+ Gdk.EventMask.ENTER_NOTIFY_MASK #| \
+ #Gdk.EventMask.FOCUS_CHANGE_MASK
)
#setup drag and drop
- self.drag_dest_set(Gtk.DestDefaults.ALL, DND_TARGETS, Gdk.DragAction.COPY)
+ self.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
self.connect('drag-data-received', self._handle_drag_data_received)
+ self.drag_dest_set_target_list(None)
+ self.drag_dest_add_text_targets()
#setup the focus flag
self._focus_flag = False
self.get_focus_flag = lambda: self._focus_flag
def _handle_notify_event(widget, event, focus_flag): self._focus_flag = focus_flag
self.connect('leave-notify-event', _handle_notify_event, False)
self.connect('enter-notify-event', _handle_notify_event, True)
- self.set_flags(Gtk.CAN_FOCUS) # self.set_can_focus(True)
- self.connect('focus-out-event', self._handle_focus_lost_event)
-
- def new_pixmap(self, width, height):
- return Gdk.Pixmap(self.window, width, height, -1)
-
- def get_screenshot(self, transparent_bg=False):
- pixmap = self._pixmap
- W, H = pixmap.get_size()
- pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, 0, 8, W, H)
- pixbuf.fill(0xFF + Colors.FLOWGRAPH_BACKGROUND_COLOR.pixel << 8)
- pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, W-1, H-1)
- if transparent_bg:
- bgc = Colors.FLOWGRAPH_BACKGROUND_COLOR
- pixbuf = pixbuf.add_alpha(True, bgc.red, bgc.green, bgc.blue)
- return pixbuf
-
+# self.set_flags(Gtk.CAN_FOCUS) # self.set_can_focus(True)
+# self.connect('focus-out-event', self._handle_focus_lost_event)
##########################################################################
## Handlers
@@ -96,7 +82,7 @@ class DrawingArea(Gtk.DrawingArea):
"""
Handle a drag and drop by adding a block at the given coordinate.
"""
- self._flow_graph.add_new_block(selection_data.data, (x, y))
+ self._flow_graph.add_new_block(selection_data.get_text(), (x, y))
def _handle_mouse_scroll(self, widget, event):
if event.get_state() & Gdk.ModifierType.SHIFT_MASK:
@@ -113,7 +99,7 @@ class DrawingArea(Gtk.DrawingArea):
self.ctrl_mask = event.get_state() & Gdk.ModifierType.CONTROL_MASK
self.mod1_mask = event.get_state() & Gdk.ModifierType.MOD1_MASK
if event.button == 1: self._flow_graph.handle_mouse_selector_press(
- double_click=(event.type == Gdk._2BUTTON_PRESS),
+ double_click=(event.type == Gdk.EventType._2BUTTON_PRESS),
coordinate=(event.x, event.y),
)
if event.button == 3: self._flow_graph.handle_mouse_context_press(
@@ -148,27 +134,8 @@ class DrawingArea(Gtk.DrawingArea):
"""
self._flow_graph.update()
- def _handle_window_configure(self, widget, event):
- """
- Called when the window is resized.
- Create a new pixmap for background buffer.
- """
- self._pixmap = self.new_pixmap(*self.get_size_request())
-
- def _handle_window_expose(self, widget, event):
- """
- Called when window is exposed, or queue_draw is called.
- Double buffering: draw to pixmap, then draw pixmap to window.
- """
- gc = self.window.new_gc()
- self._flow_graph.draw(gc, self._pixmap)
- self.window.draw_drawable(gc, self._pixmap, 0, 0, 0, 0, -1, -1)
- # draw a light grey line on the bottom and right end of the canvas.
- # this is useful when the theme uses the same panel bg color as the canvas
- W, H = self._pixmap.get_size()
- gc.set_foreground(Colors.FLOWGRAPH_EDGE_COLOR)
- self.window.draw_line(gc, 0, H-1, W, H-1)
- self.window.draw_line(gc, W-1, 0, W-1, H)
+ def draw(self, widget, cr):
+ self._flow_graph.draw(widget, cr)
def _handle_focus_lost_event(self, widget, event):
# don't clear selection while context menu is active