-
Notifications
You must be signed in to change notification settings - Fork 8
/
LD.py
116 lines (99 loc) · 3.68 KB
/
LD.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
import os.path
import appdirs
import files
from menuclass import *
class LoadMenu(Menu):
def __init__(self, process):
super().__init__(process, "LD")
datadir = appdirs.user_data_dir("RWE+", "timofey26", roaming=True)
recentfile = os.path.join(datadir, "recentProjects.json")
if not os.path.exists(recentfile):
os.makedirs(datadir, exist_ok=True)
open(recentfile, "w").write("{ \"files\": [] }")
self.recent = json.load(open(recentfile, "r"))
self.filedata = {}
self.selector = widgets.Selector(self, self.generate_data(), "s1")
self.selector.callback = self.selectorset
self.selector.callbackafterchange = False
def selectorset(self, buttondata):
self.owner.__init__(self.owner.manager, buttondata["path"])
def generate_data(self) -> ItemData:
data = ItemData()
items = []
for i in self.recent["files"][:20]:
if not os.path.exists(i["path"]):
continue
desc = f'Path: {i["path"]}\nLast modified: {filetime(i["path"])}'
items.append({
"nm": i["name"],
"color": color2,
"description": desc,
"path": i["path"]
})
data.append({"name": "Recent files", "color": gray, "items": items})
weps = []
txts = []
wepcount = 0
weppage = 1
txtcount = 0
txtpage = 1
for root, dirs, files in os.walk(path2levels):
for i, file in enumerate(files):
fpath = os.path.join(root, file)
if not os.path.exists(fpath):
continue
desc = f'Path: {fpath}\nLast modified: {filetime(fpath)}'
_, ext = os.path.splitext(file)
dat = {
"nm": file,
"color": gray,
"description": desc,
"path": fpath
}
if ext.lower() == ".wep":
weps.append(dat)
wepcount += 1
if wepcount > globalsettings["recent_items_per_category"]:
data.append({"name": f"All .wep files p{weppage}", "color": gray, "items": weps})
weps = []
weppage += 1
wepcount = 0
elif ext.lower() == ".txt":
txts.append(dat)
txtcount += 1
if txtcount > globalsettings["recent_items_per_category"]:
data.append({"name": f"All .txt files p{txtpage}", "color": gray, "items": txts})
txts = []
txtpage += 1
txtcount = 0
data.append({"name": f"All .wep files p{weppage}", "color": gray, "items": weps})
data.append({"name": f"All .txt files p{txtpage}", "color": gray, "items": txts})
return data
def resize(self):
super().resize()
if hasattr(self, "selector"):
self.selector.resize()
def blit(self):
self.selector.blit()
super().blit()
self.selector.blittooltip()
def tutorial(self):
tutorial()
def open(self):
self.sendtoowner("open")
def new(self):
self.sendtoowner("new")
def report(self):
report()
def github(self):
github()
def lt(self):
self.selector.left()
def rt(self):
self.selector.right()
@property
def touchesanything(self):
return super().touchesanything or self.selector.touchesanything
@property
def custom_info(self):
return "Have fun!"