-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenz.py
392 lines (355 loc) · 14.6 KB
/
screenz.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
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.graphics import *
from kivy.lang import Builder
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
from myWids import *
from kivy.graphics import Rectangle
class QuickAddScreen(Screen):
qab=ObjectProperty()
sub_btn=ObjectProperty()
det_btn=ObjectProperty()
back_btn=ObjectProperty()
prev='main'; prevTrans='left'
class RMScreen(Screen):
log=ObjectProperty()
lab=ObjectProperty()
date_bx=ObjectProperty()
day_btn=ObjectProperty()
ent_btn=ObjectProperty()
cancel=ObjectProperty()
prev='help'; prevTrans='down'
def dayBtnPush(self, obj):
if not self.date_bx.nameMode: self.removeDay(obj)
def entBtnPush(self, obj):
if not self.date_bx.nameMode: self.removeEntry(obj)
def __init__(self, **kwargs):
super(RMScreen, self).__init__(**kwargs)
self.day_btn.bind(on_release=self.dayBtnPush)
self.ent_btn.bind(on_release=self.entBtnPush)
self.genlog()
def reset(self):
self.date_bx.text=date.today().strftime('%B %d %Y')
self.genlog()
self.lab.text="What day has the problem?\n"+\
"(RET to delete entire day)"
self.date_bx.nameMode=False
def genlog(self):
self.log.text=printAll(App.get_running_app().d, True)
def removeEntry(self, obj):
"""Change display to 1 day, clear text in, change label to ask which entry """
self.date_bx.l=str(self.date_bx.text).split(' ')
try:
self.log.text=printDay(App.get_running_app().d, self.date_bx.l, False)
self.lab.text='What is the name of the entry you wish to remove?'+\
'\n(RET to submit)'
self.date_bx.nameMode=True
self.date_bx.text=''
except KeyError, ValueError:
self.dayNotFound()
def actuallyRemoveEntry(self, l, text):
l=[s.title() for s in l]
try:
remove(App.get_running_app().d, l, text)
self.rmSuccess(True)
self.reset()
except KeyError:
self.dayNotFound()
except ValueError:
self.entryNotFound()
def entryNotFound(self):
pu=MyPopUp(title="Failure..", size_hint=(1,.75))
blo=BoxLayout(orientation='vertical', spacing="5dp")
lab=Label(text_size=pu.size, text='There is no record for that entry\n'+\
'Check your input', valign='middle', halign='center')
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
blo.add_widget(lab)
backBtn=Button(text='Go Back', size_hint=(1,.33))
backBtn.bind(on_press=self.toHelp, on_release=pu.dismiss)
blo.add_widget(backBtn)
stayBtn=Button(text='Stay Here', size_hint=(1,.33))
stayBtn.bind(on_release=pu.dismiss)
blo.add_widget(stayBtn)
pu.content=blo
pu.on_dismiss=self.reset
pu.open()
def dayNotFound(self):
pu=MyPopUp(title="Failure..", size_hint=(1,.75))
blo=BoxLayout(orientation='vertical', spacing="5dp")
lab=Label(text_size=pu.size, text='There is no record for that day\n'+\
'Check Help->Input Help for acceptable date formats', halign='center', valign='middle')
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
blo.add_widget(lab)
backBtn=Button(text='Go Back', size_hint=(1,.33))
backBtn.bind(on_press=self.toHelp, on_release=pu.dismiss)
blo.add_widget(backBtn)
stayBtn=Button(text='Stay Here', size_hint=(1,.33))
stayBtn.bind(on_release=pu.dismiss)
blo.add_widget(stayBtn)
pu.content=blo
pu.on_dismiss=self.reset
pu.open()
def rmSuccess(self, entry=False):
pu=MyPopUp(title="Success!", size_hint=(1,.75))
blo=BoxLayout(orientation='vertical', spacing="5dp")
lab=Label(text=('Day' if not entry else 'Entry')+\
' removed successfully',halign='center', valign='middle')
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
blo.add_widget(lab)
backBtn=Button(text='Go Back', size_hint=(1,.33))
backBtn.bind(on_press=self.toHelp, on_release=pu.dismiss)
blo.add_widget(backBtn)
stayBtn=Button(text='Stay Here', size_hint=(1,.33))
stayBtn.bind(on_release=pu.dismiss)
blo.add_widget(stayBtn)
pu.content=blo
pu.on_dismiss=self.reset
pu.open()
def removeDay(self, obj=None):
l=str(self.date_bx.text).split(' ')
try:
rmday(App.get_running_app().d, l)
dump(App.get_running_app().d, open(App.get_running_app().fName, 'wb'))
self.genlog()
self.rmSuccess()
except KeyError:
self.dayNotFound()
def toHelp(self, obj):
self.reset()
self.manager.transition=SlideTransition(direction="down")
self.manager.current='help'
class InputScreen(Screen):
doc=ObjectProperty()
prev='help';prevTrans='right'
def __init__(self, **kwargs):
super(InputScreen, self).__init__(**kwargs)
self.doc.source='help.rst'
def toHelp(self, obj=None):
self.manager.transition=SlideTransition(direction="right")
self.manager.current='help'
def toMain(self, obj=None):
self.manager.transition=SlideTransition(direction="down")
self.manager.current='main'
class BkdwnScreen(Screen):
rst=ObjectProperty()
mo_btn=ObjectProperty()
wk_btn=ObjectProperty()
at_btn=ObjectProperty()
prev='anlz';prevTrans= 'left'
def __init__(self, **kwargs):
super(BkdwnScreen, self).__init__(**kwargs)
self.rst.text=breakdown(App.get_running_app().d)
self.mo_btn.on_release=partial(breakdown,\
App.get_running_app().d, 30, self.rst)
self.wk_btn.on_release=partial(breakdown,\
App.get_running_app().d, 7, self.rst)
self.at_btn.on_release=partial(breakdown,\
App.get_running_app().d, -1, self.rst)
class TotScreen(Screen):
title=ObjectProperty()
tots=ObjectProperty()
top_title=ObjectProperty()
tops=ObjectProperty()
grd=ObjectProperty()
wk_btn=ObjectProperty()
mo_btn=ObjectProperty()
at_btn=ObjectProperty()
prev= 'anlz'; prevTrans='up'
def __init__(self, **kwargs):
super(TotScreen, self).__init__(**kwargs)
self.displayATTops()
self.tots.text=self.displayTots()
def displayATTops(self):
self.top_title.text='Top Items (All Time)'
d=App.get_running_app().d
l=getTopNames(d, True)
s=''
for i in range(len(l)):
s+=str(i+1)+'. '+l[i]+' ('+sumItem(d,l[i])+')'+'\n'
self.tops.text= s
def displayMOTops(self):
self.top_title.text='Top Items (This Month)'
d=App.get_running_app().d
l=getTopNames(d, True, 30)
s=''
for i in range(len(l)):
s+=str(i+1)+'. '+l[i]+' ('+sumItem(d,l[i], 30)+')'+'\n'
self.tops.text=s
def displayWKTops(self):
self.top_title.text='Top Items (This Week)'
d=App.get_running_app().d
l=getTopNames(d, True, 7)
s=''
for i in range(len(l)):
s+=str(i+1)+'. '+l[i]+' ('+sumItem(d,l[i],7)+')'+'\n'
self.tops.text=s
def displayTots(self):
d=App.get_running_app().d
s='Daily total '+sumTime(d, 1)+'\n'
s+='Weekly total '+sumTime(d, 7)+'\n'
s+='Monthly total '+sumTime(d, 30)
return s
def itemSum(self):
textl=['herp'] # stupid trick
pu=MyPopUp(title='Which?', size_hint=(1,.75))
lay=BoxLayout(orientation='vertical')
lab=Label(text_size=pu.size, text='Which item do you want to get totals for?', halign='center', valign='middle')
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
txi=SumNameIn(pu, multiline=False)
btn=Button(text='Submit', on_release=pu.dismiss)
lay.add_widget(lab)
lay.add_widget(txi)
lay.add_widget(btn)
pu.content=lay
pu.on_dismiss=lambda: self.actuallyItemSum(txi.text)
pu.open()
def actuallyItemSum(self, name):
t=float(sumItem(App.get_running_app().d, name)[1:])
s='Amount spent on '+name+' this week: '+sumItem(App.get_running_app().d, name, 7)+'\n'
s+='This month: '+sumItem(App.get_running_app().d, name, 30)+'\n'
s+='All time: '+sumItem(App.get_running_app().d, name)+'\n'
pu=MyPopUp(title='Totals', size_hint=(1,.75))
lay=BoxLayout(orientation='vertical')
lab=Label(text_size=pu.size, text=(s if t>0 else 'There is no record of any entry with that name.\nTry again' ),\
halign='center',valign='middle')
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
btn=Button(text='OK', on_release=pu.dismiss, size_hint_y=.3)
lay.add_widget(lab)
lay.add_widget(btn)
pu.content=lay
pu.open()
def reset(self):
self.displayATTops()
self.tots.text=self.displayTots()
def gotoMain(self, obj):
self.manager.current='main'
class AddScreen(Screen):
name_box=ObjectProperty()
price_box=ObjectProperty()
date_box=ObjectProperty()
cat_box=ObjectProperty()
save=ObjectProperty()
prev='qadd';prevTrans='left'
def print_data(self):
d=App.get_running_app().d
l=[]
l+=self.date_box.text.split(' '); self.date_box.text=date.today().strftime('%B %d %Y')
l+=[str(self.name_box.text.strip())]; self.name_box.text=''
l+=[str(self.price_box.text.strip())]; self.price_box.text=''
l+=[str(self.cat_box.text.strip()) if str(self.cat_box.text.strip())!='' else 'Misc.']; self.cat_box.text=''
try:
addComplete(d,l)
App.get_running_app().man.get_screen('view').refresh()
return True
except:
pu=MyPopUp(title='Input Error', size_hint=(1,.75), auto_dismiss=False)
App.get_running_app().popup=pu
label=Label(text_size=pu.size,
text='Something seems to be wrong with your input.\nCheck help if you\'re unsure what\'s wrong.',
halign='center',valign='middle')
label.bind(size=label.setter('text_size'))
label.size_hint=(1,1)
disBtn=Button(text='OK', size_hint=(1,.4))
disBtn.bind(on_release=lambda disBtn: pu.dismiss(disBtn))
puLO=BoxLayout(orientation='vertical')
puLO.add_widget(label); puLO.add_widget(disBtn);
pu.content=puLO
pu.open()
return False
class ViewScreen(Screen):
log=ObjectProperty()
check=ObjectProperty()
prev='main' ; prevTrans='right'
def __init__(self,**kwargs):
super(ViewScreen,self).__init__(**kwargs)
self.check.bind(active=self.on_checkbox_activate)
self.logs=printAllTup(App.get_running_app().d)
def reload(self):
self.log.text=self.logs[1 if self.check.active else 0]
def refresh(self):
"""Recalculate view screen. Call when something has changed. """
self.logs=printAllTup(App.get_running_app().d)
def on_checkbox_activate(self, cb, val):
self.reload()
class AnlzScreen(Screen):
prev='main'; prevTrans='up'
class MainScreen(Screen):
prev='main'; prevTrans='left'
lo=ObjectProperty()
viewbtn=ObjectProperty()
def __init__(self, **kwargs):
super(MainScreen,self).__init__(**kwargs)
if App.get_running_app().firstRun: Clock.schedule_once(self.firstRun, .1)
def _update_bkgd(self, instance, value):
self.bkgd.pos=instance.pos
self.bkgd.size=instance.size
def firstRun(self, obj):
pu=MyPopUp(size_hint=(1, .6), title='Welcome to Cost!')
lo=BoxLayout(orientation='vertical')
lab=Label(text="Hi! Cost is a program designed to help you track and "+\
"understand where your money is going. We've provided you with a one-month "+\
"example record so that you can explore some of the analysis features. "+\
"When you think you get the idea go to Help->Clear Record from the main screen "+\
"and hit OK at the prompt. Enjoy, and remember that this tool will only help you "
"if you record every expense, no matter how minor. Those $2.11 coffees add up ;)", valign='middle', halign='center')
lab.bind(size=lab.setter('text_size'))
lab.size_hint=(1,1)
btn=Button(text='Got it', on_release=pu.dismiss, size_hint_y=.25)
lo.add_widget(lab)
lo.add_widget(btn)
pu.content=lo
lab.text_size=lab.size
print lab.size
pu.open()
class HelpScreen(Screen):
prev='main' ; prevTrans='down'
clearPU=None
def clearRecord(self):
s ="Are you sure about this? This action will remove your"
s+="record as it is. It will be saved as /sdcard/cost/cost_backup."
s+="If you want to restore it, you will have to rename that file to"
s+="cost_save manually, and as of now there is no way to merge records"
s+="Of course, if you're just removing the example and want to get"
s+="started, go right ahead"
pu=MyPopUp(size_hint=(.8, .6), title='Are you sure?')
self.clearPU=pu
lo=BoxLayout(orientation='vertical')
lab=Label(text=s,halign='center',valign='middle')
btn1=Button(text='Do it', on_release=self.doIt, size_hint_y=.25)
btn2=Button(text='On second thought...', on_release=pu.dismiss, size_hint_y=.25)
lo.add_widget(lab)
lo.add_widget(btn1)
lo.add_widget(btn2)
pu.content=lo
pu.open()
def reset(self):
"""Don't ask """
pass
def doIt(self, obj):
dump(App.get_running_app().d, open(App.get_running_app().user_data_dir+'/cost_backup', 'wb'))
App.get_running_app().d={}
App.get_running_app().save()
self.clearPU.dismiss()