[gnome-clocks] Restructure folders
- From: Seif Lotfy <seiflotfy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Restructure folders
- Date: Sat, 4 Aug 2012 15:39:08 +0000 (UTC)
commit eb24c724202d2c3e6f7d1f7f87f24aaa2e0f60c2
Author: Seif Lotfy <seif lotfy com>
Date: Sat Aug 4 17:35:31 2012 +0200
Restructure folders
.gitignore | 2 +
data/gtk-style.css | 60 ++++++
src/Makefile.am | 26 +++
src/about.py | 27 +++
alarm.py => src/alarm.py | 31 +++-
alarms_handler.py => src/alarms_handler.py | 0
clocks.py => src/clocks.py | 46 ++++--
main.py => src/gnome_clocks.py | 14 +-
main.py => src/gnome_clocks.py~ | 13 +-
main.py => src/main.py | 12 +-
storage.py => src/storage.py | 0
timer.py => src/timer.py | 0
widgets.py => src/widgets.py | 285 +++++++++++++++++++---------
13 files changed, 391 insertions(+), 125 deletions(-)
---
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3cbf1a8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+src/Makefile
+src/Makefile.in
diff --git a/data/gtk-style.css b/data/gtk-style.css
new file mode 100644
index 0000000..3706a51
--- /dev/null
+++ b/data/gtk-style.css
@@ -0,0 +1,60 @@
+ define-color clocks_continue_color #5f8dd3;
+ define-color clocks_start_color #006B09;
+ define-color clocks_lap_color #999999;
+ define-color clocks_stop_color #ff0000;
+
+.grey-bg {
+ background-color: #f1f2f1
+}
+
+.clocks-continue {
+ background-image: -gtk-gradient (linear,
+ left top, left bottom,
+ from (@clocks_continue_color),
+ to (darker (@clocks_continue_color)));
+ color: #ffffff;
+ border-image: none;
+ border-width: 0;
+}
+
+
+.clocks-continue:active {
+ background-image: -gtk-gradient (linear,
+ left bottom, left top,
+ from (@clocks_continue_color),
+ to (darker (@clocks_continue_color)));
+ color: #ffffff;
+ border-image: none;
+ border-width: 0;
+}
+
+.clocks-start {
+ background-image: -gtk-gradient (linear,
+ left top, left bottom,
+ from (@clocks_start_color),
+ to (darker (@clocks_start_color)));
+ color: #ffffff;
+ border-image: none;
+ border-width: 0;
+}
+
+.clocks-lap {
+ background-image: -gtk-gradient (linear,
+ left top, left bottom,
+ from (@clocks_lap_color),
+ to (darker (@clocks_lap_color)));
+ color: #ffffff;
+ border-image: none;
+ border-width: 0;
+}
+
+.clocks-stop {
+ background-image: -gtk-gradient (linear,
+ left top, left bottom,
+ from (@clocks_stop_color),
+ to (darker (@clocks_stop_color)));
+ color: #ffffff;
+ border-image: none;
+ border-width: 0;
+}
+
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..6555821
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,26 @@
+## Process this file with automake to produce Makefile.in
+## Created by Anjuta
+
+## The main script
+bin_SCRIPTS = gnome_clocks.py
+
+## Directory where .class files will be installed
+gnome_clocksdir = $(pythondir)/gnome_clocks
+
+
+gnome_clocks_PYTHON = \
+ gnome_clocks.py \
+ about.py \
+ clocks.py \
+ about.py \
+ alarm.py \
+ alarms_handler.py \
+ clocks.py \
+ storage.py \
+ timer.py \
+ widgets.py
+
+# Remove ui directory on uninstall
+uninstall-local:
+
+ -rm -r $(pkgdatadir)
diff --git a/src/about.py b/src/about.py
new file mode 100644
index 0000000..db1ba2b
--- /dev/null
+++ b/src/about.py
@@ -0,0 +1,27 @@
+from gi.repository import Gtk
+from gi.repository.GdkPixbuf import Pixbuf
+
+icons = ["gtk-cut", "gtk-paste", "gtk-copy"]
+
+class IconViewWindow(Gtk.Window):
+
+ def __init__(self):
+ Gtk.Window.__init__(self)
+ self.set_default_size(200, 200)
+
+ liststore = Gtk.ListStore(Pixbuf, str)
+ iconview = Gtk.IconView.new()
+ iconview.set_model(liststore)
+ iconview.set_pixbuf_column(0)
+ iconview.set_text_column(1)
+
+ for icon in icons:
+ pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0)
+ liststore.append([pixbuf, ""])
+
+ self.add(iconview)
+
+win = IconViewWindow()
+win.connect("delete-event", Gtk.main_quit)
+win.show_all()
+Gtk.main()
diff --git a/alarm.py b/src/alarm.py
similarity index 54%
rename from alarm.py
rename to src/alarm.py
index a55000a..c6d3985 100644
--- a/alarm.py
+++ b/src/alarm.py
@@ -1,12 +1,13 @@
import datetime, vobject, time
class AlarmItem:
- def __init__(self, name, time, repeat, h, m):
+ def __init__(self, name, time, repeat, h, m, p):
self.name = name
self.time = time
self.repeat = repeat
self.h = h
self.m = m
+ self.p = p
def set_alarm_time(self, time):
self.time = time
@@ -28,11 +29,25 @@ class AlarmItem:
def get_vobject(self):
alarm = vobject.newFromBehavior('vevent')
- alarm.add('summary').value = self.name
- #t = datetime.datetime.utcfromtimestamp(self.time)
- alarm.add('dtstart').value = datetime.datetime.combine(datetime.date.today(), datetime.time(self.h, self.m))
- alarm.add('dtend').value = datetime.datetime.combine(datetime.date.today(), datetime.time(self.h+1, self.m))
- alarm.add('rrule').value = 'FREQ=WEEKLY;BYDAY=%s' % ','.join(self.repeat)
- alarm.add('action').value = 'audio'
- alarm.add('attach').value = '/usr/share/sounds/gnome/default/alerts/glass.ogg'
+ alarm.add('summary').value = self.name
+ if self.p == 'AM':
+ print self.h
+ if self.h == 12:
+ self.h = 0
+ h_end = self.h+1
+ m_end = self.m
+ elif self.p == 'PM':
+ self.h += 12
+ h_end = self.h+1
+ m_end = self.m
+ if self.h == 24:
+ self.h = 23
+ h_end = 23
+ m_end = 59
+ else:
+ h_end = self.h
+ m_end = 59
+ alarm.add('dtstart').value = datetime.datetime.combine(datetime.date.today(), datetime.time(self.h, self.m))
+ alarm.add('dtend').value = datetime.datetime.combine(datetime.date.today(), datetime.time(h_end, m_end))
+ alarm.add('rrule').value = 'FREQ=WEEKLY;BYDAY=%s' % ','.join(self.repeat)
return alarm
diff --git a/alarms_handler.py b/src/alarms_handler.py
similarity index 100%
rename from alarms_handler.py
rename to src/alarms_handler.py
diff --git a/clocks.py b/src/clocks.py
similarity index 91%
rename from clocks.py
rename to src/clocks.py
index 27535d1..2d469aa 100644
--- a/clocks.py
+++ b/src/clocks.py
@@ -21,7 +21,7 @@
from gi.repository import Gtk, GObject, Gio, Gdk, Gst, Notify, cairo
from gi.repository.GdkPixbuf import Pixbuf
-from widgets import NewWorldClockDialog, DigitalClock, NewAlarmDialog, AlarmWidget
+from widgets import NewWorldClockDialog, DigitalClock, NewAlarmDialog, AlarmWidget, WorldEmpty
from alarms_handler import AlarmsHandler
from storage import worldclockstorage
@@ -91,6 +91,8 @@ class World (Clock):
self.liststore = liststore = Gtk.ListStore(Pixbuf, str, GObject.TYPE_PYOBJECT)
self.iconview = iconview = Gtk.IconView.new()
+ self.empty_view = WorldEmpty ()
+
iconview.set_model(liststore)
iconview.set_spacing(3)
iconview.set_pixbuf_column(0)
@@ -101,9 +103,9 @@ class World (Clock):
iconview.pack_start(renderer_text, True)
iconview.add_attribute(renderer_text, "markup", 1)
- scrolledwindow = Gtk.ScrolledWindow()
+ self.scrolledwindow = scrolledwindow = Gtk.ScrolledWindow()
scrolledwindow.add(iconview)
- self.add(scrolledwindow)
+ #self.add(scrolledwindow)
iconview.connect ("selection-changed", self._on_selection_changed)
@@ -126,11 +128,15 @@ class World (Clock):
def load_clocks(self):
self.clocks = worldclockstorage.load_clocks ()
- for clock in self.clocks:
- d = DigitalClock (clock)
- 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()
+ print self.clocks
+ if len(self.clocks) == 0:
+ self.load_empty_clocks_view ()
+ else:
+ for clock in self.clocks:
+ d = DigitalClock (clock)
+ view_iter = self.liststore.append([d.drawing.pixbuf, "<b>"+d.location.get_city_name()+"</b>", d])
+ d.set_iter(self.liststore, view_iter)
+ self.load_clocks_view ()
def add_clock(self, location):
location_id = location.id + "---" + location.location.get_code ()
@@ -141,16 +147,19 @@ class World (Clock):
d.set_iter(self.liststore, view_iter)
self.show_all()
worldclockstorage.save_clocks (self.clocks)
+ if len(self.clocks) > 0:
+ self.load_clocks_view ()
def delete_clock (self, d):
self.clocks.remove (d.location)
self.liststore.remove (d.view_iter)
self.iconview.unselect_all ()
+ if len(self.clocks) == 0:
+ self.load_empty_clocks_view ()
def open_new_dialog(self):
parent = self.get_parent().get_parent().get_parent()
window = NewWorldClockDialog(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()
@@ -160,6 +169,17 @@ class World (Clock):
self.addButton.set_sensitive(False)
self.emit('show-requested')
+ def load_clocks_view (self):
+ if self.empty_view in self.get_children ():
+ self.remove (self.empty_view)
+ self.add (self.scrolledwindow)
+ self.show_all ()
+
+ def load_empty_clocks_view (self):
+ if self.scrolledwindow in self.get_children ():
+ self.remove (self.scrolledwindow)
+ self.add (self.empty_view)
+ self.show_all ()
class Alarm (Clock):
def __init__ (self):
@@ -191,8 +211,8 @@ class Alarm (Clock):
alarms = ah.load_alarms()
for alarm in alarms:
name = alarm.summary.value
- trigger = alarm.dtstart.value
- d = AlarmWidget(trigger)
+ time = alarm.dtstart.value
+ d = AlarmWidget(time)
view_iter = self.liststore.append([d.drawing.pixbuf, "<b>" + name + "</b>", d])
d.set_iter(self.liststore, view_iter)
self.show_all()
@@ -200,7 +220,7 @@ class Alarm (Clock):
def add_alarm(self, alarm):
ah = AlarmsHandler()
ah.add_alarm(alarm.get_vobject())
- d = AlarmWidget(datetime.utcfromtimestamp(alarm.time))
+ d = AlarmWidget(datetime.utcfromtimestamp(alarm.time))
view_iter = self.liststore.append([d.drawing.pixbuf, "<b>" + alarm.get_alarm_name() + "</b>", d])
d.set_iter(self.liststore, view_iter)
self.show_all()
@@ -267,7 +287,7 @@ class Stopwatch (Clock):
vbox.pack_start (Gtk.Box (), True, True, 48)
vbox.pack_start (center, False, False, 0)
- vbox.pack_start (Gtk.Box (), True, True, 0)
+ vbox.pack_start (Gtk.Box (), True, True, 1)
vbox.pack_start (Gtk.Box (), True, True, 41)
self.leftButton.connect("clicked", self._on_left_button_clicked)
diff --git a/main.py b/src/gnome_clocks.py
old mode 100644
new mode 100755
similarity index 96%
copy from main.py
copy to src/gnome_clocks.py
index 9fe168d..68a0213
--- a/main.py
+++ b/src/gnome_clocks.py
@@ -1,3 +1,5 @@
+#! /usr/bin/env python
+# -.- coding: utf-8 -.-
"""
Copyright (c) 2011-2012 Collabora, Ltd.
@@ -157,14 +159,15 @@ class ClocksToolbar (Gtk.Toolbar):
self.newButton.add(label)
self.leftBox = box = Gtk.Box ()
- box.pack_start (self.newButton, False, False, 3)
+ box.pack_start (self.newButton, False, False, 0)
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.LARGE_TOOLBAR)
+ image.set_from_gicon (icon, Gtk.IconSize.MENU)
self.backButton.add(image)
+ self.backButton.set_size_request (33, 33)
self.backButton.connect ("clicked", lambda w: self.emit ("view-clock", self._buttonMap[self.last_widget]))
self.newButton.connect("clicked", self._on_new_clicked)
@@ -186,11 +189,12 @@ class ClocksToolbar (Gtk.Toolbar):
#self.applyButton.get_style_context ().add_class ('raised');
icon = Gio.ThemedIcon.new_with_default_fallbacks ("object-select-symbolic")
image = Gtk.Image ()
- image.set_from_gicon (icon, Gtk.IconSize.SMALL_TOOLBAR)
+ image.set_from_gicon (icon, Gtk.IconSize.MENU)
self.applyButton.add (image)
+ self.applyButton.set_size_request (32, 32)
self.applyButton.connect('clicked', self._on_selection_mode)
self.rightBox = box = Gtk.Box ()
- box.pack_end (self.applyButton, False, False, 3)
+ box.pack_end (self.applyButton, False, False, 0)
toolbox.pack_start (box, True, True, 0)
self._buttonMap = {}
@@ -228,7 +232,7 @@ class ClocksToolbar (Gtk.Toolbar):
self.newButton.hide ()
self.applyButton.hide ()
if not self.backButton.get_parent ():
- self.leftBox.pack_start (self.backButton, False, False, 3)
+ self.leftBox.pack_start (self.backButton, False, False, 0)
self.backButton.show_all ()
self.city_label.show ()
diff --git a/main.py b/src/gnome_clocks.py~
similarity index 97%
copy from main.py
copy to src/gnome_clocks.py~
index 9fe168d..9cac58f 100644
--- a/main.py
+++ b/src/gnome_clocks.py~
@@ -1,3 +1,4 @@
+#!python
"""
Copyright (c) 2011-2012 Collabora, Ltd.
@@ -157,14 +158,15 @@ class ClocksToolbar (Gtk.Toolbar):
self.newButton.add(label)
self.leftBox = box = Gtk.Box ()
- box.pack_start (self.newButton, False, False, 3)
+ box.pack_start (self.newButton, False, False, 0)
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.LARGE_TOOLBAR)
+ image.set_from_gicon (icon, Gtk.IconSize.MENU)
self.backButton.add(image)
+ self.backButton.set_size_request (33, 33)
self.backButton.connect ("clicked", lambda w: self.emit ("view-clock", self._buttonMap[self.last_widget]))
self.newButton.connect("clicked", self._on_new_clicked)
@@ -186,11 +188,12 @@ class ClocksToolbar (Gtk.Toolbar):
#self.applyButton.get_style_context ().add_class ('raised');
icon = Gio.ThemedIcon.new_with_default_fallbacks ("object-select-symbolic")
image = Gtk.Image ()
- image.set_from_gicon (icon, Gtk.IconSize.SMALL_TOOLBAR)
+ image.set_from_gicon (icon, Gtk.IconSize.MENU)
self.applyButton.add (image)
+ self.applyButton.set_size_request (32, 32)
self.applyButton.connect('clicked', self._on_selection_mode)
self.rightBox = box = Gtk.Box ()
- box.pack_end (self.applyButton, False, False, 3)
+ box.pack_end (self.applyButton, False, False, 0)
toolbox.pack_start (box, True, True, 0)
self._buttonMap = {}
@@ -228,7 +231,7 @@ class ClocksToolbar (Gtk.Toolbar):
self.newButton.hide ()
self.applyButton.hide ()
if not self.backButton.get_parent ():
- self.leftBox.pack_start (self.backButton, False, False, 3)
+ self.leftBox.pack_start (self.backButton, False, False, 0)
self.backButton.show_all ()
self.city_label.show ()
diff --git a/main.py b/src/main.py
similarity index 97%
rename from main.py
rename to src/main.py
index 9fe168d..7f9599c 100644
--- a/main.py
+++ b/src/main.py
@@ -157,14 +157,15 @@ class ClocksToolbar (Gtk.Toolbar):
self.newButton.add(label)
self.leftBox = box = Gtk.Box ()
- box.pack_start (self.newButton, False, False, 3)
+ box.pack_start (self.newButton, False, False, 0)
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.LARGE_TOOLBAR)
+ image.set_from_gicon (icon, Gtk.IconSize.MENU)
self.backButton.add(image)
+ self.backButton.set_size_request (33, 33)
self.backButton.connect ("clicked", lambda w: self.emit ("view-clock", self._buttonMap[self.last_widget]))
self.newButton.connect("clicked", self._on_new_clicked)
@@ -186,11 +187,12 @@ class ClocksToolbar (Gtk.Toolbar):
#self.applyButton.get_style_context ().add_class ('raised');
icon = Gio.ThemedIcon.new_with_default_fallbacks ("object-select-symbolic")
image = Gtk.Image ()
- image.set_from_gicon (icon, Gtk.IconSize.SMALL_TOOLBAR)
+ image.set_from_gicon (icon, Gtk.IconSize.MENU)
self.applyButton.add (image)
+ self.applyButton.set_size_request (32, 32)
self.applyButton.connect('clicked', self._on_selection_mode)
self.rightBox = box = Gtk.Box ()
- box.pack_end (self.applyButton, False, False, 3)
+ box.pack_end (self.applyButton, False, False, 0)
toolbox.pack_start (box, True, True, 0)
self._buttonMap = {}
@@ -228,7 +230,7 @@ class ClocksToolbar (Gtk.Toolbar):
self.newButton.hide ()
self.applyButton.hide ()
if not self.backButton.get_parent ():
- self.leftBox.pack_start (self.backButton, False, False, 3)
+ self.leftBox.pack_start (self.backButton, False, False, 0)
self.backButton.show_all ()
self.city_label.show ()
diff --git a/storage.py b/src/storage.py
similarity index 100%
rename from storage.py
rename to src/storage.py
diff --git a/timer.py b/src/timer.py
similarity index 100%
rename from timer.py
rename to src/timer.py
diff --git a/widgets.py b/src/widgets.py
similarity index 64%
rename from widgets.py
rename to src/widgets.py
index 1bd6aad..6614bbd 100644
--- a/widgets.py
+++ b/src/widgets.py
@@ -35,7 +35,7 @@ class NewWorldClockDialog (Gtk.Dialog):
self.set_transient_for(parent)
self.set_modal(True)
self.set_border_width (9)
- self.set_size_request(-1,-1)
+ self.set_size_request(400,-1)
box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
box.set_spacing(9)
area = self.get_content_area()
@@ -47,10 +47,14 @@ class NewWorldClockDialog (Gtk.Dialog):
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...")
+ self.find_gicon = Gio.ThemedIcon.new_with_default_fallbacks('edit-find-symbolic')
+ self.clear_gicon = Gio.ThemedIcon.new_with_default_fallbacks('edit-clear-symbolic')
+ self.searchEntry.set_icon_from_gicon(Gtk.EntryIconPosition.SECONDARY, self.find_gicon)
+ #self.searchEntry.set_can_focus(False)
+ 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>")
+ header.set_markup("<span size='x-large'><b>Add a New World Clock</b></span>")
btnBox = Gtk.Box()
@@ -65,6 +69,7 @@ class NewWorldClockDialog (Gtk.Dialog):
self.searchEntry.connect("activate", self._set_city)
self.searchEntry.connect("changed", self._set_city)
+ self.searchEntry.connect("icon-release", self._icon_released)
self.connect("response", self._on_response_clicked)
self.location = None
self.show_all ()
@@ -79,16 +84,27 @@ class NewWorldClockDialog (Gtk.Dialog):
def _set_city (self, widget):
location = self.searchEntry.get_location()
widget = self.get_widget_for_response (1)
+ if self.searchEntry.get_text () == '':
+ self.searchEntry.set_icon_from_gicon(Gtk.EntryIconPosition.SECONDARY, self.find_gicon)
+ else:
+ self.searchEntry.set_icon_from_gicon(Gtk.EntryIconPosition.SECONDARY, self.clear_gicon)
if location:
widget.set_sensitive(True)
else:
- widget.set_sensitive(False)
+ widget.set_sensitive(False)
def get_selection (self):
return self.location
+
+ def _icon_released(self, icon_pos, event, data):
+ if self.searchEntry.get_icon_gicon(Gtk.EntryIconPosition.SECONDARY) == self.clear_gicon:
+ self.searchEntry.set_text('')
+ self.searchEntry.set_icon_from_gicon(Gtk.EntryIconPosition.SECONDARY, self.find_gicon)
+ widget = self.get_widget_for_response (1)
+ widget.set_sensitive(False)
class DigitalClock ():
- def __init__(self, location):
+ def __init__(self, location):
self.location = location.location
self.id = location.id
self.timezone = self.location.get_timezone()
@@ -100,7 +116,7 @@ class DigitalClock ():
self.list_store = None
self.drawing = DigitalClockDrawing ()
- self.standalone = DigitalClockStandalone (self.location)
+ self.standalone = DigitalClockStandalone (self.location)
self.update ()
GObject.timeout_add(1000, self.update)
@@ -116,9 +132,9 @@ class DigitalClock ():
return text
def get_system_clock_format(self):
- settings = Gio.Settings.new('org.gnome.desktop.interface')
- systemClockFormat = settings.get_string('clock-format')
- return systemClockFormat
+ settings = Gio.Settings.new('org.gnome.desktop.interface')
+ systemClockFormat = settings.get_string('clock-format')
+ return systemClockFormat
def get_image(self):
local_time = self.get_local_time ()
@@ -135,44 +151,53 @@ class DigitalClock ():
return False
def update(self):
- t = self.get_local_time_text ()
- systemClockFormat = self.get_system_clock_format ()
- if systemClockFormat == '12h':
- t = time.strftime("%I:%M %p", self.get_local_time ())
- else:
- t = time.strftime("%H:%M", self.get_local_time ()) #Convert to 24h
- if not t == self._last_time:
- img = self.get_image ()
- 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, systemClockFormat)
- self._last_time = t
- return True
+ t = self.get_local_time_text ()
+ systemClockFormat = self.get_system_clock_format ()
+ if systemClockFormat == '12h':
+ t = time.strftime("%I:%M %p", self.get_local_time ())
+ else:
+ t = time.strftime("%H:%M", self.get_local_time ()) #Convert to 24h
+ if not t == self._last_time:
+ img = self.get_image ()
+ 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, systemClockFormat)
+ self._last_time = t
+ return True
def set_iter (self, list_store, view_iter):
self.view_iter = view_iter
self.list_store = list_store
-
+
def get_standalone_widget (self):
return self.standalone
class AlarmWidget():
- def __init__(self, time_given):
- t = time_given.strftime("%I:%M %p")
- self.drawing = DigitalClockDrawing ()
+ def __init__(self, t_given):
+ self.drawing = DigitalClockDrawing ()
+ clockformat = self.get_system_clock_format()
+ if clockformat == '12h':
+ t = t_given.strftime("%I:%M %p")
+ else:
+ t = t_given.strftime("%H:%M")
isDay = self.get_is_day(t)
if isDay == True:
img = "data/cities/day.png"
else:
img = "data/cities/night.png"
self.drawing.render(t, img, isDay)
+
+ def get_system_clock_format(self):
+ settings = Gio.Settings.new('org.gnome.desktop.interface')
+ systemClockFormat = settings.get_string('clock-format')
+ return systemClockFormat
def get_is_day(self, t):
if t[6:8] == 'AM':
- return True
+ return True
else:
- return False
+ return False
def set_iter (self, list_store, view_iter):
self.view_iter = view_iter
@@ -191,10 +216,10 @@ class DigitalClockStandalone (Gtk.VBox):
self.connect ("size-allocate", lambda x, y: self.update (None, self.text, self.systemClockFormat))
- imagebox = Gtk.VBox ()
- imagebox.pack_start (self.img, False, False, 0)
+ #imagebox = Gtk.VBox ()
+ #imagebox.pack_start (self.img, False, False, 0)
#imagebox.pack_start (self.city_label, False, False, 0)
- imagebox.set_size_request (230, 230)
+ #imagebox.set_size_request (230, 230)
self.timebox = timebox = Gtk.VBox ()
self.time_label.set_alignment (0.0, 0.5)
@@ -204,8 +229,8 @@ class DigitalClockStandalone (Gtk.VBox):
self.hbox.set_homogeneous (False)
self.hbox.pack_start (Gtk.Label(), True, True, 0)
- self.hbox.pack_start (imagebox, False, False, 0)
- self.hbox.pack_start (Gtk.Label (), False, False, 30)
+ # self.hbox.pack_start (imagebox, False, False, 0)
+ # self.hbox.pack_start (Gtk.Label (), False, False, 30)
self.hbox.pack_start (timebox, False, False, 0)
self.hbox.pack_start (Gtk.Label(), True, True, 0)
@@ -334,37 +359,69 @@ class NewAlarmDialog (Gtk.Dialog):
self.set_modal(True)
self.repeat_days = []
- table1 = Gtk.Table(4, 5, False)
+ self.cf = cf = self.get_system_clock_format()
+ if cf == "12h":
+ table1 = Gtk.Table(4, 6, False)
+ else:
+ table1 = Gtk.Table(4, 5, False)
table1.set_row_spacings(9)
table1.set_col_spacings(9)
content_area = self.get_content_area ()
content_area.pack_start(table1, True, True, 0)
- self.add_buttons("Cancel", 0, "Save", 1)
+ cancel = self.add_button("Cancel", 0)
+ self.save = save = self.add_button("Save", 1)
+ save.get_style_context().add_class('raised')
+ save.set_sensitive(False)
self.connect("response", self.on_response)
table1.set_border_width (5)
- hour = Gtk.Label ("Hour")
- hour.set_alignment(1.0, 0.5)
- minute = Gtk.Label ("Minutes")
- minute.set_alignment(1.0, 0.5)
-
- houradjust = Gtk.Adjustment(0, 0, 24, 1, 1, 0)
+ t = time.localtime()
+ h = t.tm_hour
+ m = t.tm_min
+ p = time.strftime("%p", t)
+ time_label = Gtk.Label ("Time")
+ time_label.set_alignment(1.0, 0.5)
+ points = Gtk.Label (":")
+ points.set_alignment(0.5, 0.5)
+
+ if cf == "12h":
+ houradjust = Gtk.Adjustment(h, 0, 12, 1, 1, 0)
+ else:
+ houradjust = Gtk.Adjustment(h, 0, 23, 1, 1, 0)
self.hourselect = hourselect = Gtk.SpinButton()
+ hourselect.connect('value-changed', self._on_hours_changed)
hourselect.set_adjustment(houradjust)
hourbox = Gtk.Box(True, 0)
- hourbox.pack_start (hourselect, True, True, 0)
+ hourbox.pack_start (hourselect, False, True, 0)
- minuteadjust = Gtk.Adjustment(0, 0, 60, 1, 1, 0)
+ minuteadjust = Gtk.Adjustment(m, 0, 59, 1, 1, 0)
self.minuteselect = minuteselect = Gtk.SpinButton()
+ minuteselect.connect('value-changed', self._on_minutes_changed)
minuteselect.set_adjustment(minuteadjust)
minutebox = Gtk.Box(True, 0)
- minutebox.pack_start (minuteselect, True, True, 0)
-
- table1.attach (hour, 0, 1, 0, 1)
- table1.attach (hourbox, 1, 2, 0, 1)
- table1.attach (minute, 2, 3, 0, 1)
- table1.attach (minutebox, 3, 4, 0, 1)
+ minutebox.pack_start (minuteselect, False, True, 0)
+
+ if cf == "12h":
+ self.ampm = ampm = Gtk.ComboBoxText()
+ ampm.append_text("AM")
+ ampm.append_text("PM")
+ if p == 'AM':
+ ampm.set_active(0)
+ else:
+ ampm.set_active(1)
+
+ table1.attach (time_label, 0, 1, 0, 1)
+ table1.attach (hourbox, 1, 2, 0, 1)
+ table1.attach (points, 2, 3, 0, 1)
+ table1.attach (minutebox, 3, 4, 0, 1)
+ table1.attach (ampm, 4, 5, 0, 1)
+ else:
+ table1.attach (time_label, 0, 1, 0, 1)
+ table1.attach (hourbox, 1, 2, 0, 1)
+ table1.attach (points, 2, 3, 0, 1)
+ table1.attach (minutebox, 3, 4, 0, 1)
+
name = Gtk.Label ("Name")
name.set_alignment(1.0, 0.5)
repeat = Gtk.Label ("Repeat Every")
@@ -379,21 +436,24 @@ class NewAlarmDialog (Gtk.Dialog):
self.entry = entry = Gtk.Entry ()
entry.set_text("New Alarm")
entry.set_editable (True)
- table1.attach(entry, 1, 4, 1, 2)
+ if cf == "12h":
+ table1.attach(entry, 1, 5, 1, 2)
+ else:
+ table1.attach(entry, 1, 4, 1, 2)
- buttond1 = Gtk.ToggleButton(label="Sun")
+ buttond1 = Gtk.ToggleButton(label="Mon")
buttond1.connect("clicked", self.on_d1_clicked)
- buttond2 = Gtk.ToggleButton(label="Mon")
+ buttond2 = Gtk.ToggleButton(label="Tue")
buttond2.connect("clicked", self.on_d2_clicked)
- buttond3 = Gtk.ToggleButton(label="Tue")
+ buttond3 = Gtk.ToggleButton(label="Wed")
buttond3.connect("clicked", self.on_d3_clicked)
- buttond4 = Gtk.ToggleButton(label="Wed")
+ buttond4 = Gtk.ToggleButton(label="Thu")
buttond4.connect("clicked", self.on_d4_clicked)
- buttond5 = Gtk.ToggleButton(label="Thu")
+ buttond5 = Gtk.ToggleButton(label="Fri")
buttond5.connect("clicked", self.on_d5_clicked)
- buttond6 = Gtk.ToggleButton(label="Fri")
+ buttond6 = Gtk.ToggleButton(label="Sat")
buttond6.connect("clicked", self.on_d6_clicked)
- buttond7 = Gtk.ToggleButton(label="Sat")
+ buttond7 = Gtk.ToggleButton(label="Sun")
buttond7.connect("clicked", self.on_d7_clicked)
# create a box and put them all in it
@@ -406,10 +466,18 @@ class NewAlarmDialog (Gtk.Dialog):
box.pack_start (buttond5, True, True, 0)
box.pack_start (buttond6, True, True, 0)
box.pack_start (buttond7, True, True, 0)
- table1.attach(box, 1, 4, 2, 3)
+ if cf == "12h":
+ table1.attach(box, 1, 5, 2, 3)
+ else:
+ table1.attach(box, 1, 4, 2, 3)
soundbox = Gtk.ComboBox ()
#table1.attach(soundbox, 1, 3, 3, 4)
+
+ def get_system_clock_format(self):
+ settings = Gio.Settings.new('org.gnome.desktop.interface')
+ systemClockFormat = settings.get_string('clock-format')
+ return systemClockFormat
def on_response(self, widget, id):
if id == 0:
@@ -418,62 +486,101 @@ class NewAlarmDialog (Gtk.Dialog):
name = self.entry.get_text() #Perfect
time = self.hourselect.get_value_as_int() * 60 * 60 + self.minuteselect.get_value_as_int() * 60
repeat = self.repeat_days
- new_alarm = AlarmItem(name, time, repeat, self.hourselect.get_value_as_int(), self.minuteselect.get_value_as_int())
+ if self.cf == "12h":
+ r = self.ampm.get_active()
+ if r == 0:
+ p = 'AM'
+ else:
+ p = 'PM'
+ new_alarm = AlarmItem(name, time, repeat, self.hourselect.get_value_as_int(), self.minuteselect.get_value_as_int(), p)
+ else:
+ new_alarm = AlarmItem(name, time, repeat, self.hourselect.get_value_as_int(), self.minuteselect.get_value_as_int(), None)
self.emit('add-alarm', new_alarm)
self.destroy ()
else:
pass
-
- def on_d1_clicked(self, btn):
- if btn.get_active() == True:
- self.repeat_days.append('SU')
- if btn.get_active() == False:
- self.repeat_days.remove('SU')
-
- def on_d2_clicked(self, btn):
+
+ def _on_hours_changed(self, btn):
+ self.check_save_button_status()
+
+ def _on_minutes_changed(self, btn):
+ self.check_save_button_status()
+
+ def check_save_button_status(self):
+ if len(self.repeat_days) != 0:
+ self.save.set_sensitive(True)
+ else:
+ self.save.set_sensitive(False)
+
+ def on_d1_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('MO')
if btn.get_active() == False:
self.repeat_days.remove('MO')
-
- def on_d3_clicked(self, btn):
+ self.check_save_button_status()
+
+ def on_d2_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('TU')
- if btn.get_active() == False:
+ else:
self.repeat_days.remove('TU')
+ self.check_save_button_status()
- def on_d4_clicked(self, btn):
+ def on_d3_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('WE')
- if btn.get_active() == False:
+ else:
self.repeat_days.remove('WE')
+ self.check_save_button_status()
- def on_d5_clicked(self, btn):
+ def on_d4_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('TH')
- if btn.get_active() == False:
+ else:
self.repeat_days.remove('TH')
+ self.check_save_button_status()
- def on_d6_clicked(self, btn):
+ def on_d5_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('FR')
- if btn.get_active() == False:
+ else:
self.repeat_days.remove('FR')
+ self.check_save_button_status()
- def on_d7_clicked(self, btn):
+ def on_d6_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('SA')
- if btn.get_active() == False:
+ else:
self.repeat_days.remove('SA')
+ self.check_save_button_status()
+
+ def on_d7_clicked(self, btn):
+ if btn.get_active() == True:
+ self.repeat_days.append('SU')
+ else:
+ self.repeat_days.remove('SU')
+ self.check_save_button_status()
-"""
-if text.startswith("0"):
- text = text[1:]
-
+class ClocksHome(Gtk.Box):
+ def __init__(self):
+ Gt.Box.__init__(self)
+ self.set_orientation(Gtk.Orientation.VERTICAL)
+
+class WorldEmpty(Gtk.Box):
+ def __init__(self):
+ Gtk.Box.__init__(self)
+ self.set_orientation(Gtk.Orientation.VERTICAL)
+ gicon = Gio.ThemedIcon.new_with_default_fallbacks("document-open-recent-symbolic")
+ image = Gtk.Image.new_from_gicon(gicon, Gtk.IconSize.DIALOG)
+ image.set_sensitive (False)
+ text = Gtk.Label("")
+ text.set_markup("<span color='darkgrey'>Select <b>New</b> to add a world clock</span>")
+ self.pack_start(Gtk.Label(""), True, True, 0)
+ self.pack_start(image, False, False, 6)
+ self.pack_start(text, False, False, 6)
+ self.pack_start(Gtk.Label(""), True, True, 0)
+ self.button = Gtk.ToggleButton()
+ self.show_all()
-def get_image(self, local_time):
- if local_time.tm_hour > 7 and local_time.tm_hour < 19:
- return "data/cities/day.png"
- else:
- return "data/cities/night.png"
-"""
+ def unselect_all(self):
+ pass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]