[kupfer: 9/24] plugin.top: Update at most every 5 seconds



commit 6ab94b2b211f1a11f996677b9b598cfc48733169
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Nov 22 02:16:59 2009 +0100

    plugin.top: Update at most every 5 seconds
    
    Instead of dynamically updating with each new filter/search in the
    Running Tasks subcatalog, we can make the Source only update itself
    maximum every five seconds -- this makes repeated filtering more
    responsive.

 kupfer/plugin/top.py |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/plugin/top.py b/kupfer/plugin/top.py
index bb6332d..f3abeea 100644
--- a/kupfer/plugin/top.py
+++ b/kupfer/plugin/top.py
@@ -4,8 +4,9 @@ import os
 import subprocess
 
 from kupfer.objects import Action, Source, Leaf
-from kupfer import utils
+from kupfer import scheduler, utils
 from kupfer import plugin_support
+from kupfer.helplib import PicklingHelperMixin
 
 __kupfer_name__ = _("Top")
 __kupfer_sources__ = ("TaskSource", )
@@ -85,14 +86,22 @@ class _SignalsSource(Source):
 		yield _Signal
 
 
-class TaskSource(Source):
+class TaskSource(Source, PicklingHelperMixin):
 	def __init__(self, name=_("Running Tasks")):
 		Source.__init__(self, name)
+		self.unpickle_finish()
 
-	def is_dynamic(self):
-		return True
+	def pickle_prepare(self):
+		# clear saved processes
+		self.mark_for_update()
+		self._timer = None
+
+	def unpickle_finish(self):
+		self._timer = scheduler.Timer()
 
 	def get_items(self):
+		# update after a few seconds
+		self._timer.set(5, self.mark_for_update)
 		# tasks for current user
 		uid = os.getuid()
 		command = 'top -b -n 1 -u %d' % uid



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]