-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
128 lines (114 loc) · 4.31 KB
/
handler.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
118
119
120
121
122
123
124
125
126
127
import ConfigParser
from prayertime import *
import os
import datetime
class Handler:
def __init__(self):
print "DEBUG: connecting to handler @%s" % (str(datetime.datetime.now()))
pass
def GetCalMethods(self):
methods = ['UmmAlQuraUniv', 'EgyptianGeneralAuthorityOfSurvey', 'UnivOfIslamicSciencesKarachi',
'IslamicSocietyOfNorthAmerica', 'MuslimWorldLeague']
return methods
def GetMazaheb(self):
mazaheb = ['Hanafi','Default']
return mazaheb
def GetClockFormats(self):
clockformats = ['12h', '24h']
return clockformats
def GetOptions(self):# Gets Settings From The Configuration File
print "DEBUG: getting settings file @%s" % (str(datetime.datetime.now()))
options = {}
cparse = ConfigParser.ConfigParser()
cparse.read([os.path.expanduser('~/.indicator-prayer-times')])
try:
city = cparse.get('DEFAULT', 'city')
calcmthdname = cparse.get('DEFAULT', 'calculation-method')
mazhabname = cparse.get('DEFAULT', 'mazhab')
hourfmt = cparse.get('DEFAULT', 'clock-format')
city_lat = float(cparse.get('DEFAULT','latitude'))
city_lon = float(cparse.get('DEFAULT','longitude'))
city_tz = float(cparse.get('DEFAULT','timezone'))
notif = float(cparse.get('DEFAULT','notif'))
iconlabel = float(cparse.get('DEFAULT','iconlabel'))
if calcmthdname == 'UmmAlQuraUniv':
calcmthd=Calendar.UmmAlQuraUniv
if calcmthdname == 'EgyptianGeneralAuthorityOfSurvey':
calcmthd=Calendar.EgyptianGeneralAuthorityOfSurvey
if calcmthdname == 'UnivOfIslamicSciencesKarachi':
calcmthd=Calendar.UnivOfIslamicSciencesKarachi
if calcmthdname == 'IslamicSocietyOfNorthAmerica':
calcmthd=Calendar.IslamicSocietyOfNorthAmerica
if calcmthdname == 'MuslimWorldLeague':
calcmthd=Calendar.MuslimWorldLeague
if mazhabname == 'Default':
mazhab=Mazhab.Default
if mazhabname == 'Hanafi':
mazhab=Mazhab.Hanafi
options['city'] = city
options['city_lat'] = city_lat
options['city_lon'] = city_lon
options['city_tz'] = city_tz
options['cal_method_name'] = calcmthdname
options['mazhab_name'] = mazhabname
options['hourfmt'] = hourfmt
options['notif'] = notif
options['iconlabel'] = iconlabel
return options
except ConfigParser.NoOptionError:
print "DEBUG: No configration file using default settings"
options['city'] = "Makkah"
options['city_lat'] = 21.25
options['city_lon'] = 39.49
options['city_tz'] = 3
options['cal_method_name'] = 'UmmAlQuraUniv'
options['mazhab_name'] = 'Default'
options['hourfmt'] = '24h'
options['notif'] = '10'
options['iconlabel'] = '1'
self.SaveOptions(options)
return options
except ValueError:
print "DEBUG: Problem while reading setting file, using the default settings"
os.system("rm ~/.indicator-prayer-times")
options['city'] = "Makkah"
options['city_lat'] = 21.25
options['city_lon'] = 39.49
options['city_tz'] = 3
options['cal_method_name'] = 'UmmAlQuraUniv'
options['mazhab_name'] = 'Default'
options['hourfmt'] = '24h'
options['notif'] = '10'
options['iconlabel'] = '1'
self.SaveOptions(options)
return options
def SaveOptions(self, options):
print "DEBUG: saving settings file @%s" % (str(datetime.datetime.now()))
config = open(os.path.expanduser('~/.indicator-prayer-times'), 'w')
Text='''# Indicator-Prayer-Times Settings File
# PLEASE RESTART THE APPLICATION TO APPLY THE CHANGES
[DEFAULT]
city = %s
# Possible Values for Calculation Methods
# UmmAlQuraUniv
# EgyptianGeneralAuthorityOfSurvey
# UnivOfIslamicSciencesKarachi
# IslamicSocietyOfNorthAmerica
# MuslimWorldLeague
calculation-method = %s
# Possible Values for Mazahab
# Default
# Hanafi
mazhab = %s
# Possible Values for Clock Format
# 24h
# 12h
clock-format = %s
latitude = %s
longitude = %s
timezone = %s
notif = %s
iconlabel = %s''' % (options['city'],options['cal_method_name'], options['mazhab_name'], options['hourfmt'], options['city_lat'],
options['city_lon'],options['city_tz'], options['notif'], options['iconlabel'])
config.write(Text)
config.close()