-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.py
More file actions
60 lines (50 loc) · 1.79 KB
/
FileManager.py
File metadata and controls
60 lines (50 loc) · 1.79 KB
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
# -*- coding: utf-8 -*-
import winreg
from pickle import load, dump
from Searcher import Searcher
class File:
def __init__(self):
self.Searcher = Searcher()
def readfile(self, path):
with open(file=path, mode='r', encoding='UTF-8') as f:
text = f.read()
return text
def anafile(self, text, gui=None, is_lemmas=False, qpb=None, title=None):
word, origin, textlen, dl, exact = "", [], 0, 0, 0
textlen = len(text)
dl = 1 / textlen * 100
for s in text:
exact += dl
if qpb is not None:
qpb.setValue(int(exact))
if title is not None:
title.setWindowTitle("分析中{}%".format(int(exact)))
if gui is not None:
gui()
if s.isupper():
s = s.lower()
if s < 'a' or s > 'z':
if word != "":
if is_lemmas:
word = self.Searcher.lemmas(word)
origin.append(word)
word = ""
else:
word += s
return origin
def fliterfile(self, origin, lib):
s_origin = set(origin)
return s_origin - lib
def savefile(self, file, text):
with open(file=file, mode="w", encoding='UTF-8') as f:
f.write(text)
def readsettings(self, file):
with open(file=file, mode="rb") as f:
return load(f)
def savesettings(self, file, settings):
with open(file=file, mode="wb") as f:
dump(settings, f)
def getdesktop(self):
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders')
return winreg.QueryValueEx(key, "Desktop")[0]