-
Notifications
You must be signed in to change notification settings - Fork 1
/
screenmanager.py
164 lines (132 loc) · 4.67 KB
/
screenmanager.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
import kivy
import codecs
kivy.require('1.8.0')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.progressbar import ProgressBar
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.dropdown import DropDown
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.clock import Clock
from kivy.uix.textinput import TextInput
u = codecs.open('users.txt', 'r', 'utf-8')
users = u.read().splitlines()
#print users
u.close()
sel_user = ''
sel_test = ''
class TestScreen(Screen):
def recordTest(self, testname):
sel_test = testname
#we are friends, and friendship is forever
class UserScreen(Screen):
def __init__(self, **kwargs):
super(UserScreen, self).__init__(**kwargs)
self.createMenu()
self.createMenu()
def recordUser(self):
sel_user = self.mainbutton.text
def refresh(self):
self.createMenu()
def createMenu(self):
d = DropDown()
for user in users:
btn = Button(text=str(user), size_hint_y=None, height=35)
btn.bind(on_press=lambda btn: d.select(btn.text))
d.add_widget(btn)
self.mainbutton = Button(text="Select User", size_hint=[.4, .05], pos_hint={'x': .3, 'y': .5})
self.mainbutton.bind(on_release=d.open)
d.bind(on_select=lambda d, x: setattr(self.mainbutton, 'text', x))
self.add_widget(self.mainbutton)
class ResultsLabel(Label):
def __init__(self, filename, *args, **kwargs):
super(ResultsLabel, self).__init__(*args, **kwargs)
f = open(filename, 'r')
text = ''
for line in f:
text += str(line)
f.close()
self.bind(text_size=self.setter("size"))
self.size=self.texture_size
self.text_size=app.width, app.height
self.text=text
self.halign='center'
self.valign='middle'
class InstructionLabel(Label):
def __init__(self, *args, **kwargs):
super(InstructionLabel, self).__init__(*args, **kwargs)
self.bind(text_size=self.setter("size"))
self.size=self.texture_size
self.text_size=1500, 1500
self.halign='center'
self.valign='middle'
class ResultsPopUp(Popup):
def __init__(self, **kwa):
super(ResultsPopUp, self).__init__(**kwa)
layout = BoxLayout(orientation='vertical')
b = Button(text='Close', size_hint=[.2, .075],
pos_hint={'x':.4, 'y':.5})
l = ResultsLabel('directions.txt')
layout.add_widget(l)
layout.add_widget(b)
self.popup = Popup(title='Results', content=layout)
b.bind(on_press=self.popup.dismiss)
def show(self):
self.popup.open()
class ProgressBarScreen(Screen):
progress_bar = ObjectProperty()
def __init__(self, **kwa):
super(ProgressBarScreen, self).__init__(**kwa)
self.progress_bar = ProgressBar()
self.popup = Popup(
title='Running, Do Not Exit',
content=self.progress_bar
)
self.popup.bind(on_open=self.puopen)
layout = BoxLayout(orientation='horizontal', size_hint=[.5, .1],
pos_hint={'x':.5, 'y':0})
layout.add_widget(Button(text='Run Current Test', on_release=self.pop))
layout2 = BoxLayout(orientation='vertical', size_hint=[1, .9],
pos_hint={'x':0, 'y':.1})
layout2.add_widget(Label(text='Here are the instructions'))
f = open('directions.txt', 'r')
n = 0
for line in f:
n += 1
layout2.add_widget(InstructionLabel(text='#' + str(n) + '. ' + str(line)))
f.close()
self.add_widget(layout)
self.add_widget(layout2)
def pop(self, instance):
self.progress_bar.value = 1
self.popup.open()
def next(self, dt):
self.progress_bar.value += 1
def puopen(self, instance):
while self.progress_bar.value<100:
Clock.schedule_once(self.next, 5)
self.progress_bar.value += 1
if self.progress_bar.value>=100:
self.popup.dismiss()
ResultsPopUp().show()
class CreateNewUserScreen(Screen):
def createNewUser(self, string):
users.append(string)
u_w = codecs.open('users.txt', 'w', 'utf-8')
for x in users:
x = x + '\n'
u_w.write(x)
class ScreenManagement(ScreenManager):
pass
app = Builder.load_file("tests.kv")
class TestApp(App):
def build(self):
return app
if __name__ == '__main__':
TestApp().run()