[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8809 - in grc/trunk: notes src/grc src/grc/elements s
From: |
jblum |
Subject: |
[Commit-gnuradio] r8809 - in grc/trunk: notes src/grc src/grc/elements src/grc/gui src/grc/gui/elements |
Date: |
Sun, 6 Jul 2008 02:28:36 -0600 (MDT) |
Author: jblum
Date: 2008-07-06 02:28:35 -0600 (Sun, 06 Jul 2008)
New Revision: 8809
Modified:
grc/trunk/notes/todo.txt
grc/trunk/src/grc/ActionHandler.py
grc/trunk/src/grc/Actions.py
grc/trunk/src/grc/elements/FlowGraph.py
grc/trunk/src/grc/gui/Bars.py
grc/trunk/src/grc/gui/Dialogs.py
grc/trunk/src/grc/gui/elements/FlowGraph.py
Log:
cut/copy/paste blocks
Modified: grc/trunk/notes/todo.txt
===================================================================
--- grc/trunk/notes/todo.txt 2008-07-06 05:28:12 UTC (rev 8808)
+++ grc/trunk/notes/todo.txt 2008-07-06 08:28:35 UTC (rev 8809)
@@ -1,32 +1,21 @@
-############ GRC Reloaded: #############
--html documentation/tutorial
--default platform for preferences block
-
############ Blocks to Add: ####################
--see checklist
-pad source/sink
-hier block
-optparse block
+-ofdm wrappers
############ Features to Add: ####################
-save working directory after close
-create sub-flow graphs to be used in larger flow graphs
--copy and paste blocks
--disable blocks (grey out, keep in design file, but generate ignores)
-param editor, expand entry boxes in focus
-change param dialog to panel within main window
+-default platform for preferences block
+-command line option for additional block wrappers
+-block tree class
+-dtd for external blocks
+-hotkeys in action descriptions
############ Suggestions: ####################
--scope sink constructor needs average option and triggering option
--const sink constructor needs marker option
--clean up const sink display (hide x:t)
--clean up scope sink display (hide x:t)
+-simple usrp
-tune_result in usrp.py needs __str__ method
-############ Get GTK Stock IDs: ####################
-gtk.stock_list_ids()
-
-############ connect packet mod to demod: ####################
-gr.packed_to_unpacked_bb(self.bits_per_symbol(), gr.GR_MSB_FIRST)
-gr.unpack_k_bits_bb(self.bits_per_symbol())
-
Modified: grc/trunk/src/grc/ActionHandler.py
===================================================================
--- grc/trunk/src/grc/ActionHandler.py 2008-07-06 05:28:12 UTC (rev 8808)
+++ grc/trunk/src/grc/ActionHandler.py 2008-07-06 08:28:35 UTC (rev 8809)
@@ -48,6 +48,7 @@
@param file_paths a list of flow graph file passed from command
line
@param platform platform module
"""
+ self.clipboard = None
platform = Platform(platform)
if PY_GTK_ICON:
gtk.window_set_default_icon_from_file(PY_GTK_ICON)
for action in ACTIONS_LIST: action.connect('activate',
self._handle_actions)
@@ -91,6 +92,13 @@
self.handle_states(FLOW_GRAPH_NEW)
elif ctrl and keyname == 'q':
self.handle_states(FLOW_GRAPH_CLOSE)
+ #################### Cut/Copy/Paste
###############################
+ elif self.get_focus_flag() and ctrl and keyname == 'x': #mouse
focus
+ self.handle_states(BLOCK_CUT)
+ elif self.get_focus_flag() and ctrl and keyname == 'c': #mouse
focus
+ self.handle_states(BLOCK_COPY)
+ elif self.get_focus_flag() and ctrl and keyname == 'v': #mouse
focus
+ self.handle_states(BLOCK_PASTE)
#################### Undo/Redo
###############################
elif ctrl and keyname == 'z':
self.handle_states(FLOW_GRAPH_UNDO)
@@ -98,7 +106,7 @@
self.handle_states(FLOW_GRAPH_REDO)
#################### Delete ###############################
elif self.get_focus_flag() and keyname == 'Delete': #mouse
focus
- self.handle_states(ELEMENT_REMOVE)
+ self.handle_states(ELEMENT_DELETE)
#################### Params ###############################
elif self.get_focus_flag() and keyname == 'Return': #mouse
focus
self.handle_states(BLOCK_PARAM_MODIFY)
@@ -147,7 +155,7 @@
def _handle_actions(self, event):
"""
Handle all of the activate signals from the gtk actions.
- The action signals derive from clicking on a toolbar or menu
bar button.
+ The action signals derive from clicking on a toolbar or menu
bar button.
Forward the action to the state handler.
"""
self.handle_states(event.get_name())
@@ -158,7 +166,7 @@
Handle all of the state changes that arise from the action
handler or other gui and
inputs in the application. The state passed to the
handle_states method is a string descriping
the change. A series of if/elif statements handle the state by
greying out action buttons, causing
- changes in the flow graph, saving/opening files... The
handle_states method is passed to the
+ changes in the flow graph, saving/opening files... The
handle_states method is passed to the
contructors of many of the classes used in this application
enabling them to report any state change.
@param state a string describing the state change
"""
@@ -188,14 +196,14 @@
# Selections
##############################################################################################
elif state == BLOCK_SELECT or state == PORT_SELECT:
- for action in (ELEMENT_REMOVE, BLOCK_PARAM_MODIFY,
BLOCK_ROTATE_RIGHT, BLOCK_ROTATE_LEFT):
+ for action in (ELEMENT_DELETE, BLOCK_PARAM_MODIFY,
BLOCK_ROTATE_RIGHT, BLOCK_ROTATE_LEFT):
get_action_from_name(action).set_sensitive(True)
elif state == CONNECTION_SELECT:
- get_action_from_name(ELEMENT_REMOVE).set_sensitive(True)
+ get_action_from_name(ELEMENT_DELETE).set_sensitive(True)
for action in (BLOCK_PARAM_MODIFY, BLOCK_ROTATE_RIGHT,
BLOCK_ROTATE_LEFT):
get_action_from_name(action).set_sensitive(False)
elif state == NOTHING_SELECT:
- for action in (ELEMENT_REMOVE, BLOCK_PARAM_MODIFY,
BLOCK_ROTATE_RIGHT, BLOCK_ROTATE_LEFT):
+ for action in (ELEMENT_DELETE, BLOCK_PARAM_MODIFY,
BLOCK_ROTATE_RIGHT, BLOCK_ROTATE_LEFT):
get_action_from_name(action).set_sensitive(False)
self.get_flow_graph().unselect()
##############################################################################################
@@ -210,6 +218,18 @@
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
self.get_page().set_saved(False)
##############################################################################################
+ # Cut/Copy/Paste
+
##############################################################################################
+ elif state == BLOCK_CUT:
+ self.handle_states(BLOCK_COPY)
+ self.handle_states(ELEMENT_DELETE)
+ elif state == BLOCK_COPY:
+ block = self.get_flow_graph().get_selected_block()
+ if block: self.clipboard = block.export_data()
+ elif state == BLOCK_PASTE:
+ if self.clipboard:
+ block =
self.get_flow_graph().add_new_block(key=self.clipboard['key'], n=self.clipboard)
+
##############################################################################################
# Move/Rotate/Delete/Create
##############################################################################################
elif state == BLOCK_MOVE:
@@ -223,7 +243,7 @@
if self.get_flow_graph().rotate_selected(DIR_RIGHT):
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
self.get_page().set_saved(False)
- elif state == ELEMENT_REMOVE:
+ elif state == ELEMENT_DELETE:
if self.get_flow_graph().remove_selected():
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
self.handle_states(NOTHING_SELECT)
@@ -345,6 +365,10 @@
##############################################################################################
# Global Actions for all States
##############################################################################################
+ #update cut/copy/paste
+
get_action_from_name(BLOCK_CUT).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
+
get_action_from_name(BLOCK_COPY).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
+
get_action_from_name(BLOCK_PASTE).set_sensitive(bool(self.clipboard))
#update enable/disable
get_action_from_name(BLOCK_ENABLE).set_sensitive(bool(
self.get_flow_graph().get_selected_block() and not
self.get_flow_graph().get_selected_block().get_enabled()
Modified: grc/trunk/src/grc/Actions.py
===================================================================
--- grc/trunk/src/grc/Actions.py 2008-07-06 05:28:12 UTC (rev 8808)
+++ grc/trunk/src/grc/Actions.py 2008-07-06 08:28:35 UTC (rev 8809)
@@ -49,12 +49,16 @@
BLOCK_ENABLE = 'block enable'
BLOCK_DISABLE = 'block disable'
+BLOCK_CUT = 'block cut'
+BLOCK_COPY = 'block copy'
+BLOCK_PASTE = 'block paste'
+
PORT_CONTROLLER_INC = 'port controller increment'
PORT_CONTROLLER_DEC = 'port controller decrement'
CONNECTION_SELECT = 'connection select'
CONNECTION_CREATE = 'conection create'
-ELEMENT_REMOVE = 'element remove'
+ELEMENT_DELETE = 'element remove'
FLOW_GRAPH_OPEN = 'flow graph open'
FLOW_GRAPH_UNDO = 'flow graph undo'
@@ -85,12 +89,15 @@
gtk.Action(APPLICATION_QUIT, '_Quit', 'Quit program', 'gtk-quit'),
gtk.Action(FLOW_GRAPH_UNDO, '_Undo', 'Undo a change to the flow graph',
'gtk-undo'),
gtk.Action(FLOW_GRAPH_REDO, '_Redo', 'Redo a change to the flow graph',
'gtk-redo'),
- gtk.Action(ELEMENT_REMOVE, '_Delete', 'Delete the selected block',
'gtk-delete'),
+ gtk.Action(ELEMENT_DELETE, '_Delete', 'Delete the selected block',
'gtk-delete'),
gtk.Action(BLOCK_ROTATE_LEFT, 'Rotate _Left', 'Rotate the block 90
degrees', 'gtk-go-back'),
gtk.Action(BLOCK_ROTATE_RIGHT, 'Rotate _Right', 'Rotate the block -90
degrees', 'gtk-go-forward'),
gtk.Action(BLOCK_PARAM_MODIFY, '_Properties', 'Modify params for the
selected block', 'gtk-properties'),
gtk.Action(BLOCK_ENABLE, 'E_nable', 'Enable the block', 'gtk-connect'),
gtk.Action(BLOCK_DISABLE, 'D_isable', 'Disable the block',
'gtk-disconnect'),
+ gtk.Action(BLOCK_CUT, 'Cu_t', 'Cut', 'gtk-cut'),
+ gtk.Action(BLOCK_COPY, '_Copy', 'Copy', 'gtk-copy'),
+ gtk.Action(BLOCK_PASTE, '_Paste', 'Paste', 'gtk-paste'),
gtk.Action(PREFS_WINDOW_DISPLAY, '_Preferences', 'Configure
Preferences', 'gtk-preferences'),
gtk.Action(ABOUT_WINDOW_DISPLAY, '_About', 'About this program',
'gtk-about'),
gtk.Action(HOTKEYS_WINDOW_DISPLAY, '_HotKeys', 'Hot Keys', 'gtk-info'),
Modified: grc/trunk/src/grc/elements/FlowGraph.py
===================================================================
--- grc/trunk/src/grc/elements/FlowGraph.py 2008-07-06 05:28:12 UTC (rev
8808)
+++ grc/trunk/src/grc/elements/FlowGraph.py 2008-07-06 08:28:35 UTC (rev
8809)
@@ -29,7 +29,7 @@
from grc import Messages
class FlowGraph(Element):
-
+
def __init__(self, platform):
"""!
Make a flow graph from the arguments.
@@ -42,9 +42,9 @@
Element.__init__(self, platform)
#inital blank import
self.import_data({'flow_graph': {}})
-
+
def __str__(self): return 'FlowGraph - "%s"'%self.get_option('name')
-
+
def get_option(self, key):
"""!
Get the option for a given key.
@@ -53,9 +53,9 @@
@return the value held by that param
"""
return self._options_block.get_param(key).evaluate()
-
+
def is_flow_graph(self): return True
-
+
##############################################
## Access Elements
##############################################
@@ -67,7 +67,7 @@
Get a list of all the elements.
Always ensure that the options block is in the list.
@return the element list
- """
+ """
if self._options_block not in self._elements:
self._elements.append(self._options_block)
#ensure uniqueness of the elements list
element_set = set()
@@ -78,7 +78,7 @@
#store cleaned up list
self._elements = element_list
return self._elements
-
+
def get_new_block(self, key):
"""!
Get a new block of the specified key.
@@ -88,10 +88,10 @@
"""
self.flag()
if key not in self.get_parent().get_block_keys(): return None
- block = self.get_parent().get_new_block(self, key)
+ block = self.get_parent().get_new_block(self, key)
self.get_elements().append(block)
- return block
-
+ return block
+
def connect(self, porta, portb):
"""!
Create a connection between porta and portb.
@@ -104,7 +104,7 @@
connection = self.get_parent().Connection(self, porta, portb)
self.get_elements().append(connection)
return connection
-
+
def remove_element(self, element):
"""!
Remove the element from the list of elements.
@@ -115,24 +115,24 @@
self.flag()
if element not in self.get_elements(): return
#found a port, set to parent signal block
- if element.is_source() or element.is_sink():
- element = element.get_parent()
- #remove block, remove all involved connections
- if element.is_block():
+ if element.is_source() or element.is_sink():
+ element = element.get_parent()
+ #remove block, remove all involved connections
+ if element.is_block():
for port in element.get_sources() + element.get_sinks():
map(lambda c: self.remove_element(c),
port.get_connections())
#remove a connection
elif element.is_connection(): pass
self.get_elements().remove(element)
-
+
def evaluate(self, expr):
"""!
Evaluate the expression.
@param expr the string expression
@throw NotImplementedError
"""
- raise NotImplementedError
-
+ raise NotImplementedError
+
def validate(self):
"""
Validate the flow graph.
@@ -141,10 +141,10 @@
for c in self.get_elements():
try: assert(c.is_valid())
except AssertionError: self._add_error_message('Element
"%s" is not valid.'%c)
-
+
##############################################
## Import/Export Methods
- ##############################################
+ ##############################################
def export_data(self):
"""
Export this flow graph to nested data.
@@ -157,7 +157,7 @@
n['block'] = [block.export_data() for block in
self.get_blocks()]
n['connection'] = [connection.export_data() for connection in
self.get_connections()]
return {'flow_graph': n}
-
+
def import_data(self, n):
"""
Import blocks and connections into this flow graph.
@@ -169,14 +169,14 @@
self._elements = list()
#the flow graph tag must exists, or use blank data
if 'flow_graph' in n.keys(): fg_n = n['flow_graph']
- else:
+ else:
Messages.send_error_load('Flow graph data not found,
loading blank flow graph.')
fg_n = {}
blocks_n = Utils.listify(fg_n, 'block')
connections_n = Utils.listify(fg_n, 'connection')
#create option block
- self._options_block = self.get_parent().get_new_block(self,
'options')
- self._options_block.get_param('id').set_value('options')
+ self._options_block = self.get_parent().get_new_block(self,
'options')
+ self._options_block.get_param('id').set_value('options')
#build the blocks
for block_n in blocks_n:
key = block_n['key']
@@ -184,7 +184,7 @@
else: block = self.get_new_block(key)
#only load the block when the block key was valid
if block: block.import_data(block_n)
- else: Messages.send_error_load('Block key "%s" not
found in %s'%(key, self.get_parent()))
+ else: Messages.send_error_load('Block key "%s" not
found in %s'%(key, self.get_parent()))
#build the connections
for connection_n in connections_n:
#test that the data tags exist
@@ -195,7 +195,7 @@
assert('sink_key' in connection_n.keys())
except AssertionError: continue
#try to make the connection
- try:
+ try:
#get the block ids
source_block_id =
connection_n['source_block_id']
sink_block_id = connection_n['sink_block_id']
@@ -208,15 +208,15 @@
assert(sink_block_id in block_ids)
#get the blocks
source_block = self.get_block(source_block_id)
- sink_block = self.get_block(sink_block_id)
+ sink_block = self.get_block(sink_block_id)
#verify the ports
assert(source_key in
source_block.get_source_keys())
assert(sink_key in sink_block.get_sink_keys())
#get the ports
source = source_block.get_source(source_key)
- sink = sink_block.get_sink(sink_key)
+ sink = sink_block.get_sink(sink_key)
#build the connection
self.connect(source, sink)
except AssertionError:
Messages.send_error_load('Connection between %s(%s) and %s(%s) could not be
made.'%(source_block_id, source_key, sink_block_id, sink_key))
self.validate()
-
+
Modified: grc/trunk/src/grc/gui/Bars.py
===================================================================
--- grc/trunk/src/grc/gui/Bars.py 2008-07-06 05:28:12 UTC (rev 8808)
+++ grc/trunk/src/grc/gui/Bars.py 2008-07-06 08:28:35 UTC (rev 8809)
@@ -30,9 +30,15 @@
FLOW_GRAPH_NEW,
FLOW_GRAPH_OPEN,
FLOW_GRAPH_SAVE,
+ FLOW_GRAPH_CLOSE,
None,
FLOW_GRAPH_SCREEN_CAPTURE,
None,
+ BLOCK_CUT,
+ BLOCK_COPY,
+ BLOCK_PASTE,
+ ELEMENT_DELETE,
+ None,
FLOW_GRAPH_UNDO,
FLOW_GRAPH_REDO,
None,
@@ -40,7 +46,6 @@
FLOW_GRAPH_EXEC,
FLOW_GRAPH_KILL,
None,
- ELEMENT_REMOVE,
BLOCK_ROTATE_LEFT,
BLOCK_ROTATE_RIGHT,
None,
@@ -66,13 +71,18 @@
FLOW_GRAPH_UNDO,
FLOW_GRAPH_REDO,
None,
- ELEMENT_REMOVE,
+ BLOCK_CUT,
+ BLOCK_COPY,
+ BLOCK_PASTE,
+ ELEMENT_DELETE,
+ None,
BLOCK_ROTATE_LEFT,
BLOCK_ROTATE_RIGHT,
- BLOCK_PARAM_MODIFY,
None,
BLOCK_ENABLE,
BLOCK_DISABLE,
+ None,
+ BLOCK_PARAM_MODIFY,
]),
(gtk.Action('Build', '_Build', None, None), [
FLOW_GRAPH_GEN,
Modified: grc/trunk/src/grc/gui/Dialogs.py
===================================================================
--- grc/trunk/src/grc/gui/Dialogs.py 2008-07-06 05:28:12 UTC (rev 8808)
+++ grc/trunk/src/grc/gui/Dialogs.py 2008-07-06 08:28:35 UTC (rev 8809)
@@ -121,6 +121,9 @@
('Open Flow Graph', 'Ctrl + o'),
('Save Flow Graph', 'Ctrl + s'),
('Close Flow Graph', 'Ctrl + q'),
+ ('Cut Block', 'Ctrl + x'),
+ ('Copy Block', 'Ctrl + c'),
+ ('Paste Block', 'Ctrl + v'),
('Undo Change', 'Ctrl + z'),
('Redo Change', 'Ctrl + y'),
('Delete Block', 'Delete'),
Modified: grc/trunk/src/grc/gui/elements/FlowGraph.py
===================================================================
--- grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-06 05:28:12 UTC (rev
8808)
+++ grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-06 08:28:35 UTC (rev
8809)
@@ -20,6 +20,7 @@
#A flow graph structure for storing signal blocks and their connections.
address@hidden Josh Blum
+from grc import Utils
from grc.Constants import *
from grc.Actions import *
from Colors import BACKGROUND_COLOR, TXT_COLOR
@@ -73,10 +74,11 @@
# Flow Graph Access Methods
###########################################################################
- def add_new_block(self, key):
+ def add_new_block(self, key, n=None):
"""!
Add a block of the given key to this flow graph.
@param key the block key
+ @param n nested data preloader for block
"""
index = -1
while True:
@@ -93,6 +95,14 @@
block.set_coordinate((x, y))
block.set_rotation(0)
block.get_param('id').set_value(id)
+ #set params from n
+ if n:
+ params_n = Utils.listify(n, 'param')
+ for param_n in params_n:
+ key = param_n['key']
+ value = param_n['value']
+ if not (key.startswith('_') or
key.startswith('gui') or key == 'id'):
+
block.get_param(key).set_value(value)
#handle new state
self.handle_states(BLOCK_CREATE)
self.update()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8809 - in grc/trunk: notes src/grc src/grc/elements src/grc/gui src/grc/gui/elements,
jblum <=