forked from Jessewb786/Silaty
-
Notifications
You must be signed in to change notification settings - Fork 3
/
home.py
executable file
·117 lines (98 loc) · 4.13 KB
/
home.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Silaty
# Copyright (c) 2018 - 2021 AXeL
# Copyright (c) 2014 - 2015 Jessewb786
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GObject, Gtk, Gdk
from hijrical import *
from translate import translate_text as _
import datetime
class Home(Gtk.Box):
def __init__(self, parent):
Gtk.Box.__init__(self)
self.parent = parent
self.set_orientation(Gtk.Orientation.VERTICAL)
self.set_margin_bottom(6)
self.titlelabel = Gtk.Label(halign=Gtk.Align.FILL, margin_bottom=12, margin_top=12, margin_left=6, margin_right=6)
self.set_title()
self.pack_start(self.titlelabel, False, True, 0)
self.prayers = []
self.nprayers = 0
self.connect("prayers-updated", self.update_prayers_highlight)
def set_title(self):
# Set the Date in the Title
now_time = datetime.datetime.now().strftime("%H:%M")
now_wd = datetime.datetime.now().strftime("%A")
g_day = datetime.datetime.now().strftime("%d")
g_month = datetime.datetime.now().strftime("%B")
g_year = datetime.datetime.now().strftime("%Y")
g_date = '%s %s %s' % (g_day, _(g_month), g_year)
calc = HijriCal(self.parent.prayertimes.options.hijrical_adjustment)
h_months = ['Muharram', 'Safar', 'Rabi al Awwal', 'Rabi al Akhira', 'Jumada al Ula', 'Jumada al Akhira', 'Rajab', "Sha'ban", 'Ramadan', 'Shawwal', "Dhu al Qa'da", 'Dhu al Hijja']
h_year, h_month, h_day, h_week_day = calc.today
h_date = '%i %s %i' % (h_day, _(h_months[int(h_month-1)]), h_year)
self.titlelabel.set_label(_('%s - %s, %s / %s') % (now_time, _(now_wd), h_date, g_date))
def add_prayer(self, prayer, prayertime, colored):
# Prayer Listbox
prayercontainer = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
prayercontainer.set_size_request(380, 0)
prayerbox = Prayer(prayer, prayertime, colored)
prayerbox.set_halign(Gtk.Align.FILL)
prayerbox.set_valign(Gtk.Align.CENTER)
if self.nprayers % 2 == 0:
color = 235.0/256.0
prayerbox.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA.from_color(Gdk.Color.from_floats(color,color,color)))
color = 204.0/256.0
prayercontainer.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA.from_color(Gdk.Color.from_floats(color,color,color)))
prayerbox.props.margin_top = 1
prayerbox.props.margin_bottom = 1
self.nprayers += 1
self.prayers.append(prayerbox)
prayercontainer.pack_start(prayerbox, True, False, 0)
self.pack_start(prayercontainer, False, True, 0)
def update_prayers_highlight(self, widget, prayername):
print ("DEBUG: received update prayers signal")
for prayer in self.prayers:
if prayer.name == prayername:
prayer.prayerlabel.set_markup("<span color=\"#55c1ec\">"+prayer.name+"</span>")
prayer.timelabel.set_markup("<span color=\"#55c1ec\">"+prayer.time+"</span>")
else:
prayer.prayerlabel.set_markup(prayer.name)
prayer.timelabel.set_markup(prayer.time)
class Prayer(Gtk.Box):
def __init__(self, prayer, prayertime, state):
Gtk.Box.__init__(self)
self.set_orientation(Gtk.Orientation.HORIZONTAL)
self.set_halign(Gtk.Align.FILL)
self.set_valign(Gtk.Align.CENTER)
self._state = state
self._name = prayer
self._time = prayertime
self.prayerlabel = Gtk.Label(halign=Gtk.Align.START, margin_bottom=6, margin_top=6, margin_left=12, margin_right=12)
self.prayerlabel.set_use_markup(True)
if state == True:
self.prayerlabel.set_markup("<span color=\"#55c1ec\">"+prayer+"</span>")
else:
self.prayerlabel.set_label(prayer)
self.pack_start(self.prayerlabel, True, True, 0)
self.timelabel = Gtk.Label(label=prayertime, halign=Gtk.Align.END, margin_bottom=6, margin_top=6, margin_right=12, margin_left=12)
self.timelabel.set_use_markup(True)
if state == True:
self.timelabel.set_markup("<span color=\"#55c1ec\">"+prayertime+"</span>")
else:
self.timelabel.set_label(prayertime)
self.pack_end(self.timelabel, True, True, 0)
@property
def time(self):
return self._time
@time.setter
def time(self, value):
self._time = value
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
GObject.type_register(Home)
GObject.signal_new("prayers-updated", Home, GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, [GObject.TYPE_STRING])