[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/25: grc: some action handler refactoring
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/25: grc: some action handler refactoring, add flow_graph.update() wrapper |
Date: |
Fri, 27 May 2016 19:14:58 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 93684ad812196ae59150912d0193e40b8eeaf769
Author: Sebastian Koslowski <address@hidden>
Date: Sat May 7 14:03:34 2016 +0200
grc: some action handler refactoring, add flow_graph.update() wrapper
---
grc/gui/ActionHandler.py | 300 ++++++++++++++++++++++++-----------------------
grc/gui/FlowGraph.py | 6 +-
2 files changed, 159 insertions(+), 147 deletions(-)
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 422d107..e5f14bc 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -61,7 +61,6 @@ class ActionHandler:
self.main_window.connect('delete-event', self._quit)
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.get_focus_flag
#setup the messages
Messages.register_messenger(self.main_window.add_report_line)
@@ -104,6 +103,12 @@ class ActionHandler:
def _handle_action(self, action, *args):
#print action
+ page = self.main_window.get_page()
+ flow_graph = page.get_flow_graph() if page else None
+
+ def flow_graph_update(fg=flow_graph):
+ fg.update()
+
##################################################
# Initialize/Quit
##################################################
@@ -115,7 +120,8 @@ class ActionHandler:
if file_path: self.main_window.new_page(file_path) #load pages
from file paths
if Preferences.file_open() in self.init_file_paths:
self.main_window.new_page(Preferences.file_open(), show=True)
- if not self.get_page(): self.main_window.new_page() #ensure that
at least a blank page exists
+ if not self.get_page():
+ self.main_window.new_page() # ensure that at least a blank
page exists
self.main_window.btwin.search_entry.hide()
@@ -156,27 +162,27 @@ class ActionHandler:
elif action == Actions.ELEMENT_SELECT:
pass #do nothing, update routines below
elif action == Actions.NOTHING_SELECT:
- self.get_flow_graph().unselect()
+ flow_graph.unselect()
elif action == Actions.SELECT_ALL:
- self.get_flow_graph().select_all()
+ flow_graph.select_all()
##################################################
# Enable/Disable
##################################################
elif action == Actions.BLOCK_ENABLE:
- if self.get_flow_graph().enable_selected(True):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.enable_selected(True):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.BLOCK_DISABLE:
- if self.get_flow_graph().enable_selected(False):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.enable_selected(False):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.BLOCK_BYPASS:
- if self.get_flow_graph().bypass_selected():
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.bypass_selected():
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
##################################################
# Cut/Copy/Paste
##################################################
@@ -184,20 +190,20 @@ class ActionHandler:
Actions.BLOCK_COPY()
Actions.ELEMENT_DELETE()
elif action == Actions.BLOCK_COPY:
- self.clipboard = self.get_flow_graph().copy_to_clipboard()
+ self.clipboard = flow_graph.copy_to_clipboard()
elif action == Actions.BLOCK_PASTE:
if self.clipboard:
- self.get_flow_graph().paste_from_clipboard(self.clipboard)
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ flow_graph.paste_from_clipboard(self.clipboard)
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
##################################################
# Create heir block
##################################################
elif action == Actions.BLOCK_CREATE_HIER:
# keeping track of coordinates for pasting later
- coords =
self.get_flow_graph().get_selected_blocks()[0].get_coordinate()
+ coords =
flow_graph.get_selected_blocks()[0].get_coordinate()
x,y = coords
x_min = x
y_min = y
@@ -206,15 +212,15 @@ class ActionHandler:
params = [];
# Save the state of the leaf blocks
- for block in
self.get_flow_graph().get_selected_blocks():
+ for block in flow_graph.get_selected_blocks():
# Check for string variables within the blocks
for param in block.get_params():
- for variable in
self.get_flow_graph().get_variables():
+ for variable in flow_graph.get_variables():
# If a block parameter exists that is a
variable, create a parameter for it
if param.get_value() == variable.get_id():
params.append(param.get_value())
- for flow_param in
self.get_flow_graph().get_parameters():
+ for flow_param in flow_graph.get_parameters():
# If a block parameter exists that is a
parameter, create a parameter for it
if param.get_value() ==
flow_param.get_id():
params.append(param.get_value())
@@ -234,10 +240,10 @@ class ActionHandler:
sink_id =
connection.get_sink().get_parent().get_id()
# If connected block is not in the list of
selected blocks create a pad for it
- if self.get_flow_graph().get_block(source_id)
not in self.get_flow_graph().get_selected_blocks():
+ if flow_graph.get_block(source_id) not in
flow_graph.get_selected_blocks():
pads.append({'key':
connection.get_sink().get_key(), 'coord':
connection.get_source().get_coordinate(), 'block_id' : block.get_id(),
'direction': 'source'})
- if self.get_flow_graph().get_block(sink_id)
not in self.get_flow_graph().get_selected_blocks():
+ if flow_graph.get_block(sink_id) not in
flow_graph.get_selected_blocks():
pads.append({'key':
connection.get_source().get_key(), 'coord':
connection.get_sink().get_coordinate(), 'block_id' : block.get_id(),
'direction': 'sink'})
@@ -247,26 +253,26 @@ class ActionHandler:
self.main_window.new_page()
Actions.BLOCK_PASTE()
coords = (x_min,y_min)
- self.get_flow_graph().move_selected(coords)
+ flow_graph.move_selected(coords)
# Set flow graph to heir block type
- top_block =
self.get_flow_graph().get_block("top_block")
+ top_block = flow_graph.get_block("top_block")
top_block.get_param('generate_options').set_value('hb')
# this needs to be a unique name
top_block.get_param('id').set_value('new_heir')
# Remove the default samp_rate variable block that is
created
- remove_me =
self.get_flow_graph().get_block("samp_rate")
- self.get_flow_graph().remove_element(remove_me)
+ remove_me = flow_graph.get_block("samp_rate")
+ flow_graph.remove_element(remove_me)
# Add the param blocks along the top of the window
x_pos = 150
for param in params:
- param_id =
self.get_flow_graph().add_new_block('parameter',(x_pos,10))
- param_block =
self.get_flow_graph().get_block(param_id)
+ param_id =
flow_graph.add_new_block('parameter',(x_pos,10))
+ param_block = flow_graph.get_block(param_id)
param_block.get_param('id').set_value(param)
x_pos = x_pos + 100
@@ -275,13 +281,13 @@ class ActionHandler:
if pad['direction'] == 'sink':
# Add new PAD_SINK block to the canvas
- pad_id =
self.get_flow_graph().add_new_block('pad_sink', pad['coord'])
+ pad_id = flow_graph.add_new_block('pad_sink',
pad['coord'])
# setup the references to the sink and source
- pad_block =
self.get_flow_graph().get_block(pad_id)
+ pad_block = flow_graph.get_block(pad_id)
pad_sink = pad_block.get_sinks()[0]
- source_block =
self.get_flow_graph().get_block(pad['block_id'])
+ source_block =
flow_graph.get_block(pad['block_id'])
source = source_block.get_source(pad['key'])
# Ensure the port types match
@@ -293,16 +299,16 @@ class ActionHandler:
pad_block.type_controller_modify(1)
# Connect the pad to the proper sinks
- new_connection =
self.get_flow_graph().connect(source,pad_sink)
+ new_connection =
flow_graph.connect(source,pad_sink)
elif pad['direction'] == 'source':
- pad_id =
self.get_flow_graph().add_new_block('pad_source', pad['coord'])
+ pad_id =
flow_graph.add_new_block('pad_source', pad['coord'])
# setup the references to the sink and source
- pad_block =
self.get_flow_graph().get_block(pad_id)
+ pad_block = flow_graph.get_block(pad_id)
pad_source = pad_block.get_sources()[0]
- sink_block =
self.get_flow_graph().get_block(pad['block_id'])
+ sink_block =
flow_graph.get_block(pad['block_id'])
sink = sink_block.get_sink(pad['key'])
# Ensure the port types match
@@ -313,77 +319,75 @@ class ActionHandler:
pad_block.type_controller_modify(1)
# Connect the pad to the proper sinks
- new_connection =
self.get_flow_graph().connect(pad_source,sink)
+ new_connection =
flow_graph.connect(pad_source,sink)
# update the new heir block flow graph
- self.get_flow_graph().update()
+ flow_graph_update()
##################################################
# Move/Rotate/Delete/Create
##################################################
elif action == Actions.BLOCK_MOVE:
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
-
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action in Actions.BLOCK_ALIGNMENTS:
- if self.get_flow_graph().align_selected(action):
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
-
+ if flow_graph.align_selected(action):
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.BLOCK_ROTATE_CCW:
- if self.get_flow_graph().rotate_selected(90):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.rotate_selected(90):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.BLOCK_ROTATE_CW:
- if self.get_flow_graph().rotate_selected(-90):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.rotate_selected(-90):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.ELEMENT_DELETE:
- if self.get_flow_graph().remove_selected():
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+ if flow_graph.remove_selected():
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
Actions.NOTHING_SELECT()
- self.get_page().set_saved(False)
+ page.set_saved(False)
elif action == Actions.ELEMENT_CREATE:
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
Actions.NOTHING_SELECT()
- self.get_page().set_saved(False)
+ page.set_saved(False)
elif action == Actions.BLOCK_INC_TYPE:
- if self.get_flow_graph().type_controller_modify_selected(1):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.type_controller_modify_selected(1):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.BLOCK_DEC_TYPE:
- if self.get_flow_graph().type_controller_modify_selected(-1):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.type_controller_modify_selected(-1):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.PORT_CONTROLLER_INC:
- if self.get_flow_graph().port_controller_modify_selected(1):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.port_controller_modify_selected(1):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
elif action == Actions.PORT_CONTROLLER_DEC:
- if self.get_flow_graph().port_controller_modify_selected(-1):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ if flow_graph.port_controller_modify_selected(-1):
+ flow_graph_update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
##################################################
# Window stuff
##################################################
elif action == Actions.ABOUT_WINDOW_DISPLAY:
- platform = self.get_flow_graph().get_parent()
+ platform = flow_graph.get_parent()
Dialogs.AboutDialog(platform.config)
elif action == Actions.HELP_WINDOW_DISPLAY:
Dialogs.HelpDialog()
elif action == Actions.TYPES_WINDOW_DISPLAY:
- Dialogs.TypesDialog(self.get_flow_graph().get_parent())
+ Dialogs.TypesDialog(flow_graph.get_parent())
elif action == Actions.ERRORS_WINDOW_DISPLAY:
- Dialogs.ErrorsDialog(self.get_flow_graph())
+ Dialogs.ErrorsDialog(flow_graph)
elif action == Actions.TOGGLE_REPORTS_WINDOW:
if action.get_active():
self.main_window.reports_scrolled_window.show()
@@ -405,7 +409,7 @@ class ActionHandler:
elif action == Actions.CLEAR_REPORTS:
self.main_window.text_display.clear()
elif action == Actions.SAVE_REPORTS:
- file_path =
SaveReportsFileDialog(self.get_page().get_file_path()).run()
+ file_path = SaveReportsFileDialog(page.get_file_path()).run()
if file_path is not None:
self.main_window.text_display.save(file_path)
elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS:
@@ -421,7 +425,7 @@ class ActionHandler:
elif action == Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY:
action.save_to_preferences()
for page in self.main_window.get_pages():
- page.get_flow_graph().update()
+ flow_graph_update(page.get_flow_graph())
elif action == Actions.TOGGLE_HIDE_VARIABLES:
Actions.NOTHING_SELECT()
action.save_to_preferences()
@@ -429,31 +433,34 @@ class ActionHandler:
# Param Modifications
##################################################
elif action == Actions.BLOCK_PARAM_MODIFY:
- selected_block = self.get_flow_graph().get_selected_block()
+ if action.args:
+ selected_block = action.args[0]
+ else:
+ selected_block = flow_graph.get_selected_block()
if selected_block:
self.dialog = PropsDialog(selected_block)
response = gtk.RESPONSE_APPLY
while response == gtk.RESPONSE_APPLY: # rerun the dialog if
Apply was hit
response = self.dialog.run()
if response in (gtk.RESPONSE_APPLY, gtk.RESPONSE_ACCEPT):
- self.get_flow_graph().update()
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_page().set_saved(False)
+ flow_graph_update()
+
page.get_state_cache().save_new_state(flow_graph.export_data())
+ page.set_saved(False)
else: # restore the current state
- n =
self.get_page().get_state_cache().get_current_state()
- self.get_flow_graph().import_data(n)
- self.get_flow_graph().update()
+ n = page.get_state_cache().get_current_state()
+ flow_graph.import_data(n)
+ flow_graph_update()
if response == gtk.RESPONSE_APPLY:
# null action, that updates the main window
Actions.ELEMENT_SELECT()
self.dialog.destroy()
self.dialog = None
elif action == Actions.EXTERNAL_UPDATE:
-
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
- self.get_flow_graph().update()
+ page.get_state_cache().save_new_state(flow_graph.export_data())
+ flow_graph_update()
if self.dialog is not None:
self.dialog.update_gui(force=True)
- self.get_page().set_saved(False)
+ page.set_saved(False)
##################################################
# View Parser Errors
##################################################
@@ -463,29 +470,29 @@ class ActionHandler:
# Undo/Redo
##################################################
elif action == Actions.FLOW_GRAPH_UNDO:
- n = self.get_page().get_state_cache().get_prev_state()
+ n = page.get_state_cache().get_prev_state()
if n:
- self.get_flow_graph().unselect()
- self.get_flow_graph().import_data(n)
- self.get_flow_graph().update()
- self.get_page().set_saved(False)
+ flow_graph.unselect()
+ flow_graph.import_data(n)
+ flow_graph_update()
+ page.set_saved(False)
elif action == Actions.FLOW_GRAPH_REDO:
- n = self.get_page().get_state_cache().get_next_state()
+ n = page.get_state_cache().get_next_state()
if n:
- self.get_flow_graph().unselect()
- self.get_flow_graph().import_data(n)
- self.get_flow_graph().update()
- self.get_page().set_saved(False)
+ flow_graph.unselect()
+ flow_graph.import_data(n)
+ flow_graph_update()
+ page.set_saved(False)
##################################################
# New/Open/Save/Close
##################################################
elif action == Actions.FLOW_GRAPH_NEW:
self.main_window.new_page()
if args:
-
self.get_flow_graph()._options_block.get_param('generate_options').set_value(args[0])
- self.get_flow_graph().update()
+
flow_graph._options_block.get_param('generate_options').set_value(args[0])
+ flow_graph_update()
elif action == Actions.FLOW_GRAPH_OPEN:
- file_paths = args if args else
OpenFlowGraphFileDialog(self.get_page().get_file_path()).run()
+ file_paths = args if args else
OpenFlowGraphFileDialog(page.get_file_path()).run()
if file_paths: #open a new page for each file, show only the first
for i,file_path in enumerate(file_paths):
self.main_window.new_page(file_path, show=(i==0))
@@ -507,60 +514,60 @@ class ActionHandler:
self.main_window.close_page()
elif action == Actions.FLOW_GRAPH_SAVE:
#read-only or undefined file path, do save-as
- if self.get_page().get_read_only() or not
self.get_page().get_file_path():
+ if page.get_read_only() or not page.get_file_path():
Actions.FLOW_GRAPH_SAVE_AS()
#otherwise try to save
else:
try:
- ParseXML.to_file(self.get_flow_graph().export_data(),
self.get_page().get_file_path())
- self.get_flow_graph().grc_file_path =
self.get_page().get_file_path()
- self.get_page().set_saved(True)
+ ParseXML.to_file(flow_graph.export_data(),
page.get_file_path())
+ flow_graph.grc_file_path = page.get_file_path()
+ page.set_saved(True)
except IOError:
- Messages.send_fail_save(self.get_page().get_file_path())
- self.get_page().set_saved(False)
+ Messages.send_fail_save(page.get_file_path())
+ page.set_saved(False)
elif action == Actions.FLOW_GRAPH_SAVE_AS:
- file_path =
SaveFlowGraphFileDialog(self.get_page().get_file_path()).run()
+ file_path = SaveFlowGraphFileDialog(page.get_file_path()).run()
if file_path is not None:
- self.get_page().set_file_path(file_path)
+ page.set_file_path(file_path)
Actions.FLOW_GRAPH_SAVE()
Preferences.add_recent_file(file_path)
self.main_window.tool_bar.refresh_submenus()
self.main_window.menu_bar.refresh_submenus()
elif action == Actions.FLOW_GRAPH_SCREEN_CAPTURE:
- file_path, background_transparent =
SaveScreenShotDialog(self.get_page().get_file_path()).run()
+ file_path, background_transparent =
SaveScreenShotDialog(page.get_file_path()).run()
if file_path is not None:
- pixbuf =
self.get_flow_graph().get_drawing_area().get_screenshot(background_transparent)
+ pixbuf =
flow_graph.get_drawing_area().get_screenshot(background_transparent)
pixbuf.save(file_path, Constants.IMAGE_FILE_EXTENSION[1:])
##################################################
# Gen/Exec/Stop
##################################################
elif action == Actions.FLOW_GRAPH_GEN:
- if not self.get_page().get_proc():
- if not self.get_page().get_saved() or not
self.get_page().get_file_path():
+ if not page.get_proc():
+ if not page.get_saved() or not page.get_file_path():
Actions.FLOW_GRAPH_SAVE() #only save if file path missing
or not saved
- if self.get_page().get_saved() and
self.get_page().get_file_path():
- generator = self.get_page().get_generator()
+ if page.get_saved() and page.get_file_path():
+ generator = page.get_generator()
try:
Messages.send_start_gen(generator.get_file_path())
generator.write()
except Exception,e: Messages.send_fail_gen(e)
else: self.generator = None
elif action == Actions.FLOW_GRAPH_EXEC:
- if not self.get_page().get_proc():
+ if not page.get_proc():
Actions.FLOW_GRAPH_GEN()
xterm = self.platform.config.xterm_executable
if Preferences.xterm_missing() != xterm:
if not os.path.exists(xterm):
Dialogs.MissingXTermDialog(xterm)
Preferences.xterm_missing(xterm)
- if self.get_page().get_saved() and
self.get_page().get_file_path():
+ if page.get_saved() and page.get_file_path():
Executor.ExecFlowGraphThread(self)
elif action == Actions.FLOW_GRAPH_KILL:
- if self.get_page().get_proc():
+ if page.get_proc():
try:
- self.get_page().get_proc().kill()
+ page.get_proc().kill()
except:
- print "could not kill process: %d" %
self.get_page().get_proc().pid
+ print "could not kill process: %d" % page.get_proc().pid
elif action == Actions.PAGE_CHANGE: # pass and run the global actions
pass
elif action == Actions.RELOAD_BLOCKS:
@@ -578,23 +585,23 @@ class ActionHandler:
self.main_window.btwin.search_entry.show()
self.main_window.btwin.search_entry.grab_focus()
elif action == Actions.OPEN_HIER:
- for b in self.get_flow_graph().get_selected_blocks():
+ for b in flow_graph.get_selected_blocks():
if b._grc_source:
self.main_window.new_page(b._grc_source, show=True)
elif action == Actions.BUSSIFY_SOURCES:
n = {'name':'bus', 'type':'bus'}
- for b in self.get_flow_graph().get_selected_blocks():
+ for b in flow_graph.get_selected_blocks():
b.bussify(n, 'source')
- self.get_flow_graph()._old_selected_port = None
- self.get_flow_graph()._new_selected_port = None
+ flow_graph._old_selected_port = None
+ flow_graph._new_selected_port = None
Actions.ELEMENT_CREATE()
elif action == Actions.BUSSIFY_SINKS:
n = {'name':'bus', 'type':'bus'}
- for b in self.get_flow_graph().get_selected_blocks():
+ for b in flow_graph.get_selected_blocks():
b.bussify(n, 'sink')
- self.get_flow_graph()._old_selected_port = None
- self.get_flow_graph()._new_selected_port = None
+ flow_graph._old_selected_port = None
+ flow_graph._new_selected_port = None
Actions.ELEMENT_CREATE()
elif action == Actions.TOOLS_RUN_FDESIGN:
@@ -606,12 +613,15 @@ class ActionHandler:
##################################################
# Global Actions for all States
##################################################
- selected_block = self.get_flow_graph().get_selected_block()
- selected_blocks = self.get_flow_graph().get_selected_blocks()
+ page = self.main_window.get_page() # page and flowgraph might have
changed
+ flow_graph = page.get_flow_graph() if page else None
+
+ selected_blocks = flow_graph.get_selected_blocks()
+ selected_block = selected_blocks[0] if selected_blocks else None
#update general buttons
- Actions.ERRORS_WINDOW_DISPLAY.set_sensitive(not
self.get_flow_graph().is_valid())
-
Actions.ELEMENT_DELETE.set_sensitive(bool(self.get_flow_graph().get_selected_elements()))
+ Actions.ERRORS_WINDOW_DISPLAY.set_sensitive(not flow_graph.is_valid())
+
Actions.ELEMENT_DELETE.set_sensitive(bool(flow_graph.get_selected_elements()))
Actions.BLOCK_PARAM_MODIFY.set_sensitive(bool(selected_block))
Actions.BLOCK_ROTATE_CCW.set_sensitive(bool(selected_blocks))
Actions.BLOCK_ROTATE_CW.set_sensitive(bool(selected_blocks))
@@ -643,17 +653,17 @@ class ActionHandler:
#set the exec and stop buttons
self.update_exec_stop()
#saved status
- Actions.FLOW_GRAPH_SAVE.set_sensitive(not self.get_page().get_saved())
+ Actions.FLOW_GRAPH_SAVE.set_sensitive(not page.get_saved())
self.main_window.update()
try: #set the size of the flow graph area (if changed)
- new_size = (self.get_flow_graph().get_option('window_size') or
+ new_size = (flow_graph.get_option('window_size') or
self.platform.config.default_canvas_size)
- if self.get_flow_graph().get_size() != tuple(new_size):
- self.get_flow_graph().set_size(*new_size)
+ if flow_graph.get_size() != tuple(new_size):
+ flow_graph.set_size(*new_size)
except: pass
#draw the flow graph
- self.get_flow_graph().update_selected()
- self.get_flow_graph().queue_draw()
+ flow_graph.update_selected()
+ flow_graph.queue_draw()
return True #action was handled
def update_exec_stop(self):
@@ -661,7 +671,7 @@ class ActionHandler:
Update the exec and stop buttons.
Lock and unlock the mutex for race conditions with exec flow graph
threads.
"""
- sensitive = self.get_flow_graph().is_valid() and not
self.get_page().get_proc()
+ sensitive = self.main_window.get_flow_graph().is_valid() and not
self.get_page().get_proc()
Actions.FLOW_GRAPH_GEN.set_sensitive(sensitive)
Actions.FLOW_GRAPH_EXEC.set_sensitive(sensitive)
Actions.FLOW_GRAPH_KILL.set_sensitive(self.get_page().get_proc() is
not None)
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index c3a88e9..67e28c5 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -586,7 +586,8 @@ class FlowGraph(Element, _Flowgraph):
Returns:
a block or None
"""
- return self.get_selected_blocks() and self.get_selected_blocks()[0] or
None
+ selected_blocks = self.get_selected_blocks()
+ return selected_blocks[0] if selected_blocks else None
def get_selected_elements(self):
"""
@@ -604,7 +605,8 @@ class FlowGraph(Element, _Flowgraph):
Returns:
a block, port, or connection or None
"""
- return self.get_selected_elements() and
self.get_selected_elements()[0] or None
+ selected_elements = self.get_selected_elements()
+ return selected_elements[0] if selected_elements else None
def update_selected_elements(self):
"""
- [Commit-gnuradio] [gnuradio] 10/25: grc: Variable editor tweaks., (continued)
- [Commit-gnuradio] [gnuradio] 10/25: grc: Variable editor tweaks., git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 25/25: Merge remote-tracking branch 'dkozel/uhd_lo_api', git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 16/25: Added controls for importing, exporting, and sharing LOs, git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 17/25: grc-refactor: fix custom canvas font sizes, git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 08/25: grc: Added the variable editor panel, git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 09/25: grc: Added context menu to variable editor, git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 06/25: grc: remove some dead code in FlowGraph.what_is_selected(), git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 23/25: Merge remote-tracking branch 'mbr0wn/modtool/versioning', git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 02/25: grc: block alignment tools, git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 03/25: grc: minor fixes/clean-ups, git, 2016/05/27
- [Commit-gnuradio] [gnuradio] 05/25: grc: some action handler refactoring, add flow_graph.update() wrapper,
git <=