diff options
author | Seth Hitefield <sdhitefield@gmail.com> | 2014-06-05 14:23:50 -0400 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2014-06-13 11:04:07 +0200 |
commit | 8949a9e00e989e98abf334f839b7a4e91a2339e4 (patch) | |
tree | 1b372500379afbf692cb2e171b080341d55bbece /grc | |
parent | 34ee3b7d45678dfcca221d03ca6d796a46e41288 (diff) |
grc: Fixed scroll functionality in GRC.
Also added clear and scrollback capability for the logging window
Diffstat (limited to 'grc')
-rw-r--r-- | grc/gui/ActionHandler.py | 14 | ||||
-rw-r--r-- | grc/gui/Actions.py | 9 | ||||
-rw-r--r-- | grc/gui/Bars.py | 3 | ||||
-rw-r--r-- | grc/gui/Dialogs.py | 41 | ||||
-rw-r--r-- | grc/gui/MainWindow.py | 3 | ||||
-rw-r--r-- | grc/gui/Preferences.py | 6 |
6 files changed, 73 insertions, 3 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 65969e0d6f..d76940515f 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -61,6 +61,9 @@ class ActionHandler: self.main_window = MainWindow(platform) self.main_window.connect('delete-event', self._quit) self.main_window.connect('key-press-event', self._handle_key_press) + # Add actions the report/log text_view can call back to from its context menu + self.main_window.text_display.clear_action = Actions.CLEAR_REPORTS + self.main_window.text_display.scroll_action = Actions.TOGGLE_SCROLL_LOCK 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 @@ -117,7 +120,7 @@ class ActionHandler: 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.TOOLS_RUN_FDESIGN, Actions.TOGGLE_SCROLL_LOCK, Actions.CLEAR_REPORTS, ): action.set_sensitive(True) if ParseXML.xml_failures: Messages.send_xml_errors_if_any(ParseXML.xml_failures) @@ -135,6 +138,7 @@ class ActionHandler: self.main_window.btwin.search_entry.hide() Actions.TOGGLE_REPORTS_WINDOW.set_active(Preferences.reports_window_visibility()) Actions.TOGGLE_BLOCKS_WINDOW.set_active(Preferences.blocks_window_visibility()) + Actions.TOGGLE_SCROLL_LOCK.set_active(Preferences.scroll_lock()) elif action == Actions.APPLICATION_QUIT: if self.main_window.close_pages(): gtk.main_quit() @@ -373,6 +377,14 @@ class ActionHandler: else: self.main_window.btwin.hide() Preferences.blocks_window_visibility(visible) + elif action == Actions.TOGGLE_SCROLL_LOCK: + visible = action.get_active() + self.main_window.text_display.scroll_lock = visible + if visible: + self.main_window.text_display.scroll_to_end() + elif action == Actions.CLEAR_REPORTS: + self.main_window.text_display.clear() + elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS: Actions.NOTHING_SELECT() ################################################## diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index f633e7ced0..bf05ea71e5 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -281,6 +281,10 @@ TOGGLE_BLOCKS_WINDOW = ToggleAction( tooltip='Toggle visibility of the block tree widget', keypresses=(gtk.keysyms.b, gtk.gdk.CONTROL_MASK), ) +TOGGLE_SCROLL_LOCK = ToggleAction( + label='_Scroll Lock', + tooltip='Toggle scrool lock of the logging window', +) ABOUT_WINDOW_DISPLAY = Action( label='_About', tooltip='About this program', @@ -345,6 +349,11 @@ FIND_BLOCKS = Action( keypresses=(gtk.keysyms.f, gtk.gdk.CONTROL_MASK, gtk.keysyms.slash, NO_MODS_MASK), ) +CLEAR_REPORTS = Action( + label='_Clear Logs', + tooltip='Clear Logs', + stock_id=gtk.STOCK_CLEAR, +) OPEN_HIER = Action( label='Open H_ier', tooltip='Open the source of the selected hierarchical block', diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index da1b1469e1..defde1cc57 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -55,6 +55,7 @@ TOOLBAR_LIST = ( Actions.RELOAD_BLOCKS, Actions.OPEN_HIER, Actions.BUSSIFY_SOURCES, + Actions.CLEAR_REPORTS, ) ##The list of actions and categories for the menu bar. @@ -88,10 +89,12 @@ MENU_BAR_LIST = ( Actions.BLOCK_DISABLE, None, Actions.BLOCK_PARAM_MODIFY, + Actions.CLEAR_REPORTS, ]), (gtk.Action('View', '_View', None, None), [ Actions.TOGGLE_BLOCKS_WINDOW, Actions.TOGGLE_REPORTS_WINDOW, + Actions.TOGGLE_SCROLL_LOCK, None, Actions.ERRORS_WINDOW_DISPLAY, Actions.FIND_BLOCKS, diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py index 04e4f0a862..f9a355128d 100644 --- a/grc/gui/Dialogs.py +++ b/grc/gui/Dialogs.py @@ -39,12 +39,20 @@ class TextDisplay(gtk.TextView): self.set_editable(False) self.set_cursor_visible(False) self.set_wrap_mode(gtk.WRAP_WORD_CHAR) + + # Added for scroll locking + self.scroll_lock = True + + # Add a signal for populating the popup menu + self.connect("populate-popup", self.populate_popup) def insert(self, line): # make backspaces work line = self._consume_backspaces(line) # add the remaining text to buffer self.get_buffer().insert(self.get_buffer().get_end_iter(), line) + # Automatically scroll on insert + self.scroll_to_end() def _consume_backspaces(self, line): """removes text from the buffer if line starts with \b*""" @@ -61,6 +69,39 @@ class TextDisplay(gtk.TextView): # return remaining text return line[back_count:] + def scroll_to_end(self): + if (self.scroll_lock == True): + buffer = self.get_buffer() + buffer.move_mark(buffer.get_insert(), buffer.get_end_iter()) + self.scroll_to_mark(buffer.get_insert(), 0.0) + + def clear(self): + buffer = self.get_buffer() + buffer.delete(buffer.get_start_iter(), buffer.get_end_iter()) + + # Callback functions to handle the scrolling lock and clear context menus options + # Action functions are set by the ActionHandler's init function + def clear_cb(self, menu_item, web_view): + self.clear_action() + def scroll_back_cb(self, menu_item, web_view): + # Trigger the toggle action + self.scroll_action() + + # Create a popup menu for the scroll lock and clear functions. + def populate_popup(self, view, menu): + menu.append(gtk.SeparatorMenuItem()) + + lock = gtk.CheckMenuItem("Scroll Lock") + menu.append(lock) + lock.set_active(self.scroll_lock) + lock.connect('activate', self.scroll_back_cb, view) + + clear = gtk.ImageMenuItem(gtk.STOCK_CLEAR) + menu.append(clear) + clear.connect('activate', self.clear_cb, view) + menu.show_all() + return False + def MessageDialogHelper(type, buttons, title=None, markup=None): """ Create a modal message dialog and run it. diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py index 12f3b203b0..e763855fd4 100644 --- a/grc/gui/MainWindow.py +++ b/grc/gui/MainWindow.py @@ -155,8 +155,7 @@ class MainWindow(gtk.Window): line: the new text """ self.text_display.insert(line) - self.text_display.scroll_mark_onscreen(self.text_display.get_buffer().get_insert()) - + ############################################################ # Pages: create and close ############################################################ diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py index b15fb9738b..a6bd0d6603 100644 --- a/grc/gui/Preferences.py +++ b/grc/gui/Preferences.py @@ -95,3 +95,9 @@ def blocks_window_visibility(visible=None): else: try: return _config_parser.getboolean('main', 'blocks_window_visible') except: return True + +def scroll_lock(visible=None): + if visible is not None: _config_parser.set('main', 'scroll_lock', visible) + else: + try: return _config_parser.getboolean('main', 'scroll_lock') + except: return True |