[clocks] Added storage and new single clock viewy
- From: Seif Lotfy <seiflotfy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clocks] Added storage and new single clock viewy
- Date: Sun, 20 May 2012 20:50:17 +0000 (UTC)
commit 6817582a14eb5a04e291d5c2f1f3c09074904fa5
Author: Seif Lotfy <seif lotfy collabora co uk>
Date: Sun May 20 22:49:51 2012 +0200
Added storage and new single clock viewy
clocks.py | 49 ++++++++++++++++++++++++++-----------------------
main.py | 56 ++++++++++++++++++++++++++++++++++++++++----------------
storage.py | 37 +++++++++++++++++++++++++++++++++++++
widgets.py | 24 ++++++++++++++++++++++--
4 files changed, 125 insertions(+), 41 deletions(-)
---
diff --git a/clocks.py b/clocks.py
index 97edd09..5c578e7 100644
--- a/clocks.py
+++ b/clocks.py
@@ -22,6 +22,8 @@ from gi.repository import Gtk, GObject, Gio, Gdk
from gi.repository.GdkPixbuf import Pixbuf
from widgets import NewWorldClockWidget, DigitalClock
+from storage import worldclockstorage
+
from datetime import datetime, timedelta
from pytz import timezone
import pytz, time, os
@@ -51,7 +53,10 @@ class ToggleButton(Gtk.ToggleButton):
class Clock (Gtk.EventBox):
__gsignals__ = {'show-requested': (GObject.SignalFlags.RUN_LAST,
- None, ())}
+ None, ()),
+ 'show-clock': (GObject.SignalFlags.RUN_LAST,
+ None, (GObject.TYPE_PYOBJECT,))}
+
def __init__ (self, label, hasNew = False):
Gtk.EventBox.__init__ (self)
self.button = ToggleButton (label)
@@ -75,7 +80,7 @@ class World (Clock):
#self.grid.set_column_spacing (15)
#self.add(self.grid)
- self.liststore = liststore = Gtk.ListStore(Pixbuf, str)
+ self.liststore = liststore = Gtk.ListStore(Pixbuf, str, GObject.TYPE_PYOBJECT)
iconview = Gtk.IconView.new()
iconview.set_model(liststore)
@@ -84,34 +89,39 @@ class World (Clock):
iconview.set_pixbuf_column(0)
iconview.set_markup_column(1)
iconview.set_item_width(160)
-
+
scrolledwindow = Gtk.ScrolledWindow()
scrolledwindow.add(iconview)
self.add(scrolledwindow)
-
+
+ iconview.connect ("selection-changed", self._on_selection_changed)
+
self.clocks = []
self.load_clocks()
self.show_all()
-
+
+ def _on_selection_changed (self, iconview):
+ path = iconview.get_selected_items ()[0]
+ d = self.liststore [path][2]
+ self.emit ("show-clock", d)
+
def set_addButton(self, btn):
self.addButton = btn
-
+
def load_clocks(self):
- #d = DigitalClock("Berlin", "data/cities/berlin.png")
- #self.grid.add(d)
- #d = DigitalClock("London", "data/cities/london.png", 60*60*1000)
- #self.grid.add(d)
- #self.show_all()
- pass
-
+ self.clocks = worldclockstorage.load_clocks ()
+ for clock in self.clocks:
+ self.add_clock (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>"])
+ 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()
@@ -131,14 +141,7 @@ class World (Clock):
self.notebook.set_current_page(0)
self.addButton.set_sensitive(False)
self.emit('show-requested')
-
- def add_new_clock(self):
- location = self.newWorldClockWidget.get_selection()
- self.add_clock(location)
- self.newWorldClockWidget.reset()
- self.notebook.set_current_page(0)
- self.addButton.set_sensitive(False)
- self.emit('show-requested')
+
class Alarm (Clock):
def __init__ (self):
diff --git a/main.py b/main.py
index 1fdd5ee..fd38baa 100644
--- a/main.py
+++ b/main.py
@@ -42,33 +42,43 @@ class Window (Gtk.Window):
self.toolbar = ClocksToolbar ()
vbox.pack_start (self.toolbar, False, False, 0)
-
+
self.world = World ()
self.alarm = Alarm ()
self.stopwatch = Stopwatch ()
self.timer = Timer ()
-
+
self.views = (self.world, self.alarm, self.stopwatch, self.timer)
self.toolbar.set_clocks (self.views)
-
+ self.single_evbox = Gtk.EventBox ()
+
self.show_all ()
-
+
vbox.pack_end (self.notebook, True, True, 0)
vbox.pack_end (Gtk.Separator(), False, False, 1)
for view in self.views:
self.notebook.append_page (view, Gtk.Label(str(view)))
-
+ self.notebook.append_page (self.single_evbox, Gtk.Label("Widget"))
+
+ self.world.connect ("show-clock", self._on_show_clock)
self.toolbar.connect("view-clock", self._on_view_clock)
self.toolbar.newButton.connect("clicked", self._on_new_clicked)
self.show_all ()
-
-
+
+ def _on_show_clock (self, widget, d):
+ self.toolbar._set_single_toolbar ()
+ self.notebook.set_current_page (-1)
+ for child in self.single_evbox.get_children ():
+ self.single_evbox.remove (child)
+ self.single_evbox.add (d.get_standalone_widget ())
+ self.single_evbox.show_all ()
+
def _on_view_clock (self, button, index):
self.notebook.set_current_page (index)
-
+
def _on_new_clicked (self, button):
self.show_all()
-
+
def _on_cancel_clicked (self, button):
self.show_all()
@@ -100,6 +110,12 @@ class ClocksToolbar (Gtk.Toolbar):
box.pack_start (self.newButton, False, False, 3)
toolbox.pack_start (box, True, True, 0)
+ self.backButton = Gtk.Button ()
+ icon = Gio.ThemedIcon.new_with_default_fallbacks ("go-previous-symbolic")
+ image = Gtk.Image ()
+ image.set_from_gicon (icon, Gtk.IconSize.BUTTON)
+ self.backButton.add(image)
+
self.newButton.connect("clicked", self._on_new_clicked)
toolbox.pack_start (Gtk.Label(""), True, True, 0)
@@ -115,12 +131,13 @@ class ClocksToolbar (Gtk.Toolbar):
#self.applyButton.get_style_context ().add_class ('raised');
icon = Gio.ThemedIcon.new_with_default_fallbacks ("action-unavailable-symbolic")
image = Gtk.Image ()
- image.set_from_gicon (icon, Gtk.IconSize.LARGE_TOOLBAR)
+ image.set_from_gicon (icon, Gtk.IconSize.BUTTON)
self.applyButton.add (image)
self.rightBox = box = Gtk.Box ()
box.pack_end (self.applyButton, False, False, 3)
toolbox.pack_start (box, True, True, 0)
+
self._buttonMap = {}
self._busy = False
@@ -129,12 +146,6 @@ class ClocksToolbar (Gtk.Toolbar):
if view.button.get_active():
view.open_new_dialog()
break
-
- def _on_cancel_clicked (self, widget):
- for view in self.views:
- if view.button.get_active():
- view.close_new_dialog()
- break
def set_clocks (self, views):
self.views = views
@@ -147,6 +158,19 @@ class ClocksToolbar (Gtk.Toolbar):
if i == 0:
view.button.set_active (True)
+ def _set_overview_toolbar (self):
+ self.buttonBox.show ()
+ self.newButton.show ()
+ self.applyButton.show ()
+ self.backButton.hide ()
+
+ def _set_single_toolbar (self):
+ self.buttonBox.hide ()
+ self.newButton.hide ()
+ self.applyButton.hide ()
+ self.leftBox.pack_start (self.backButton, False, False, 3)
+ self.backButton.show_all ()
+
def _on_toggled (self, widget):
if not self._busy:
self._busy = True
diff --git a/storage.py b/storage.py
new file mode 100644
index 0000000..7a27949
--- /dev/null
+++ b/storage.py
@@ -0,0 +1,37 @@
+"""
+ Copyright (c) 2012 Collabora, Ltd.
+
+ Gnome Clocks is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ Gnome Clocks is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Gnome Documents; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Author: Seif Lotfy <seif lotfy collabora co uk>
+"""
+
+import os
+import pickle
+from xdg import BaseDirectory
+
+DATA_PATH = BaseDirectory.save_data_path("clocks") + "/clocks"
+
+class WorldClockStorage ():
+ def __init__ (self):
+ pass
+
+ def save_clocks (self, clocks):
+ pass
+
+ def load_clocks (self):
+ return []
+
+worldclockstorage = WorldClockStorage ()
diff --git a/widgets.py b/widgets.py
index adeae21..bed99a1 100644
--- a/widgets.py
+++ b/widgets.py
@@ -108,7 +108,8 @@ class DigitalClock ():
self.view_iter = None
self.list_store = None
- self.drawing = DigitalClockDawing()
+ self.drawing = DigitalClockDrawing ()
+ self.standalone = DigitalClockStandalone ()
self.update ()
GObject.timeout_add(1000, self.update)
@@ -144,6 +145,7 @@ class DigitalClock ():
self.drawing.render(t, img, self.get_is_day ())
if self.view_iter and self.list_store:
self.list_store.set_value(self.view_iter, 0, self.drawing.pixbuf)
+ self.standalone.update (img, t)
self._last_time = t
return True
@@ -151,7 +153,25 @@ class DigitalClock ():
self.view_iter = view_iter
self.list_store = list_store
-class DigitalClockDawing (Gtk.DrawingArea):
+ def get_standalone_widget (self):
+ return self.standalone
+
+
+class DigitalClockStandalone (Gtk.HBox):
+ def __init__ (self):
+ Gtk.HBox.__init__ (self, True)
+ self.img = Gtk.Image ()
+ self.label = Gtk.Label ()
+ self.pack_start (self.img, True, True, 0)
+ self.pack_start (self.label, True, True, 0)
+
+ def update (self, img, text):
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size (img, 256, 256)
+ self.img.set_from_pixbuf (pixbuf)
+ self.label.set_markup ("<span size='xx-large'><b>%s</b></span>" %(text,))
+
+
+class DigitalClockDrawing (Gtk.DrawingArea):
width = 160
height = 160
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]