-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpowlite_fm.py
254 lines (244 loc) · 10.4 KB
/
powlite_fm.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#-*- encoding:utf-8 -*-
'''name:powlite_fm
文件管理模块,支持触屏
by爱不只是说说
2011/07/01
'''
cn = lambda x:x.decode('u8')
class manager:
__name__ == 'powlite_fm'
def __init__(s, filepath=None):
import os
import appuifw
try:
import cfileman
s.CF = cfileman.FileMan()
s.EA, s.ES = cfileman.EAttMatchMask, cfileman.ESortByName
except:s.CF = None
s.A, s.E, s.O = appuifw, appuifw.e32, os
s.lock = s.E.Ao_lock()
s.path = None
if type(filepath) == unicode:
filepath = filepath.encode('u8')
s.filepath = filepath
del filepath
def main(s, __Listing=[]):
if s.path:
s.A.app.title=cn(s.path)
else:
s.A.app.title=cn('文件管理')
seat = s.A.selection_list(__Listing, 1)
if seat <> None:
if seat == 0:
if __Listing[0] == u'<<<':
s.path = s.path[:-len(s.path.split('\\')[-2])-1]
elif __Listing[0] == cn('最近打开'):
s.A.app.title=cn('最近打开')
__Listing = []
if s.filepath and s.O.path.isfile(s.filepath) and s.find == 'file':
__Listing = [cn(i.replace('\r\n','')) for i in open(s.filepath).readlines() if s.O.path.isfile(i)]
if s.ext:
__Listing = [i for i in __Listing if s.O.path.splitext(i)[1].lower() in s.ext]
elif s.filepath and s.O.path.isfile(s.filepath) and s.find == 'dir':
__Listing = [cn(i.replace('\r\n','')) for i in open(s.filepath).readlines() if s.O.path.isdir(i)]
if s.find == 'file':
__list = [u'<<<']
if __Listing:
for i in __Listing:
path = s.O.path.split(i.encode('u8'))
__list += [cn('%s 位于 %s'%(path[1], path[0]))]
del path
__seat = s.A.selection_list(__list, 1)
if __seat:
if s.markmod:
__seat = s.A.multi_selection_list(__list[1:], search_field = 1)
if __seat:
s.path = [__Listing[i] for i in __seat]
s.quit(1)
return
else:
s.path = __Listing[__seat-1]
s.quit(1)
return
elif s.find == 'dir':
__seat = s.A.selection_list([u'<<<']+__Listing, 1)
if __seat:
if s.markmod:
__seat = s.A.multi_selection_list(__Listing, search_field = 1)
if __seat:
s.path = [__Listing[i] for i in __seat]
s.quit(1)
return
else:
s.path = __Listing[__seat-1]
s.quit(1)
return
else:
if not s.path:
s.path = __Listing[seat].encode('u8')+'\\'
elif seat == 1 and s.find == 'dir':
if s.markmod:
__list = __Listing[2:]
if __list:
__seat = s.A.multi_selection_list(__list, search_field = 1)
if __seat:
s.path = [cn(s.path)+__list[i][1:-1]+u'\\' for i in __seat]
s.quit(1)
return
else:
s.A.note(cn('没有可标记目录!'),'error')
s.path = s.path[:-len(s.path.split('\\')[-2])-1]
del __list
else:
s.path = cn(s.path)
s.quit(1)
return
else:
name = __Listing[seat][1:-1].encode('u8')
if name:
path = s.path+name
del name
else:path = None
if path and s.O.path.isdir(path):
s.path = path+'\\'
del path
else:
if s.markmod:
__list = [i for i in __Listing[1:] if s.O.path.isfile(s.path+i.encode('u8'))]
seat = s.A.multi_selection_list(__list, search_field = 1)
if seat:
s.path = [cn(s.path)+ __list[i] for i in seat]
s.quit(1)
return
del __list
else:
s.path = cn(s.path)+__Listing[seat]
s.quit(1)
return
del __Listing
try:s.scan()
except:
s.path = None
s.scan()
else:
if s.back and s.path:
s.path = s.path[:-len(s.path.split('\\')[-2])-1]
s.scan()
else:s.quit()
def AskUser(s, path = None, find = 'file', ext = [], markmod = False, back = False):
s.path = path
s.find = find
s.ext = ext
s.markmod = markmod
s.back = back
Screen, Title = s.A.app.screen, s.A.app.title
s.A.app.screen = 'normal'
if type(s.path) == unicode:
s.path = s.path.encode('u8')
if s.path and not s.O.path.isdir(s.path):
s.path = None
if s.path:
s.path = s.path.replace('/','\\')
if s.path[-1] <> '\\':
s.path += '\\'
if s.ext:
s.ext=[i.lower() for i in s.ext]
if s.find <> 'dir':
s.find = 'file'
try:s.scan()
except:
s.path = None
s.scan()
s.lock.wait()
s.A.app.screen, s.A.app.title = Screen, Title
del Screen, Title
return s.path
def scan(s):
if s.path and not s.O.path.isdir(s.path):
s.path = None
if s.path:
s.A.app.title = cn('请稍后……')
__list1, __list2 = [u'<<<'], []
if s.find == 'dir':
if s.markmod:__list1 += [cn('☆标记当前目录☆')]
else:__list1 += [cn('☆选择当前目录☆')]
if s.CF:
__list0 = s.CF.listdir(cn(s.path), s.EA, s.ES)
__list1 += [u'['+i+u']' for i in __list0[0]]
if s.find == 'file':
if s.ext:
__list2 = [i for i in __list0[1] if s.O.path.splitext(s.path+i.encode('u8'))[1].lower() in s.ext]
else:
__list2 = list(__list0[1])
else:
__list0 = s.O.listdir(s.path)
__list1, __list2 = [u'<<<'], []
if __list0:
for i in __list0:
if s.O.path.isdir(s.path+i):
__list1.append(cn('[%s]'%i))
elif s.find == 'file':
if s.ext:
if s.O.path.splitext(s.path+i)[1].lower() in s.ext:
__list2.append(cn(i))
else:
__list2.append(cn(i))
__Listing = __list1+__list2
del __list0, __list1, __list2
else:
if s.CF:
__list = s.CF.drive_space().keys()
__list.sort()
__Listing = [cn('最近打开')]+__list
del __list
else:__Listing = [cn('最近打开')]+s.E.drive_list()
s.main(__Listing)
def quit(s, x=0):
if not x:s.path = None
elif s.filepath and s.path:
__list0, __list1 = [], []
if s.O.path.isfile(s.filepath):
for i in open(s.filepath).readlines():
i = i.replace('\r\n','')
if s.O.path.isdir(i):
__list0.append(i)
else:
__list1.append(i)
if s.markmod:
path = [i.encode('u8') for i in s.path]
if s.find == 'dir':
for i in path:
if not i in __list0:
__list0 = [i]+__list0
else:
for i in path:
if not i in __list1:
__list1 = [i]+__list1
else:
path = s.path.encode('u8')
if s.find == 'dir':
if not path in __list0:
__list0 = [path]+__list0
else:
if not path in __list1:
__list1 = [path]+__list1
__list = __list0[:8]+__list1[:8]
try:
a=open(s.filepath,'w')
[a.write('%s\r\n'%i) for i in __list]
a.close()
del a
except:pass
del __list, __list0, __list1, path
s.lock.signal()
if (__name__ == '__main__'):
filemain=manager(filepath='d:\\file.txt')#初始化,以下函数基于此类
#manager([filepath=None])
#filepath:最近打开记录路径,没有则不保存
print filemain.AskUser(path=None, ext=[], find='file', markmod=0, back=0)
#AskUser([path=None, ext=[], find='file', markmod=0, back=0])
#path:初始目录路径
#ext:过滤文件后缀,多个用,号隔开如ext=['.py', '.pyc']
#find:选择类型,find='file'查找文件,find='dir'查找目录。
#markmod:markmod=True时为标记模式
#back:back=True时按取消将返回上级目录,否则退出