[clocks] Changed dialogs to implement standard buttons



commit e4e45057307c178e3c76ae5c47ebb0fe56c798b7
Author: Seif Lotfy <seif lotfy collabora co uk>
Date:   Fri Jun 8 02:17:46 2012 +0200

    Changed dialogs to implement standard buttons

 clocks.py  |   28 ++++------------------
 widgets.py |   74 ++++++++++++++++++++++++-----------------------------------
 2 files changed, 35 insertions(+), 67 deletions(-)
---
diff --git a/clocks.py b/clocks.py
index ead55e3..a20e030 100644
--- a/clocks.py
+++ b/clocks.py
@@ -84,20 +84,14 @@ class World (Clock):
     def __init__ (self):
         Clock.__init__ (self, "World", True)
         self.addButton = None
-        #self.grid = Gtk.Grid()
-        #self.grid.set_border_width(15)
-        #self.grid.set_column_spacing (15)
-        #self.add(self.grid)
         
         self.liststore = liststore = Gtk.ListStore(Pixbuf, str, GObject.TYPE_PYOBJECT)
         self.iconview = iconview = Gtk.IconView.new()
         
         iconview.set_model(liststore)
-        
         iconview.set_spacing(3)
         iconview.set_pixbuf_column(0)
         iconview.set_markup_column(1)
-        #iconview.set_item_width(32)
 
         scrolledwindow = Gtk.ScrolledWindow()
         scrolledwindow.add(iconview)
@@ -130,28 +124,20 @@ class World (Clock):
     def add_clock(self, location):
         d = DigitalClock(location)
         self.clocks.append(d)
-        #self.grid.add(d)
         view_iter = self.liststore.append([d.drawing.pixbuf, "<b>"+d.location.get_city_name()+"</b>", d])
         d.set_iter(self.liststore, view_iter)
         self.show_all()
         worldclockstorage.save_clocks (location)
 
     def open_new_dialog(self):
-        #self.newWorldClockWidget.
-        #self.newWorldClockWidget.searchEntry.grab_focus()
-        window = Gtk.Dialog("Add New Clock")
         parent = self.get_parent().get_parent().get_parent()
-        window.set_transient_for(parent)
-        window.set_modal(True)
-        widget = NewWorldClockWidget()
-        #window.add(widget)
-        window.get_children()[0].pack_start(widget, False, False, 0)
-        widget.connect("add-clock", lambda w, l: self.add_clock(l))
-        widget.connect_after("add-clock", lambda w, e: window.destroy())
+        window = NewWorldClockWidget(parent)
+
+        #window.get_children()[0].pack_start(widget, False, False, 0)
+        window.connect("add-clock", lambda w, l: self.add_clock(l))
         window.show_all()
 
     def close_new_dialog(self):
-        self.newWorldClockWidget.reset()
         self.notebook.set_current_page(0)
         self.addButton.set_sensitive(False)
         self.emit('show-requested')
@@ -263,13 +249,9 @@ class Stopwatch (Clock):
     def count(self):
         timediff = time.time() - self.start_time + self.time_diff
         (elapsed_minutes, elapsed_seconds) = divmod(timediff, 60.0)
-        
         self.stopwatchLabel.set_markup (STOPWATCH_LABEL_MARKUP%(elapsed_minutes,
             elapsed_seconds))
-        
         return True
-        
-
 
 class Timer (Clock):
 	
@@ -311,7 +293,7 @@ class Timer (Clock):
 		if self.g_id == 0: 
 			hours = self.timer_welcome_screen.hours.get_value()
 			minutes = self.timer_welcome_screen.minutes.get_value()
-			self.timer_screen.timerLabel.set_markup (TIMER_LABEL_MARKUP%(hours, minutes, 60))
+			self.timer_screen.timerLabel.set_markup (TIMER_LABEL_MARKUP%(hours, minutes, 00))
 			self.time = (hours * 60 * 60) + (minutes * 60) 
 			self.state = 1
 			self.g_id = GObject.timeout_add(1000, self.count)
diff --git a/widgets.py b/widgets.py
index 0ffe8c4..12deb46 100644
--- a/widgets.py
+++ b/widgets.py
@@ -22,78 +22,64 @@ from gi.repository import Gtk, GObject, Gio, PangoCairo, Pango, GWeather
 from gi.repository import Gdk, GdkPixbuf
 import cairo, time
 
-class NewWorldClockWidget (Gtk.Box):
+class NewWorldClockWidget (Gtk.Dialog):
 
     __gsignals__ = {'add-clock': (GObject.SignalFlags.RUN_LAST,
                     None, (GObject.TYPE_PYOBJECT,))}
 
-    def __init__ (self):
-        Gtk.Box.__init__(self)
+    def __init__ (self, parent):
+        Gtk.Dialog.__init__(self, "Add New Clock", parent)
+        self.set_transient_for(parent)
+        self.set_modal(True)
         self.set_border_width (9)
-        self.set_size_request(400,-1)
+        self.set_size_request(-1,-1)
         box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
         box.set_spacing(9)
-        self.pack_start(Gtk.Label(), True, True, 0)
-        self.pack_start(box, True, True, 9)
-        self.pack_start(Gtk.Label(), True, True, 0)
-        
+        area = self.get_content_area()
+        area.pack_start(box, True, True, 9)
+
         self.label = Gtk.Label()
         self.label.set_markup("Search for a city or a time zone...")
         self.label.set_alignment(0.0, 0.5)
-        
+
         world = GWeather.Location.new_world(True)
         self.searchEntry = GWeather.LocationEntry.new(world)
         #self.searchEntry.set_placeholder_text("Search for a city or a time zone...")
-        
+
         header = Gtk.Label("Add New Clock")
         header.set_markup("<span size='x-large'><b>Add New Clock</b></span>")
         
         btnBox = Gtk.Box()
-        
-        self.addBtn = Gtk.Button()
-        label = Gtk.Label ("Add")
-        label.set_padding(6, 0)
-        self.addBtn.add(label)
-        #self.addBtn.get_style_context ().add_class ("clocks-continue");
-        
-        self.addBtn.set_sensitive(False)
-        
-        self.cancelBtn = Gtk.Button()
-        label = Gtk.Label ("Cancel")
-        label.set_padding(6, 0)
-        self.cancelBtn.add(label)
-        
-        btnBox.set_size_request (-1, 33)
-        btnBox.set_spacing(9)
-        btnBox.pack_end(self.addBtn, False, False, 0)
-        btnBox.pack_end(self.cancelBtn, False, False, 0)
-        
+
+        self.add_buttons("Cancel", 0, "Save", 1)
+        widget = self.get_widget_for_response (1)
+        widget.set_sensitive (False)
+
         box.pack_start(header, True, True, 0)
         box.pack_start(Gtk.Label(), True, True, 3)
         box.pack_start(self.label, False, False, 0)
         box.pack_start(self.searchEntry, False, False, 9)
-        box.pack_start(btnBox, True, True, 0)
-        
+
         self.searchEntry.connect("activate", self._set_city)
         self.searchEntry.connect("changed", self._set_city)
-        self.addBtn.connect("clicked", self._add_clock)
+        self.connect("response", self._on_response_clicked)
         self.location = None
         self.show_all ()
-        
+
+    def _on_response_clicked (self, widget, response_id):
+      if response_id == 1:
+        location = self.searchEntry.get_location()
+        self.emit("add-clock", location)
+      self.destroy ()
+
     def _set_city (self, widget):
         location = widget.get_location()
+        widget = self.get_widget_for_response (1)
         if location:
-            self.addBtn.set_sensitive(True)
+            widget.set_sensitive(True)
         else:
-            self.addBtn.set_sensitive(False)
-    
-    def _add_clock(self, widget):
-        location = self.searchEntry.get_location()
-        self.emit("add-clock", location)
-    
-    def reset(self):
-        self.searchEntry.set_text("")
-    
+            widget.set_sensitive(False)
+
     def get_selection (self):
         return self.location
 
@@ -199,7 +185,7 @@ class DigitalClockDrawing (Gtk.DrawingArea):
 
     def __init__(self):
         Gtk.DrawingArea.__init__(self)
-        self.set_size_request(160,160)
+        #self.set_size_request(width,height)
         self.pango_context = None
         self.ctx = None
         self.pixbuf = None



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