From 8949a9e00e989e98abf334f839b7a4e91a2339e4 Mon Sep 17 00:00:00 2001 From: Seth Hitefield <sdhitefield@gmail.com> Date: Thu, 5 Jun 2014 14:23:50 -0400 Subject: grc: Fixed scroll functionality in GRC. Also added clear and scrollback capability for the logging window --- grc/gui/Dialogs.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'grc/gui/Dialogs.py') 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. -- cgit v1.2.3