-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·174 lines (151 loc) · 5.69 KB
/
main.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# -*- encoding: utf-8 -*-
# Android Park
# Copyright (C) 2015 Julian Santander
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License v2 as published by
# the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.5.1'
import kivy
kivy.require('1.0.5')
from kivy.app import App
from ui.settings import SettingPassword, SettingBoundedNumeric
from logic.query_thread import QueryThread, Refresh, Modify, Ping
from Queue import Queue
from kivy.utils import platform
from logic import L
class CalendarApp(App):
def __init__(self, **kwargs):
super(CalendarApp, self).__init__(**kwargs)
self.service = None
self.queue = None
self.query_thread = None
def on_start(self):
self.service = None
self.queue = Queue()
self.query_thread = QueryThread(self.queue)
self.start_service()
self.root.init()
def on_stop(self):
self.query_thread.on_stop()
def on_pause(self):
self.query_thread.on_pause()
return True
def on_resume(self):
self.query_thread.on_resume()
return True
def do_refresh(self):
self.queue.put(Refresh())
def do_ping(self):
self.queue.put(Ping())
def do_modify(self, operations):
self.queue.put(Modify(operations))
def build_config(self, config):
# config.setdefaults('credentials',
# {'username' : "PA0013282",
# 'password' : "w7gYg3DT"})
config.setdefaults('credentials',
{'username': "",
'password': ""})
config.setdefaults('network', {'host': "79.148.237.226"})
config.setdefaults('general', {'pattern': ""})
config.setdefaults('timers',
{'data_refresh': 5,
'frequency': 120,
'frequency2': 5,
'timeout': 15})
def start_service(self):
if self.service is not None:
return
L.info("Trying to start service")
if platform == 'android':
from android import AndroidService
service = AndroidService('AndroidPark(ing)', 'en ejecución...')
service.start('service started')
self.service = service
def stop_service(self):
if self.service is None:
return
L.info("Trying to stop service")
if platform == 'android':
from android import AndroidService
self.service.stop()
self.service = None
def build_settings(self, settings):
settings.register_type("password", SettingPassword)
settings.register_type("bounded_numeric", SettingBoundedNumeric)
jsondata = """
[
{ "type": "title",
"title": "Android Park" },
{ "type": "string",
"title": "Nombre de Usuario",
"desc": "Nombre de usuario en la web del parking",
"section": "credentials",
"key": "username"
},
{ "type": "password",
"title": "Password",
"desc": "Password para la web del parking",
"section": "credentials",
"key": "password"
},
{ "type": "string",
"title": "Patrón automático",
"desc": "Patrón (e.g. L,M,X,J,V) que se aplicará cuando se abre un mes",
"section": "general",
"key": "pattern"
},
{ "type": "string",
"title": "Host",
"desc": "Web del parking",
"section": "network",
"key": "host"
},
{ "type": "bounded_numeric",
"min": 0,
"max": 1440,
"title": "Refresco de datos",
"desc": "Tiempo en minutos entre consultas al servidor para refrescar los datos [0-1440], 0 significa que no se refrescará",
"section": "timers",
"key": "data_refresh"
},
{ "type": "bounded_numeric",
"title": "Reintentos",
"min": 0,
"max": 1440,
"desc": "Tiempo en minutos entre reintentos de peticiones al servidor (00:00-14:59/17:30-23:59) [0-1440], 0 significa que no se reintentará",
"section": "timers",
"key": "frequency"
},
{ "type": "bounded_numeric",
"title": "Reintentos en la repesca",
"min": 0,
"max": 1440,
"desc": "Tiempo en minutos entre reintentos de peticiones al servidor (15:00-17:30) [0-1440], 0 significa que no se reintentará",
"section": "timers",
"key": "frequency2"
},
{ "type": "bounded_numeric",
"title": "Temporizador de Servicio",
"min": 1,
"max": 60,
"desc": "Timeout en segundos de la comunicacion App y Service [1-60]",
"section": "timers",
"key": "timeout"
}
]
"""
settings.add_json_panel('Android Park', self.config, data=jsondata)
def on_config_change(self, config, section, key, value):
self.root.refresh_request()
if __name__ == '__main__':
CalendarApp().run()