[gnome-clocks] Fix styling to be PEP8 compatible
- From: Seif Lotfy <seiflotfy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Fix styling to be PEP8 compatible
- Date: Fri, 17 Aug 2012 12:02:16 +0000 (UTC)
commit 4fa99e386ce471f32f56c7be14cdfe093b649d9c
Author: Seif Lotfy <seif lotfy com>
Date: Fri Aug 17 13:44:53 2012 +0200
Fix styling to be PEP8 compatible
Signed-off-by: Seif Lotfy <seif lotfy com>
gnome-clocks | 12 +-
gnomeclocks/alarm.py | 23 ++-
gnomeclocks/app.py | 29 +++--
gnomeclocks/clocks.py | 291 ++++++++++++++++++++-----------------
gnomeclocks/storage.py | 20 ++-
gnomeclocks/timer.py | 106 +++++++-------
gnomeclocks/widgets.py | 382 ++++++++++++++++++++++++++----------------------
7 files changed, 470 insertions(+), 393 deletions(-)
---
diff --git a/gnome-clocks b/gnome-clocks
index e06574f..ebae4a6 100755
--- a/gnome-clocks
+++ b/gnome-clocks
@@ -47,17 +47,17 @@ import gettext
from gnomeclocks.utils import Dirs
locale_domain = "gnome-clocks"
-locale.setlocale(locale.LC_ALL,'')
-gettext.bindtextdomain(locale_domain, Dirs.get_locale_dir ())
+locale.setlocale(locale.LC_ALL, '')
+gettext.bindtextdomain(locale_domain, Dirs.get_locale_dir())
gettext.textdomain(locale_domain)
-gettext.install(locale_domain, Dirs.get_locale_dir ())
+gettext.install(locale_domain, Dirs.get_locale_dir())
from gnomeclocks.app import ClocksApplication
if __name__ == "__main__":
- app = ClocksApplication ()
- # FIXME: Get rid of the following line which has the only purpose of working
- # around Ctrl+C not exiting Gtk applications from bug 622084.
+ app = ClocksApplication()
+ # FIXME: Get rid of the following line which has the only purpose of
+ # working around Ctrl+C not exiting Gtk applications from bug 622084.
# https://bugzilla.gnome.org/show_bug.cgi?id=622084
signal.signal(signal.SIGINT, signal.SIG_DFL)
exit_status = app.run(sys.argv)
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index 7a3e1ab..de545c4 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -16,7 +16,11 @@
#
# Author: Seif Lotfy <seif lotfy collabora co uk>
-import datetime, vobject, time, os
+import datetime
+import vobject
+import time
+import os
+
class ICSHandler():
def __init__(self):
@@ -47,7 +51,6 @@ class ICSHandler():
ics.write(vcal.serialize())
ics.close()
-
def delete_alarm(self, alarm_uid):
with open('alarms.ics', 'r+') as ics:
data = vobject.readOne(ics.read())
@@ -56,7 +59,8 @@ class ICSHandler():
#delete event
break
- def edit_alarm(self, alarm_uid, new_name=None, new_hour=None, new_mins=None, new_p=None, new_repeat=None):
+ def edit_alarm(self, alarm_uid, new_name=None, new_hour=None,
+ new_mins=None, new_p=None, new_repeat=None):
with open(self.ics_file, 'r+') as ics:
vcal = vobject.readOne(ics.read())
for event in vcal.vevent_list:
@@ -65,6 +69,7 @@ class ICSHandler():
del event.summary
event.add('summary').value = new_name
+
class AlarmItem:
def __init__(self, name=None, repeat=None, h=None, m=None, p=None):
self.name = name
@@ -105,7 +110,6 @@ class AlarmItem:
h = self.h
return "%2i:%02i %s" % (h, self.m, self.p)
-
def get_time_24h_as_string(self):
if self.p == 'AM' or self.p == 'PM':
h = self.h + 12
@@ -142,10 +146,15 @@ class AlarmItem:
elif self.p == "AM":
if h == 12:
h = 0
- vevent.add('dtstart').value = datetime.datetime.combine(datetime.date.today(), datetime.time(h, m))
- vevent.add('dtend').value = datetime.datetime.combine(datetime.date.today(), datetime.time(h, 59))
+ vevent.add('dtstart').value =\
+ datetime.datetime.combine(datetime.date.today(),
+ datetime.time(h, m))
+ vevent.add('dtend').value =\
+ datetime.datetime.combine(datetime.date.today(),
+ datetime.time(h, 59))
if len(self.repeat) == 0:
vevent.add('rrule').value = 'FREQ=DAILY;'
else:
- vevent.add('rrule').value = 'FREQ=WEEKLY;BYDAY=%s' % ','.join(self.repeat)
+ vevent.add('rrule').value = 'FREQ=WEEKLY;BYDAY=%s' %\
+ ','.join(self.repeat)
return vevent
diff --git a/gnomeclocks/app.py b/gnomeclocks/app.py
index 5c83d11..d57b63c 100644
--- a/gnomeclocks/app.py
+++ b/gnomeclocks/app.py
@@ -19,18 +19,22 @@
import os
from gi.repository import Gtk, Gdk, GObject, Gio
-
from clocks import World, Alarm, Timer, Stopwatch
from utils import Dirs
-
from gnomeclocks import __version__, AUTHORS
+COPYRIGHTS = "(c) Collabora Ltd\n(c) Emily Gonyer\n(c) Eslam Mostafa"
+
+
class Window(Gtk.ApplicationWindow):
def __init__(self, app):
- Gtk.ApplicationWindow.__init__(self, title=_("Clocks"), application=app, hide_titlebar_when_maximized=True)
+ Gtk.ApplicationWindow.__init__(self, title=_("Clocks"),
+ application=app,
+ hide_titlebar_when_maximized=True)
css_provider = Gtk.CssProvider()
- css_provider.load_from_path(os.path.join(Dirs.get_data_dir(), "gtk-style.css"))
+ css_provider.load_from_path(os.path.join(Dirs.get_data_dir(),
+ "gtk-style.css"))
context = Gtk.StyleContext()
context.add_provider_for_screen(Gdk.Screen.get_default(),
css_provider,
@@ -97,8 +101,9 @@ class Window(Gtk.ApplicationWindow):
about.set_program_name(_("GNOME Clocks"))
about.set_logo_icon_name("clocks")
about.set_version(__version__)
- about.set_copyright("(c) Collabora Ltd\n(c) Emily Gonyer\n(c) Eslam Mostafa")
- about.set_comments(_("Clocks is a clock application for the GNOME Desktop"))
+ about.set_copyright(COPYRIGHTS)
+ about.set_comments(
+ _("Clocks is a clock application for the GNOME Desktop"))
about.set_authors(AUTHORS)
about.set_translator_credits(_("translator-credits"))
about.connect("response", lambda w, r: about.destroy())
@@ -142,7 +147,7 @@ class ClocksToolbar(Gtk.Toolbar):
self.get_style_context().add_class("clocks-toolbar")
self.set_icon_size(Gtk.IconSize.MENU)
- self.get_style_context ().add_class(Gtk.STYLE_CLASS_MENUBAR)
+ self.get_style_context().add_class(Gtk.STYLE_CLASS_MENUBAR)
toolitem = Gtk.ToolItem()
toolitem.set_expand(True)
@@ -165,12 +170,15 @@ class ClocksToolbar(Gtk.Toolbar):
toolbox.pack_start(box, True, True, 0)
self.backButton = Gtk.Button()
- icon = Gio.ThemedIcon.new_with_default_fallbacks("go-previous-symbolic")
+ icon = Gio.ThemedIcon.new_with_default_fallbacks(
+ "go-previous-symbolic")
image = Gtk.Image()
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.backButton.connect("clicked",
+ lambda w: self.emit("view-clock",
+ self._buttonMap[self.last_widget]))
self.newButton.connect("clicked", self._on_new_clicked)
@@ -189,7 +197,8 @@ class ClocksToolbar(Gtk.Toolbar):
self.applyButton = Gtk.Button()
#self.applyButton.get_style_context().add_class('raised');
- icon = Gio.ThemedIcon.new_with_default_fallbacks("object-select-symbolic")
+ icon = Gio.ThemedIcon.new_with_default_fallbacks(
+ "object-select-symbolic")
image = Gtk.Image()
image.set_from_gicon(icon, Gtk.IconSize.MENU)
self.applyButton.add(image)
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index 803ae77..45bdf09 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -1,8 +1,8 @@
-# Copyright (c) 2011-2012 Collabora, Ltd.
+# Copyright(c) 2011-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
+# 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
@@ -19,15 +19,18 @@
from gi.repository import Gtk, GObject, Gio, Gdk, Gst, Notify, cairo
from gi.repository.GdkPixbuf import Pixbuf
-from widgets import NewWorldClockDialog, DigitalClock, NewAlarmDialog, AlarmWidget, WorldEmpty, AlarmsEmpty
+from widgets import NewWorldClockDialog, NewAlarmDialog
+from widgets import DigitalClock, AlarmWidget, WorldEmpty, AlarmsEmpty
from storage import worldclockstorage
from datetime import datetime, timedelta
from pytz import timezone
from timer import TimerWelcomeScreen, TimerScreen, Spinner
from alarm import AlarmItem, ICSHandler
-import pytz, time, os
+import pytz
+import time
+import os
STOPWATCH_LABEL_MARKUP = "<span font_desc=\"64.0\">%02i:%02i</span>"
STOPWATCH_BUTTON_MARKUP = "<span font_desc=\"18.0\">%s</span>"
@@ -35,34 +38,36 @@ STOPWATCH_BUTTON_MARKUP = "<span font_desc=\"18.0\">%s</span>"
TIMER_LABEL_MARKUP = "<span font_desc=\"64.0\">%02i:%02i:%02i</span>"
TIMER = "<span font_desc=\"64.0\">%02i</span>"
+
class ToggleButton(Gtk.ToggleButton):
def __init__(self, text):
Gtk.ToggleButton.__init__(self)
self.text = text
self.label = Gtk.Label()
- self.label.set_markup("%s" %text)
+ self.label.set_markup("%s" % text)
self.add(self.label)
self.connect("toggled", self._on_toggled)
self.set_size_request(100, 34)
def _on_toggled(self, label):
if self.get_active():
- self.label.set_markup("<b>%s</b>"%self.text)
+ self.label.set_markup("<b>%s</b>" % self.text)
else:
- self.label.set_markup("%s" %self.text)
+ self.label.set_markup("%s" % self.text)
+
-class Clock (Gtk.EventBox):
+class Clock(Gtk.EventBox):
__gsignals__ = {'show-requested': (GObject.SignalFlags.RUN_LAST,
None, ()),
'show-clock': (GObject.SignalFlags.RUN_LAST,
- None, (GObject.TYPE_PYOBJECT,))}
+ None, (GObject.TYPE_PYOBJECT, ))}
- def __init__ (self, label, hasNew = False, hasSelectionMode = False):
- Gtk.EventBox.__init__ (self)
- self.button = ToggleButton (label)
+ def __init__(self, label, hasNew=False, hasSelectionMode=False):
+ Gtk.EventBox.__init__(self)
+ self.button = ToggleButton(label)
self.hasNew = hasNew
self.hasSelectionMode = hasSelectionMode
- self.get_style_context ().add_class ('grey-bg')
+ self.get_style_context().add_class('grey-bg')
def open_new_dialog(self):
pass
@@ -73,80 +78,87 @@ class Clock (Gtk.EventBox):
def add_new_clock(self):
pass
- def unselect_all (self):
+ def unselect_all(self):
pass
-class World (Clock):
- def __init__ (self):
- Clock.__init__ (self, _("World"), True, True)
+
+class World(Clock):
+ def __init__(self):
+ Clock.__init__(self, _("World"), True, True)
self.addButton = None
- self.liststore = liststore = Gtk.ListStore(Pixbuf, str, GObject.TYPE_PYOBJECT)
+ self.liststore = liststore = Gtk.ListStore(Pixbuf, str,
+ GObject.TYPE_PYOBJECT)
self.iconview = iconview = Gtk.IconView.new()
- self.empty_view = WorldEmpty ()
+ self.empty_view = WorldEmpty()
iconview.set_model(liststore)
iconview.set_spacing(3)
iconview.set_pixbuf_column(0)
- iconview.get_style_context ().add_class ('grey-bg')
+ iconview.get_style_context().add_class('grey-bg')
renderer_text = Gtk.CellRendererText()
- renderer_text.set_alignment (0.5, 0.5)
+ renderer_text.set_alignment(0.5, 0.5)
iconview.pack_start(renderer_text, True)
iconview.add_attribute(renderer_text, "markup", 1)
self.scrolledwindow = scrolledwindow = Gtk.ScrolledWindow()
scrolledwindow.add(iconview)
- iconview.connect ("selection-changed", self._on_selection_changed)
+ iconview.connect("selection-changed", self._on_selection_changed)
self.clocks = []
self.load_clocks()
self.show_all()
- def unselect_all (self):
- self.iconview.unselect_all ()
+ def unselect_all(self):
+ self.iconview.unselect_all()
- def _on_selection_changed (self, iconview):
- items = iconview.get_selected_items ()
+ def _on_selection_changed(self, iconview):
+ items = iconview.get_selected_items()
if items:
- path = iconview.get_selected_items ()[0]
- d = self.liststore [path][2]
- self.emit ("show-clock", d)
+ 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):
- self.clocks = worldclockstorage.load_clocks ()
+ self.clocks = worldclockstorage.load_clocks()
if len(self.clocks) == 0:
- self.load_empty_clocks_view ()
+ 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 = 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 ()
+ self.load_clocks_view()
def add_clock(self, location):
- location_id = location.id + "---" + location.location.get_code ()
+ location_id = location.id + "---" + location.location.get_code()
if not location_id in worldclockstorage.locations_dump:
d = DigitalClock(location)
self.clocks.append(location)
- view_iter = self.liststore.append([d.drawing.pixbuf, "<b>"+d.location.get_city_name()+"</b>", 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 (self.clocks)
+ worldclockstorage.save_clocks(self.clocks)
if len(self.clocks) > 0:
- self.load_clocks_view ()
+ self.load_clocks_view()
- def delete_clock (self, d):
- self.clocks.remove (d.location)
- self.liststore.remove (d.view_iter)
- self.iconview.unselect_all ()
+ 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 ()
+ self.load_empty_clocks_view()
def open_new_dialog(self):
parent = self.get_parent().get_parent().get_parent()
@@ -160,34 +172,35 @@ 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_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 ()
+ 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):
- Clock.__init__ (self, _("Alarm"), True, True)
- self.liststore = liststore = Gtk.ListStore(Pixbuf, str, GObject.TYPE_PYOBJECT)
+class Alarm(Clock):
+ def __init__(self):
+ Clock.__init__(self, _("Alarm"), True, True)
+ self.liststore = liststore = Gtk.ListStore(Pixbuf, str,
+ GObject.TYPE_PYOBJECT)
self.iconview = iconview = Gtk.IconView.new()
self.empty_view = AlarmsEmpty()
-
iconview.set_model(liststore)
+
iconview.set_spacing(3)
iconview.set_pixbuf_column(0)
- iconview.get_style_context ().add_class ('grey-bg')
+ iconview.get_style_context().add_class('grey-bg')
renderer_text = Gtk.CellRendererText()
- renderer_text.set_alignment (0.5, 0.5)
+ renderer_text.set_alignment(0.5, 0.5)
iconview.pack_start(renderer_text, True)
iconview.add_attribute(renderer_text, "markup", 1)
@@ -215,11 +228,12 @@ class Alarm (Clock):
d = AlarmWidget(alarm.get_time_12h_as_string())
else:
d = AlarmWidget(alarm.get_time_24h_as_string())
- view_iter = self.liststore.append([d.drawing.pixbuf, "<b>" + alarm.get_alarm_name() + "</b>", d])
+ view_iter = self.liststore.append([d.drawing.pixbuf,
+ "<b>" + alarm.get_alarm_name() + "</b>", d])
d.set_iter(self.liststore, view_iter)
self.load_alarms_view()
else:
- self.load_empty_alarms_view ()
+ self.load_empty_alarms_view()
def load_alarms_view(self):
if self.empty_view in self.get_children():
@@ -241,7 +255,8 @@ class Alarm (Clock):
d = AlarmWidget(alarm.get_time_12h_as_string())
else:
d = AlarmWidget(alarm.get_time_24h_as_string())
- view_iter = self.liststore.append([d.drawing.pixbuf, "<b>" + alarm.get_alarm_name() + "</b>", d])
+ 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()
vevents = handler.load_vevents()
@@ -249,99 +264,101 @@ class Alarm (Clock):
self.load_alarms_view()
def open_new_dialog(self):
- parent = self.get_parent ().get_parent ().get_parent ()
- window = NewAlarmDialog (parent)
+ parent = self.get_parent().get_parent().get_parent()
+ window = NewAlarmDialog(parent)
window.connect("add-alarm", lambda w, l: self.add_alarm(l))
- window.show_all ()
+ window.show_all()
+
-class Stopwatch (Clock):
+class Stopwatch(Clock):
class State:
RESET = 0
RUNNING = 1
STOPPED = 2
- def __init__ (self):
- Clock.__init__ (self, _("Stopwatch"))
- vbox = Gtk.Box (orientation = Gtk.Orientation.VERTICAL)
- self.add (vbox)
+ def __init__(self):
+ Clock.__init__(self, _("Stopwatch"))
+ vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ self.add(vbox)
top_spacer = Gtk.Box()
- center = Gtk.Box (orientation=Gtk.Orientation.VERTICAL)
- bottom_spacer = Gtk.Box (orientation=Gtk.Orientation.VERTICAL)
+ center = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ bottom_spacer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
- self.stopwatchLabel = Gtk.Label ()
- self.stopwatchLabel.set_alignment (0.5, 0.5)
- self.stopwatchLabel.set_markup (STOPWATCH_LABEL_MARKUP%(0,0))
+ self.stopwatchLabel = Gtk.Label()
+ self.stopwatchLabel.set_alignment(0.5, 0.5)
+ self.stopwatchLabel.set_markup(STOPWATCH_LABEL_MARKUP % (0, 0))
hbox = Gtk.Box()
- self.leftButton = Gtk.Button ()
+ self.leftButton = Gtk.Button()
self.leftButton.set_size_request(200, -1)
- self.leftLabel = Gtk.Label ()
- self.leftButton.add (self.leftLabel)
- self.rightButton = Gtk.Button ()
+ self.leftLabel = Gtk.Label()
+ self.leftButton.add(self.leftLabel)
+ self.rightButton = Gtk.Button()
self.rightButton.set_size_request(200, -1)
- self.rightLabel = Gtk.Label ()
- self.rightButton.add (self.rightLabel)
+ self.rightLabel = Gtk.Label()
+ self.rightButton.add(self.rightLabel)
self.rightButton.set_sensitive(False)
- self.leftButton.get_style_context ().add_class ("clocks-go")
- #self.rightButton.get_style_context ().add_class ("clocks-lap")
+ self.leftButton.get_style_context().add_class("clocks-go")
+ #self.rightButton.get_style_context().add_class("clocks-lap")
- hbox.pack_start (Gtk.Box(), True, False, 0)
- hbox.pack_start (self.leftButton, False, False, 0)
- hbox.pack_start (Gtk.Box(), False, False, 24)
- hbox.pack_start (self.rightButton, False, False, 0)
- hbox.pack_start (Gtk.Box(), True, False, 0)
+ hbox.pack_start(Gtk.Box(), True, False, 0)
+ hbox.pack_start(self.leftButton, False, False, 0)
+ hbox.pack_start(Gtk.Box(), False, False, 24)
+ hbox.pack_start(self.rightButton, False, False, 0)
+ hbox.pack_start(Gtk.Box(), True, False, 0)
self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Start")))
- self.leftLabel.set_padding (6, 0)
- self.rightLabel.set_markup (STOPWATCH_BUTTON_MARKUP % (_("Reset")))
- self.rightLabel.set_padding (6, 0)
+ self.leftLabel.set_padding(6, 0)
+ self.rightLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Reset")))
+ self.rightLabel.set_padding(6, 0)
- center.pack_start (self.stopwatchLabel, False, False, 0)
+ center.pack_start(self.stopwatchLabel, False, False, 0)
space = Gtk.EventBox()
- center.pack_start (Gtk.Box (), True, True, 41)
- center.pack_start (hbox, False, False, 0)
+ center.pack_start(Gtk.Box(), True, True, 41)
+ center.pack_start(hbox, False, False, 0)
self.state = Stopwatch.State.RESET
self.g_id = 0
self.start_time = 0
self.time_diff = 0
- vbox.pack_start (Gtk.Box (), True, True, 48)
- vbox.pack_start (center, False, False, 0)
- vbox.pack_start (Gtk.Box (), True, True, 1)
- vbox.pack_start (Gtk.Box (), True, True, 41)
+ vbox.pack_start(Gtk.Box(), True, True, 48)
+ vbox.pack_start(center, False, False, 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)
self.rightButton.connect("clicked", self._on_right_button_clicked)
- def _on_left_button_clicked (self, widget):
- if self.state == Stopwatch.State.RESET or self.state == Stopwatch.State.STOPPED:
+ def _on_left_button_clicked(self, widget):
+ if self.state in (Stopwatch.State.RESET, Stopwatch.State.STOPPED):
self.state = Stopwatch.State.RUNNING
self.start()
self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Stop")))
-
- self.leftButton.get_style_context ().add_class ("clocks-stop")
+ self.leftButton.get_style_context().add_class("clocks-stop")
self.rightButton.set_sensitive(True)
elif self.state == Stopwatch.State.RUNNING:
self.state = Stopwatch.State.STOPPED
self.stop()
- self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Continue")))
- self.rightLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Reset")))
- self.leftButton.get_style_context ().remove_class ("clocks-stop")
- self.leftButton.get_style_context ().add_class ("clocks-go")
-
- def _on_right_button_clicked (self, widget):
+ self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP %
+ (_("Continue")))
+ self.rightLabel.set_markup(STOPWATCH_BUTTON_MARKUP %
+ (_("Reset")))
+ self.leftButton.get_style_context().remove_class("clocks-stop")
+ self.leftButton.get_style_context().add_class("clocks-go")
+
+ def _on_right_button_clicked(self, widget):
if self.state == Stopwatch.State.RUNNING:
pass
if self.state == Stopwatch.State.STOPPED:
self.state = Stopwatch.State.RESET
self.time_diff = 0
self.leftLabel.set_markup(STOPWATCH_BUTTON_MARKUP % (_("Start")))
- self.leftButton.get_style_context ().add_class ("clocks-go")
- #self.rightButton.get_style_context ().add_class ("clocks-lap")
- self.stopwatchLabel.set_markup (STOPWATCH_LABEL_MARKUP%(0,0))
+ self.leftButton.get_style_context().add_class("clocks-go")
+ #self.rightButton.get_style_context().add_class("clocks-lap")
+ self.stopwatchLabel.set_markup(STOPWATCH_LABEL_MARKUP % (0, 0))
self.rightButton.set_sensitive(False)
def start(self):
@@ -361,37 +378,38 @@ class Stopwatch (Clock):
def count(self):
timediff = time.time() - self.start_time + self.time_diff
- (elapsed_minutes, elapsed_seconds) = divmod(timediff, 60)
- elapsed_milli_seconds = int ((elapsed_seconds*100)%100)
- self.stopwatchLabel.set_markup (STOPWATCH_LABEL_MARKUP%(elapsed_minutes,
- elapsed_seconds))
+ elapsed_minutes, elapsed_seconds = divmod(timediff, 60)
+ elapsed_milli_seconds = int((elapsed_seconds * 100) % 100)
+ self.stopwatchLabel.set_markup(STOPWATCH_LABEL_MARKUP %
+ (elapsed_minutes, elapsed_seconds))
return True
-class Timer (Clock):
+
+class Timer(Clock):
class State:
STOPPED = 0
RUNNING = 1
PAUSED = 2
- def __init__ (self):
- Clock.__init__ (self, _("Timer"))
+ def __init__(self):
+ Clock.__init__(self, _("Timer"))
self.state = Timer.State.STOPPED
self.g_id = 0
self.alert = Alert()
- self.vbox = Gtk.Box (orientation = Gtk.Orientation.VERTICAL)
- box = Gtk.Box ()
- self.add (box)
- box.pack_start (Gtk.Box (), True, True, 0)
- box.pack_start (self.vbox, False, False, 0)
- box.pack_end (Gtk.Box (), True, True, 0)
-
- self.timerbox = Gtk.Box (orientation = Gtk.Orientation.VERTICAL)
- self.vbox.pack_start (Gtk.Box (), True, True, 0)
- self.vbox.pack_start (self.timerbox, False, False, 0)
- self.vbox.pack_start (Gtk.Box (), True, True, 0)
- self.vbox.pack_start (Gtk.Box (), True, True, 46)
+ self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ box = Gtk.Box()
+ self.add(box)
+ box.pack_start(Gtk.Box(), True, True, 0)
+ box.pack_start(self.vbox, False, False, 0)
+ box.pack_end(Gtk.Box(), True, True, 0)
+
+ self.timerbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ self.vbox.pack_start(Gtk.Box(), True, True, 0)
+ self.vbox.pack_start(self.timerbox, False, False, 0)
+ self.vbox.pack_start(Gtk.Box(), True, True, 0)
+ self.vbox.pack_start(Gtk.Box(), True, True, 46)
self.timer_welcome_screen = TimerWelcomeScreen(self)
self.timer_screen = TimerScreen(self)
@@ -419,7 +437,8 @@ class Timer (Clock):
hours = self.timer_welcome_screen.hours.get_value()
minutes = self.timer_welcome_screen.minutes.get_value()
seconds = self.timer_welcome_screen.seconds.get_value()
- self.timer_screen.timerLabel.set_markup (TIMER_LABEL_MARKUP%(hours, minutes, seconds))
+ self.timer_screen.timerLabel.set_markup(TIMER_LABEL_MARKUP %
+ (hours, minutes, seconds))
self.time = (hours * 60 * 60) + (minutes * 60) + seconds
self.state = Timer.State.RUNNING
self.g_id = GObject.timeout_add(1000, self.count)
@@ -446,7 +465,8 @@ class Timer (Clock):
minutes, seconds = divmod(self.time, 60)
hours, minutes = divmod(minutes, 60)
- self.timer_screen.timerLabel.set_markup (TIMER_LABEL_MARKUP%(hours, minutes, seconds))
+ self.timer_screen.timerLabel.set_markup(TIMER_LABEL_MARKUP %
+ (hours, minutes, seconds))
if hours == 00 and minutes == 00 and seconds == 00:
self.alert.do_alert("Ta Da !")
self.state = Timer.State.STOPPED
@@ -459,6 +479,7 @@ class Timer (Clock):
else:
return True
+
class Alert:
def __init__(self):
Gst.init('gst')
@@ -468,8 +489,8 @@ class Alert:
Alert = Notify.Notification.new("Clocks", msg, 'test')
Alert.show()
playbin = Gst.ElementFactory.make('playbin', None)
- playbin.set_property('uri', 'file:///usr/share/sounds/gnome/default/alerts/glass.ogg')
+ playbin.set_property('uri',
+ 'file:///usr/share/sounds/gnome/default/alerts/glass.ogg')
playbin.set_state(Gst.State.PLAYING)
else:
print "Error: Could not trigger Alert"
-
diff --git a/gnomeclocks/storage.py b/gnomeclocks/storage.py
index d7907ec..4655453 100644
--- a/gnomeclocks/storage.py
+++ b/gnomeclocks/storage.py
@@ -1,8 +1,8 @@
-# Copyright (c) 2011-2012 Collabora, Ltd.
+# Copyright(c) 2011-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
+# 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
@@ -44,12 +44,14 @@ class WorldClockStorage():
def __init__(self):
world = GWeather.Location.new_world(True)
self.searchEntry = GWeather.LocationEntry.new(world)
- self.searchEntry.show_all ()
+ self.searchEntry.show_all()
self.locations_dump = ""
pass
def save_clocks(self, locations):
- self.locations_dump = locations = "|".join([location.id + "---" + location.location.get_code () for location in locations])
+ self.locations_dump = locations = "|".join(
+ [location.id +\
+ "---" + location.location.get_code() for location in locations])
f = open(DATA_PATH, "wb")
pickle.dump(locations, f)
f.close()
@@ -58,14 +60,14 @@ class WorldClockStorage():
clocks = []
try:
f = open(DATA_PATH, "rb")
- self.locations_dump = locations = pickle.load (f)
- f.close ()
+ self.locations_dump = locations = pickle.load(f)
+ f.close()
locations = locations.split("|")
for location in locations:
loc = location.split("---")
if self.searchEntry.set_city(loc[0], loc[1]):
- loc = self.searchEntry.get_location ()
- loc = Location(self.searchEntry.get_location ())
+ loc = self.searchEntry.get_location()
+ loc = Location(self.searchEntry.get_location())
clocks.append(loc)
except IOError as e:
if e.errno == errno.ENOENT:
@@ -83,4 +85,4 @@ class WorldClockStorage():
f.write("")
f.close()
-worldclockstorage = WorldClockStorage ()
+worldclockstorage = WorldClockStorage()
diff --git a/gnomeclocks/timer.py b/gnomeclocks/timer.py
index bd85fb5..2b26c9e 100644
--- a/gnomeclocks/timer.py
+++ b/gnomeclocks/timer.py
@@ -1,8 +1,8 @@
-# Copyright (c) 2011-2012 Collabora, Ltd.
+# Copyright(c) 2011-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
+# 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
@@ -18,10 +18,10 @@
from gi.repository import Gtk, Gio, Gdk
-TIMER = "<span font_desc=\"64.0\">%02i</span>"
-TIMER_LABEL_MARKUP = "<span font_desc=\"64.0\">%02i:%02i:%02i</span>"
-TIMER = "<span font_desc=\"64.0\">%02i</span>"
-TIMER_BUTTON_MARKUP = "<span font_desc=\"18.0\">%s</span>"
+TIMER = "<span font_desc=\"64.0\">% 02i</span>"
+TIMER_LABEL_MARKUP = "<span font_desc=\"64.0\">% 02i:% 02i:% 02i</span>"
+TIMER = "<span font_desc=\"64.0\">% 02i</span>"
+TIMER_BUTTON_MARKUP = "<span font_desc=\"18.0\">% s</span>"
class Spinner(Gtk.Box):
@@ -30,8 +30,9 @@ class Spinner(Gtk.Box):
self.max_value = max_value
self.timer_welcome_screen = timer_welcome_screen
self.set_orientation(Gtk.Orientation.VERTICAL)
- iconUp = Gio.ThemedIcon.new_with_default_fallbacks ("go-up-symbolic")
- iconDown = Gio.ThemedIcon.new_with_default_fallbacks ("go-down-symbolic")
+ iconUp = Gio.ThemedIcon.new_with_default_fallbacks("go-up-symbolic")
+ iconDown = Gio.ThemedIcon.new_with_default_fallbacks(
+ "go-down-symbolic")
imageUp = Gtk.Image.new_from_gicon(iconUp, Gtk.IconSize.DND)
imageDown = Gtk.Image.new_from_gicon(iconDown, Gtk.IconSize.DND)
#Up Button
@@ -40,8 +41,8 @@ class Spinner(Gtk.Box):
self.up.set_relief(Gtk.ReliefStyle.NONE)
#Value
self.value = Gtk.Label('')
- self.value.set_markup(TIMER%(0))
- self.value.set_alignment (0.5, 0.5)
+ self.value.set_markup(TIMER % (0))
+ self.value.set_alignment(0.5, 0.5)
#Down Button
self.down = Gtk.Button()
self.down.set_image(imageDown)
@@ -58,7 +59,7 @@ class Spinner(Gtk.Box):
return int(self.value.get_text())
def set_value(self, newValue):
- self.value.set_markup(TIMER%(newValue))
+ self.value.set_markup(TIMER % (newValue))
def _increase(self, widget):
value = self.get_value()
@@ -79,47 +80,47 @@ class Spinner(Gtk.Box):
self.timer_welcome_screen.update_start_button_status()
-class TimerScreen (Gtk.Box):
+class TimerScreen(Gtk.Box):
def __init__(self, timer):
super(TimerScreen, self).__init__()
self.set_orientation(Gtk.Orientation.VERTICAL)
self.timer = timer
- top_spacer = Gtk.Box ()
- center = Gtk.Box (orientation=Gtk.Orientation.VERTICAL)
- bottom_spacer = Gtk.Box (orientation=Gtk.Orientation.VERTICAL)
+ top_spacer = Gtk.Box()
+ center = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ bottom_spacer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
- self.timerLabel = Gtk.Label ()
- self.timerLabel.set_alignment (0.5, 0.5)
- self.timerLabel.set_markup (TIMER_LABEL_MARKUP%(0,0,0))
+ self.timerLabel = Gtk.Label()
+ self.timerLabel.set_alignment(0.5, 0.5)
+ self.timerLabel.set_markup(TIMER_LABEL_MARKUP % (0, 0, 0))
- center.pack_start (Gtk.Label (""), False, True, 30)
- center.pack_start (self.timerLabel, False, True, 6)
- center.pack_start (Gtk.Label (""), False, True, 24)
+ center.pack_start(Gtk.Label(""), False, True, 30)
+ center.pack_start(self.timerLabel, False, True, 6)
+ center.pack_start(Gtk.Label(""), False, True, 24)
hbox = Gtk.Box()
- self.leftButton = Gtk.Button ()
+ self.leftButton = Gtk.Button()
self.leftButton.set_size_request(200, -1)
- self.leftLabel = Gtk.Label ()
- self.leftButton.add (self.leftLabel)
- self.rightButton = Gtk.Button ()
+ self.leftLabel = Gtk.Label()
+ self.leftButton.add(self.leftLabel)
+ self.rightButton = Gtk.Button()
self.rightButton.set_size_request(200, -1)
- self.rightLabel = Gtk.Label ()
- self.rightButton.add (self.rightLabel)
+ self.rightLabel = Gtk.Label()
+ self.rightButton.add(self.rightLabel)
- hbox.pack_start (self.leftButton, True, True, 0)
- hbox.pack_start (Gtk.Box(), True, True, 24)
- hbox.pack_start (self.rightButton, True, True, 0)
+ hbox.pack_start(self.leftButton, True, True, 0)
+ hbox.pack_start(Gtk.Box(), True, True, 24)
+ hbox.pack_start(self.rightButton, True, True, 0)
self.leftLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Pause")))
- self.leftLabel.set_padding (6, 0)
+ self.leftLabel.set_padding(6, 0)
self.rightLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Reset")))
- self.rightLabel.set_padding (6, 0)
+ self.rightLabel.set_padding(6, 0)
self.leftButton.connect('clicked', self._on_left_button_clicked)
self.rightButton.connect('clicked', self._on_right_button_clicked)
- self.pack_start(Gtk.Box (), False, False, 7)
+ self.pack_start(Gtk.Box(), False, False, 7)
self.pack_start(center, False, False, 6)
self.pack_start(hbox, False, False, 5)
@@ -131,25 +132,26 @@ class TimerScreen (Gtk.Box):
if self.timer.state == 1:
self.timer.pause()
self.leftLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Continue")))
- self.leftButton.get_style_context ().add_class ("clocks-go")
+ self.leftButton.get_style_context().add_class("clocks-go")
elif self.timer.state == 2:
self.timer.cont()
self.leftLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Pause")))
- self.leftButton.get_style_context ().remove_class ("clocks-go")
+ self.leftButton.get_style_context().remove_class("clocks-go")
# FIXME: work around the fact that gtk does recalculate the label style
# if the button class changes
- self.leftLabel.get_style_context ().invalidate ()
+ self.leftLabel.get_style_context().invalidate()
-class TimerWelcomeScreen (Gtk.Box):
- def __init__ (self, timer):
- super(TimerWelcomeScreen, self).__init__ ()
+
+class TimerWelcomeScreen(Gtk.Box):
+ def __init__(self, timer):
+ super(TimerWelcomeScreen, self).__init__()
self.timer = timer
self.set_orientation(Gtk.Orientation.VERTICAL)
- top_spacer = Gtk. Box ()
- center = Gtk.Box (orientation=Gtk.Orientation.VERTICAL)
- bottom_spacer = Gtk.Box (orientation=Gtk.Orientation.VERTICAL) #Contains Start Button
+ top_spacer = Gtk. Box()
+ center = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ bottom_spacer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.hours = Spinner(24, self)
self.minutes = Spinner(59, self)
@@ -159,7 +161,7 @@ class TimerWelcomeScreen (Gtk.Box):
another_colon = Gtk.Label('')
another_colon.set_markup('<span font_desc=\"64.0\">:</span>')
- spinner = Gtk.Box () #Contains 3 columns to set the time
+ spinner = Gtk.Box()
spinner.pack_start(self.hours, False, False, 0)
spinner.pack_start(colon, False, False, 0)
spinner.pack_start(self.minutes, False, False, 0)
@@ -172,17 +174,17 @@ class TimerWelcomeScreen (Gtk.Box):
self.startButton.set_size_request(200, -1)
self.startLabel = Gtk.Label()
self.startLabel.set_markup(TIMER_BUTTON_MARKUP % (_("Start")))
- self.startLabel.set_padding (6, 0)
+ self.startLabel.set_padding(6, 0)
self.startButton.add(self.startLabel)
self.startButton.connect('clicked', self._on_start_clicked)
- bottom_spacer.pack_start (self.startButton, False, False, 0)
+ bottom_spacer.pack_start(self.startButton, False, False, 0)
- center.pack_start (Gtk.Label (""), False, True, 16)
- center.pack_start (spinner, False, True, 5)
- center.pack_start (Gtk.Label (""), False, True, 3)
+ center.pack_start(Gtk.Label(""), False, True, 16)
+ center.pack_start(spinner, False, True, 5)
+ center.pack_start(Gtk.Label(""), False, True, 3)
- self.pack_start (center, False, False, 6)
- self.pack_start (bottom_spacer, False, False, 6)
+ self.pack_start(center, False, False, 6)
+ self.pack_start(bottom_spacer, False, False, 6)
def update_start_button_status(self):
hours = self.hours.get_value()
@@ -190,10 +192,10 @@ class TimerWelcomeScreen (Gtk.Box):
seconds = self.seconds.get_value()
if hours == 0 and minutes == 0 and seconds == 0:
self.startButton.set_sensitive(False)
- self.startButton.get_style_context ().remove_class ("clocks-go")
+ self.startButton.get_style_context().remove_class("clocks-go")
else:
self.startButton.set_sensitive(True)
- self.startButton.get_style_context ().add_class ("clocks-go")
+ self.startButton.get_style_context().add_class("clocks-go")
def _on_start_clicked(self, data):
if self.timer.state == 0:
diff --git a/gnomeclocks/widgets.py b/gnomeclocks/widgets.py
index e0d3921..92fc0ef 100644
--- a/gnomeclocks/widgets.py
+++ b/gnomeclocks/widgets.py
@@ -1,8 +1,8 @@
-# Copyright (c) 2011-2012 Collabora, Ltd.
+# Copyright(c) 2011-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
+# 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
@@ -16,49 +16,55 @@
#
# Author: Seif Lotfy <seif lotfy collabora co uk>
-from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Gio, PangoCairo, Pango, GWeather
+from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Gio, PangoCairo
+from gi.repository import Pango, GWeather
from storage import Location
from alarm import AlarmItem
from utils import Dirs
import os
-import cairo, time
+import cairo
+import time
-class NewWorldClockDialog (Gtk.Dialog):
+class NewWorldClockDialog(Gtk.Dialog):
__gsignals__ = {'add-clock': (GObject.SignalFlags.RUN_LAST,
- None, (GObject.TYPE_PYOBJECT,))}
+ None, (GObject.TYPE_PYOBJECT, ))}
- def __init__ (self, parent):
+ def __init__(self, parent):
Gtk.Dialog.__init__(self, _("Add New Clock"), parent)
self.set_transient_for(parent)
self.set_modal(True)
- self.set_size_request(400,-1)
- box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
+ self.set_size_request(400, -1)
+ box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
area = self.get_content_area()
area.pack_start(box, True, True, 0)
self.label = Gtk.Label()
- self.label.set_markup(_("Search for a city:"))
+ self.label.set_markup(_("Search for a city: "))
self.label.set_alignment(0.0, 0.5)
world = GWeather.Location.new_world(True)
self.searchEntry = GWeather.LocationEntry.new(world)
- 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.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)
header = Gtk.Label(_("Add New Clock"))
- header.set_markup("<span size='medium'><b>%s</b></span>" % (_("Add a New World Clock")))
+ header.set_markup("<span size='medium'><b>%s</b></span>"
+ % (_("Add a New World Clock")))
btnBox = Gtk.Box()
self.add_buttons(_("Cancel"), 0, _("Add"), 1)
- widget = self.get_widget_for_response (1)
- widget.set_sensitive (False)
+ 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, 1)
@@ -71,38 +77,43 @@ class NewWorldClockDialog (Gtk.Dialog):
self.searchEntry.connect("icon-release", self._icon_released)
self.connect("response", self._on_response_clicked)
self.location = None
- self.show_all ()
+ self.show_all()
- def _on_response_clicked (self, widget, response_id):
+ def _on_response_clicked(self, widget, response_id):
if response_id == 1:
location = self.searchEntry.get_location()
- location = Location (location)
+ location = Location(location)
self.emit("add-clock", location)
- self.destroy ()
+ self.destroy()
- def _set_city (self, widget):
+ 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)
+ 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)
+ self.searchEntry.set_icon_from_gicon(
+ Gtk.EntryIconPosition.SECONDARY, self.clear_gicon)
if location:
widget.set_sensitive(True)
else:
widget.set_sensitive(False)
- def get_selection (self):
+ 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:
+ 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)
+ 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 ():
+
+class DigitalClock():
def __init__(self, location):
self.location = location.location
self.id = location.id
@@ -114,18 +125,18 @@ class DigitalClock ():
self.view_iter = None
self.list_store = None
- self.drawing = DigitalClockDrawing ()
- self.standalone = DigitalClockStandalone (self.location)
- self.update ()
+ self.drawing = DigitalClockDrawing()
+ self.standalone = DigitalClockStandalone(self.location)
+ self.update()
GObject.timeout_add(1000, self.update)
- def get_local_time (self):
+ def get_local_time(self):
t = time.time() + time.timezone + self.offset
t = time.localtime(t)
return t
- def get_local_time_text (self):
- text = time.strftime("%I:%M %p", self.get_local_time ())
+ def get_local_time_text(self):
+ text = time.strftime("%I:%M%p", self.get_local_time())
if text.startswith("0"):
text = text[1:]
return text
@@ -136,133 +147,144 @@ class DigitalClock ():
return systemClockFormat
def get_image(self):
- local_time = self.get_local_time ()
+ local_time = self.get_local_time()
if local_time.tm_hour > 7 and local_time.tm_hour < 19:
- return os.path.join (Dirs.get_image_dir (), "cities", "day.png")
+ return os.path.join(Dirs.get_image_dir(), "cities", "day.png")
else:
- return os.path.join (Dirs.get_image_dir (), "cities", "night.png")
+ return os.path.join(Dirs.get_image_dir(), "cities", "night.png")
def get_is_day(self):
- local_time = self.get_local_time ()
+ local_time = self.get_local_time()
if local_time.tm_hour > 7 and local_time.tm_hour < 19:
return True
else:
return False
def update(self):
- t = self.get_local_time_text ()
- systemClockFormat = self.get_system_clock_format ()
+ 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 ())
+ t = time.strftime("%I:%M%p", self.get_local_time())
else:
- t = time.strftime("%H:%M", self.get_local_time ()) #Convert to 24h
+ 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 ())
+ 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.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):
+ def set_iter(self, list_store, view_iter):
self.view_iter = view_iter
self.list_store = list_store
- def get_standalone_widget (self):
+ def get_standalone_widget(self):
return self.standalone
-class DigitalClockStandalone (Gtk.VBox):
- def __init__ (self, location):
- Gtk.VBox.__init__ (self, False)
- self.img = Gtk.Image ()
- self.time_label = Gtk.Label ()
- self.city_label = Gtk.Label ()
- self.city_label.set_markup ("<b>"+location.get_city_name()+"</b>")
+
+class DigitalClockStandalone(Gtk.VBox):
+ def __init__(self, location):
+ Gtk.VBox.__init__(self, False)
+ self.img = Gtk.Image()
+ self.time_label = Gtk.Label()
+ self.city_label = Gtk.Label()
+ self.city_label.set_markup("<b>" + location.get_city_name() + "</b>")
self.text = ""
self.systemClockFormat = None
- 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.pack_start (self.city_label, False, False, 0)
- #imagebox.set_size_request (230, 230)
-
- self.timebox = timebox = Gtk.VBox ()
- self.time_label.set_alignment (0.0, 0.5)
- timebox.pack_start (self.time_label, True, True, 0)
-
- self.hbox = hbox = Gtk.HBox ()
- 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 (timebox, False, False, 0)
- self.hbox.pack_start (Gtk.Label(), True, True, 0)
-
- self.pack_start (Gtk.Label (), True, True, 25)
- self.pack_start (hbox, False, False, 0)
- self.pack_start (Gtk.Label (), True, True, 0)
-
- sunrise_label = Gtk.Label ()
- sunrise_label.set_markup("<span size ='large' color='dimgray'>%s</span>" % (_("Sunrise")))
- sunrise_label.set_alignment (1.0, 0.5)
- self.sunrise_time_label = Gtk.Label ()
- self.sunrise_time_label.set_alignment (0.0, 0.5)
- sunrise_hbox = Gtk.Box (True, 9)
- sunrise_hbox.pack_start (sunrise_label, False, False, 0)
- sunrise_hbox.pack_start (self.sunrise_time_label, False, False, 0)
-
- sunset_label = Gtk.Label ()
- sunset_label.set_markup("<span size ='large' color='dimgray'>%s</span>" % (_("Sunset")))
- sunset_label.set_alignment (1.0, 0.5)
- self.sunset_time_label = Gtk.Label ()
- self.sunset_time_label.set_alignment (0.0, 0.5)
- sunset_hbox = Gtk.Box (True, 9)
- sunset_hbox.pack_start (sunset_label, False, False, 0)
- sunset_hbox.pack_start (self.sunset_time_label, False, False, 0)
-
- sunbox = Gtk.VBox (True, 3)
- sunbox.pack_start (sunrise_hbox, False, False, 3)
- sunbox.pack_start (sunset_hbox, False, False, 3)
-
- hbox = Gtk.HBox ()
- hbox.pack_start (Gtk.Label (), True, True, 0)
- hbox.pack_start (sunbox, False, False, 0)
- hbox.pack_start (Gtk.Label (), True, True, 0)
- self.pack_end (hbox, False, False, 30)
-
- def update (self, img, text, systemClockFormat):
- size = 72000 #(self.get_allocation ().height / 300) * 72000
+ 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.pack_start(self.city_label, False, False, 0)
+ #imagebox.set_size_request(230, 230)
+
+ self.timebox = timebox = Gtk.VBox()
+ self.time_label.set_alignment(0.0, 0.5)
+ timebox.pack_start(self.time_label, True, True, 0)
+
+ self.hbox = hbox = Gtk.HBox()
+ 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(timebox, False, False, 0)
+ self.hbox.pack_start(Gtk.Label(), True, True, 0)
+
+ self.pack_start(Gtk.Label(), True, True, 25)
+ self.pack_start(hbox, False, False, 0)
+ self.pack_start(Gtk.Label(), True, True, 0)
+
+ sunrise_label = Gtk.Label()
+ sunrise_label.set_markup(
+ "<span size ='large' color='dimgray'>%s</span>" % (_("Sunrise")))
+ sunrise_label.set_alignment(1.0, 0.5)
+ self.sunrise_time_label = Gtk.Label()
+ self.sunrise_time_label.set_alignment(0.0, 0.5)
+ sunrise_hbox = Gtk.Box(True, 9)
+ sunrise_hbox.pack_start(sunrise_label, False, False, 0)
+ sunrise_hbox.pack_start(self.sunrise_time_label, False, False, 0)
+
+ sunset_label = Gtk.Label()
+ sunset_label.set_markup(
+ "<span size ='large' color='dimgray'>%s</span>" % (_("Sunset")))
+ sunset_label.set_alignment(1.0, 0.5)
+ self.sunset_time_label = Gtk.Label()
+ self.sunset_time_label.set_alignment(0.0, 0.5)
+ sunset_hbox = Gtk.Box(True, 9)
+ sunset_hbox.pack_start(sunset_label, False, False, 0)
+ sunset_hbox.pack_start(self.sunset_time_label, False, False, 0)
+
+ sunbox = Gtk.VBox(True, 3)
+ sunbox.pack_start(sunrise_hbox, False, False, 3)
+ sunbox.pack_start(sunset_hbox, False, False, 3)
+
+ hbox = Gtk.HBox()
+ hbox.pack_start(Gtk.Label(), True, True, 0)
+ hbox.pack_start(sunbox, False, False, 0)
+ hbox.pack_start(Gtk.Label(), True, True, 0)
+ self.pack_end(hbox, False, False, 30)
+
+ def update(self, img, text, systemClockFormat):
+ size = 72000 # FIXME: (self.get_allocation().height / 300) * 72000
if img:
- pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size (img, 500, 380)
- pixbuf = pixbuf.new_subpixbuf(0 , 0 , 208, 208)
- self.img.set_from_pixbuf (pixbuf)
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(img, 500, 380)
+ pixbuf = pixbuf.new_subpixbuf(0, 0, 208, 208)
+ self.img.set_from_pixbuf(pixbuf)
self.text = text
- self.time_label.set_markup ("<span size='%i' color='dimgray'><b>%s</b></span>" %(size, text))
+ self.time_label.set_markup(
+ "<span size='%i' color='dimgray'><b>%s</b></span>" % (size, text))
if systemClockFormat != self.systemClockFormat:
sunrise_markup = ""
sunset_markup = ""
if systemClockFormat == "12h":
- sunrise_markup = sunrise_markup + "<span size ='large'>" + "7:00 AM" + "</span>"
- sunset_markup = sunset_markup + "<span size ='large'>" + "7:00 PM" + "</span>"
+ sunrise_markup = sunrise_markup + "<span size ='large'>" +\
+ "7: 00 AM" + "</span>"
+ sunset_markup = sunset_markup + "<span size ='large'>" +\
+ "7: 00 PM" + "</span>"
else:
- sunrise_markup = sunrise_markup + "<span size ='large'>" + "07:00" + "</span>"
- sunset_markup = sunset_markup + "<span size ='large'>" + "19:00" + "</span>"
- self.sunrise_time_label.set_markup (sunrise_markup)
- self.sunset_time_label.set_markup (sunset_markup)
+ sunrise_markup = sunrise_markup + "<span size ='large'>" +\
+ "07: 00" + "</span>"
+ sunset_markup = sunset_markup + "<span size ='large'>" +\
+ "19: 00" + "</span>"
+ self.sunrise_time_label.set_markup(sunrise_markup)
+ self.sunset_time_label.set_markup(sunset_markup)
self.systemClockFormat = systemClockFormat
-class DigitalClockDrawing (Gtk.DrawingArea):
+
+class DigitalClockDrawing(Gtk.DrawingArea):
width = 160
height = 160
def __init__(self):
Gtk.DrawingArea.__init__(self)
- #self.set_size_request(width,height)
+ #self.set_size_request(width, height)
self.pango_context = None
self.ctx = None
@@ -282,23 +304,27 @@ class DigitalClockDrawing (Gtk.DrawingArea):
radius = 10
degrees = 0.017453293
- x = (self.width - width)/2
- y = (self.height - height)/2
+ x = (self.width - width) / 2
+ y = (self.height - height) / 2
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.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)
+ 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)
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)
+ 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)
@@ -306,23 +332,26 @@ class DigitalClockDrawing (Gtk.DrawingArea):
ctx.set_source_rgb(0.0, 0.0, 0.0)
text_width, text_height = self.pango_layout.get_pixel_size()
- ctx.move_to(x + (width - text_width)/2, y + (height - text_height)/2)
+ ctx.move_to(x + (width - text_width) / 2,
+ y + (height - text_height) / 2)
PangoCairo.show_layout(ctx, self.pango_layout)
- pixbuf = Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.width, self.height)
+ pixbuf = Gdk.pixbuf_get_from_surface(self.surface, 0, 0, self.width,
+ self.height)
self.pixbuf = pixbuf
return self.pixbuf
+
class AlarmWidget():
def __init__(self, time_given):
- self.drawing = DigitalClockDrawing ()
+ self.drawing = DigitalClockDrawing()
clockformat = self.get_system_clock_format()
t = time_given
isDay = self.get_is_day(t)
if isDay == True:
- img = os.path.join (Dirs.get_image_dir (), "cities", "day.png")
+ img = os.path.join(Dirs.get_image_dir(), "cities", "day.png")
else:
- img = os.path.join (Dirs.get_image_dir (), "cities", "night.png")
+ img = os.path.join(Dirs.get_image_dir(), "cities", "night.png")
self.drawing.render(t, img, isDay)
def get_system_clock_format(self):
@@ -331,23 +360,24 @@ class AlarmWidget():
return systemClockFormat
def get_is_day(self, t):
- if t[6:8] == 'AM':
+ if t[6: 8] == 'AM':
return True
else:
return False
- def set_iter (self, list_store, view_iter):
+ def set_iter(self, list_store, view_iter):
self.view_iter = view_iter
self.list_store = list_store
-class NewAlarmDialog (Gtk.Dialog):
+
+class NewAlarmDialog(Gtk.Dialog):
__gsignals__ = {'add-alarm': (GObject.SignalFlags.RUN_LAST,
- None, (GObject.TYPE_PYOBJECT,))}
+ None, (GObject.TYPE_PYOBJECT, ))}
def __init__(self, parent):
Gtk.Dialog.__init__(self, _("New Alarm"), parent)
- self.set_border_width (12)
+ self.set_border_width(12)
self.parent = parent
self.set_transient_for(parent)
self.set_modal(True)
@@ -360,19 +390,19 @@ class NewAlarmDialog (Gtk.Dialog):
table1 = Gtk.Table(4, 5, False)
table1.set_row_spacings(9)
table1.set_col_spacings(9)
- content_area = self.get_content_area ()
+ content_area = self.get_content_area()
content_area.pack_start(table1, True, True, 0)
self.add_buttons(_("Cancel"), 0, _("Save"), 1)
self.connect("response", self.on_response)
- table1.set_border_width (5)
+ table1.set_border_width(5)
t = time.localtime()
h = t.tm_hour
m = t.tm_min
p = time.strftime("%p", t)
- time_label = Gtk.Label (_("Time"))
+ time_label = Gtk.Label(_("Time"))
time_label.set_alignment(1.0, 0.5)
- points = Gtk.Label (":")
+ points = Gtk.Label(": ")
points.set_alignment(0.5, 0.5)
hour_spinbutton = Gtk.SpinButton()
@@ -386,7 +416,7 @@ class NewAlarmDialog (Gtk.Dialog):
if cf == "12h":
if p == "PM":
- h = h-12
+ h = h - 12
hour_spinbutton.set_range(1.0, 12.0)
hour_spinbutton.set_value(h)
self.hourselect = hourselect = hour_spinbutton
@@ -407,16 +437,16 @@ class NewAlarmDialog (Gtk.Dialog):
else:
ampm.set_active(1)
- table1.attach (time_label, 0, 1, 0, 1)
- table1.attach (hourselect, 1, 2, 0, 1)
- table1.attach (points, 2, 3, 0, 1)
- table1.attach (minuteselect, 3, 4, 0, 1)
- table1.attach (ampm, 4, 5, 0, 1)
+ table1.attach(time_label, 0, 1, 0, 1)
+ table1.attach(hourselect, 1, 2, 0, 1)
+ table1.attach(points, 2, 3, 0, 1)
+ table1.attach(minuteselect, 3, 4, 0, 1)
+ table1.attach(ampm, 4, 5, 0, 1)
else:
- table1.attach (time_label, 0, 1, 0, 1)
- table1.attach (hourselect, 1, 2, 0, 1)
- table1.attach (points, 2, 3, 0, 1)
- table1.attach (minuteselect, 3, 4, 0, 1)
+ table1.attach(time_label, 0, 1, 0, 1)
+ table1.attach(hourselect, 1, 2, 0, 1)
+ table1.attach(points, 2, 3, 0, 1)
+ table1.attach(minuteselect, 3, 4, 0, 1)
name = Gtk.Label(_("Name"))
name.set_alignment(1.0, 0.5)
@@ -429,9 +459,9 @@ class NewAlarmDialog (Gtk.Dialog):
table1.attach(repeat, 0, 1, 2, 3)
#table1.attach(sound, 0, 1, 3, 4)
- self.entry = entry = Gtk.Entry ()
+ self.entry = entry = Gtk.Entry()
entry.set_text(_("New Alarm"))
- entry.set_editable (True)
+ entry.set_editable(True)
if cf == "12h":
table1.attach(entry, 1, 5, 1, 2)
else:
@@ -453,25 +483,25 @@ class NewAlarmDialog (Gtk.Dialog):
buttond7.connect("clicked", self.on_d7_clicked)
# create a box and put them all in it
- box = Gtk.Box (True, 0)
+ box = Gtk.Box(True, 0)
box.get_style_context().add_class("linked")
- box.pack_start (buttond1, True, True, 0)
- box.pack_start (buttond2, True, True, 0)
- box.pack_start (buttond3, True, True, 0)
- box.pack_start (buttond4, True, True, 0)
- box.pack_start (buttond5, True, True, 0)
- box.pack_start (buttond6, True, True, 0)
- box.pack_start (buttond7, True, True, 0)
+ box.pack_start(buttond1, True, True, 0)
+ box.pack_start(buttond2, True, True, 0)
+ box.pack_start(buttond3, True, True, 0)
+ box.pack_start(buttond4, True, True, 0)
+ box.pack_start(buttond5, True, True, 0)
+ box.pack_start(buttond6, True, True, 0)
+ box.pack_start(buttond7, True, True, 0)
if cf == "12h":
table1.attach(box, 1, 5, 2, 3)
else:
table1.attach(box, 1, 4, 2, 3)
- soundbox = Gtk.ComboBox ()
+ soundbox = Gtk.ComboBox()
#table1.attach(soundbox, 1, 3, 3, 4)
def show_leading_zeros(self, spin_button):
- spin_button.set_text('{:02d}'.format(spin_button.get_value_as_int()))
+ spin_button.set_text('{: 02d}'.format(spin_button.get_value_as_int()))
return True
def get_system_clock_format(self):
@@ -481,9 +511,9 @@ class NewAlarmDialog (Gtk.Dialog):
def on_response(self, widget, id):
if id == 0:
- self.destroy ()
+ self.destroy()
if id == 1:
- name = self.entry.get_text() #Perfect
+ name = self.entry.get_text()
repeat = self.repeat_days
h = self.hourselect.get_value_as_int()
m = self.minuteselect.get_value_as_int()
@@ -497,11 +527,10 @@ class NewAlarmDialog (Gtk.Dialog):
p = None
new_alarm = AlarmItem(name, repeat, h, m, p)
self.emit('add-alarm', new_alarm)
- self.destroy ()
+ self.destroy()
else:
pass
-
def on_d1_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('MO')
@@ -544,15 +573,18 @@ class NewAlarmDialog (Gtk.Dialog):
else:
self.repeat_days.remove('SU')
+
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")
+ 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)
+ image.set_sensitive(False)
text = Gtk.Label("")
- text.set_markup("<span color='darkgrey'>" + _("Select <b>New</b> to add a world clock") + "</span>")
+ 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)
@@ -563,15 +595,17 @@ class WorldEmpty(Gtk.Box):
def unselect_all(self):
pass
+
class AlarmsEmpty(Gtk.Box):
def __init__(self):
Gtk.Box.__init__(self)
self.set_orientation(Gtk.Orientation.VERTICAL)
gicon = Gio.ThemedIcon.new_with_default_fallbacks("alarm-symbolic")
image = Gtk.Image.new_from_gicon(gicon, Gtk.IconSize.DIALOG)
- image.set_sensitive (False)
+ image.set_sensitive(False)
text = Gtk.Label("")
- text.set_markup("<span color='darkgrey'>" + _("Select <b>New</b> to add an alarm") + "</span>")
+ text.set_markup("<span color='darkgrey'>" +
+ _("Select <b>New</b> to add an alarm") + "</span>")
self.pack_start(Gtk.Label(""), True, True, 0)
self.pack_start(image, False, False, 6)
self.pack_start(text, False, False, 6)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]