mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
fix
This commit is contained in:
parent
240290649f
commit
2bccff08dc
@ -360,8 +360,8 @@ class MAINUI() :
|
|||||||
|
|
||||||
def selectprocess(self,selectedp):
|
def selectprocess(self,selectedp):
|
||||||
self.textsource=None
|
self.textsource=None
|
||||||
pids,pexe,hwnd=( selectedp)
|
pids,pexe,hwnd=( selectedp)
|
||||||
checkifnewgame(pexe)
|
checkifnewgame(pexe,windows.GetWindowText(hwnd))
|
||||||
if globalconfig['sourcestatus2']['texthook']['use']:
|
if globalconfig['sourcestatus2']['texthook']['use']:
|
||||||
self.textsource=texthook(pids,hwnd,pexe)
|
self.textsource=texthook(pids,hwnd,pexe)
|
||||||
elif globalconfig['sourcestatus2']['fridahook']['use']:
|
elif globalconfig['sourcestatus2']['fridahook']['use']:
|
||||||
|
@ -29,7 +29,6 @@ from myutils.utils import checkifnewgame ,loadfridascriptslist
|
|||||||
from myutils.proxy import getproxy
|
from myutils.proxy import getproxy
|
||||||
from gui.usefulwidget import yuitsu_switch,saveposwindow,getboxlayout
|
from gui.usefulwidget import yuitsu_switch,saveposwindow,getboxlayout
|
||||||
from myutils.vndb import parsehtmlmethod
|
from myutils.vndb import parsehtmlmethod
|
||||||
from webview import Webview
|
|
||||||
class ItemWidget(QWidget):
|
class ItemWidget(QWidget):
|
||||||
focuschanged=pyqtSignal(bool,str)
|
focuschanged=pyqtSignal(bool,str)
|
||||||
doubleclicked=pyqtSignal(str)
|
doubleclicked=pyqtSignal(str)
|
||||||
@ -256,7 +255,7 @@ class browserdialog(QDialog):
|
|||||||
|
|
||||||
def parsehtml(self,exepath):
|
def parsehtml(self,exepath):
|
||||||
try:
|
try:
|
||||||
newpath=parsehtmlmethod(savehook_new_data[exepath]['vid'],savehook_new_data[exepath]['infopath'])
|
newpath=parsehtmlmethod(savehook_new_data[exepath]['infopath'])
|
||||||
except:
|
except:
|
||||||
print_exc()
|
print_exc()
|
||||||
newpath=savehook_new_data[exepath]['infopath']
|
newpath=savehook_new_data[exepath]['infopath']
|
||||||
@ -264,42 +263,56 @@ class browserdialog(QDialog):
|
|||||||
newpath=os.path.abspath(newpath)
|
newpath=os.path.abspath(newpath)
|
||||||
return newpath
|
return newpath
|
||||||
def resizeEvent(self, a0: QResizeEvent) -> None:
|
def resizeEvent(self, a0: QResizeEvent) -> None:
|
||||||
|
if self._resizable==False:return
|
||||||
self.nettab.resize(a0.size().width(),self.nettab.height())
|
self.nettab.resize(a0.size().width(),self.nettab.height())
|
||||||
if self.webviewv==0:
|
if self.webviewv==0:
|
||||||
self.browser.resize(0,self.nettab.height(),a0.size().width(),a0.size().height()-self.nettab.height())
|
self.browser.resize(0,self.nettab.height(),a0.size().width(),a0.size().height()-self.nettab.height())
|
||||||
elif self.webviewv==1:
|
elif self.webviewv==1:
|
||||||
self.browser.set_geo(0,self.nettab.height(),a0.size().width(),a0.size().height()-self.nettab.height())
|
self.browser.set_geo(0,self.nettab.height(),a0.size().width(),a0.size().height()-self.nettab.height())
|
||||||
def __init__(self, parent,exepath ) -> None:
|
def __init__(self, parent,textsource_or_exepath ) -> None:
|
||||||
super().__init__(parent, Qt.WindowMinMaxButtonsHint|Qt.WindowCloseButtonHint)
|
super().__init__(parent, Qt.WindowMinMaxButtonsHint|Qt.WindowCloseButtonHint)
|
||||||
self.exepath=exepath
|
if isinstance(textsource_or_exepath,str):
|
||||||
|
self.exepath=textsource_or_exepath
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.exepath=textsource_or_exepath.pname
|
||||||
|
except:
|
||||||
|
self.exepath='0'
|
||||||
|
self._resizable=False
|
||||||
|
self.resize(1300,801)
|
||||||
self.webviewv=globalconfig['usewebview']
|
self.webviewv=globalconfig['usewebview']
|
||||||
self.resize(1300,800)
|
|
||||||
if self.webviewv==0:
|
if self.webviewv==0:
|
||||||
self.browser= winsharedutils.HTMLBrowser(int(self.winId()))
|
self.browser= winsharedutils.HTMLBrowser(int(self.winId()))
|
||||||
elif self.webviewv==1:
|
elif self.webviewv==1:
|
||||||
self.browser=Webview(0,int(self.winId()))
|
from webview import Webview
|
||||||
self.setWindowTitle(savehook_new_data[exepath]['title'])
|
self.browser=Webview(0,int(self.winId())) #构造函数里会触发ResizeEvent。虽然确实有问题,但很奇怪前一天晚上正常,第二天起来就崩溃了。
|
||||||
|
self.setWindowTitle(savehook_new_data[self.exepath]['title'])
|
||||||
self.nettab=QTabWidget(self)
|
self.nettab=QTabWidget(self)
|
||||||
self.nettab.setFixedHeight(self.nettab.tabBar().height()+10)
|
self.nettab.setFixedHeight(self.nettab.tabBar().height()+10)
|
||||||
tabBar = CustomTabBar(self)
|
tabBar = CustomTabBar(self)
|
||||||
self.nettab.setTabBar(tabBar)
|
self.nettab.setTabBar(tabBar)
|
||||||
tabBar.lastclick.connect(self.lastclicked)
|
tabBar.lastclick.connect(self.lastclicked)
|
||||||
#self.nettab.setSizePolicy( QSizePolicy.Preferred,QSizePolicy.Fixed)
|
#self.nettab.setSizePolicy( QSizePolicy.Preferred,QSizePolicy.Fixed)
|
||||||
self.nettab.addTab(QWidget(),"vndb")
|
self.hasvndb=bool(savehook_new_data[self.exepath]['infopath'] and os.path.exists(savehook_new_data[self.exepath]['infopath']))
|
||||||
|
if self.hasvndb:
|
||||||
|
self.nettab.addTab(QWidget(),"vndb")
|
||||||
for lnk in savehook_new_data[self.exepath]['relationlinks']:
|
for lnk in savehook_new_data[self.exepath]['relationlinks']:
|
||||||
self.nettab.addTab(QWidget(),lnk[0])
|
self.nettab.addTab(QWidget(),lnk[0])
|
||||||
self.nettab.addTab(QWidget(),"+")
|
self.nettab.addTab(QWidget(),"+")
|
||||||
self.nettab.currentChanged.connect(self.changetab)
|
self.nettab.currentChanged.connect(self.changetab)
|
||||||
self.nettab.setContextMenuPolicy(Qt.CustomContextMenu)
|
self.nettab.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||||
self.nettab.customContextMenuRequested.connect(self.showmenu)
|
self.nettab.customContextMenuRequested.connect(self.showmenu)
|
||||||
self.changetab(0)
|
if self.hasvndb + len(savehook_new_data[self.exepath]['relationlinks']):
|
||||||
|
self.changetab(0)
|
||||||
#vbox.addWidget(self.nettab)
|
#vbox.addWidget(self.nettab)
|
||||||
#vbox.addWidget(qww)
|
#vbox.addWidget(qww)
|
||||||
|
self._resizable=True
|
||||||
|
self.resize(1300,800)
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
def showmenu(self,p):
|
def showmenu(self,p):
|
||||||
tab_index = self.nettab.tabBar().tabAt(p)
|
tab_index = self.nettab.tabBar().tabAt(p)
|
||||||
if tab_index ==0 or tab_index==self.nettab.count()-1:
|
if (self.hasvndb and tab_index ==0) or tab_index==self.nettab.count()-1:
|
||||||
return
|
return
|
||||||
menu=QMenu(self )
|
menu=QMenu(self )
|
||||||
shanchu=QAction(_TR("删除"))
|
shanchu=QAction(_TR("删除"))
|
||||||
@ -310,7 +323,7 @@ class browserdialog(QDialog):
|
|||||||
if action==shanchu:
|
if action==shanchu:
|
||||||
self.nettab.setCurrentIndex(0)
|
self.nettab.setCurrentIndex(0)
|
||||||
self.nettab.removeTab(tab_index)
|
self.nettab.removeTab(tab_index)
|
||||||
savehook_new_data[self.exepath]['relationlinks'].pop(tab_index-1)
|
savehook_new_data[self.exepath]['relationlinks'].pop(tab_index-self.hasvndb)
|
||||||
elif action==cache:
|
elif action==cache:
|
||||||
def cachehtml(exepath,idx):
|
def cachehtml(exepath,idx):
|
||||||
url=savehook_new_data[exepath]['relationlinks'][idx][1]
|
url=savehook_new_data[exepath]['relationlinks'][idx][1]
|
||||||
@ -343,7 +356,7 @@ class browserdialog(QDialog):
|
|||||||
savehook_new_data[exepath]['relationlinks'][i][2]=fn
|
savehook_new_data[exepath]['relationlinks'][i][2]=fn
|
||||||
else:
|
else:
|
||||||
savehook_new_data[exepath]['relationlinks'][i].append(fn)
|
savehook_new_data[exepath]['relationlinks'][i].append(fn)
|
||||||
threading.Thread(target=cachehtml,args=(self.exepath,tab_index-1)).start()
|
threading.Thread(target=cachehtml,args=(self.exepath,tab_index-self.hasvndb)).start()
|
||||||
def lastclicked(self):
|
def lastclicked(self):
|
||||||
def callback(texts):
|
def callback(texts):
|
||||||
if len(texts[0].strip()) and len(texts[1].strip()):
|
if len(texts[0].strip()) and len(texts[1].strip()):
|
||||||
@ -351,13 +364,13 @@ class browserdialog(QDialog):
|
|||||||
self.nettab.insertTab(self.nettab.count()-1,QWidget(),texts[0])
|
self.nettab.insertTab(self.nettab.count()-1,QWidget(),texts[0])
|
||||||
gobject.baseobject.Prompt.call.emit(_TR('添加关联页面'),_TR('页面类型_页面链接'),[['vndb/2df/...'],'about:blank'],[callback])
|
gobject.baseobject.Prompt.call.emit(_TR('添加关联页面'),_TR('页面类型_页面链接'),[['vndb/2df/...'],'about:blank'],[callback])
|
||||||
def changetab(self,idx):
|
def changetab(self,idx):
|
||||||
if idx==0:
|
if self.hasvndb and idx==0:
|
||||||
try:
|
try:
|
||||||
self.browser.navigate((self.parsehtml( self.exepath)))
|
self.browser.navigate((self.parsehtml( self.exepath)))
|
||||||
except:
|
except:
|
||||||
self.browser.navigate('about:blank')
|
self.browser.navigate('about:blank')
|
||||||
else:
|
else:
|
||||||
lnks=savehook_new_data[self.exepath]['relationlinks'][idx-1]
|
lnks=savehook_new_data[self.exepath]['relationlinks'][idx-self.hasvndb]
|
||||||
if len(lnks)==3 and os.path.exists(lnks[2]):
|
if len(lnks)==3 and os.path.exists(lnks[2]):
|
||||||
link=os.path.abspath(lnks[2])
|
link=os.path.abspath(lnks[2])
|
||||||
else:
|
else:
|
||||||
|
@ -275,7 +275,7 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
("simulate_key_ctrl",lambda:threading.Thread(target=simulate_key_ctrl).start()),
|
("simulate_key_ctrl",lambda:threading.Thread(target=simulate_key_ctrl).start()),
|
||||||
("simulate_key_enter",lambda:threading.Thread(target=simulate_key_enter).start() ),
|
("simulate_key_enter",lambda:threading.Thread(target=simulate_key_enter).start() ),
|
||||||
("copy_once",lambda:gobject.baseobject.textgetmethod(winsharedutils.clipboard_get(),False) ),
|
("copy_once",lambda:gobject.baseobject.textgetmethod(winsharedutils.clipboard_get(),False) ),
|
||||||
("open_relative_link",lambda:browserdialog(gobject.baseobject.settin_ui,gobject.baseobject.textsource.pname) ),
|
("open_relative_link",lambda:browserdialog(gobject.baseobject.settin_ui,gobject.baseobject.textsource) ),
|
||||||
|
|
||||||
("ocr_once",lambda:rangeselct_function(self,ocroncefunction,False,False) ),
|
("ocr_once",lambda:rangeselct_function(self,ocroncefunction,False,False) ),
|
||||||
("minmize",self.hide_and_disableautohide),
|
("minmize",self.hide_and_disableautohide),
|
||||||
|
@ -46,7 +46,7 @@ except:
|
|||||||
translatorsetting=tryreadconfig('translatorsetting.json')
|
translatorsetting=tryreadconfig('translatorsetting.json')
|
||||||
ocrsetting=tryreadconfig('ocrsetting.json')
|
ocrsetting=tryreadconfig('ocrsetting.json')
|
||||||
|
|
||||||
def getdefaultsavehook(gamepath):
|
def getdefaultsavehook(gamepath,title=None):
|
||||||
default={
|
default={
|
||||||
'localeswitcher':0,
|
'localeswitcher':0,
|
||||||
'onloadautochangemode2':0,
|
'onloadautochangemode2':0,
|
||||||
@ -63,7 +63,6 @@ def getdefaultsavehook(gamepath):
|
|||||||
'inserthooktimeout':0,
|
'inserthooktimeout':0,
|
||||||
'needinserthookcode':[],
|
'needinserthookcode':[],
|
||||||
"removeuseless":False,
|
"removeuseless":False,
|
||||||
'title':os.path.basename(os.path.dirname(gamepath))+'/'+ os.path.basename(gamepath),
|
|
||||||
"codepage_index":0,
|
"codepage_index":0,
|
||||||
"allow_tts_auto_names":'',
|
"allow_tts_auto_names":'',
|
||||||
"hooktypeasname":{},
|
"hooktypeasname":{},
|
||||||
@ -72,6 +71,12 @@ def getdefaultsavehook(gamepath):
|
|||||||
"searchnoresulttime":0,
|
"searchnoresulttime":0,
|
||||||
'relationlinks':[]
|
'relationlinks':[]
|
||||||
}
|
}
|
||||||
|
if gamepath=='0':
|
||||||
|
default['title']='No Game'
|
||||||
|
elif title and len(title):
|
||||||
|
default['title']=title
|
||||||
|
else:
|
||||||
|
default['title']=os.path.basename(os.path.dirname(gamepath))+'/'+ os.path.basename(gamepath)
|
||||||
return default
|
return default
|
||||||
|
|
||||||
_dfsavehook=getdefaultsavehook('')
|
_dfsavehook=getdefaultsavehook('')
|
||||||
|
@ -84,12 +84,14 @@ def everymethodsthread():
|
|||||||
if succ==False:
|
if succ==False:
|
||||||
savehook_new_data[gamepath]['searchnoresulttime']=time.time()
|
savehook_new_data[gamepath]['searchnoresulttime']=time.time()
|
||||||
threading.Thread(target=everymethodsthread).start()
|
threading.Thread(target=everymethodsthread).start()
|
||||||
def checkifnewgame(gamepath):
|
def checkifnewgame(gamepath,title=None):
|
||||||
if gamepath not in savehook_new_list:
|
if gamepath not in savehook_new_list:
|
||||||
savehook_new_list.insert(0,gamepath)
|
savehook_new_list.insert(0,gamepath)
|
||||||
if gamepath not in savehook_new_data:
|
if gamepath not in savehook_new_data:
|
||||||
savehook_new_data[gamepath]=getdefaultsavehook(gamepath)
|
savehook_new_data[gamepath]=getdefaultsavehook(gamepath,title)
|
||||||
dispatachtask(gamepath)
|
if gamepath!='0':
|
||||||
|
dispatachtask(gamepath)
|
||||||
|
checkifnewgame('0')
|
||||||
kanjichs2ja=str.maketrans(static_data['kanjichs2ja'])
|
kanjichs2ja=str.maketrans(static_data['kanjichs2ja'])
|
||||||
def kanjitrans(k):
|
def kanjitrans(k):
|
||||||
return k.translate(kanjichs2ja)
|
return k.translate(kanjichs2ja)
|
||||||
|
@ -118,7 +118,7 @@ def searchforidimage(title):
|
|||||||
return {'vid':vid,'infopath':vndbdowloadinfo(vid),'imagepath':vndbdownloadimg(img)}
|
return {'vid':vid,'infopath':vndbdowloadinfo(vid),'imagepath':vndbdownloadimg(img)}
|
||||||
|
|
||||||
import re
|
import re
|
||||||
def parsehtmlmethod(vid,infopath):
|
def parsehtmlmethod(infopath):
|
||||||
with open(infopath,'r',encoding='utf8') as ff:
|
with open(infopath,'r',encoding='utf8') as ff:
|
||||||
text=ff.read()
|
text=ff.read()
|
||||||
##隐藏横向滚动
|
##隐藏横向滚动
|
||||||
|
@ -9,44 +9,43 @@ class stripwrapper(dict):
|
|||||||
return t.strip()
|
return t.strip()
|
||||||
else:
|
else:
|
||||||
return t
|
return t
|
||||||
def Singleton(cls,**kw):
|
def Singleton_impl(cls,behavior='activate'):
|
||||||
_instance={}
|
|
||||||
def _singleton(*args,**kwagrs):
|
|
||||||
try:
|
|
||||||
if _instance[cls] .isHidden():
|
|
||||||
_instance[cls].deleteLater()
|
|
||||||
_instance[cls]=cls(*args,**kwagrs)
|
|
||||||
else:
|
|
||||||
_instance[cls].activateWindow()
|
|
||||||
_instance[cls].show()
|
|
||||||
except:
|
|
||||||
_instance[cls]=cls(*args,**kwagrs)
|
|
||||||
return _instance[cls]
|
|
||||||
return _singleton
|
|
||||||
def Singleton_close(cls,**kw):
|
|
||||||
_instance={}
|
|
||||||
_lock=threading.Lock()
|
_lock=threading.Lock()
|
||||||
_status={}
|
_instance={}
|
||||||
def _singleton(*args,**kwagrs):
|
def _singleton(*args,**kwagrs):
|
||||||
_lock.acquire()
|
if _lock.locked():
|
||||||
if len(_status): #qapp.processevent会导致卡在#1处,从而多次点击鼠标都会弹出
|
if cls not in _instance:#__init__很慢,来不及放入_instance
|
||||||
_lock.release()
|
pass
|
||||||
return None
|
elif behavior=='activate':
|
||||||
_status[0]=0
|
_instance[cls].activateWindow()
|
||||||
_lock.release()
|
_instance[cls].show()
|
||||||
try:
|
elif behavior=='close':
|
||||||
if _instance[cls].isHidden():
|
_instance[cls].close()
|
||||||
_instance[cls].deleteLater()
|
return
|
||||||
_instance[cls]=cls(*args,**kwagrs) #1
|
_lock.acquire()
|
||||||
else:
|
class __(cls):
|
||||||
_instance[cls].close()
|
Singleton_flag=1
|
||||||
except:
|
def closeEvent( self, a0 ) -> None:
|
||||||
_instance[cls]=cls(*args,**kwagrs)
|
super().closeEvent(a0)
|
||||||
_lock.acquire()
|
self.Singleton_flag=0
|
||||||
_status.pop(0)
|
if cls not in _instance:
|
||||||
_lock.release()
|
pass #__init__没做完的时候不能deletelator
|
||||||
return _instance[cls]
|
else:
|
||||||
|
for child in (self.children()):
|
||||||
|
if hasattr(child,'Singleton_flag'):
|
||||||
|
child.close()
|
||||||
|
self.deleteLater()
|
||||||
|
_instance.pop(cls)
|
||||||
|
_lock.release()
|
||||||
|
_inst=__(*args,**kwagrs)
|
||||||
|
if _inst.Singleton_flag:
|
||||||
|
_instance[cls]=_inst
|
||||||
|
return _inst
|
||||||
return _singleton
|
return _singleton
|
||||||
|
def Singleton(cls):
|
||||||
|
return Singleton_impl(cls,behavior='activate')
|
||||||
|
def Singleton_close(cls):
|
||||||
|
return Singleton_impl(cls,behavior='close')
|
||||||
def retryer(**kw):
|
def retryer(**kw):
|
||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
def _wrapper(*args,**kwargs):
|
def _wrapper(*args,**kwargs):
|
||||||
|
@ -153,5 +153,5 @@ extern "C" __declspec(dllexport) void html_release(void* web) {
|
|||||||
if(!web)return;
|
if(!web)return;
|
||||||
auto ww = static_cast<MWebBrowser*>(web);
|
auto ww = static_cast<MWebBrowser*>(web);
|
||||||
ww->Destroy();
|
ww->Destroy();
|
||||||
ww->Release();
|
//ww->Release(); Destroy减少引用计数,自动del
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user