-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
89 lines (69 loc) · 2.61 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
import wx
import os
from config_manager import config
import sqlite3
from views import MainFrame
from utils import ApplicationUtil
import i18n
import builtins
builtins._ = i18n.t
def setup_translation():
locales_dir = os.path.join(ApplicationUtil.bundle_dir(), 'assets', 'locales')
i18n.load_path.append(locales_dir)
i18n.set("filename_format", "{locale}.{format}")
i18n.set("locale", config.get("APP", "language"))
i18n.set("enable_memoization", True)
def setup_locale():
config_language = config.get("APP", "language")
if config_language == "en":
wx.Locale(language=wx.LANGUAGE_ENGLISH_US)
elif config_language == "cn":
wx.Locale(language=wx.LANGUAGE_CHINESE_SIMPLIFIED)
if wx.Platform == "__WXMSW__":
import locale
if config_language == "en":
locale.setlocale(locale.LC_ALL, 'en-US.UTF-8')
elif config_language == "cn":
locale.setlocale(locale.LC_ALL, 'zh-CN.UTF-8')
def setup_db():
db_file_existed = os.path.exists(config.get('PATH', 'db_file'))
conn = sqlite3.connect(config.get("PATH", "db_file"))
cursor = conn.cursor()
if not db_file_existed:
with open(os.path.join(ApplicationUtil.bundle_dir(),'assets','sqlite_schema.sql'),'r',encoding='utf-8') as f:
schema_content = f.read()
cursor.executescript(schema_content)
conn.commit()
notebook_count = cursor.execute("SELECT count(*) FROM notebooks").fetchone()[0]
if not notebook_count:
cursor.execute("insert into notebooks(name, description) values(?,?)", (
_("notebook.initial_name"), _("notebook.initial_desc")))
conn.commit()
conn.close()
def link_images_dir():
note_images_link = os.path.join("assets", "text_editor", "note_images")
current_note_images_path = str(os.path.realpath(note_images_link))
real_note_images_path = config.get("PATH", "images_dir")
if not os.path.exists(note_images_link) or current_note_images_path != real_note_images_path:
os.system(f"ln -sfn '{real_note_images_path}' '{note_images_link}'")
def sync_notes():
print("sync notes...")
if config.getboolean("APP", "git_sync"):
data_dir = config.get("PATH", "data_dir")
git_clone = f"cd \"{data_dir}\" && git pull"
print(git_clone)
os.system(git_clone)
class App(wx.App):
def OnInit(self):
setup_locale()
setup_translation()
setup_db()
link_images_dir()
sync_notes()
return True
if __name__ == "__main__":
app = App(False)
frame = MainFrame()
frame.Show()
app.SetTopWindow(frame)
app.MainLoop()