gnome-applets r10770 - in trunk/invest-applet: . invest



Author: callum
Date: Mon Mar 31 02:20:28 2008
New Revision: 10770
URL: http://svn.gnome.org/viewvc/gnome-applets?rev=10770&view=rev

Log:
Major UI update for the invest applet from Matteo Zandi.

Modified:
   trunk/invest-applet/ChangeLog
   trunk/invest-applet/invest/applet.py
   trunk/invest-applet/invest/widgets.py

Modified: trunk/invest-applet/invest/applet.py
==============================================================================
--- trunk/invest-applet/invest/applet.py	(original)
+++ trunk/invest-applet/invest/applet.py	Mon Mar 31 02:20:28 2008
@@ -37,27 +37,35 @@
 		self.prefs = InvestAppletPreferences(applet)
 		
 		self.investwidget = InvestWidget()
-		self.investticker = InvestTrend()#InvestTicker()
-		
-		self.pw = ProgramWindow(applet, self.investticker)
-		self.pw.add(self.investwidget)
-		self.tb = ToggleButton(applet, self.pw)
-		
-		self.investwidget.connect('row-activated', lambda treeview, path, view_column: self.tb.set_active(False))
+
 		get_quotes_updater().connect('quotes-updated', self._on_quotes_updated)
-			
-		box = gtk.HBox()
-		box.add(self.tb)
-		box.add(self.investticker)
-		
-		self.applet.add(box)
+
 		self.applet.setup_menu_from_file (
 			invest.SHARED_DATA_DIR, "Invest_Applet.xml",
 			None, [("About", self.on_about), ("Prefs", self.on_preferences), ("Refresh", self.on_refresh)])
 
+		evbox = gtk.HBox()
+		applet_icon = gtk.Image()
+		try:
+			pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(join(invest.ART_DATA_DIR, "invest-button.png"), -1,-1)
+			applet_icon.set_from_pixbuf(pixbuf)
+		except Exception, msg:
+			applet_icon.set_from_icon_name("stock_chart-autoformat", gtk.ICON_SIZE_BUTTON)
+		
+		applet_icon.show()
+		evbox.add(applet_icon)
+
+		self.ilw = InvestmentsListWindow(self.applet, self.investwidget)
+
+		self.applet.add(evbox)
+		self.applet.connect("button-press-event",self.button_clicked)
 		self.applet.show_all()
 		get_quotes_updater().refresh()
-		
+
+	def button_clicked(self, widget,event):
+		if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
+			self.ilw.toggle_show()
+	
 	def on_about(self, component, verb):
 		invest.about.show_about()
 	
@@ -77,111 +85,46 @@
 		#	_("Quotes updated"),
 		#	3000)
 
-class ToggleButton(gtk.ToggleButton):
-	def __init__(self, applet, pw):
-		gtk.ToggleButton.__init__(self)
-		self.pw = pw
-
-		self.connect("toggled", self.toggled)
-        	self.connect("button-press-event", self.on_button_press)
-
-		self.set_relief(gtk.RELIEF_NONE)
-
-		image = gtk.Image()
-		try:
-			pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(join(invest.ART_DATA_DIR, "invest-button.png"), -1,-1)
-			image.set_from_pixbuf(pixbuf)
-		except Exception, msg:
-			image.set_from_icon_name("stock_chart", gtk.ICON_SIZE_BUTTON)
-		
-		hbox = gtk.HBox()
-		hbox.pack_start(image)
-		
-		orient = applet.get_orient()
-		arrow_dir = gtk.ARROW_DOWN
-		if orient == gnomeapplet.ORIENT_RIGHT:
-			arrow_dir = gtk.ARROW_RIGHT
-		elif orient == gnomeapplet.ORIENT_LEFT:
-			arrow_dir = gtk.ARROW_LEFT
-		elif orient == gnomeapplet.ORIENT_DOWN:
-			arrow_dir = gtk.ARROW_DOWN
-		elif orient == gnomeapplet.ORIENT_UP:
-			arrow_dir = gtk.ARROW_UP
-			
-		hbox.pack_start(gtk.Arrow(arrow_dir, gtk.SHADOW_NONE))
-		
-		self.add(hbox)
-			
-	def toggled(self, togglebutton):
-		if togglebutton.get_active():
-			self.pw.update_position()
-			self.pw.show_all()
-			self.pw.grab_focus()
-		else:
-			self.pw.hide()
-
-	def on_button_press(self, togglebutton, event):
-		if event.button != 1:
-			togglebutton.stop_emission("button-press-event")
-
-gobject.type_register(ToggleButton)
-	
-class ProgramWindow(gtk.Window):
-	"""
-	Borderless window aligning itself to a given widget.
-	Use CuemiacWindow.update_position() to align it.
-	"""
-	def __init__(self, applet, widgetToAlignWith):
-		"""
-		alignment should be one of
-			gnomeapplet.ORIENT_{DOWN,UP,LEFT,RIGHT}
-		
-		Call CuemiacWindow.update_position () to position the window.
-		"""
+class InvestmentsListWindow(gtk.Window):
+	def __init__(self, applet, list):
 		gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
-		self.set_decorated (False)
-		self.set_resizable (False)
-
-		# Skip the taskbar, and the pager, stick and stay on top
+		self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
 		self.stick()
-		self.set_keep_above(True)
-		self.set_skip_pager_hint(True)
-		self.set_skip_taskbar_hint(True)
 		
-		self.widgetToAlignWith = widgetToAlignWith		
 		self.applet = applet
-		self.alignment = applet.get_orient ()
-
-		self.realize_status = None
-		self.connect ("realize", lambda win : self.__register_realize ())
-		self.connect ("size-allocate", self.__resize_event)
+		self.alignment = self.applet.get_orient ()
 		
-	def __resize_event (self, event, data):
-		self.update_position ()
-	
+		self.add(list)
+		list.show()
+
+		# boolean variable that identifies if the window is visible
+		# show/hide is triggered by left-clicking on the applet
+		self.hidden = True
+
+	def toggle_show(self):
+		if self.hidden == True:
+			self.update_position()
+			self.show()
+			self.hidden = False
+		elif self.hidden == False:
+			self.hide()
+			self.hidden = True
+
 	def update_position (self):
 		"""
 		Calculates the position and moves the window to it.
-		IMPORATNT: widgetToAlignWith should be realized!
 		"""
-		if self.realize_status == None:
-			self.realize_status = False
-			self.realize ()
-			return
-		
-		if self.realize_status == False:
-			return
-			
+
 		# Get our own dimensions & position
-		(wx, wy) = self.window.get_origin ()
-		(ax, ay) = self.widgetToAlignWith.window.get_origin ()
+		#(wx, wy) = self.get_origin()
+		(ax, ay) = self.applet.window.get_origin()
 
-		(ww, wh) = self.window.get_size ()
-		(aw, ah) = self.widgetToAlignWith.window.get_size ()
+		(ww, wh) = self.get_size ()
+		(aw, ah) = self.applet.window.get_size ()
 
-		screen = self.get_screen()
+		screen = self.applet.window.get_screen()
 		monitor = screen.get_monitor_geometry (screen.get_monitor_at_window (self.applet.window))
-		
+
 		if self.alignment == gnomeapplet.ORIENT_LEFT:
 				x = ax - ww
 				y = ay
@@ -193,7 +136,7 @@
 					y = 0
 				
 				if (y + wh > monitor.height / 2):
-					gravity = gtk.gdk.GRAVITY_SOUTH_WEST	
+					gravity = gtk.gdk.GRAVITY_SOUTH_WEST
 				else:
 					gravity = gtk.gdk.GRAVITY_NORTH_WEST
 					
@@ -234,12 +177,6 @@
 					x = 0
 
 				gravity = gtk.gdk.GRAVITY_SOUTH_WEST
-		
+
 		self.move(x, y)
 		self.set_gravity(gravity)
-	
-	def __register_realize (self):
-		self.realize_status = True
-		self.update_position()
-		
-gobject.type_register (ProgramWindow)

Modified: trunk/invest-applet/invest/widgets.py
==============================================================================
--- trunk/invest-applet/invest/widgets.py	(original)
+++ trunk/invest-applet/invest/widgets.py	Mon Mar 31 02:20:28 2008
@@ -39,47 +39,66 @@
 class InvestWidget(gtk.TreeView):
 	def __init__(self):
 		gtk.TreeView.__init__(self)
-				
-		self.set_property("headers-visible", False)
+
 		self.set_property("rules-hint", True)
 		self.set_reorderable(True)
-		
-		cell = gtk.CellRendererText ()
-		self.column_description = gtk.TreeViewColumn ("Description", cell)
-		self.column_description.set_cell_data_func(cell, self._get_cell_data)
-		
-		self.append_column(self.column_description)
+
+		# model: SYMBOL, TICKER_ONLY, BALANCE, BALANCE_PCT, VALUE, VARIATION
+		# old col_names = ['Symbol', 'Value/Balance', 'Variation/Balance PCT', 'Value']
+		col_names = ['Symbol', 'Last', 'Change', 'Gain', 'Gain %']
+		col_cellgetdata_functions = [self._getcelldata_symbol, self._getcelldata_value,
+			self._getcelldata_variation, self._getcelldata_balance, self._getcelldata_balancepct]
+		for i, col_name in enumerate(col_names):
+			cell = gtk.CellRendererText ()
+			column = gtk.TreeViewColumn (col_name, cell)
+			column.set_cell_data_func(cell, col_cellgetdata_functions[i])
+			self.append_column(column)
+
 		self.connect('row-activated', self.on_row_activated)
-		
 		self.set_model(get_quotes_updater())
-	
-	def _get_cell_data(self, column, cell, model, iter):
-		if model[iter][model.TICKER_ONLY]:
-			color = GREEN
-			if model[iter][model.VARIATION] < 0:
-				color = RED
-							
-			cell.set_property('markup',
-				"<span face='Monospace'>%s: <span foreground='%s'>%+.2f</span> (<span foreground='%s'>%+.2f%%</span>)</span>" %
-				(model[iter][model.SYMBOL], color, model[iter][model.VALUE], color, model[iter][model.VARIATION]))
+
+	def _getcelldata_symbol(self, column, cell, model, iter):
+		cell.set_property('text', model[iter][model.SYMBOL])
+
+	def _getcelldata_value(self, column, cell, model, iter):
+		cell.set_property('text', "%.5g" % model[iter][model.VALUE])
+
+	def _getcelldata_variation(self, column, cell, model, iter):
+		color = GREEN
+		if model[iter][model.VARIATION] < 0: color = RED
+		cell.set_property('markup',
+			"<span foreground='%s'>%+.2f%%</span>" %
+			(color, model[iter][model.VARIATION]))
+
+	def _getcelldata_balance(self, column, cell, model, iter):
+		is_ticker_only = model[iter][model.TICKER_ONLY]
+		color = GREEN
+		if model[iter][model.BALANCE] < 0: color = RED
+		if is_ticker_only:
+			cell.set_property('text', '')
 		else:
-			color = GREEN
-			if model[iter][model.BALANCE] < 0:
-				color = RED
-							
-			cell.set_property('markup',
-				"<span face='Monospace'>%s: <span foreground='%s'>%.2f</span> (<span foreground='%s'>%+.2f%%</span>) %.2f</span>" %
-				(model[iter][model.SYMBOL], color, model[iter][model.BALANCE], color, model[iter][model.BALANCE_PCT], model[iter][model.VALUE]))
-				
+					cell.set_property('markup',
+			"<span foreground='%s'>%+.2f</span>" %
+			(color, model[iter][model.BALANCE]))
+
+	def _getcelldata_balancepct(self, column, cell, model, iter):
+		is_ticker_only = model[iter][model.TICKER_ONLY]
+		color = GREEN
+		if model[iter][model.BALANCE] < 0: color = RED
+		if is_ticker_only:
+			cell.set_property('text', '')
+		else:
+					cell.set_property('markup',
+			"<span foreground='%s'>%+.2f%%</span>" %
+			(color, model[iter][model.BALANCE_PCT]))
+
 	def on_row_activated(self, treeview, path, view_column):
 		ticker = self.get_model()[self.get_model().get_iter(path)][0]
 		if ticker == None:
 			return
-		
+
 		invest.chart.show_chart([ticker])
 
-gobject.type_register(InvestWidget)
-	
 #class InvestTicker(gtk.Label):
 #	def __init__(self):
 #		gtk.Label.__init__(self, _("Waiting..."))



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