-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
99 lines (73 loc) · 2.51 KB
/
main.py
File metadata and controls
99 lines (73 loc) · 2.51 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
#python3
#main.py
import kivy, openpyxl, os, datetime
kivy.require('1.11.1')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
from kivy.properties import NumericProperty, ObjectProperty, StringProperty
from kivy.factory import Factory
from kivy.uix.popup import Popup
# Widget for the window itself
class CylinderTask(GridLayout):
# Setup property variables for right, left, both
right = NumericProperty(0)
left = NumericProperty(0)
both = NumericProperty(0)
animal = StringProperty('')
trial = StringProperty('')
trialCode = StringProperty('')
def process(self):
self.animal = self.ids['animalBox'].text
self.trial = self.ids['trialBox'].text
self.trialCode = '%s%s' % (self.animal, self.trial)
def completeTrial(self):
results = (self.right, self.left, self.both)
print('Trial Complete')
print(results)
print(self.trialCode)
fName = '%s.xlsx' % self.trialCode
wb = openpyxl.Workbook()
ws = wb.active
ws.title = self.trialCode
ws['a1']= 'Right:'
ws['b1']= self.right
ws['a2']= 'Left:'
ws['b2']= self.left
ws['a3']= 'Both:'
ws['b3']= self.both
ws['a4']= datetime.datetime.today()
wb.save(filename = 'results/%s' % fName)
wb.close()
def __init__(self, **kwargs):
super(CylinderTask, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(
self._keyboard_closed, self, 'text')
if self._keyboard.widget:
# If it exists, this widget is a VKeyboard object which you can use
# to change the keyboard layout.
pass
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def _keyboard_closed(self):
pass
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
key = keycode[1]
if key == 'left':
self.left += 1
if key == 'right':
self.right += 1
if key == 'up':
self.both += 1
if key == 'down':
self.left, self.right, self.both = 0, 0, 0
if key == 'enter':
self.completeTrial()
class CylinderTaskApp(App):
def build(self):
task = CylinderTask()
return task
if __name__=='__main__':
CylinderTaskApp().run()