[gnome-clocks] Added subtexts for clocks and alarms
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Added subtexts for clocks and alarms
- Date: Fri, 17 Aug 2012 19:06:51 +0000 (UTC)
commit 951ab0f4decca20c584f4f81db7995f93cce31c0
Author: Alex Anthony <alex anthony28991 gmail com>
Date: Fri Aug 17 16:13:53 2012 +0100
Added subtexts for clocks and alarms
Used for yesterday/today on clocks and repeat information on alarms.
https://bugzilla.gnome.org/show_bug.cgi?id=681949
gnomeclocks/alarm.py | 34 +++++++++++++++++
gnomeclocks/clocks.py | 16 ++++++---
gnomeclocks/widgets.py | 95 ++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 124 insertions(+), 21 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index a4690ef..6dfba35 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -76,12 +76,17 @@ class AlarmItem:
self.p = p
def new_from_vevent(self, vevent):
+ self.vevent = vevent
self.name = vevent.summary.value
self.time = vevent.dtstart.value
self.h = int(self.time.strftime("%H"))
self.m = int(self.time.strftime("%M"))
self.p = self.time.strftime("%p")
self.uid = vevent.uid.value
+ if vevent.rrule.value == 'FREQ=DAILY;':
+ self.repeat = ['FR', 'MO', 'SA', 'SU', 'TH', 'TU', 'WE']
+ else:
+ self.repeat = vevent.rrule.value[19:].split(',')
def set_alarm_time(self, h, m, p):
self.h = h
@@ -126,6 +131,35 @@ class AlarmItem:
def get_alarm_repeat(self):
return self.repeat
+ def get_alarm_repeat_string(self):
+ # lists only compare the same if corresponing elements are the same
+ # we form self.repeat by random appending
+ # sorted(list of days)
+ sorted_repeat = sorted(self.repeat)
+ if sorted_repeat == ['FR', 'MO', 'SA', 'SU', 'TH', 'TU', 'WE']:
+ return "Every day"
+ elif sorted_repeat == ['FR', 'MO', 'TH', 'TU', 'WE']:
+ return "Weekdays"
+ elif len(sorted_repeat) == 0:
+ return None
+ else:
+ repeat_string = ""
+ if 'MO' in self.repeat:
+ repeat_string += 'Mon, '
+ if 'TU' in self.repeat:
+ repeat_string += 'Tue, '
+ if 'WE' in self.repeat:
+ repeat_string += 'Wed, '
+ if 'TH' in self.repeat:
+ repeat_string += 'Thu, '
+ if 'FR' in self.repeat:
+ repeat_string += 'Fri, '
+ if 'SA' in self.repeat:
+ repeat_string += 'Sat, '
+ if 'SU' in self.repeat:
+ repeat_string += 'Sun, '
+ return repeat_string[:-2]
+
def get_uid(self):
return self.vevent.uid.value
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index 5f2a593..5d81f3f 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -221,11 +221,15 @@ class Alarm(Clock):
alarm.new_from_vevent(vevent)
scf = self.get_system_clock_format()
if scf == "12h":
- d = AlarmWidget(alarm.get_time_12h_as_string())
+ d = AlarmWidget(alarm.get_time_12h_as_string(),
+ alarm.get_alarm_repeat_string())
else:
- d = AlarmWidget(alarm.get_time_24h_as_string())
+ d = AlarmWidget(alarm.get_time_24h_as_string(),
+ alarm.get_alarm_repeat_string())
view_iter = self.liststore.append([d.drawing.pixbuf,
- "<b>" + alarm.get_alarm_name() + "</b>", d])
+ "<b>"
+ + alarm.get_alarm_name()
+ + "</b>", d])
d.set_iter(self.liststore, view_iter)
self.load_alarms_view()
else:
@@ -248,9 +252,11 @@ class Alarm(Clock):
handler.add_vevent(alarm.get_vevent())
scf = self.get_system_clock_format()
if scf == "12h":
- d = AlarmWidget(alarm.get_time_12h_as_string())
+ d = AlarmWidget(alarm.get_time_12h_as_string(),
+ alarm.get_alarm_repeat_string())
else:
- d = AlarmWidget(alarm.get_time_24h_as_string())
+ d = AlarmWidget(alarm.get_time_24h_as_string(),
+ alarm.get_alarm_repeat_string())
view_iter = self.liststore.append([d.drawing.pixbuf,
"<b>" + alarm.get_alarm_name() + "</b>", d])
d.set_iter(self.liststore, view_iter)
diff --git a/gnomeclocks/widgets.py b/gnomeclocks/widgets.py
index 517644f..d62e80d 100644
--- a/gnomeclocks/widgets.py
+++ b/gnomeclocks/widgets.py
@@ -16,7 +16,7 @@
#
# Author: Seif Lotfy <seif lotfy collabora co uk>
-from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Gio, PangoCairo
+from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Gio, Pango, PangoCairo
from gi.repository import GWeather
from storage import Location
@@ -161,7 +161,11 @@ class DigitalClock():
t = time.strftime("%H:%M", self.get_local_time())
if not t == self._last_time:
img = self.get_image()
- self.drawing.render(t, img, self.get_is_day())
+ day = self.get_day()
+ if day == "Today":
+ self.drawing.render(t, img, self.get_is_day())
+ else:
+ self.drawing.render(t, img, self.get_is_day(), day)
if self.view_iter and self.list_store:
self.list_store.set_value(
self.view_iter, 0, self.drawing.pixbuf)
@@ -176,6 +180,27 @@ class DigitalClock():
def get_standalone_widget(self):
return self.standalone
+ def get_day(self):
+ clock_time_day = self.get_local_time().tm_yday
+ local_time_day = time.localtime().tm_yday
+
+ if clock_time_day == local_time_day:
+ return "Today"
+ # if its 31st Dec here and 1st Jan there, clock_time_day = 1,
+ # local_time_day = 365/366
+ # if its 1st Jan here and 31st Dec there, clock_time_day = 365/366,
+ # local_time_day = 1
+ elif clock_time_day > local_time_day:
+ if local_time_day == 1:
+ return "Yesterday"
+ else:
+ return "Tomorrow"
+ elif clock_time_day < local_time_day:
+ if clock_time_day == 1:
+ return "Tomorrow"
+ else:
+ return "Yesterday"
+
class DigitalClockStandalone(Gtk.VBox):
def __init__(self, location):
@@ -284,7 +309,7 @@ class DigitalClockDrawing(Gtk.DrawingArea):
self.surface = None
self.show_all()
- def render(self, text, img, isDay):
+ def render(self, text, img, isDay, sub_text=None):
self.surface = cairo.ImageSurface.create_from_png(img)
ctx = cairo.Context(self.surface)
ctx.scale(1.0, 1.0)
@@ -299,25 +324,47 @@ class DigitalClockDrawing(Gtk.DrawingArea):
x = (self.width - width) / 2
y = (self.height - height) / 2
+ # has to be before the drawing of the rectangle so the rectangle
+ # takes the right size if we have subtexts
+ self.pango_layout = self.create_pango_layout(text)
+ self.pango_layout.set_markup(
+ "<span size='xx-large'><b>%s</b></span>" % text, -1)
+ if sub_text:
+ self.pango_layout_subtext = self.create_pango_layout(sub_text)
+ self.pango_layout_subtext.set_markup(
+ "<span size='medium'>%s</span>" % sub_text, -1)
+ self.pango_layout_subtext.set_width(width * Pango.SCALE)
+ subtext_is_wrapped = self.pango_layout_subtext.is_wrapped()
+ if subtext_is_wrapped:
+ self.pango_layout_subtext.set_alignment(Pango.Alignment.CENTER)
+
if not isDay:
ctx.set_source_rgba(0.0, 0.0, 0.0, 0.7)
else:
ctx.set_source_rgba(1.0, 1.0, 1.0, 0.7)
+ ctx.move_to(x, y)
ctx.arc(x + width - radius, y + radius, radius, -90 * degrees,
- 0 * degrees)
- ctx.arc(x + width - radius, y + height - radius, radius, 0 * degrees,
- 90 * degrees)
- ctx.arc(x + radius, y + height - radius, radius, 90 * degrees,
- 180 * degrees)
+ 0 * degrees)
+ if sub_text and subtext_is_wrapped:
+ ctx.arc(x + width - radius, y + height - radius + 25, radius,
+ 0 * degrees, 90 * degrees)
+ ctx.arc(x + radius, y + height - radius + 25, radius,
+ 90 * degrees, 180 * degrees)
+ elif sub_text and not subtext_is_wrapped:
+ ctx.arc(x + width - radius, y + height - radius + 10, radius,
+ 0 * degrees, 90 * degrees)
+ ctx.arc(x + radius, y + height - radius + 10, radius,
+ 90 * degrees, 180 * degrees)
+ else:
+ ctx.arc(x + width - radius, y + height - radius, radius,
+ 0 * degrees, 90 * degrees)
+ ctx.arc(x + radius, y + height - radius, radius,
+ 90 * degrees, 180 * degrees)
ctx.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees)
ctx.close_path()
ctx.fill()
- self.pango_layout = self.create_pango_layout(text)
- self.pango_layout.set_markup(
- "<span size='xx-large'><b>%s</b></span>" % text, -1)
-
if not isDay:
ctx.set_source_rgb(1.0, 1.0, 1.0)
else:
@@ -325,17 +372,33 @@ class DigitalClockDrawing(Gtk.DrawingArea):
text_width, text_height = self.pango_layout.get_pixel_size()
ctx.move_to(x + (width - text_width) / 2,
- y + (height - text_height) / 2)
+ y + (height - text_height) / 2)
PangoCairo.show_layout(ctx, self.pango_layout)
+ if sub_text:
+ sub_text_width, sub_text_height =\
+ self.pango_layout_subtext.get_pixel_size()
+ # centered on x axis, 5 pixels below main text on y axis
+ # for some reason setting the alignment adds an extra frame
+ # around it, slight change to allow for this
+ if subtext_is_wrapped:
+ ctx.move_to(x + (width - sub_text_width) / 2 - 10,
+ y + (height - text_height) / 2 +
+ sub_text_height - 10)
+ else:
+ ctx.move_to(x + (width - sub_text_width) / 2,
+ y + (height - text_height) / 2 +
+ sub_text_height + 10)
+ PangoCairo.show_layout(ctx, self.pango_layout_subtext)
+
pixbuf = Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.width,
- self.height)
+ self.height)
self.pixbuf = pixbuf
return self.pixbuf
class AlarmWidget():
- def __init__(self, time_given):
+ def __init__(self, time_given, repeat):
self.drawing = DigitalClockDrawing()
t = time_given
isDay = self.get_is_day(t)
@@ -343,7 +406,7 @@ class AlarmWidget():
img = os.path.join(Dirs.get_image_dir(), "cities", "day.png")
else:
img = os.path.join(Dirs.get_image_dir(), "cities", "night.png")
- self.drawing.render(t, img, isDay)
+ self.drawing.render(t, img, isDay, repeat)
def get_system_clock_format(self):
settings = Gio.Settings.new('org.gnome.desktop.interface')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]