Here is a patch that handles repeated RC events. It allows to browse
faster long lists (i.e. directories containing lots of things, or the TV
Guide), by simply pressing continuously a button on the remote control.
Events buffered inside pyLirc are discarded, and only the most recent
event is taken into consideration (this avoids the ``inertia'' in the
movement, which would otherwise continue for some time when the RC's
button has been released). Another feature is also that the repeats are
progressively faster.
The number of times the event has been repeated is passed along with the
type of event, but this information is not used anywhere (I don't know
how to pass it to the various event handlers).

Matthieu
-- 
 (~._.~)        Matthieu Weber - Universit� de Jyv�skyl�         (~._.~)
  ( ? )                email : [EMAIL PROTECTED]                  ( ? ) 
 ()- -()               public key id : 452AE0AD                  ()- -()
 (_)-(_)  "Humor ist, wenn man trotzdem lacht (Germain Muller)"  (_)-(_)
Index: rc.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/rc.py,v
retrieving revision 1.20
diff -u -r1.20 rc.py
--- rc.py       24 Jul 2003 00:12:05 -0000      1.20
+++ rc.py       1 Aug 2003 06:49:32 -0000
@@ -90,6 +90,7 @@
 # ----------------------------------------------------------------------- */
 #endif
 
+import copy
 import socket
 import config
 import util
@@ -168,6 +169,17 @@
         self.app = None
         self.context = 'menu'
         self.queue = []
+        self.previous_returned_code = None
+        self.previous_code = None;
+        self.repeat_count = 0
+
+        # Take into consideration only 1 event out of ``modulo''
+        self.default_repeat_modulo = 4 # Config
+
+        # After how many repeats do we decrease the modulo?
+        self.repeat_modulo_decrease_threshhold = 5 # Config
+        
+        self.repeat_modulo = self.default_repeat_modulo
 
 
     def set_app(self, app, context):
@@ -204,23 +216,56 @@
         print 'send button event BUTTON arg=%s' % key
         return Event(BUTTON, arg=key)
     
+    def get_last_code(self):
+        result = (None, None) # (Code, is_it_new?)
+        if self.previous_code != None:
+            # Let's empty the buffer and return the most recent code
+            while 1:
+                list = pylirc.nextcode();
+                if list != []:
+                    break
+        else:
+            list = pylirc.nextcode()
+        if list == []:
+            # It's a repeat, the flag is 0
+            list = self.previous_returned_code
+            result = (list, 0)
+        elif list != None:
+            self.previous_returned_code = list
+            # It's a new code (i.e. IR key was released), the flag is 1
+            result = (list, 1)
+        self.previous_code = list
+        return result
         
     def poll(self):
         if len(self.queue):
             ret = self.queue[0]
             del self.queue[0]
-            return ret
+            return (ret, None)
 
         e = self.key_event_mapper(self.osd._cb())
-        if e:
-            return e
+        if e != None:
+            return (e, None)
         
         if self.pylirc:
-            list = pylirc.nextcode()
-            if list:
+            list, flag = self.get_last_code()
+            if flag == 1:
+                self.repeat_count = 0
+                self.repeat_modulo = self.default_repeat_modulo
+
+            if list != None:
+                if self.repeat_count > self.repeat_modulo_decrease_threshhold * \
+                  (self.default_repeat_modulo - self.repeat_modulo + 1) \
+                  and self.repeat_modulo > 1:
+                      self.repeat_modulo -= 1
+                if self.repeat_count % self.repeat_modulo != 0:
+                    list = []
+                self.repeat_count += 1
+
                 for code in list:
-                    e = self.key_event_mapper(code)
-                   if not e:  e = self.key_event_mapper(self.osd._cb)
+                    e = (self.key_event_mapper(code), self.repeat_count)
+
+                   if not e:  e = (self.key_event_mapper(self.osd._cb), None)
                     if e:
                         return e
                 
@@ -236,4 +281,4 @@
                 # No data available
                 pass
 
-        return None
+        return (None, None)
Index: main.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/main.py,v
retrieving revision 1.53
diff -u -r1.53 main.py
--- main.py     13 Jul 2003 19:35:44 -0000      1.53
+++ main.py     1 Aug 2003 06:49:32 -0000
@@ -311,7 +311,8 @@
         # Get next command
         while 1:
 
-            event = rc_object.poll()
+            event, event_repeat_count = rc_object.poll()
+            # OK, now we have a repeat_count... to whom could we give it?
             if event:
                 break
 
@@ -322,7 +323,7 @@
                         p.poll_counter = 0
                         p.poll()
 
-            time.sleep(0.1)
+            time.sleep(0.01)
 
         for p in poll_plugins:
             if not (rc_object.app and p.poll_menu_only):

Reply via email to