[rhythmbox] Port some common python code to GI



commit 0352574ed8167e29e83f34d6405f040c4f139d60
Author: Jonathan Matthew <jonathan d14n org>
Date:   Fri Feb 4 23:38:27 2011 +1000

    Port some common python code to GI

 plugins/rb/Loader.py   |   16 +++++++++-------
 plugins/rb/URLCache.py |    3 ++-
 plugins/rb/__init__.py |   20 +++++++-------------
 3 files changed, 18 insertions(+), 21 deletions(-)
---
diff --git a/plugins/rb/Loader.py b/plugins/rb/Loader.py
index 0ed46b3..22854f5 100644
--- a/plugins/rb/Loader.py
+++ b/plugins/rb/Loader.py
@@ -25,20 +25,21 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
 import gobject
-import gtk
+import gi
+from gi.repository import Gdk
 import sys
 import gio
 
 def callback_with_gdk_lock(callback, data, args):
-	gtk.gdk.threads_enter()
+	Gdk.threads_enter()
 	try:
 		v = callback(data, *args)
-		gtk.gdk.threads_leave()
+		Gdk.threads_leave()
 		return v
 	except Exception, e:
 		print "Exception caught in loader callback: %s" % str(e)
 		sys.excepthook(*sys.exc_info())
-		gtk.gdk.threads_leave()
+		Gdk.threads_leave()
 
 
 class Loader(object):
@@ -76,13 +77,14 @@ class ChunkLoader(object):
 		return self.callback(result, self.total, *self.args)
 
 	def _callback_gdk(self, result):
-		gtk.gdk.threads_enter()
+		Gdk.threads_enter()
 		try:
 			v = self._callback(result)
-			gtk.gdk.threads_leave()
+			Gdk.threads_leave()
 			return v
 		except Exception, e:
-			gtk.gdk.threads_leave()
+			Gdk.threads_leave()
+			sys.excepthook(*sys.exc_info())
 			raise e
 
 	def _error_idle_cb(self, error):
diff --git a/plugins/rb/URLCache.py b/plugins/rb/URLCache.py
index e304dbf..462882e 100644
--- a/plugins/rb/URLCache.py
+++ b/plugins/rb/URLCache.py
@@ -30,6 +30,7 @@ import time
 import errno
 
 import rb
+from gi.repository import RB
 
 SECS_PER_DAY = 86400
 
@@ -49,7 +50,7 @@ class URLCache(object):
         if path.startswith("/"):
             self.path = path
         else:
-            self.path = os.path.join(rb.user_cache_dir(), path)
+            self.path = os.path.join(RB.user_cache_dir(), path)
 
         self.refresh = refresh
         self.discard = discard
diff --git a/plugins/rb/__init__.py b/plugins/rb/__init__.py
index 5f616c6..92893f0 100644
--- a/plugins/rb/__init__.py
+++ b/plugins/rb/__init__.py
@@ -29,8 +29,10 @@
 import sys
 import os.path
 import os
+import time
+import thread
 
-import gtk
+from gi.repository import RB
 
 # rb classes
 from Loader import Loader
@@ -39,12 +41,6 @@ from Loader import UpdateCheck
 from Coroutine import Coroutine
 from URLCache import URLCache
 
-#def _excepthandler (exc_class, exc_inst, trace):
-#	import sys
-#	# print out stuff ignoring our debug redirect
-#	sys.__excepthook__ (exc_class, exc_inst, trace)
-
-
 def try_load_icon(theme, icon, size, flags):
 	try:
 		return theme.load_icon(icon, size, flags)
@@ -69,10 +65,9 @@ class _rbdebugfile:
 	def __init__(self, fn):
 		self.fn = fn
 
-	def write(self, str):
-		if str == '\n':
+	def write(self, data):
+		if data == '\n':
 			return
-		import rb
 		fr = sys._getframe(1)
 
 		co = fr.f_code
@@ -90,7 +85,8 @@ class _rbdebugfile:
 		if fr.f_locals.has_key('self'):
 			methodname = '%s.%s' % (fr.f_locals['self'].__class__.__name__, methodname)
 
-		rb._debug (methodname, filename, co.co_firstlineno + fr.f_lineno,  True, str)
+		ln = co.co_firstlineno + fr.f_lineno
+		RB.debug_real (methodname, filename, ln, True, str(data))
 
 	def close(self):         pass
 	def flush(self):         pass
@@ -105,5 +101,3 @@ class _rbdebugfile:
 	truncate = tell
 
 sys.stdout = _rbdebugfile(sys.stdout.fileno())
-#sys.excepthook = _excepthandler
-



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