-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
187 lines (151 loc) · 5.86 KB
/
main.py
File metadata and controls
187 lines (151 loc) · 5.86 KB
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
# Main file. Manages ActionBar, universal popups, time, screen manager, etc
from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.actionbar import ActionBar
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager
from kivy.properties import StringProperty, ListProperty, ObjectProperty, BooleanProperty, NumericProperty
from kivy.core.window import Window
from kivy.uix.widget import Widget
#import pyjnius
from time import localtime, strftime
import datetime
from subprocess import call
from classes.FlappyBird import FlappyBirdApp
from classes.data_manager import DataManager
from classes.blood_glucose_tester import BloodGlucoseTester
from classes.data_screen import DataScreen
from classes.home_screen import HomeScreen
from classes.bg_screen import BGScreen
from classes.settings_screen import SettingsScreen
from classes.extras_screen import ExtrasScreen
#from classes import settings
homescreen = HomeScreen(name='home')
datascreen = DataScreen(name='data')
bgscreen = BGScreen(name='bgtest')
settingsscreen = SettingsScreen(name='settings')
extrasscreen = ExtrasScreen(name='extras')
class NewEntryPopup(Popup):
def __init__(self, **kwargs):
self.date = datetime.datetime.now()
self.dm = DataManager()
super(NewEntryPopup, self).__init__(**kwargs)
def get_date(self):
return self.date.strftime('%Y-%m-%d')
def get_time(self):
return self.date.strftime('%H:%M')
def submit(self):
ids = self.ids
time = ids.time.text
date = ids.date.text
bg = ids.bg.text
carbs = ids.carbs.text
bolus = ids.bolus.text
notes = ids.notes.text
if time != '' and date != '' and (bg != '' or carbs != '' or bolus != '' or notes != ''):
if bg == '':
bg = 0
if carbs == '':
carbs = 0
if bolus == '':
bolus = 0
if notes == '':
notes = ' '
datetime = date + ' ' + time
self.dm.new_entry(datetime, bg, carbs, bolus, notes)
Clock.schedule_once(datascreen.refresh, 2)
self.dismiss()
class CustomScreenManager(ScreenManager):
screen_ids = ['bgtest', 'data', 'settings', 'extras']
screen_names = ['BG test', 'Data', 'Settings', 'Extras']
def __init__(self, **kwargs):
super(CustomScreenManager,self).__init__(**kwargs)
self.add_widget(homescreen)
self.add_widget(datascreen)
self.add_widget(bgscreen)
self.add_widget(settingsscreen)
self.add_widget(extrasscreen)
class Glucometer(App):
test = StringProperty('test')
screen_names = CustomScreenManager.screen_names
screen_ids = CustomScreenManager.screen_ids
width, height = Window.size
def __init_(self, **kwargs):
super(Glucometer, self).__init__(**kwargs)
def build(self):
self.root.ids.spnr.text = "Home"
def refresh_data_screen(self):
datascreen.refresh()
def flappy(self):
FlappyBirdApp().run()
def set_previous(self, screen_id):
# sm = self.root.ids.sm
if self.root and screen_id != 'home':
self.root.ids.previousid.with_previous = True
#print self.root.ids.previousid.with_previous
elif self.root:
self.root.ids.previousid.with_previous = False
def set_time(self, dt):
Clock.schedule_once(self.set_time, 30)
today = datetime.datetime.now()
hour = today.hour
minute = today.minute
if today.hour > 12:
hour = today.hour - 12
if minute < 10:
minute = '0' + str(minute)
time = "%s %s %s:%s" % (today.strftime('%B')[:3], today.day, hour, minute)
if self.root:
self.root.ids.previousid.title = time
return time
def set_screen(self):
sm = self.root.ids.sm
#print sm.current_screen.name
for i in xrange(0,len(self.screen_names)):
if self.screen_names[i] == self.root.ids.spnr.text:
sm.transition.direction = 'left'
sm.current = self.screen_ids[i]
self.set_previous(self.screen_ids[i])
break;
def open_new_entry_popup(self):
popup = NewEntryPopup()
popup.open()
def on_pause(self):
return True
class MyKeyboardListener(Widget):
def __init__(self, **kwargs):
super(MyKeyboardListener, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(
self._keyboard_closed, self, 'text')
if self._keyboard.widget:
print type(self._keyboard.widget)
print type(self._keyboard)
vkeyboard = self._keyboard.widget
vkeyboard.layout = 'numeric.json'
# If it exists, this widget is a VKeyboard object which you can use
# to change the keyboard layout.
else:
print 'tru'
print 'tru'
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def _keyboard_closed(self):
print('My keyboard have been closed!')
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard = None
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
print('The key', keycode, 'have been pressed')
print(' - text is %r' % text)
print(' - modifiers are %r' % modifiers)
# Keycode is composed of an integer + a string
# If we hit escape, release the keyboard
if keycode[1] == 'escape':
keyboard.release()
# Return True to accept the key. Otherwise, it will be used by
# the system.
return True
Glucometer().run()