diff options
Diffstat (limited to 'grc/gui/ActionHandler.py')
-rw-r--r-- | grc/gui/ActionHandler.py | 118 |
1 files changed, 76 insertions, 42 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 15565127e3..b9135418a3 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -18,23 +18,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import os -from Constants import IMAGE_FILE_EXTENSION -import Actions +import subprocess +from threading import Thread + import pygtk pygtk.require('2.0') import gtk import gobject -import subprocess -import Preferences -from threading import Thread -import Messages + from .. base import ParseXML, Constants -from MainWindow import MainWindow -from PropsDialog import PropsDialog -from ParserErrorsDialog import ParserErrorsDialog -import Dialogs -from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, SaveReportsFileDialog, SaveImageFileDialog -from . Constants import DEFAULT_CANVAS_SIZE +from .. python.Constants import XTERM_EXECUTABLE + +from . import Dialogs, Messages, Preferences, Actions +from .ParserErrorsDialog import ParserErrorsDialog +from .MainWindow import MainWindow +from .PropsDialog import PropsDialog +from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, + SaveReportsFileDialog, SaveImageFileDialog, + OpenQSSFileDialog) +from .Constants import DEFAULT_CANVAS_SIZE, IMAGE_FILE_EXTENSION, GR_PREFIX gobject.threads_init() @@ -56,10 +58,11 @@ class ActionHandler: platform: platform module """ self.clipboard = None + self.dialog = None for action in Actions.get_all_actions(): action.connect('activate', self._handle_action) #setup the main window - self.platform = platform; - self.main_window = MainWindow(platform) + self.platform = platform + self.main_window = MainWindow(platform, self._handle_action) 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 @@ -106,33 +109,18 @@ class ActionHandler: Actions.APPLICATION_QUIT() return True - def _handle_action(self, action): + def _handle_action(self, action, *args): #print action ################################################## # Initialize/Quit ################################################## if action == Actions.APPLICATION_INITIALIZE: - for action in Actions.get_all_actions(): action.set_sensitive(False) #set all actions disabled - #enable a select few actions - for action in ( - Actions.APPLICATION_QUIT, Actions.FLOW_GRAPH_NEW, - Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS, - Actions.FLOW_GRAPH_CLOSE, Actions.ABOUT_WINDOW_DISPLAY, - Actions.FLOW_GRAPH_SCREEN_CAPTURE, Actions.HELP_WINDOW_DISPLAY, - Actions.TYPES_WINDOW_DISPLAY, Actions.TOGGLE_BLOCKS_WINDOW, - Actions.TOGGLE_REPORTS_WINDOW, Actions.TOGGLE_HIDE_DISABLED_BLOCKS, - Actions.TOOLS_RUN_FDESIGN, Actions.TOGGLE_SCROLL_LOCK, - Actions.CLEAR_REPORTS, Actions.SAVE_REPORTS, - Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, Actions.TOGGLE_SNAP_TO_GRID, - Actions.TOGGLE_SHOW_BLOCK_COMMENTS, - Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB, - ): action.set_sensitive(True) if ParseXML.xml_failures: Messages.send_xml_errors_if_any(ParseXML.xml_failures) Actions.XML_PARSER_ERRORS_DISPLAY.set_sensitive(True) if not self.init_file_paths: - self.init_file_paths = filter(os.path.exists, Preferences.files_open()) + self.init_file_paths = filter(os.path.exists, Preferences.get_open_files()) if not self.init_file_paths: self.init_file_paths = [''] for file_path in self.init_file_paths: if file_path: self.main_window.new_page(file_path) #load pages from file paths @@ -141,15 +129,28 @@ class ActionHandler: 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() + + # Disable all actions, then re-enable a few + for action in Actions.get_all_actions(): action.set_sensitive(False) #set all actions disabled for action in ( - Actions.TOGGLE_REPORTS_WINDOW, - Actions.TOGGLE_BLOCKS_WINDOW, - Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, - Actions.TOGGLE_SCROLL_LOCK, - Actions.TOGGLE_SNAP_TO_GRID, + Actions.APPLICATION_QUIT, Actions.FLOW_GRAPH_NEW, + Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS, + Actions.FLOW_GRAPH_CLOSE, Actions.ABOUT_WINDOW_DISPLAY, + Actions.FLOW_GRAPH_SCREEN_CAPTURE, Actions.HELP_WINDOW_DISPLAY, + Actions.TYPES_WINDOW_DISPLAY, Actions.TOGGLE_BLOCKS_WINDOW, + Actions.TOGGLE_REPORTS_WINDOW, Actions.TOGGLE_HIDE_DISABLED_BLOCKS, + Actions.TOOLS_RUN_FDESIGN, Actions.TOGGLE_SCROLL_LOCK, + Actions.CLEAR_REPORTS, Actions.SAVE_REPORTS, + Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, Actions.TOGGLE_SNAP_TO_GRID, Actions.TOGGLE_SHOW_BLOCK_COMMENTS, Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB, - ): action.load_from_preferences() + Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY, + Actions.FLOW_GRAPH_OPEN_QSS_THEME, + ): + action.set_sensitive(True) + if hasattr(action, 'load_from_preferences'): + action.load_from_preferences() + elif action == Actions.APPLICATION_QUIT: if self.main_window.close_pages(): gtk.main_quit() @@ -415,16 +416,20 @@ class ActionHandler: action.save_to_preferences() elif action == Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB: action.save_to_preferences() + elif action == Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY: + action.save_to_preferences() + for page in self.main_window.get_pages(): + page.get_flow_graph().update() ################################################## # Param Modifications ################################################## elif action == Actions.BLOCK_PARAM_MODIFY: selected_block = self.get_flow_graph().get_selected_block() if selected_block: - dialog = PropsDialog(selected_block) + self.dialog = PropsDialog(selected_block) response = gtk.RESPONSE_APPLY while response == gtk.RESPONSE_APPLY: # rerun the dialog if Apply was hit - response = dialog.run() + 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()) @@ -436,7 +441,14 @@ class ActionHandler: if response == gtk.RESPONSE_APPLY: # null action, that updates the main window Actions.ELEMENT_SELECT() - dialog.destroy() + 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() + if self.dialog is not None: + self.dialog.update_gui(force=True) + self.get_page().set_saved(False) ################################################## # View Parser Errors ################################################## @@ -464,11 +476,27 @@ class ActionHandler: ################################################## 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() elif action == Actions.FLOW_GRAPH_OPEN: - file_paths = OpenFlowGraphFileDialog(self.get_page().get_file_path()).run() + file_paths = args if args else OpenFlowGraphFileDialog(self.get_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)) + 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_OPEN_QSS_THEME: + file_paths = OpenQSSFileDialog(GR_PREFIX + '/share/gnuradio/themes/').run() + if file_paths: + try: + from gnuradio import gr + gr.prefs().set_string("qtgui", "qss", file_paths[0]) + gr.prefs().save() + except Exception as e: + Messages.send("Failed to save QSS preference: " + str(e)) elif action == Actions.FLOW_GRAPH_CLOSE: self.main_window.close_page() elif action == Actions.FLOW_GRAPH_SAVE: @@ -489,6 +517,9 @@ class ActionHandler: if file_path is not None: self.get_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 = SaveImageFileDialog(self.get_page().get_file_path()).run() if file_path is not None: @@ -511,6 +542,10 @@ class ActionHandler: elif action == Actions.FLOW_GRAPH_EXEC: if not self.get_page().get_proc(): Actions.FLOW_GRAPH_GEN() + if Preferences.xterm_missing() != XTERM_EXECUTABLE: + if not os.path.exists(XTERM_EXECUTABLE): + Dialogs.MissingXTermDialog(XTERM_EXECUTABLE) + Preferences.xterm_missing(XTERM_EXECUTABLE) if self.get_page().get_saved() and self.get_page().get_file_path(): ExecFlowGraphThread(self) elif action == Actions.FLOW_GRAPH_KILL: @@ -634,7 +669,6 @@ class ExecFlowGraphThread(Thread): self.flow_graph = action_handler.get_flow_graph() #store page and dont use main window calls in run self.page = action_handler.get_page() - Messages.send_start_exec(self.page.get_generator().get_file_path()) #get the popen try: self.p = self.page.get_generator().get_popen() |