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

Manuel Kaufmann humitos at gmail.com
Wed Apr 11 09:53:47 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.

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

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

diff --git a/activity.py b/activity.py
index 297d57b..48bfafd 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,6 +278,27 @@ 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):
         text = entry.props.text
         logger.debug('Entry: %s' % text)
-- 
1.7.9.5



More information about the Sugar-devel mailing list