[gnome-applets/wip/dont-use-deprecated: 11/11] invest-applet: cleanup Gtk3 porting modifications for a clean diff



commit 69bcb1525a98485ab35052ccd0b0469a32f34cdc
Author: Enrico Minack <enrico-minack gmx de>
Date:   Mon May 2 22:58:03 2011 +0200

    invest-applet: cleanup Gtk3 porting modifications for a clean diff

 invest-applet/invest/__init__.py      |   20 +++-----------
 invest-applet/invest/applet.py        |   20 ++-----------
 invest-applet/invest/chart.py         |    4 +-
 invest-applet/invest/invest-applet.py |   49 +++++++++-----------------------
 invest-applet/invest/quotes.py        |   14 +++------
 5 files changed, 28 insertions(+), 79 deletions(-)
---
diff --git a/invest-applet/invest/__init__.py b/invest-applet/invest/__init__.py
index b8fdb92..5f4f914 100644
--- a/invest-applet/invest/__init__.py
+++ b/invest-applet/invest/__init__.py
@@ -5,34 +5,25 @@ import datetime
 from gi.repository import GObject, Gtk, Gdk, GConf
 import cPickle
 import networkmanager
-import random
-
 
 # Autotools set the actual data_dir in defs.py
 from defs import *
 
 DEBUGGING = False
 
-LOGFILE = open('/tmp/investapplet.%d.log' % random.randint(1000000, 9999999), 'w')
-
-
 # central debugging and error method
 def debug(msg):
 	if DEBUGGING:
-		msg = "%s: %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), msg)
-		print msg
-		LOGFILE.write(msg + "\n")
+		print "%s: %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), msg)
 
 def error(msg):
-	msg = "%s: ERROR: %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), msg)
-	print msg
-	LOGFILE.write(msg + "\n")
+	print "%s: ERROR: %s" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), msg)
 
 
 def exceptionhandler(t, value, tb):
-	print "%s occurred: %s" % (t.__name__, value)
+	error("%s occurred: %s" % (t.__name__, value))
 	for elem in traceback.extract_tb(tb):
-		print "\t%s:%d in %s: %s" % (elem[0], elem[1], elem[2], elem[3])
+		error("\t%s:%d in %s: %s" % (elem[0], elem[1], elem[2], elem[3]))
 
 # redirect uncaught exceptions to this exception handler
 debug("Installing default exception handler")
@@ -232,6 +223,3 @@ get_gnome_proxy(client)
 # connect to Network Manager to identify current network connectivity
 debug("Connecting to the NetworkManager")
 nm = networkmanager.NetworkManager()
-
-debug("Finished __init__")
-
diff --git a/invest-applet/invest/applet.py b/invest-applet/invest/applet.py
index 0425746..6e199ba 100644
--- a/invest-applet/invest/applet.py
+++ b/invest-applet/invest/applet.py
@@ -18,28 +18,17 @@ class InvestApplet(PanelApplet.Applet):
 		self.applet = applet
 
 		# name, stock_id, label, accellerator, tooltip, callback
-		invest.debug("defining menu actions");
-		menu_actions = [("About", Gtk.STOCK_HELP, _("About"), None, None, self.on_about), 
+		menu_actions = [("About", Gtk.STOCK_HELP, _("About"), None, None, self.on_about),
 				("Help", Gtk.STOCK_HELP, _("Help"), None, None, self.on_help),
 				("Prefs", Gtk.STOCK_PREFERENCES, _("Preferences"), None, None, self.on_preferences),
 				("Refresh", Gtk.STOCK_REFRESH, _("Refresh"), None, None, self.on_refresh)
 				]
-
-		invest.debug("creating action group")
 		actiongroup = Gtk.ActionGroup.new("InvestAppletActions")
-
-		invest.debug("setting translationd domain to %s " % invest.defs.GETTEXT_PACKAGE)
 		actiongroup.set_translation_domain(invest.defs.GETTEXT_PACKAGE)
-
-		# arguments: entries (array of action descriptions), n (the number of entries), userdata (passed to the action callbacks)
-		invest.debug("adding action menue to action group")
-		# actiongroup.add_actions(menu_actions, len(menu_actions), None)
 		actiongroup.add_actions(menu_actions, None)
+		self.applet.setup_menu_from_file (join(invest.defs.PKGDATADIR, "ui/invest-applet-menu.xml"),
+						  actiongroup);
 
-		invest.debug("setting up menu from file");
-		self.applet.setup_menu_from_file (join(invest.defs.PKGDATADIR, "ui/invest-applet-menu.xml"), actiongroup);
-
-		invest.debug("creating icon");
 		evbox = Gtk.HBox()
 		self.applet_icon = Gtk.Image()
 		self.set_applet_icon(0)
@@ -53,9 +42,7 @@ class InvestApplet(PanelApplet.Applet):
 	def new_ilw(self):
 		self.quotes_updater = QuoteUpdater(self.set_applet_icon,
 						   self.set_applet_tooltip)
-		invest.debug("creating InvestWidget");
 		self.investwidget = InvestWidget(self.quotes_updater)
-		invest.debug("creating InvestListWindow");
 		self.ilw = InvestmentsListWindow(self.applet, self.investwidget)
 
 	def reload_ilw(self):
@@ -204,4 +191,3 @@ class InvestmentsListWindow(Gtk.Window):
 
 		self.move(x, y)
 		self.set_gravity(gravity)
-
diff --git a/invest-applet/invest/chart.py b/invest-applet/invest/chart.py
index 0d2784b..991ba04 100644
--- a/invest-applet/invest/chart.py
+++ b/invest-applet/invest/chart.py
@@ -11,7 +11,7 @@ import urllib
 from threading import Thread
 import time
 
-AUTOREFRESH_TIMEOUT = 15*60*1000 # 15 minutes
+AUTOREFRESH_TIMEOUT = 20*60*1000 # 15 minutes
 
 # based on http://www.johnstowers.co.nz/blog/index.php/2007/03/12/threading-and-pygtk/
 class _IdleObject(GObject.Object):
@@ -53,7 +53,7 @@ class ImageRetriever(Thread, _IdleObject):
 		else:
 			loader = GdkPixbuf.PixbufLoader()
 			loader.connect("closed", lambda loader: self.image.set_from_pixbuf(loader.get_pixbuf()))
-			loader.write(sock.read()) 
+			loader.write(sock.read())
 			sock.close()
 			loader.close()
 			self.retrieved = True
diff --git a/invest-applet/invest/invest-applet.py b/invest-applet/invest/invest-applet.py
index 68f2652..3c23748 100755
--- a/invest-applet/invest/invest-applet.py
+++ b/invest-applet/invest/invest-applet.py
@@ -32,24 +32,6 @@ def applet_factory(applet, iid, data):
 	invest.applet.InvestApplet(applet)
 	return True
 
-# Return a standalone window that holds the applet
-def build_window():
-	invest.debug("Creating panel applet container")
-	PanelApplet.Container.new()
-	invest.debug("Creating gtk window")
-	app = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
-	app.set_title(_("Invest Applet"))
-	app.connect("destroy", Gtk.main_quit)
-	app.set_property('resizable', False)
-
-	applet = PanelApplet.Applet()
-	applet_factory(applet, None)
-	applet.reparent(app)
-
-	app.show_all()
-
-	return app
-
 
 def usage():
 	print """=== Invest applet: Usage
@@ -58,13 +40,18 @@ $ invest-applet [OPTIONS]
 OPTIONS:
 	-h, --help			Print this help notice.
 	-d, --debug			Enable debug output (default=off).
-	-w, --window		Launch the applet in a standalone window for test purposes (default=no).
+
+For test purposes, you can run the applet as a standalone window by running (e.g.)
+  /usr/libexec/invest-applet -d
+and executing the panel-applet-test application:
+  env panel-test-applets
+Click 'execute'. Make sure no invest applet is currently running in the panel.
+If invest is not installed to the system, instead execute
+  env GNOME_PANEL_APPLETS_DIR=/PATH/TO/INVEST_SOURCES/data panel-test-applets
 	"""
 	sys.exit()
 
 if __name__ == "__main__":
-	standalone = False
-
 	try:
 		opts, args = getopt.getopt(sys.argv[1:], "hdw", ["help", "debug", "window"])
 	except getopt.GetoptError:
@@ -83,18 +70,10 @@ if __name__ == "__main__":
 			# because that variable was set here to be True
 			invest.debug("Data Dir: %s" % invest.SHARED_DATA_DIR)
 			invest.debug("Detected PROXY: %s" % invest.PROXY)
-		elif o in ("-w", "--window"):
-			standalone = True
-
-	if standalone:
-		invest.debug("Starting standalone applet")
-		build_window()
-		Gtk.main()
-	else:
-		invest.debug("Starting applet factory")
-		PanelApplet.Applet.factory_main(
-			"InvestAppletFactory",	# id
-			PanelApplet.Applet.__gtype__,	# gtype
-			applet_factory,			# factory callback
-			None)				# factory data pointer
 
+	invest.debug("Starting applet factory, waiting for gnome-panel to connect ...")
+	PanelApplet.Applet.factory_main(
+		"InvestAppletFactory",	# id
+		PanelApplet.Applet.__gtype__,	# gtype
+		applet_factory,			# factory callback
+		None)				# factory data pointer
diff --git a/invest-applet/invest/quotes.py b/invest-applet/invest/quotes.py
index 56b5e53..ed85dcf 100644
--- a/invest-applet/invest/quotes.py
+++ b/invest-applet/invest/quotes.py
@@ -82,7 +82,6 @@ class QuoteUpdater(Gtk.ListStore):
 		self.refresh()
 
 		# tell the network manager to notify me when network status changes
-		invest.debug("setting NM callback");
 		invest.nm.set_statechange_callback(self.nm_state_changed)
 
 	def set_update_interval(self, interval):
@@ -115,12 +114,12 @@ class QuoteUpdater(Gtk.ListStore):
 			return True
 
 		tickers = '+'.join(invest.STOCKS.keys())
-		invest.debug("creating quotes retriever")
+		invest.debug("creating QuotesRetriever")
 		quotes_retriever = QuotesRetriever(tickers)
 		quotes_retriever.connect("completed", self.on_retriever_completed)
-		invest.debug("starting")
+		invest.debug("starting QuotesRetriever")
 		quotes_retriever.start()
-		invest.debug("started")
+		invest.debug("started QuotesRetriever")
 
 		return True
 
@@ -134,15 +133,15 @@ class QuoteUpdater(Gtk.ListStore):
 		return locale.format("%+.2f", value, True, True)
 
 	def on_retriever_completed(self, retriever):
-		invest.debug("retriever completed");
 		if retriever.retrieved == False:
-			invest.debug("retrieval failed");
+			invest.debug("QuotesRetriever failed");
 			tooltip = [_('Invest could not connect to Yahoo! Finance')]
 			if self.last_updated != None:
 				# Translators: %s is an hour (%H:%M)
 				tooltip.append(_('Updated at %s') % self.last_updated.strftime("%H:%M"))
 			self.set_tooltip_callback('\n'.join(tooltip))
 		else:
+			invest.debug("QuotesRetriever completed");
 			self.populate(self.parse_yahoo_csv(csv.reader(retriever.data)))
 			self.updated = True
 			self.last_updated = datetime.datetime.now()
@@ -412,6 +411,3 @@ class QuoteUpdater(Gtk.ListStore):
 					res = False
 					break
 		return res
-
-#if Gtk.version < (2,8,0):
-#	gobject.type_register(QuoteUpdater)



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