-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
132 lines (124 loc) · 4.41 KB
/
main.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
from kivy.config import Config
from kivy.app import App
from kivy.clock import *
from kivy.core.window import Window
from kivy.uix.screenmanager import *
from kivy.logger import Logger
import kivy.metrics
from includes.Today import *
from includes.History import *
from includes.Report import *
from includes.DB import *
from includes.Controls.MyScreenManager import MyScreenManager
from json import *
from array import array
from datetime import date
import re
import sys
import os
import platform
import subprocess
from kivy.uix.textinput import TextInput
class DaytimeLogApp(App):
todayView=None
historyView=None
reportView=None
dataBase=None
screenManager=None
keyboard=None
sysArgs={}
def ViewInit(self):
self.todayView=TodayView('todayView',self.sysArgs)
self.historyView=HistoryView('historyView',self.sysArgs)
self.reportView=ReportView('reportView',self.sysArgs)
#Set auto save
#autoSave=Clock.schedule_interval(self.SaveLog,1800)
#Set Menu
self.screenManager.add_widget(self.todayView)
self.screenManager.add_widget(self.historyView)
self.screenManager.add_widget(self.reportView)
Logger.info('SYS_INFO: window size, %d, %d'%(Window.width, Window.height))
def resize(*args):
self.todayView.resize()
self.historyView.resize()
self.reportView.resize()
Window.bind(on_resize=resize)
def SysInit(self):
BASEPATH=''
userSystem=platform.system()
Logger.info('SYS_INFO: system %s'%str(platform.uname()))
if userSystem=='Window':
pass
elif userSystem=='Linux' :#and re.search('arm',platform.machine())!=None:
#basepath
if getattr( sys, 'frozen', False ) :
BASEPATH=os.path.dirname(sys.executable)+'/'
else :
BASEPATH=''
self.sysArgs['BASEPATH']=BASEPATH
#filepath
self.sysArgs['FILEPATH']=os.path.abspath('..')+'/'
#size
self.sysArgs['WIDTH']=Window.width
self.sysArgs['HEIGHT']=Window.height
#open shortcut
self.sysArgs['DESKTOP']=False
#keyboard mode
Window.softinput_mode='below_target'
else:#elif userSystem=='Darwin':
#basepath
if getattr( sys, 'frozen', False ) :
BASEPATH=os.path.dirname(sys.executable)+'/'
else :
BASEPATH=''
self.sysArgs['BASEPATH']=BASEPATH
#file path
filepath=os.path.expanduser('~')+'/.DaytimeLog'
if not os.path.exists(filepath):
os.mkdir(filepath)
self.sysArgs['FILEPATH']=filepath+'/'
#window size
Window.size=375,667
self.sysArgs['WIDTH']=kivy.metrics.dp(375)
self.sysArgs['HEIGHT']=kivy.metrics.dp(667)
#open shortcut
self.sysArgs['DESKTOP']=True
Logger.info('SYS_INFO: shortcut %s'%str(self.sysArgs['DESKTOP']))
#database
self.dataBase=DBDaytimeLog(self.sysArgs['FILEPATH'])
self.sysArgs['DB']=self.dataBase
#ScreenManager
self.screenManager=MyScreenManager(transition=NoTransition())
self.sysArgs['SM']=self.screenManager
#window
self.sysArgs['WINDOW']=Window
#config file
Config.read(BASEPATH+'includes/config.ini')
#config logs
Config.set('kivy','log_dir',self.sysArgs['FILEPATH'])
#config logo
#Config.set('kivy','window_icon', BASEPATH+'includes/icons/DaytimeLog.png')
self.icon='includes/icons/DaytimeLog.png'
#keyboard
#Window.keyboard_on_key_down=
def TaskInit(self):
#in suppose that you use the app today and still open it tommorrow
Window.bind(on_cursor_enter=self.RefreshContent)
#when request close
Window.bind(on_request_close=self.screenManager.OnLeaving)
#listen to shortcut
#self.screenManager.RequestKeyboard()
#AutoSave
def RefreshContent(self,*args):
self.todayView.Refresh()
def build(self):
self.SysInit()
self.ViewInit()
self.TaskInit()
#self.screenManager.current='reportView'
return self.screenManager
if __name__=='__main__':
try:
DaytimeLogApp().run()
except:
Logger.critical('crashed',exc_info=True,stack_info=True)