-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.py
58 lines (38 loc) · 1.42 KB
/
general.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
import sqlite3
import os
import sys
basedir = os.path.dirname(__file__)
db_path = os.path.join(basedir, 'db.db')
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except:
base_path = os.path.abspath('.')
return os.path.join(base_path, relative_path)
def set_theme(theme):
con = sqlite3.connect(resource_path('db.db'))
cursor = con.cursor()
res = cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='theme'")
if res.fetchone() is None:
cursor.execute("CREATE TABLE theme(id INTEGER PRIMARY KEY NOT NULL, value TEXT)")
if cursor.execute("SELECT * FROM theme WHERE id=1").fetchone() is None:
cursor.execute(f"INSERT INTO theme (value) VALUES('{theme}')")
else:
cursor.execute(f"UPDATE theme SET value='{theme}' WHERE id=1")
con.commit()
con.close()
return theme
def get_theme():
con = sqlite3.connect(resource_path('db.db'))
cursor = con.cursor()
res = cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='theme'")
if res.fetchone() is None:
cursor.execute("CREATE TABLE theme(id INTEGER PRIMARY KEY NOT NULL, value TEXT)")
con.commit()
con.close()
return 'system'
res = cursor.execute("SELECT value FROM theme WHERE id=1")
value = res.fetchone()
if value is None:
return 'system'
return value[0]