-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
203 lines (173 loc) · 5.25 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
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
'''
Main Application.
'''
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.image import Image
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty, StringProperty, DictProperty, ListProperty
from kivy.uix.relativelayout import RelativeLayout
from kivy.core.window import Window
from kivy.clock import Clock, mainthread
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from cabinet.behaviors import *
from cabinet.helper import *
from cabinet.database import *
from cabinet.screens.inventory import InventoryScreen
from cabinet.screens.filter import FilterScreen
from cabinet.screens.menu import MenuScreen
from cabinet.screens.material import MaterialScreen
from cabinet.screens.episode import EpisodeScreen
import threading
import psycopg2
import datetime
'''
Loading the .kv files from cabinet/kv/
'''
from os import listdir
kv_path = './cabinet/kv/'
for kv in listdir(kv_path):
Builder.load_file(kv_path+kv)
class Manager(BoxLayout):
'''
Root widget which is a boxlayout, it contains a screen manager.
'''
inventory_screen = ObjectProperty()
'''
Instance of inventory screen.
'''
filter_screen = ObjectProperty()
'''
Instance of the filter screen.
'''
active_user = StringProperty('DEBUGGER TESTER USUARIO PRUEBA')
'''
Active User Information.
Defaults to: 'DEBUGGER TESTER USUARIO PRUEBA'
'''
disclamer = StringProperty('TODOS LOS DERECHOS RESERVADOS 2016 SM TECHNOLOGIA')
'''
disclamer
Defaults to: 'TODOS LOS DERECHOS RESERVADOS 2016 SM TECHNOLOGIA'
'''
servicio_logo = StringProperty('images/servicio.png')
'''
Logo.
'''
servizo_logo = StringProperty('images/servizo.png')
'''
Logo.
'''
def on_home(self):
'''
Switch to home screen.
'''
get_screen_manager().current = 'menu'
def on_report(self):
'''
Handle report.
'''
pass
def on_logout(self):
'''
Logout.
'''
pass
def on_help(self):
'''
Help
'''
pass
class MainApp(App):
'''
The Main app class, This class is called in the beginning.
'''
date = StringProperty()
'''
Reference to Date.
'''
time = StringProperty()
'''
Reference to time.
'''
ip = StringProperty()
'''
reference to current IP.
'''
database_content = ListProperty()
'''
Reference to database content.
'''
images = DictProperty({'home': 'images/home.png', 'report': 'images/report.png',
'alert': 'images/alert.png', 'wifi_on': 'images/wifi_on.png',
'wifi_off': 'images/wifi_off.png', 'help': 'images/help.png',
'sai_off': 'images/sai_off.png', 'back': 'images/back.png',
'sai_charged': 'images/sai_charged.png', 'sai_plugged': 'images/sai_plugged.png',
'logout': 'images/logout.png'})
'''
Rerference to all the images in the software.
'''
icons = DictProperty({'search': 'icons/search.png', 'move': 'icons/move.png',
'up': 'icons/up.png', 'down': 'icons/down.png',
'group': 'icons/group.png', 'business': 'icons/help.png',
'units': 'icons/units.png', 'trash': 'icons/trash.png',
'ok': 'icons/ok.png'})
'''
Rerference to all the icons in the software.
'''
def build(self):
'''
builds the application.
'''
Clock.schedule_interval(self.get_time, 1)
Clock.schedule_once(self.get_date, 0)
Clock.schedule_once(self.get_ip, 0)
Window.maximize()
self.get_database_tables()
self.title = "Smart Cabinet"
self.root = Manager()
def get_date(self, *args):
'''
Get the date to be displayed in the main screen.
'''
now = datetime.datetime.now()
date = '{}/{}/{}'.format(now.month, now.day, now.year)
self.date = date
def get_time(self, *agrs):
'''
Get the time to be displayed in the main screen.
'''
now = datetime.datetime.now()
time = '{}:{}:{}'.format(now.hour, now.minute, now.second)
self.time = time
def get_ip(self, *args):
'''
Get the current ip.
'''
import socket
self.ip = socket.gethostbyname(socket.gethostname())
def db_content(self):
'''
Return the data from the database
'''
return self.database_content
def refresh_content(self):
'''
Refresh the data from the database.
'''
self.get_database_tables()
self.db_content()
def get_database_tables(self):
'''
Extracts data from the database.
'''
myConnection = psycopg2.connect(host=hostname, user=username,
password=password, dbname=database,
port=port )
self.database_content = get_table_list(myConnection)
myConnection.close()
if __name__ == '__main__':
app = MainApp()
app.run()