-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyWids.py
153 lines (132 loc) · 5.35 KB
/
myWids.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
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.dropdown import DropDown
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.graphics import Color, Ellipse, Line
from kivy.uix.rst import RstDocument
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import *
from kivy.uix.popup import Popup
from functools import partial
from cost import *
from cPickle import load, dump
from datetime import *
from os.path import isfile
from functools import partial
class MyPopUp(Popup):
"""Make popups update App.popup """
def __init__(self,**kwargs):
super(Popup,self).__init__(**kwargs)
App.get_running_app().popup=self
def dismiss(self,*largs,**kwargs):
App.get_running_app().popup=None
super(Popup,self).dismiss()
class QuickAddBox(TextInput):
def __init__(self, **kwargs):
super(QuickAddBox, self).__init__(**kwargs)
self.on_touch_down=self.downClr
def downClr(self, touch):
if self.text=='Type the name of a previous entry..':
self.text=''
super(QuickAddBox, self).on_touch_down(touch)
else:
super(QuickAddBox, self).on_touch_down(touch)
def _keyboard_on_key_down(self, window, keycode, text, modifiers):
if self.text=='Type the name of a previous entry..':
self.text=''
super(QuickAddBox, self)._keyboard_on_key_down(
window, keycode, text, modifiers)
elif keycode[0]==13: self.addQuick(self.text)
else:
super(QuickAddBox, self)._keyboard_on_key_down(
window, keycode, text, modifiers)
def addQuick(self, item):
self.text=''
try:
cost=getLastInstance(App.get_running_app().d, item)
self.displaySuccess(cost)
except ValueError:
self.displayFailure()
def logIt(self, l, obj=None):
d=App.get_running_app().d
addComplete(d, l)
App.get_running_app().man.get_screen('view').refresh()
self.text=''
self.focus=False
def displaySuccess(self, cost):
cat=cost[:cost.find(';')].title()
name=cost[cost.find(';')+2:cost.rfind(':')].title()
price=cost[cost.rfind(':')+2:]
l=[name, price, cat]
pu=MyPopUp(title="Entry Found!", size_hint=(1,.75))
blo=BoxLayout(orientation='vertical', spacing="5dp")
lab=Label(text_size=pu.size, text='The following data were found:\n'+\
'Name: '+name+'\n'
'Price: '+price+'\n'
'Category: '+cat,valign='middle', halign='center')
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
blo.add_widget(lab)
backBtn=Button(text='Log it', size_hint=(1,.33))
backBtn.bind(on_press=lambda obj: self.logIt(l), on_release=pu.dismiss)
blo.add_widget(backBtn)
stayBtn=Button(text='Nope', size_hint=(1,.33))
stayBtn.bind(on_release=pu.dismiss)
blo.add_widget(stayBtn)
pu.content=blo
pu.open()
def displayFailure(self):
pu=MyPopUp(title="Failure..", size_hint=(1,.75))
blo=BoxLayout(orientation='vertical', spacing="5dp")
lab=Label(text_size=pu.size, text='There are no entries with that name\n'+\
'Check your input, or use the normal add function',
valign='middle', halign='center'
)
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
blo.add_widget(lab)
stayBtn=Button(text='OK', size_hint=(1,.33))
stayBtn.bind(on_release=pu.dismiss)
blo.add_widget(stayBtn)
pu.content=blo
pu.open()
class CostTextInput(TextInput):
next=ObjectProperty()
def _keyboard_on_key_down(self, window, keycode, text, modifiers):
if keycode[0] == 9 or keycode[0]==13: # 9 is the keycode for TAB
self.next.focus = True
else:
super(CostTextInput, self)._keyboard_on_key_down(
window, keycode, text, modifiers)
class SumNameIn(TextInput):
"""Exists for the sole purpose of item sum """
pu=None
def __init__(self, pu=None, **kwargs):
super(SumNameIn, self).__init__(**kwargs)
self.pu=pu
def _keyboard_on_key_down(self, window, keycode, text, modifiers):
if keycode[0]==13:
self.pu.dismiss()
else:
super(SumNameIn, self)._keyboard_on_key_down(window, keycode, text, modifiers)
class DateIn(TextInput):
nameMode=False
l=[]
def __init__(self, **kwargs):
super(DateIn, self).__init__(multiline=False,**kwargs)
def _keyboard_on_key_down(self, window, keycode, text, modifiers):
if self.nameMode and keycode[0]==13:
rms=App.get_running_app().man.get_screen('rm')
rms.actuallyRemoveEntry(self.l, self.text)
elif not self.nameMode and keycode[0]==13:
rms=App.get_running_app().man.get_screen('rm')
rms.removeDay(self.l)
else:
super(DateIn, self)._keyboard_on_key_down(
window, keycode, text, modifiers)