-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app_md.py
211 lines (192 loc) · 7.06 KB
/
test_app_md.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# -*- coding: utf-8 -*-
import kivymd.snackbar as Snackbar
from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.properties import ObjectProperty
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivymd.bottomsheet import MDListBottomSheet, MDGridBottomSheet
from kivymd.button import MDIconButton
from kivymd.label import MDLabel
from kivymd.list import ILeftBody, ILeftBodyTouch, IRightBodyTouch
from kivymd.navigationdrawer import NavigationDrawer
from kivymd.selectioncontrols import MDCheckbox
from kivymd.theming import ThemeManager
from kivymd.dialog import MDDialog
from kivymd.time_picker import MDTimePicker
from kivymd.date_picker import MDDatePicker
from kivymd.navigationdrawer import NavigationDrawerIconButton
import os
import urllib
from piso import *
#influx
from influxdb import InfluxDBClient
main_widget_kv = '''
#:import Toolbar kivymd.toolbar.Toolbar
#:import ThemeManager kivymd.theming.ThemeManager
#:import NavigationDrawer kivymd.navigationdrawer.NavigationDrawer
#:import MDList kivymd.list.MDList
#:import OneLineListItem kivymd.list.OneLineListItem
#:import TwoLineListItem kivymd.list.TwoLineListItem
#:import ThreeLineListItem kivymd.list.ThreeLineListItem
#:import OneLineAvatarListItem kivymd.list.OneLineAvatarListItem
#:import OneLineIconListItem kivymd.list.OneLineIconListItem
#:import OneLineAvatarIconListItem kivymd.list.OneLineAvatarIconListItem
#:import SingleLineTextField kivymd.textfields.SingleLineTextField
#:import MDSpinner kivymd.spinner.MDSpinner
#:import MDCard kivymd.card.MDCard
#:import MDSeparator kivymd.card.MDSeparator
#:import get_color_from_hex kivy.utils.get_color_from_hex
#:import colors kivymd.color_definitions.colors
#:import SmartTile kivymd.grid.SmartTile
#:import MDSlider kivymd.slider.MDSlider
#:import MDTabbedPanel kivymd.tabs.MDTabbedPanel
#:import MDTab kivymd.tabs.MDTab
#:import MDThemePicker kivymd.theme_picker.MDThemePicker
BoxLayout:
orientation: 'vertical'
Toolbar:
id: toolbar
title: 'Datos sensores'
background_color: app.theme_cls.primary_color
left_action_items: [['menu', lambda x: app.nav_drawer.toggle()]]
right_action_items: [['dots-vertical', lambda x: app.nav_drawer.toggle()]]
ScreenManager:
id: scr_mngr
Screen:
name: 'bottomsheet'
MDRaisedButton:
text: "Open list bottom sheet"
opposite_colors: True
size_hint: None, None
size: 4 * dp(48), dp(48)
pos_hint: {'center_x': 0.5, 'center_y': 0.6}
on_release: app.show_example_bottom_sheet()
MDRaisedButton:
text: "Open grid bottom sheet"
opposite_colors: True
size_hint: None, None
size: 4 * dp(48), dp(48)
pos_hint: {'center_x': 0.5, 'center_y': 0.3}
on_release: app.show_example_grid_bottom_sheet()
<PisoNavDrawer>
title: "Pisos"
id: pisos
<NavigationDraweIconButton>:
icon: 'checkbox-blank-circle'
<Mota>:
background_color: [0.0, 0.0, 0.0, 0.0]
size_hint: (0.1, .1)
markup: True
valign: 'bottom'
<Piso>:
flayout: flayout_id
title_color: [ 33/255., 150/255., 243/255., .9 ]
background: 'atlas:/data/images/defaulttheme/button_pressed'
FloatLayout:
id: flayout_id
size: self.parent.size
MDLabel:
id: fecha
size_hint: (0.8, .1)
pos_hint: {'top': 1.01, 'right': .6}
text: 'Ultima actualización: '
markup: True
Button:
id: actualizar
size_hint: .09,.05
#height: 30
pos_hint: {'bottom':1,'right':.1}
text: 'Actualizar'
on_press: root.actualizar_mapa()
Button:
id: config_mota_pos
size_hint: .09,.05
pos_hint: {'bottom':.2,'right':.1}
text: 'Posicionar'
on_press: root.config_mota_pos()
'''
class PisoNavDrawer(NavigationDrawer):
pass
class DatosApp(App):
theme_cls = ThemeManager()
#theme_cls.theme_style = 'Dark'
theme_cls.primary_palette = "Green"
theme_cls.secondary_palette = "Blue"
nav_drawer = ObjectProperty()
def build(self):
self.main_widget = Builder.load_string(main_widget_kv)
# self.theme_cls.theme_style = 'Dark'
#~ main_widget.ids.text_field_error.bind(
#~ on_text_validate=self.set_error_message,
#~ on_focus=self.set_error_message)
self.nav_drawer = PisoNavDrawer()
#~ self.nav_drawer.add_widget(NavigationDrawerIconButton(text="seee"))
self.iniciar("bottomsheet","piso_1")
return self.main_widget
########################################################################
def iniciar(self, actual_screen, next_screen):
#if next_screen == "info":
#Clock.schedule_interval(self.update, 0.5)
print "inicia!"
try:
self.client = InfluxDBClient('influxdb.linti.unlp.edu.ar', 8086, "lihuen", '***REMOVED***', 'uso_racional')
self.client.query('SELECT mota_id FROM medicion LIMIT 1') #por ahora la unica forma de testear la conexion.
except Exception as e:
print str(e)
print("Error al efectuar la conexion")
#popup = Popup(title='Error al conectarse', content=Label(text="Error de conexión.\nVerifique su conexión a internet y sus credenciales de acceso.\n\n\nPara cerrar el cuadro de diálogo presione fuera de este."), size_hint=(.8, .6))
#popup.open()
else:
#instancio piso y paso el client - falta ahcer una consulta para saber cuantos pisos hay
pisos = self.client.query('SELECT * FROM piso')
print pisos.get_points().next()
print "----------------------aaaaaaaaaaaaaaaaaaaa-------------------------------------"
#p_imgs = ["imagenes/plano-2piso.jpg","imagenes/primer_piso.jpg"]
self.pisos = []
#~ self.spinner = Spinner(text="1", size_hint= (.09,.05), pos_hint={'top':1,'left':.9})
for pp in pisos:
for p in pp:
print "*************************************"
print p
print "**********************pppppp*********"
#~ self.spinner.values.append(str(p))
sensores = self.client.query("SELECT * FROM mota WHERE piso_id ='"+str(p["piso_id"])+"'")
print sensores
print "+++++++++++++++++++++++++****++++++++++++++++++++++++++++++"
img = 'piso_'+str(p["piso_id"])+'.png'
print img
if ((not os.path.exists(img)) and (not os.path.exists("imagenes/"+img))):
try:
urllib.urlretrieve(str(p['mapa']),img)
except Exception as e:
print "Error al descargar la imagen del piso "+img+"\n"
print e
#~ else:
print pisos
self.pisos.append(Piso(p['piso_id'], sensores, img, self.client))
self.pisos[-1].agregar_motas()
p_nav = NavigationDrawerIconButton(text=self.pisos[-1].getName())
p_nav.icon = "checkbox-blank-circle"
p_nav.bind(on_release=partial(self.cambiar_piso, self.pisos[-1].getName()))
self.nav_drawer.add_widget(p_nav)
self.main_widget.ids["scr_mngr"].add_widget(self.pisos[-1])
else:
self.main_widget.ids["scr_mngr"].current = next_screen
def cambiar_piso(self, name, evnt):
self.main_widget.ids["scr_mngr"].current = name
def on_pause(self):
if platform == 'android':
from android import AndroidService
service = AndroidService('Datos Sensores', 'running')
service.start('service started')
self.service = service
return True
#~ #~
def on_resume(self):
self.service.stop()
self.service = None
########################################################################
if __name__ == '__main__':
DatosApp().run()