-
Notifications
You must be signed in to change notification settings - Fork 1
/
Askopenfolder.py
162 lines (123 loc) · 4.35 KB
/
Askopenfolder.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
import polyscope as ps
import polyscope.imgui as psim
import os
import getpass
import platform
SYSTEM = platform.uname().system
class Askopenfolder:
Memberlist = []
def __init__(self, name, formats, loadingfunction, mode):
self.mode = mode
self.name = name
self.loadingfunction = loadingfunction
self.FileOptions=formats
self.FileOptions_selected = self.FileOptions[0]
self.changed= False
self._is_active = False
self._is_done = False
self.locations = self.listinghomedirectory()
if SYSTEM=="Linux":
self.externallocations = self.listingadditionaldrives()
self.cwd = os.getcwd()
self.typing1=self.cwd
self.typing2="Hello"
self.NewFolderActive = False
self.newfoldername = "Hello World"
self.fileexistwarningwindow_active = False
self.fileitem = None
Askopenfolder.Memberlist.append(self)
def set_active(self, a_bool: bool):
for mem in Askopenfolder.Memberlist:
mem._is_active = False
self._is_active = a_bool
def get_active(self):
return self._is_active
def set_done(self, a_bool :bool):
self._is_done = a_bool
def get_done(self):
return self._is_done
def currentlist(self):
currentlist = os.listdir(self.cwd)
#print(currentlist)
for item in currentlist:
if os.path.isdir(item) and item[0] != ".":
psim.TextUnformatted('[Dir] '+ item)
if(psim.IsItemClicked(0)):
try:
os.chdir(item)
except PermissionError:
ps.warning("Access denied!")
self.cwd = os.getcwd()
self.typing1 = os.getcwd()
def listinghomedirectory(self):
dir = os.getcwd()
os.chdir(os.path.expanduser("~"))
dirlist = os.listdir()
dirs = []
for item in dirlist:
if os.path.isdir(item) and item[0] != ".":
dirs.append(item)
os.chdir(dir)
return dirs
def listingadditionaldrives(self):
dir = os.getcwd()
os.chdir(os.path.abspath(os.sep))
user = getpass.getuser()
os.chdir("media/"+user)
externallocs = os.listdir()
os.chdir(dir)
return externallocs
def askopenfile(self):
psim.SetNextWindowPos((550, 200))
psim.BeginChild(2, (500, 500))
psim.EndChild()
psim.SetNextWindowSize((900, 535))
psim.Begin(self.name, True)
psim.PushItemWidth(714)
psim.BeginGroup()
if(psim.ArrowButton('Up', 0)):
os.chdir('..')
self.cwd = os.getcwd()
self.typing1 = self.cwd
psim.SameLine()
if(self.typing1.startswith("/media/"+getpass.getuser())):
self.typing1 = self.typing1[len("/media/"+getpass.getuser())+1:]
_, self.typing1 = psim.InputText("L", self.typing1)
psim.SameLine()
psim.EndGroup()
psim.PopItemWidth()
psim.BeginChildFrame(4, (200, 400), 3)
for loc in self.locations:
psim.TextUnformatted(loc)
if(psim.IsItemClicked(0)):
os.chdir(os.path.expanduser("~"))
os.chdir(loc)
self.cwd = os.getcwd()
self.typing1 = self.cwd
if SYSTEM=="Linux":
for loc in self.externallocations:
psim.TextUnformatted(loc)
if(psim.IsItemClicked(0)):
os.chdir("/media/"+getpass.getuser()+"/"+loc)
self.cwd = os.getcwd()
self.typing1 = loc
psim.EndChildFrame()
psim.SameLine()
psim.BeginChildFrame(3,(685, 400), 2)
self.currentlist()
psim.EndChildFrame()
psim.PushItemWidth(815)
if(psim.Button("Open")):
try:
self._is_active = False
self.loadingfunction(self.typing2)
except TypeError:
ps.error("You did not select an item!")
psim.PopItemWidth()
psim.PushItemWidth(799)
_, self.typing2 = psim.InputText("N", self.typing2)
psim.SameLine()
if(psim.Button("Quit", size=(65, 25))):
self._is_active = False
psim.PopItemWidth()
psim.End()