[POS-commit] r75 - in Kiwi2: . examples/Faren

Lorenzo Gil Sanchez lgs at async.com.br
Mon Mar 7 11:11:23 BRT 2005


Author: lgs
Date: 2005-03-07 11:11:22 -0300 (Mon, 07 Mar 2005)
New Revision: 75

Added:
   Kiwi2/examples/Faren/faren3.py
Modified:
   Kiwi2/ChangeLog
Log:
	* examples/Faren/faren3.py: this one uses a GladeDelegate

Modified: Kiwi2/ChangeLog
===================================================================
--- Kiwi2/ChangeLog	2005-03-07 14:06:01 UTC (rev 74)
+++ Kiwi2/ChangeLog	2005-03-07 14:11:22 UTC (rev 75)
@@ -1,8 +1,9 @@
 2005-03-07  Lorenzo Gil Sanchez  <lgs at sicem.biz>
 
-	* examples/Faren/faren2.py (FarenView.get_temp): second version of
-	Faren example
+	* examples/Faren/faren3.py: this one uses a GladeDelegate
 
+	* examples/Faren/faren2.py: second version of Faren example
+
 	* examples/Faren/faren.py: ported the basic Temperature example
 
 	* examples/Simple/simple.py: ported another example to Kiwi2

Added: Kiwi2/examples/Faren/faren3.py
===================================================================
--- Kiwi2/examples/Faren/faren3.py	2005-03-07 14:06:01 UTC (rev 74)
+++ Kiwi2/examples/Faren/faren3.py	2005-03-07 14:11:22 UTC (rev 75)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+from Kiwi2 import Delegates
+from Kiwi2.initgtk import gtk, quit_if_last
+
+class Farenheit(Delegates.GladeDelegate):
+    widgets = ["quitbutton", "temperature", "celsius", "farenheit",
+               "celsius_label" , "farenheit_label", "temperature_label"]
+    def __init__(self):
+        Delegates.GladeDelegate.__init__(self, "faren", 
+                                         delete_handler=quit_if_last)
+        # Make labels bold
+        self.temperature_label.set_markup("<b>%s</b>" % \
+                                          self.temperature_label.get_text())
+        self.farenheit_label.set_markup("<b>%s</b>" % \
+                                        self.farenheit_label.get_text())
+        self.celsius_label.set_markup("<b>%s</b>" % \
+                                      self.celsius_label.get_text())
+    
+    def convert_temperature(self, temp):
+        farenheit = (temp * 9/5.0) + 32
+        celsius = (temp - 32) * 5/9.0
+        return farenheit, celsius 
+    
+    def clear_temperature(self):
+        self.farenheit.set_text("") 
+        self.celsius.set_text("")
+
+    # Signal handlers
+
+    def on_quitbutton__clicked(self, *args):
+        self.hide_and_quit()
+
+    def after_temperature__changed(self, entry, *args):
+        temp = entry.get_text().strip() or None
+        if temp is None:
+            self.clear_temperature()
+        else:
+            farenheit, celsius = self.convert_temperature(float(temp))
+            self.farenheit.set_text("%.2f" % farenheit)
+            self.celsius.set_text("%.2f" % celsius)
+
+delegate = Farenheit()
+delegate.show()
+gtk.main()


Property changes on: Kiwi2/examples/Faren/faren3.py
___________________________________________________________________
Name: svn:executable
   + *



More information about the POS-commit mailing list