[Sugar-devel] [PATCH Chat v4] Scroll the chat log

Manuel Kaufmann humitos at gmail.com
Wed Apr 11 13:08:19 EDT 2012


Check if the user pressed (Control +) Page Up, (Control +) Page Down,
Control + Home or Control + End and scroll the window according the
pressed key.

Auto scroll again if the user entry a new message in the ChatBox.

This commit solves http://bugs.sugarlabs.org/ticket/2782

Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
 activity.py |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/activity.py b/activity.py
index 297d57b..a673912 100644
--- a/activity.py
+++ b/activity.py
@@ -264,6 +264,7 @@ class Chat(activity.Activity):
                           style.COLOR_WHITE.get_gdk_color())
         entry.set_sensitive(False)
         entry.connect('activate', self.entry_activate_cb)
+        entry.connect('key-press-event', self.entry_key_press_cb)
         self.entry = entry
 
         self.chatbox = ChatBox()
@@ -277,7 +278,30 @@ class Chat(activity.Activity):
 
         return box
 
+    def entry_key_press_cb(self, widget, event):
+        """Check for scrolling keys.
+
+        Check if the user pressed Page Up, Page Down, Home or End and
+        scroll the window according the pressed key.
+        """
+        vadj = self.chatbox.get_vadjustment()
+        if event.keyval == gtk.keysyms.Page_Down:
+            value = vadj.get_value() + vadj.page_size
+            if value > vadj.upper - vadj.page_size:
+                value = vadj.upper - vadj.page_size
+            vadj.set_value(value)
+        elif event.keyval == gtk.keysyms.Page_Up:
+            vadj.set_value(vadj.get_value() - vadj.page_size)
+        elif event.keyval == gtk.keysyms.Home and \
+             event.state == gtk.gdk.CONTROL_MASK:
+            vadj.set_value(vadj.lower)
+        elif event.keyval == gtk.keysyms.End and \
+             event.state == gtk.gdk.CONTROL_MASK:
+            vadj.set_value(vadj.upper - vadj.page_size)
+
     def entry_activate_cb(self, entry):
+        self.chatbox._scroll_auto = True
+
         text = entry.props.text
         logger.debug('Entry: %s' % text)
         if text:
-- 
1.7.9.5



More information about the Sugar-devel mailing list