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/gui/Dialogs.py | |
parent | 34ee3b7d45678dfcca221d03ca6d796a46e41288 (diff) |
grc: Fixed scroll functionality in GRC.
Also added clear and scrollback capability for the logging window
Diffstat (limited to 'grc/gui/Dialogs.py')
-rw-r--r-- | grc/gui/Dialogs.py | 41 |
1 files changed, 41 insertions, 0 deletions
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. |