diff options
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/ActionHandler.py | 144 | ||||
-rw-r--r-- | grc/gui/BlockTreeWindow.py | 32 | ||||
-rw-r--r-- | grc/gui/Executor.py | 7 | ||||
-rw-r--r-- | grc/gui/MainWindow.py | 74 | ||||
-rw-r--r-- | grc/gui/NotebookPage.py | 97 | ||||
-rw-r--r-- | grc/gui/VariableEditor.py | 31 |
6 files changed, 154 insertions, 231 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index de635b61fd..492bf8de9c 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -59,7 +59,6 @@ class ActionHandler: 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 self.get_focus_flag = self.main_window.get_focus_flag #setup the messages Messages.register_messenger(self.main_window.add_console_line) @@ -103,11 +102,11 @@ class ActionHandler: def _handle_action(self, action, *args): #print action main = self.main_window - page = main.get_page() - flow_graph = page.get_flow_graph() if page else None + page = main.current_page + flow_graph = page.flow_graph if page else None def flow_graph_update(fg=flow_graph): - main.vars.update_gui() + main.vars.update_gui(fg.blocks) fg.update() ################################################## @@ -121,7 +120,7 @@ class ActionHandler: if file_path: main.new_page(file_path) #load pages from file paths if Preferences.file_open() in self.init_file_paths: main.new_page(Preferences.file_open(), show=True) - if not self.get_page(): + if not self.main_window.current_page: main.new_page() # ensure that at least a blank page exists main.btwin.search_entry.hide() @@ -174,18 +173,18 @@ class ActionHandler: elif action == Actions.BLOCK_ENABLE: if flow_graph.enable_selected(True): flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.BLOCK_DISABLE: if flow_graph.enable_selected(False): flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.BLOCK_BYPASS: if flow_graph.bypass_selected(): flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False ################################################## # Cut/Copy/Paste ################################################## @@ -198,8 +197,8 @@ class ActionHandler: if self.clipboard: 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) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False ################################################## # Create heir block ################################################## @@ -332,53 +331,53 @@ class ActionHandler: # Move/Rotate/Delete/Create ################################################## elif action == Actions.BLOCK_MOVE: - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action in Actions.BLOCK_ALIGNMENTS: if flow_graph.align_selected(action): - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.BLOCK_ROTATE_CCW: if flow_graph.rotate_selected(90): flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.BLOCK_ROTATE_CW: if flow_graph.rotate_selected(-90): flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.ELEMENT_DELETE: if flow_graph.remove_selected(): flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) + page.state_cache.save_new_state(flow_graph.export_data()) Actions.NOTHING_SELECT() - page.set_saved(False) + page.saved = False elif action == Actions.ELEMENT_CREATE: flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) + page.state_cache.save_new_state(flow_graph.export_data()) Actions.NOTHING_SELECT() - page.set_saved(False) + page.saved = False elif action == Actions.BLOCK_INC_TYPE: 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) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.BLOCK_DEC_TYPE: 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) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.PORT_CONTROLLER_INC: 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) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False elif action == Actions.PORT_CONTROLLER_DEC: 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) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False ################################################## # Window stuff ################################################## @@ -406,7 +405,7 @@ class ActionHandler: elif action == Actions.CLEAR_CONSOLE: main.text_display.clear() elif action == Actions.SAVE_CONSOLE: - file_path = SaveConsoleFileDialog(page.get_file_path()).run() + file_path = SaveConsoleFileDialog(page.file_path).run() if file_path is not None: main.text_display.save(file_path) elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS: @@ -414,7 +413,7 @@ class ActionHandler: elif action == Actions.TOGGLE_AUTO_HIDE_PORT_LABELS: action.save_to_preferences() for page in main.get_pages(): - page.get_flow_graph().create_shapes() + page.flow_graph.create_shapes() elif action in (Actions.TOGGLE_SNAP_TO_GRID, Actions.TOGGLE_SHOW_BLOCK_COMMENTS, Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB): @@ -422,7 +421,7 @@ class ActionHandler: elif action == Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY: action.save_to_preferences() for page in main.get_pages(): - flow_graph_update(page.get_flow_graph()) + flow_graph_update(page.flow_graph) elif action == Actions.TOGGLE_HIDE_VARIABLES: # Call the variable editor TOGGLE in case it needs to be showing Actions.TOGGLE_FLOW_GRAPH_VAR_EDITOR() @@ -467,10 +466,10 @@ class ActionHandler: response = self.dialog.run() if response in (Gtk.ResponseType.APPLY, Gtk.ResponseType.ACCEPT): flow_graph_update() - page.get_state_cache().save_new_state(flow_graph.export_data()) - page.set_saved(False) + page.state_cache.save_new_state(flow_graph.export_data()) + page.saved = False else: # restore the current state - n = page.get_state_cache().get_current_state() + n = page.state_cache.get_current_state() flow_graph.import_data(n) flow_graph_update() if response == Gtk.ResponseType.APPLY: @@ -479,15 +478,15 @@ class ActionHandler: self.dialog.destroy() self.dialog = None elif action == Actions.EXTERNAL_UPDATE: - page.get_state_cache().save_new_state(flow_graph.export_data()) + page.state_cache.save_new_state(flow_graph.export_data()) flow_graph_update() if self.dialog is not None: self.dialog.update_gui(force=True) - page.set_saved(False) + page.saved = False elif action == Actions.VARIABLE_EDITOR_UPDATE: - page.get_state_cache().save_new_state(flow_graph.export_data()) + page.state_cache.save_new_state(flow_graph.export_data()) flow_graph_update() - page.set_saved(False) + page.saved = False ################################################## # View Parser Errors ################################################## @@ -497,19 +496,19 @@ class ActionHandler: # Undo/Redo ################################################## elif action == Actions.FLOW_GRAPH_UNDO: - n = page.get_state_cache().get_prev_state() + n = page.state_cache.get_prev_state() if n: flow_graph.unselect() flow_graph.import_data(n) flow_graph_update() - page.set_saved(False) + page.saved = False elif action == Actions.FLOW_GRAPH_REDO: - n = page.get_state_cache().get_next_state() + n = page.state_cache.get_next_state() if n: flow_graph.unselect() flow_graph.import_data(n) flow_graph_update() - page.set_saved(False) + page.saved = False ################################################## # New/Open/Save/Close ################################################## @@ -522,7 +521,7 @@ class ActionHandler: # TODO: Disable opening the flowgraph pass ''' - file_paths = args if args else OpenFlowGraphFileDialog(page.get_file_path()).run() + file_paths = args if args else OpenFlowGraphFileDialog(page.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): main.new_page(file_path, show=(i==0)) @@ -545,27 +544,27 @@ class ActionHandler: main.close_page() elif action == Actions.FLOW_GRAPH_SAVE: #read-only or undefined file path, do save-as - if page.get_read_only() or not page.get_file_path(): + if page.get_read_only() or not page.file_path: Actions.FLOW_GRAPH_SAVE_AS() #otherwise try to save else: try: - ParseXML.to_file(flow_graph.export_data(), page.get_file_path()) - flow_graph.grc_file_path = page.get_file_path() - page.set_saved(True) + ParseXML.to_file(flow_graph.export_data(), page.file_path) + flow_graph.grc_file_path = page.file_path + page.saved = True except IOError: - Messages.send_fail_save(page.get_file_path()) - page.set_saved(False) + Messages.send_fail_save(page.file_path) + page.saved = False elif action == Actions.FLOW_GRAPH_SAVE_AS: - file_path = SaveFlowGraphFileDialog(page.get_file_path()).run() + file_path = SaveFlowGraphFileDialog(page.file_path).run() if file_path is not None: - page.set_file_path(file_path) + page.file_path = os.path.abspath(file_path) Actions.FLOW_GRAPH_SAVE() Preferences.add_recent_file(file_path) main.tool_bar.refresh_submenus() main.menu_bar.refresh_submenus() elif action == Actions.FLOW_GRAPH_SCREEN_CAPTURE: - file_path, background_transparent = SaveScreenShotDialog(page.get_file_path()).run() + file_path, background_transparent = SaveScreenShotDialog(page.file_path).run() if file_path is not None: pixbuf = flow_graph.get_drawing_area().get_screenshot(background_transparent) pixbuf.save(file_path, Constants.IMAGE_FILE_EXTENSION[1:]) @@ -573,38 +572,38 @@ class ActionHandler: # Gen/Exec/Stop ################################################## elif action == Actions.FLOW_GRAPH_GEN: - 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 page.get_saved() and page.get_file_path(): + if not page.process: + if not page.saved or not page.file_path: + Actions.FLOW_GRAPH_SAVE() # only save if file path missing or not saved + if page.saved and page.file_path: generator = page.get_generator() try: - Messages.send_start_gen(generator.get_file_path()) + Messages.send_start_gen(generator.file_path) generator.write() except Exception as e: Messages.send_fail_gen(e) else: self.generator = None elif action == Actions.FLOW_GRAPH_EXEC: - if not page.get_proc(): + if not page.process: 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 page.get_saved() and page.get_file_path(): + if page.saved and page.file_path: Executor.ExecFlowGraphThread( flow_graph_page=page, xterm_executable=xterm, callback=self.update_exec_stop ) elif action == Actions.FLOW_GRAPH_KILL: - if page.get_proc(): + if page.process: try: - page.get_proc().kill() + page.process.kill() except: - print "could not kill process: %d" % page.get_proc().pid + print "could not kill process: %d" % page.process.pid elif action == Actions.PAGE_CHANGE: # pass and run the global actions pass elif action == Actions.RELOAD_BLOCKS: @@ -650,8 +649,8 @@ class ActionHandler: ################################################## # Global Actions for all States ################################################## - page = main.get_page() # page and flowgraph might have changed - flow_graph = page.get_flow_graph() if page else None + page = main.current_page # page and flow graph might have changed + flow_graph = page.flow_graph if page else None selected_blocks = flow_graph.get_selected_blocks() selected_block = selected_blocks[0] if selected_blocks else None @@ -690,7 +689,7 @@ class ActionHandler: self.update_exec_stop() - Actions.FLOW_GRAPH_SAVE.set_sensitive(not page.get_saved()) + Actions.FLOW_GRAPH_SAVE.set_sensitive(not page.saved) main.update() flow_graph.update_selected() @@ -703,7 +702,8 @@ class ActionHandler: Update the exec and stop buttons. Lock and unlock the mutex for race conditions with exec flow graph threads. """ - sensitive = self.main_window.get_flow_graph().is_valid() and not self.get_page().get_proc() + page = self.main_window.current_page + sensitive = page.flow_graph.is_valid() and not page.process 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) + Actions.FLOW_GRAPH_KILL.set_sensitive(page.process is not None) diff --git a/grc/gui/BlockTreeWindow.py b/grc/gui/BlockTreeWindow.py index 9a147bd8be..829ddfed68 100644 --- a/grc/gui/BlockTreeWindow.py +++ b/grc/gui/BlockTreeWindow.py @@ -51,7 +51,11 @@ def _format_doc(doc): class BlockTreeWindow(Gtk.VBox): """The block selection panel.""" - def __init__(self, platform, get_flow_graph): + __gsignals__ = { + 'create_new_block': (GObject.SIGNAL_RUN_FIRST, None, (str,)) + } + + def __init__(self, platform): """ BlockTreeWindow constructor. Create a tree view of the possible blocks in the platform. @@ -60,11 +64,9 @@ class BlockTreeWindow(Gtk.VBox): Args: platform: the particular platform will all block prototypes - get_flow_graph: get the selected flow graph """ - GObject.GObject.__init__(self) + Gtk.VBox.__init__(self) self.platform = platform - self.get_flow_graph = get_flow_graph # search entry self.search_entry = Gtk.Entry() @@ -186,16 +188,6 @@ class BlockTreeWindow(Gtk.VBox): treestore, iter = selection.get_selected() return iter and treestore.get_value(iter, KEY_INDEX) or '' - def _add_selected_block(self): - """ - Add the selected block with the given key to the flow graph. - """ - key = self._get_selected_block_key() - if key: - self.get_flow_graph().add_new_block(key) - return True - return False - def _expand_category(self): treestore, iter = self.treeview.get_selection().get_selected() if iter and treestore.iter_has_child(iter): @@ -241,9 +233,13 @@ class BlockTreeWindow(Gtk.VBox): selected = self.treestore_search.iter_children(selected) if selected is not None: key = self.treestore_search.get_value(selected, KEY_INDEX) - if key: self.get_flow_graph().add_new_block(key) + if key: self.emit('create_new_block', key) elif widget == self.treeview: - self._add_selected_block() or self._expand_category() + key = self._get_selected_block_key() + if key: + self.emit('create_new_block', key) + else: + self._expand_category() else: return False # propagate event @@ -282,4 +278,6 @@ class BlockTreeWindow(Gtk.VBox): If a left double click is detected, call add selected block. """ if event.button == 1 and event.type == Gdk.EventType._2BUTTON_PRESS: - self._add_selected_block() + key = self._get_selected_block_key() + if key: + self.emit('create_new_block', key) diff --git a/grc/gui/Executor.py b/grc/gui/Executor.py index 9ed5f9da75..c39f743809 100644 --- a/grc/gui/Executor.py +++ b/grc/gui/Executor.py @@ -45,8 +45,7 @@ class ExecFlowGraphThread(threading.Thread): self.update_callback = callback try: - self.process = self._popen() - self.page.set_proc(self.process) + self.process = self.page.process = self._popen() self.update_callback() self.start() except Exception as e: @@ -57,7 +56,7 @@ class ExecFlowGraphThread(threading.Thread): """ Execute this python flow graph. """ - run_command = self.page.get_flow_graph().get_option('run_command') + run_command = self.page.flow_graph.get_option('run_command') generator = self.page.get_generator() try: @@ -100,7 +99,7 @@ class ExecFlowGraphThread(threading.Thread): def done(self): """Perform end of execution tasks.""" Messages.send_end_exec(self.process.returncode) - self.page.set_proc(None) + self.page.process = None self.update_callback() diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py index 126a9afff9..ce16074c81 100644 --- a/grc/gui/MainWindow.py +++ b/grc/gui/MainWindow.py @@ -96,8 +96,11 @@ class MainWindow(Gtk.Window): self.console_window.set_size_request(-1, DEFAULT_CONSOLE_WINDOW_WIDTH) # Create the block tree and variable panels - self.btwin = BlockTreeWindow(platform, self.get_flow_graph) - self.vars = VariableEditor(platform, self.get_flow_graph) + self.btwin = BlockTreeWindow(platform) + self.btwin.connect('create_new_block', self._add_block_to_current_flow_graph) + self.vars = VariableEditor() + self.vars.connect('create_new_block', self._add_block_to_current_flow_graph) + self.vars.connect('remove_block', self._remove_block_from_current_flow_graph) # Figure out which place to put the variable editor self.left = Gtk.VPaned() #orientation=Gtk.Orientation.VERTICAL) @@ -141,6 +144,13 @@ class MainWindow(Gtk.Window): # Event Handlers ############################################################ + def _add_block_to_current_flow_graph(self, widget, key): + self.current_flow_graph.add_new_block(key) + + def _remove_block_from_current_flow_graph(self, widget, key): + block = self.current_flow_graph.get_block(key) + self.current_flow_graph.remove_element(block) + def _quit(self, window, event): """ Handle the delete event from the main window. @@ -261,9 +271,9 @@ class MainWindow(Gtk.Window): true if all closed """ open_files = filter(lambda file: file, self._get_files()) #filter blank files - open_file = self.get_page().get_file_path() + open_file = self.current_page.file_path #close each page - for page in sorted(self.get_pages(), key=lambda p: p.get_saved()): + for page in sorted(self.get_pages(), key=lambda p: p.saved): self.page_to_be_closed = page closed = self.close_page(False) if not closed: @@ -291,23 +301,24 @@ class MainWindow(Gtk.Window): Args: ensure: boolean """ - if not self.page_to_be_closed: self.page_to_be_closed = self.get_page() + if not self.page_to_be_closed: self.page_to_be_closed = self.current_page #show the page if it has an executing flow graph or is unsaved - if self.page_to_be_closed.get_proc() or not self.page_to_be_closed.get_saved(): + if self.page_to_be_closed.process or not self.page_to_be_closed.saved: self._set_page(self.page_to_be_closed) #unsaved? ask the user - if not self.page_to_be_closed.get_saved(): + if not self.page_to_be_closed.saved: response = self._save_changes() # return value is either OK, CLOSE, or CANCEL if response == Gtk.ResponseType.OK: Actions.FLOW_GRAPH_SAVE() #try to save - if not self.page_to_be_closed.get_saved(): #still unsaved? + if not self.page_to_be_closed.saved: #still unsaved? self.page_to_be_closed = None #set the page to be closed back to None return False elif response == Gtk.ResponseType.CANCEL: self.page_to_be_closed = None return False #stop the flow graph if executing - if self.page_to_be_closed.get_proc(): Actions.FLOW_GRAPH_KILL() + if self.page_to_be_closed.process: + Actions.FLOW_GRAPH_KILL() #remove the page self.notebook.remove_page(self.notebook.page_num(self.page_to_be_closed)) if ensure and self.notebook.get_n_pages() == 0: self.new_page() #no pages, make a new one @@ -324,54 +335,40 @@ class MainWindow(Gtk.Window): Set the titles on the page tabs. Show/hide the console window. """ - page = self.get_page() + page = self.current_page - basename = os.path.basename(page.get_file_path()) - dirname = os.path.dirname(page.get_file_path()) + basename = os.path.basename(page.file_path) + dirname = os.path.dirname(page.file_path) Gtk.Window.set_title(self, ''.join(( - '*' if not page.get_saved() else '', basename if basename else NEW_FLOGRAPH_TITLE, + '*' if not page.saved else '', basename if basename else NEW_FLOGRAPH_TITLE, '(read only)' if page.get_read_only() else '', ' - ', dirname if dirname else self._platform.config.name, ))) # set tab titles for page in self.get_pages(): - file_name = os.path.splitext(os.path.basename(page.get_file_path()))[0] + file_name = os.path.splitext(os.path.basename(page.file_path))[0] page.set_markup('<span foreground="{foreground}">{title}{ro}</span>'.format( - foreground='black' if page.get_saved() else 'red', ro=' (ro)' if page.get_read_only() else '', + foreground='black' if page.saved else 'red', ro=' (ro)' if page.get_read_only() else '', title=Utils.encode(file_name or NEW_FLOGRAPH_TITLE), )) # show/hide notebook tabs self.notebook.set_show_tabs(len(self.get_pages()) > 1) # Need to update the variable window when changing - self.vars.update_gui() + self.vars.update_gui(self.current_flow_graph.blocks) def update_pages(self): """ Forces a reload of all the pages in this notebook. """ for page in self.get_pages(): - success = page.get_flow_graph().reload() + success = page.flow_graph.reload() if success: # Only set saved if errors occurred during import - page.set_saved(False) - - def get_page(self): - """ - Get the selected page. + page.saved = False - Returns: - the selected page - """ - return self.current_page - - def get_flow_graph(self): - """ - Get the selected flow graph. - - Returns: - the selected flow graph - """ - return self.get_page().get_flow_graph() + @property + def current_flow_graph(self): + return self.current_page.flow_graph def get_focus_flag(self): """ @@ -379,7 +376,7 @@ class MainWindow(Gtk.Window): Returns: the focus flag """ - return self.get_page().get_drawing_area().get_focus_flag() + return self.current_page.get_drawing_area().get_focus_flag() ############################################################ # Helpers @@ -419,7 +416,7 @@ class MainWindow(Gtk.Window): Returns: list of file paths """ - return map(lambda page: page.get_file_path(), self.get_pages()) + return map(lambda page: page.file_path, self.get_pages()) def get_pages(self): """ @@ -428,4 +425,5 @@ class MainWindow(Gtk.Window): Returns: list of pages """ - return [self.notebook.get_nth_page(page_num) for page_num in range(self.notebook.get_n_pages())] + return [self.notebook.get_nth_page(page_num) + for page_num in range(self.notebook.get_n_pages())] diff --git a/grc/gui/NotebookPage.py b/grc/gui/NotebookPage.py index e15617aec9..e7a024ab3e 100644 --- a/grc/gui/NotebookPage.py +++ b/grc/gui/NotebookPage.py @@ -41,15 +41,16 @@ class NotebookPage(Gtk.HBox): Gtk.HBox.__init__(self) self.main_window = main_window - self._flow_graph = flow_graph + self.flow_graph = flow_graph + self.file_path = file_path + self.process = None + self.saved = True # import the file - self.file_path = file_path initial_state = flow_graph.get_parent().parse_flow_graph(file_path) - self.get_flow_graph().import_data(initial_state) + flow_graph.import_data(initial_state) self.state_cache = StateCache(initial_state) - self.saved = True # tab box to hold label and close button self.label = Gtk.Label() @@ -68,7 +69,8 @@ class NotebookPage(Gtk.HBox): tab.show_all() # setup scroll window and drawing area - self.drawing_area = DrawingArea(self.get_flow_graph()) + self.drawing_area = DrawingArea(flow_graph) + flow_graph.drawing_area = self.drawing_area self.scrolled_window = Gtk.ScrolledWindow() self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT) @@ -77,8 +79,6 @@ class NotebookPage(Gtk.HBox): self.scrolled_window.add_with_viewport(self.drawing_area) self.pack_start(self.scrolled_window, True, True, 0) - # inject drawing area into flow graph - self.get_flow_graph().drawing_area = self.drawing_area self.show_all() def _handle_scroll_window_key_press(self, widget, event): @@ -97,8 +97,8 @@ class NotebookPage(Gtk.HBox): Returns: generator """ - platform = self.get_flow_graph().get_parent() - return platform.Generator(self.get_flow_graph(), self.get_file_path()) + platform = self.flow_graph.get_parent() + return platform.Generator(self.flow_graph, self.file_path) def _handle_button(self, button): """ @@ -120,33 +120,6 @@ class NotebookPage(Gtk.HBox): """ self.label.set_markup(markup) - def get_proc(self): - """ - Get the subprocess for the flow graph. - - Returns: - the subprocess object - """ - return self.process - - def set_proc(self, process): - """ - Set the subprocess object. - - Args: - process: the new subprocess - """ - self.process = process - - def get_flow_graph(self): - """ - Get the flow graph. - - Returns: - the flow graph - """ - return self._flow_graph - def get_read_only(self): """ Get the read-only state of the file. @@ -155,51 +128,7 @@ class NotebookPage(Gtk.HBox): Returns: true for read-only """ - if not self.get_file_path(): return False - return os.path.exists(self.get_file_path()) and \ - not os.access(self.get_file_path(), os.W_OK) - - def get_file_path(self): - """ - Get the file path for the flow graph. - - Returns: - the file path or '' - """ - return self.file_path - - def set_file_path(self, file_path=''): - """ - Set the file path, '' for no file path. - - Args: - file_path: file path string - """ - self.file_path = os.path.abspath(file_path) if file_path else '' - - def get_saved(self): - """ - Get the saved status for the flow graph. - - Returns: - true if saved - """ - return self.saved - - def set_saved(self, saved=True): - """ - Set the saved status. - - Args: - saved: boolean status - """ - self.saved = saved - - def get_state_cache(self): - """ - Get the state cache for the flow graph. - - Returns: - the state cache - """ - return self.state_cache + if not self.file_path: + return False + return (os.path.exists(self.file_path) and + not os.access(self.file_path, os.W_OK)) diff --git a/grc/gui/VariableEditor.py b/grc/gui/VariableEditor.py index 8729762928..299d3cdb6e 100644 --- a/grc/gui/VariableEditor.py +++ b/grc/gui/VariableEditor.py @@ -35,6 +35,7 @@ ID_INDEX = 1 class VariableEditorContextMenu(Gtk.Menu): """ A simple context menu for our variable editor """ + def __init__(self, var_edit): Gtk.Menu.__init__(self) @@ -83,12 +84,17 @@ class VariableEditor(Gtk.VBox): ENABLE_BLOCK = 5 DISABLE_BLOCK = 6 - def __init__(self, platform, get_flow_graph): + __gsignals__ = { + 'create_new_block': (GObject.SIGNAL_RUN_FIRST, None, (str,)), + 'remove_block': (GObject.SIGNAL_RUN_FIRST, None, (str,)) + } + + def __init__(self): Gtk.VBox.__init__(self) - self.platform = platform - self.get_flow_graph = get_flow_graph self._block = None self._mouse_button_pressed = False + self._imports = [] + self._variables = [] # Only use the model to store the block reference and name. # Generate everything else dynamically @@ -218,19 +224,12 @@ class VariableEditor(Gtk.VBox): if block.get_error_messages(): sp('foreground', 'red') - def update_gui(self): - if not self.get_flow_graph(): - return - self._update_blocks() + def update_gui(self, blocks): + self._imports = filter(attrgetter('is_import'), blocks) + self._variables = filter(attrgetter('is_variable'), blocks) self._rebuild() self.treeview.expand_all() - def _update_blocks(self): - self._imports = filter(attrgetter('is_import'), - self.get_flow_graph().blocks) - self._variables = filter(attrgetter('is_variable'), - self.get_flow_graph().blocks) - def _rebuild(self, *args): self.treestore.clear() imports = self.treestore.append(None, [None, 'Imports']) @@ -259,13 +258,13 @@ class VariableEditor(Gtk.VBox): key presses or mouse clicks. Also triggers an update of the flow graph and editor. """ if key == self.ADD_IMPORT: - self.get_flow_graph().add_new_block('import') + self.emit('create_new_block', 'import') elif key == self.ADD_VARIABLE: - self.get_flow_graph().add_new_block('variable') + self.emit('create_new_block', 'variable') elif key == self.OPEN_PROPERTIES: Actions.BLOCK_PARAM_MODIFY(self._block) elif key == self.DELETE_BLOCK: - self.get_flow_graph().remove_element(self._block) + self.emit('remove_block', self._block.get_id()) elif key == self.DELETE_CONFIRM: if self._confirm_delete: # Create a context menu to confirm the delete operation |