Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Feb 25, 2025
1 parent b26ec04 commit 84e9220
Show file tree
Hide file tree
Showing 43 changed files with 353 additions and 208 deletions.
14 changes: 13 additions & 1 deletion src/LunaTranslator/LunaTranslator_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ def dopathexists(file: str):


originstartfile = os.startfile
originisdir = os.path.isdir
originisfile = os.path.isfile


def doisdir(file: str):
return dopathexists(file) and originisdir(file)


def doisfile(file: str):
return dopathexists(file) and originisfile(file)


def safestartfile(f):
Expand All @@ -33,8 +43,10 @@ def safestartfile(f):

def overridepathexists():
# win7上,如果假如没有D盘,然后os.path.exists("D:/..."),就会弹窗说不存在D盘
# 对于不存在的UNC路径,会先进行网络探测,达到timeout才会返回,导致非常卡顿
os.path.exists = dopathexists

os.path.isdir = doisdir
os.path.isfile = doisfile
os.startfile = safestartfile


Expand Down
2 changes: 1 addition & 1 deletion src/LunaTranslator/gui/dialog_savedgame_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, tag, removeable=True, _type=TYPE_SEARCH, refdata=None) -> Non
def opendirforgameuid(gameuid):
f = get_launchpath(gameuid)
f = os.path.dirname(f)
if os.path.exists(f) and os.path.isdir(f):
if os.path.isdir(f):
os.startfile(f)


Expand Down
2 changes: 2 additions & 0 deletions src/LunaTranslator/gui/dialog_savedgame_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ def changepixmappath(self, path):
self.centerwidget.setVisible(False)
self.pathview.setText(path)
try:
if not os.path.isfile(extradatas["localedpath"].get(path, path)):
raise Exception()
timestamp = get_time_stamp(
ct=os.path.getctime(extradatas["localedpath"].get(path, path)), ms=False
)
Expand Down
8 changes: 0 additions & 8 deletions src/LunaTranslator/gui/selecthook.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,14 @@ class hookselect(closeashidewindow):
removehooksignal = pyqtSignal(tuple)
getfoundhooksignal = pyqtSignal(dict)
update_item_new_line = pyqtSignal(tuple, str)

SaveTextThreadRole = Qt.ItemDataRole.UserRole + 1
procchanged = pyqtSignal()

def _procchanged(self):
if self.searchhookparam:
self.searchhookparam.deleteLater()
self.searchhookparam = None

def __init__(self, parent):
super(hookselect, self).__init__(parent, globalconfig["selecthookgeo"])
self.setupUi()
self.hidesearchhookbuttons()
self.firsttimex = True
self.searchhookparam = None
self.procchanged.connect(self._procchanged)
self.removehooksignal.connect(self.removehook)
self.addnewhooksignal.connect(self.addnewhook)
self.getnewsentencesignal.connect(self.getnewsentence)
Expand Down
15 changes: 14 additions & 1 deletion src/LunaTranslator/gui/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def adjust_list_widget_width(self):
max_width = 0
for i in range(list_widget.count()):
item = list_widget.item(i)
width = font_metrics.size(0, item.text() + item.text()[0] + item.text()[-1]).width()
width = font_metrics.size(
0, item.text() + item.text()[0] + item.text()[-1]
).width()
max_width = max(max_width, width)
item.setSizeHint(QSize(0, int(font_metrics.ascent() * 2)))
list_widget.setFixedWidth(max_width)
Expand Down Expand Up @@ -77,13 +79,24 @@ class Setting(closeashidewindow):
voicelistsignal = pyqtSignal(object)
versiontextsignal = pyqtSignal(str)
progresssignal2 = pyqtSignal(str, int)
progresssignal4 = pyqtSignal(str, int)
progresssignal3 = pyqtSignal(int)
showandsolvesig = pyqtSignal(str, str)

def _progresssignal4(self, text, val):
try:
self.downloadprogress.setValue(val)
self.downloadprogress.setFormat(text)
if val or text:
self.downloadprogress.setVisible(True)
except:
self.downloadprogress_cache = text, val

def __init__(self, parent):
super(Setting, self).__init__(parent, globalconfig["setting_geo_2"])
self.setWindowIcon(qtawesome.icon("fa.gear"))

self.progresssignal4.connect(self._progresssignal4)
self.showandsolvesig.connect(functools.partial(delaysetcomparetext, self))
self.voicelistsignal.connect(functools.partial(showvoicelist, self))
self.versiontextsignal.connect(
Expand Down
20 changes: 10 additions & 10 deletions src/LunaTranslator/gui/setting_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def updatemethod(urls, self):
)

savep = gobject.getcachedir("update/" + url.split("/")[-1])
if not savep.endswith(".zip"):
savep += ".zip"
if url.startswith("https://github.com"):
__x = "github"
else:
Expand All @@ -132,7 +134,7 @@ def updatemethod(urls, self):
proxies=getproxy(("update", __x)),
)
file_size = 0
for i in r.iter_content(chunk_size=1024):
for i in r.iter_content(chunk_size=1024 * 32):
if check_interrupt():
return
if not i:
Expand All @@ -144,7 +146,7 @@ def updatemethod(urls, self):
prg = int(10000 * file_size / size)
prg100 = prg / 100
sz = int(1000 * (int(size / 1024) / 1024)) / 1000
self.downloadprogress_cache = (
self.progresssignal4.emit(
_TR("总大小_{} MB _进度_{:0.2f}%").format(sz, prg100),
prg,
)
Expand All @@ -156,7 +158,7 @@ def updatemethod(urls, self):


def uncompress(self, savep):
self.downloadprogress_cache = (_TR("正在解压"), 10000)
self.progresssignal4.emit(_TR("正在解压"), 10000)
shutil.rmtree(gobject.getcachedir("update/LunaTranslator/"))
with zipfile.ZipFile(savep) as zipf:
zipf.extractall(gobject.getcachedir("update"))
Expand All @@ -168,7 +170,7 @@ def versioncheckthread(self):
while True:
x = versionchecktask.get()
gobject.baseobject.update_avalable = False
self.downloadprogress_cache = ("", 0)
self.progresssignal4.emit("", 0)
if not x:
continue
self.versiontextsignal.emit("获取中") # ,'',url,url))
Expand All @@ -189,10 +191,10 @@ def versioncheckthread(self):
)
if not (need and globalconfig["autoupdate"]):
continue
self.downloadprogress_cache = ("……", 0)
self.progresssignal4.emit("……", 0)
savep = updatemethod(_version[1:], self)
if not savep:
self.downloadprogress_cache = (_TR("自动更新失败,请手动更新"), 0)
self.progresssignal4.emit(_TR("自动更新失败,请手动更新"), 0)
continue

uncompress(self, savep)
Expand All @@ -205,7 +207,7 @@ def versioncheckthread(self):

def createdownloadprogress(self):

self.downloadprogress = QProgressBar()
self.downloadprogress = QProgressBar(self)

self.downloadprogress.setRange(0, 10000)
self.downloadprogress.setVisible(False)
Expand All @@ -223,9 +225,7 @@ def __cb(self):
if val or text:
self.downloadprogress.setVisible(True)

self.downloadprogresstimer = QTimer(self.downloadprogress)
self.downloadprogresstimer.timeout.connect(functools.partial(__cb, self))
self.downloadprogresstimer.start(100)
__cb(self)
return self.downloadprogress


Expand Down
4 changes: 2 additions & 2 deletions src/LunaTranslator/gui/usefulwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,11 +1323,11 @@ def Addext(self, *_):
edges = os.path.join(
os.environ["LOCALAPPDATA"], r"Microsoft\Edge\User Data\Default\Extensions"
)
if os.path.exists(edges):
if os.path.isdir(edges):
edgeslen = len(os.listdir(edges))
else:
edgeslen = 0
if os.path.exists(chromes):
if os.path.isdir(chromes):
chromelen = len(os.listdir(chromes))
else:
chromelen = 0
Expand Down
Loading

0 comments on commit 84e9220

Please sign in to comment.