[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10802 - in gnuradio/branches/developers/jblum/grc/grc
From: |
jblum |
Subject: |
[Commit-gnuradio] r10802 - in gnuradio/branches/developers/jblum/grc/grc/src: gui platforms/gui |
Date: |
Sat, 11 Apr 2009 00:22:07 -0600 (MDT) |
Author: jblum
Date: 2009-04-11 00:22:06 -0600 (Sat, 11 Apr 2009)
New Revision: 10802
Modified:
gnuradio/branches/developers/jblum/grc/grc/src/gui/BlockTreeWindow.py
gnuradio/branches/developers/jblum/grc/grc/src/gui/Constants.py
gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py
gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py
Log:
Drag and Drop for adding blocks into the flow graph from the selection window.
Everybody always tries to DND the blocks, now its possible!
Modified: gnuradio/branches/developers/jblum/grc/grc/src/gui/BlockTreeWindow.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/gui/BlockTreeWindow.py
2009-04-11 03:45:38 UTC (rev 10801)
+++ gnuradio/branches/developers/jblum/grc/grc/src/gui/BlockTreeWindow.py
2009-04-11 06:22:06 UTC (rev 10802)
@@ -1,5 +1,5 @@
"""
-Copyright 2007 Free Software Foundation, Inc.
+Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
-from Constants import DEFAULT_BLOCKS_WINDOW_WIDTH
+from Constants import DEFAULT_BLOCKS_WINDOW_WIDTH, DND_TARGETS
import pygtk
pygtk.require('2.0')
import gtk
@@ -53,6 +53,9 @@
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('Blocks', renderer, text=NAME_INDEX)
self.treeview.append_column(column)
+ #setup drag and drop
+ self.treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
DND_TARGETS, gtk.gdk.ACTION_COPY)
+ self.treeview.connect('drag-data-get',
self._handle_drag_get_data)
#make the scrolled window to hold the tree view
scrolled_window = gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
@@ -127,6 +130,15 @@
############################################################
## Event Handlers
############################################################
+ def _handle_drag_get_data(self, widget, drag_context, selection_data,
info, time):
+ """
+ Handle a drag and drop by setting the key to the selection
object.
+ This will call the destination handler for drag and drop.
+ Only call set when the key is valid to ignore DND from
categories.
+ """
+ key = self._get_selected_block_key()
+ if key: selection_data.set(selection_data.target, 8, key)
+
def _handle_mouse_button_press(self, widget, event):
"""
Handle the mouse button press.
Modified: gnuradio/branches/developers/jblum/grc/grc/src/gui/Constants.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/gui/Constants.py
2009-04-11 03:45:38 UTC (rev 10801)
+++ gnuradio/branches/developers/jblum/grc/grc/src/gui/Constants.py
2009-04-11 06:22:06 UTC (rev 10802)
@@ -1,5 +1,5 @@
"""
-Copyright 2008 Free Software Foundation, Inc.
+Copyright 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -17,6 +17,9 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
+import pygtk
+pygtk.require('2.0')
+import gtk
import os
##default path for the open/save dialogs
@@ -55,3 +58,6 @@
##The size of the state saving cache in the flow graph (for undo/redo
functionality)
STATE_CACHE_SIZE = 42
+
+##Shared targets for drag and drop of blocks
+DND_TARGETS = [('STRING', gtk.TARGET_SAME_APP, 0)]
Modified: gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py
2009-04-11 03:45:38 UTC (rev 10801)
+++ gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py
2009-04-11 06:22:06 UTC (rev 10802)
@@ -1,5 +1,5 @@
"""
-Copyright 2007 Free Software Foundation, Inc.
+Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -20,7 +20,7 @@
import pygtk
pygtk.require('2.0')
import gtk
-from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT
+from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT, DND_TARGETS
class DrawingArea(gtk.DrawingArea):
"""
@@ -51,6 +51,9 @@
gtk.gdk.LEAVE_NOTIFY_MASK | \
gtk.gdk.ENTER_NOTIFY_MASK
)
+ #setup drag and drop
+ self.drag_dest_set(gtk.DEST_DEFAULT_ALL, DND_TARGETS,
gtk.gdk.ACTION_COPY)
+ self.connect('drag-data-received',
self._handle_drag_data_received)
#setup the focus flag
self._focus_flag = False
self.get_focus_flag = lambda: self._focus_flag
@@ -69,6 +72,12 @@
##########################################################################
## Handlers
##########################################################################
+ def _handle_drag_data_received(self, widget, drag_context, x, y,
selection_data, info, time):
+ """
+ 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
Modified:
gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py
2009-04-11 03:45:38 UTC (rev 10801)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py
2009-04-11 06:22:06 UTC (rev 10802)
@@ -74,20 +74,23 @@
def get_scroll_pane(self): return self.drawing_area.get_parent()
def get_ctrl_mask(self): return self.drawing_area.ctrl_mask
- def add_new_block(self, key):
+ def add_new_block(self, key, coor=None):
"""
Add a block of the given key to this flow graph.
@param key the block key
+ @param coor an optional coordinate or None for random
"""
id = self._get_unique_id(key)
#calculate the position coordinate
h_adj = self.get_scroll_pane().get_hadjustment()
v_adj = self.get_scroll_pane().get_vadjustment()
- x = int(random.uniform(.25, .75)*h_adj.page_size +
h_adj.get_value())
- y = int(random.uniform(.25, .75)*v_adj.page_size +
v_adj.get_value())
+ if coor is None: coor = (
+ int(random.uniform(.25, .75)*h_adj.page_size +
h_adj.get_value()),
+ int(random.uniform(.25, .75)*v_adj.page_size +
v_adj.get_value()),
+ )
#get the new block
block = self.get_new_block(key)
- block.set_coordinate((x, y))
+ block.set_coordinate(coor)
block.set_rotation(0)
block.get_param('id').set_value(id)
self.handle_states(ELEMENT_CREATE)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10802 - in gnuradio/branches/developers/jblum/grc/grc/src: gui platforms/gui,
jblum <=