This commit is contained in:
恍兮惚兮 2024-01-24 16:48:55 +08:00
parent 240290649f
commit 2bccff08dc
8 changed files with 78 additions and 59 deletions

View File

@ -360,8 +360,8 @@ class MAINUI() :
def selectprocess(self,selectedp):
self.textsource=None
pids,pexe,hwnd=( selectedp)
checkifnewgame(pexe)
pids,pexe,hwnd=( selectedp)
checkifnewgame(pexe,windows.GetWindowText(hwnd))
if globalconfig['sourcestatus2']['texthook']['use']:
self.textsource=texthook(pids,hwnd,pexe)
elif globalconfig['sourcestatus2']['fridahook']['use']:

View File

@ -29,7 +29,6 @@ from myutils.utils import checkifnewgame ,loadfridascriptslist
from myutils.proxy import getproxy
from gui.usefulwidget import yuitsu_switch,saveposwindow,getboxlayout
from myutils.vndb import parsehtmlmethod
from webview import Webview
class ItemWidget(QWidget):
focuschanged=pyqtSignal(bool,str)
doubleclicked=pyqtSignal(str)
@ -256,7 +255,7 @@ class browserdialog(QDialog):
def parsehtml(self,exepath):
try:
newpath=parsehtmlmethod(savehook_new_data[exepath]['vid'],savehook_new_data[exepath]['infopath'])
newpath=parsehtmlmethod(savehook_new_data[exepath]['infopath'])
except:
print_exc()
newpath=savehook_new_data[exepath]['infopath']
@ -264,42 +263,56 @@ class browserdialog(QDialog):
newpath=os.path.abspath(newpath)
return newpath
def resizeEvent(self, a0: QResizeEvent) -> None:
if self._resizable==False:return
self.nettab.resize(a0.size().width(),self.nettab.height())
if self.webviewv==0:
self.browser.resize(0,self.nettab.height(),a0.size().width(),a0.size().height()-self.nettab.height())
elif self.webviewv==1:
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)
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.resize(1300,800)
if self.webviewv==0:
self.browser= winsharedutils.HTMLBrowser(int(self.winId()))
elif self.webviewv==1:
self.browser=Webview(0,int(self.winId()))
self.setWindowTitle(savehook_new_data[exepath]['title'])
from webview import Webview
self.browser=Webview(0,int(self.winId())) #构造函数里会触发ResizeEvent。虽然确实有问题但很奇怪前一天晚上正常第二天起来就崩溃了。
self.setWindowTitle(savehook_new_data[self.exepath]['title'])
self.nettab=QTabWidget(self)
self.nettab.setFixedHeight(self.nettab.tabBar().height()+10)
tabBar = CustomTabBar(self)
self.nettab.setTabBar(tabBar)
tabBar.lastclick.connect(self.lastclicked)
#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']:
self.nettab.addTab(QWidget(),lnk[0])
self.nettab.addTab(QWidget(),"+")
self.nettab.currentChanged.connect(self.changetab)
self.nettab.setContextMenuPolicy(Qt.CustomContextMenu)
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(qww)
self._resizable=True
self.resize(1300,800)
self.show()
def showmenu(self,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
menu=QMenu(self )
shanchu=QAction(_TR("删除"))
@ -310,7 +323,7 @@ class browserdialog(QDialog):
if action==shanchu:
self.nettab.setCurrentIndex(0)
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:
def cachehtml(exepath,idx):
url=savehook_new_data[exepath]['relationlinks'][idx][1]
@ -343,7 +356,7 @@ class browserdialog(QDialog):
savehook_new_data[exepath]['relationlinks'][i][2]=fn
else:
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 callback(texts):
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])
gobject.baseobject.Prompt.call.emit(_TR('添加关联页面'),_TR('页面类型_页面链接'),[['vndb/2df/...'],'about:blank'],[callback])
def changetab(self,idx):
if idx==0:
if self.hasvndb and idx==0:
try:
self.browser.navigate((self.parsehtml( self.exepath)))
except:
self.browser.navigate('about:blank')
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]):
link=os.path.abspath(lnks[2])
else:

View File

@ -275,7 +275,7 @@ class QUnFrameWindow(resizableframeless):
("simulate_key_ctrl",lambda:threading.Thread(target=simulate_key_ctrl).start()),
("simulate_key_enter",lambda:threading.Thread(target=simulate_key_enter).start() ),
("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) ),
("minmize",self.hide_and_disableautohide),

View File

@ -46,7 +46,7 @@ except:
translatorsetting=tryreadconfig('translatorsetting.json')
ocrsetting=tryreadconfig('ocrsetting.json')
def getdefaultsavehook(gamepath):
def getdefaultsavehook(gamepath,title=None):
default={
'localeswitcher':0,
'onloadautochangemode2':0,
@ -63,7 +63,6 @@ def getdefaultsavehook(gamepath):
'inserthooktimeout':0,
'needinserthookcode':[],
"removeuseless":False,
'title':os.path.basename(os.path.dirname(gamepath))+'/'+ os.path.basename(gamepath),
"codepage_index":0,
"allow_tts_auto_names":'',
"hooktypeasname":{},
@ -72,6 +71,12 @@ def getdefaultsavehook(gamepath):
"searchnoresulttime":0,
'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
_dfsavehook=getdefaultsavehook('')

View File

@ -84,12 +84,14 @@ def everymethodsthread():
if succ==False:
savehook_new_data[gamepath]['searchnoresulttime']=time.time()
threading.Thread(target=everymethodsthread).start()
def checkifnewgame(gamepath):
def checkifnewgame(gamepath,title=None):
if gamepath not in savehook_new_list:
savehook_new_list.insert(0,gamepath)
if gamepath not in savehook_new_data:
savehook_new_data[gamepath]=getdefaultsavehook(gamepath)
dispatachtask(gamepath)
savehook_new_data[gamepath]=getdefaultsavehook(gamepath,title)
if gamepath!='0':
dispatachtask(gamepath)
checkifnewgame('0')
kanjichs2ja=str.maketrans(static_data['kanjichs2ja'])
def kanjitrans(k):
return k.translate(kanjichs2ja)

View File

@ -118,7 +118,7 @@ def searchforidimage(title):
return {'vid':vid,'infopath':vndbdowloadinfo(vid),'imagepath':vndbdownloadimg(img)}
import re
def parsehtmlmethod(vid,infopath):
def parsehtmlmethod(infopath):
with open(infopath,'r',encoding='utf8') as ff:
text=ff.read()
##隐藏横向滚动

View File

@ -9,44 +9,43 @@ class stripwrapper(dict):
return t.strip()
else:
return t
def Singleton(cls,**kw):
_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={}
def Singleton_impl(cls,behavior='activate'):
_lock=threading.Lock()
_status={}
_instance={}
def _singleton(*args,**kwagrs):
_lock.acquire()
if len(_status): #qapp.processevent会导致卡在#1处从而多次点击鼠标都会弹出
_lock.release()
return None
_status[0]=0
_lock.release()
try:
if _instance[cls].isHidden():
_instance[cls].deleteLater()
_instance[cls]=cls(*args,**kwagrs) #1
else:
_instance[cls].close()
except:
_instance[cls]=cls(*args,**kwagrs)
_lock.acquire()
_status.pop(0)
_lock.release()
return _instance[cls]
if _lock.locked():
if cls not in _instance:#__init__很慢来不及放入_instance
pass
elif behavior=='activate':
_instance[cls].activateWindow()
_instance[cls].show()
elif behavior=='close':
_instance[cls].close()
return
_lock.acquire()
class __(cls):
Singleton_flag=1
def closeEvent( self, a0 ) -> None:
super().closeEvent(a0)
self.Singleton_flag=0
if cls not in _instance:
pass #__init__没做完的时候不能deletelator
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
def Singleton(cls):
return Singleton_impl(cls,behavior='activate')
def Singleton_close(cls):
return Singleton_impl(cls,behavior='close')
def retryer(**kw):
def wrapper(func):
def _wrapper(*args,**kwargs):

View File

@ -153,5 +153,5 @@ extern "C" __declspec(dllexport) void html_release(void* web) {
if(!web)return;
auto ww = static_cast<MWebBrowser*>(web);
ww->Destroy();
ww->Release();
//ww->Release(); Destroy减少引用计数自动del
}