mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
lazy
1 Revert "1" This reverts commit 1220ec603525080d62735bc0998c027205616d36. Update dialog_savedgame.py
This commit is contained in:
parent
f3f7d01da8
commit
5566d9574d
@ -1494,6 +1494,7 @@ class dialog_savedgame_new(saveposwindow):
|
|||||||
self.flow = ScrollFlow()
|
self.flow = ScrollFlow()
|
||||||
self.flow.bgclicked.connect(ItemWidget.clearfocus)
|
self.flow.bgclicked.connect(ItemWidget.clearfocus)
|
||||||
self.formLayout.insertWidget(self.formLayout.count() - 1, self.flow)
|
self.formLayout.insertWidget(self.formLayout.count() - 1, self.flow)
|
||||||
|
|
||||||
for k in savehook_new_list:
|
for k in savehook_new_list:
|
||||||
if newtags != self.currtags:
|
if newtags != self.currtags:
|
||||||
break
|
break
|
||||||
@ -1527,9 +1528,7 @@ class dialog_savedgame_new(saveposwindow):
|
|||||||
if notshow:
|
if notshow:
|
||||||
continue
|
continue
|
||||||
self.newline(k)
|
self.newline(k)
|
||||||
if len(self.idxsave) < 10 or len(self.idxsave) % 10 == 0:
|
self.flow.refreshscroll()
|
||||||
QApplication.processEvents()
|
|
||||||
|
|
||||||
def showmenu(self, p):
|
def showmenu(self, p):
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
startgame = QAction(_TR("开始游戏"))
|
startgame = QAction(_TR("开始游戏"))
|
||||||
@ -1648,25 +1647,33 @@ class dialog_savedgame_new(saveposwindow):
|
|||||||
)
|
)
|
||||||
_btn.setEnabled(_able1)
|
_btn.setEnabled(_able1)
|
||||||
|
|
||||||
def newline(self, k, first=False):
|
def _getpixfunction(self,kk):
|
||||||
checkifnewgame(k)
|
_pix = QPixmap(savehook_new_data[kk]["imagepath"])
|
||||||
|
if _pix.isNull():
|
||||||
def _getpixfunction(kk):
|
_pix = getExeIcon(kk, False, cache=True)
|
||||||
_pix = QPixmap(savehook_new_data[kk]["imagepath"])
|
return _pix
|
||||||
if _pix.isNull():
|
def getagameitem(self,k):
|
||||||
_pix = getExeIcon(kk, False, cache=True)
|
|
||||||
return _pix
|
|
||||||
|
|
||||||
gameitem = ItemWidget(
|
gameitem = ItemWidget(
|
||||||
functools.partial(_getpixfunction, k), savehook_new_data[k]["title"]
|
functools.partial(self._getpixfunction, k), savehook_new_data[k]["title"]
|
||||||
)
|
)
|
||||||
gameitem.connectexepath(k)
|
gameitem.connectexepath(k)
|
||||||
gameitem.doubleclicked.connect(self.startgame)
|
gameitem.doubleclicked.connect(self.startgame)
|
||||||
gameitem.focuschanged.connect(self.itemfocuschanged)
|
gameitem.focuschanged.connect(self.itemfocuschanged)
|
||||||
|
return gameitem
|
||||||
|
def newline(self, k, first=False):
|
||||||
|
checkifnewgame(k)
|
||||||
|
|
||||||
|
|
||||||
if first:
|
if first:
|
||||||
self.flow.insertwidget(0, gameitem)
|
|
||||||
|
self.flow.insertwidget(0, self.getagameitem(k))
|
||||||
self.idxsave.insert(0, k)
|
self.idxsave.insert(0, k)
|
||||||
else:
|
else:
|
||||||
self.flow.addwidget(gameitem)
|
itemw = globalconfig["dialog_savegame_layout"]["itemw"]
|
||||||
|
itemh = globalconfig["dialog_savegame_layout"]["itemh"]
|
||||||
|
|
||||||
|
|
||||||
|
self.flow.addwidgetlazy( functools.partial(self.getagameitem, k),QSize(itemw,itemh))
|
||||||
|
#self.flow.addwidget( self.getagameitem(k))
|
||||||
self.idxsave.append(k)
|
self.idxsave.append(k)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from PyQt5.QtWidgets import QWidget, QSizePolicy, QListWidget, QScrollArea
|
from PyQt5.QtWidgets import QWidget, QSizePolicy, QLabel, QScrollArea,QApplication
|
||||||
from PyQt5.QtGui import QMouseEvent, QPainter, QPen, QFont, QFontMetrics
|
from PyQt5.QtGui import QMouseEvent, QPainter, QPen, QFont, QFontMetrics,QRegion
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt,QEvent
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QSpacerItem,
|
QSpacerItem,
|
||||||
QWidgetItem,
|
QWidgetItem,
|
||||||
@ -118,6 +118,39 @@ class chartwidget(QWidget):
|
|||||||
print_exc()
|
print_exc()
|
||||||
|
|
||||||
|
|
||||||
|
class ScrollArea(QScrollArea):
|
||||||
|
scrolled=pyqtSignal(QRect)
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.verticalScrollBar().valueChanged.connect(self.handleScroll)
|
||||||
|
def refreshscroll(self):
|
||||||
|
QApplication.processEvents()#必须,否则尺寸是最大的。
|
||||||
|
viewport_rect = self.viewport().rect()
|
||||||
|
self.scrolled.emit(viewport_rect)
|
||||||
|
def handleScroll(self, value):
|
||||||
|
|
||||||
|
viewport_rect = self.viewport().rect()
|
||||||
|
horizontal_scrollbar = self.horizontalScrollBar()
|
||||||
|
vertical_scrollbar = self.verticalScrollBar()
|
||||||
|
|
||||||
|
x = horizontal_scrollbar.value()
|
||||||
|
y = vertical_scrollbar.value()
|
||||||
|
width = viewport_rect.width()
|
||||||
|
height = viewport_rect.height()
|
||||||
|
|
||||||
|
visible_rect = QRect(x, y, width, height)
|
||||||
|
self.scrolled.emit(visible_rect)
|
||||||
|
class lazynotify(QWidget):
|
||||||
|
|
||||||
|
def __init__(self,getrealwid) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.done=False
|
||||||
|
self.getrealwid=getrealwid
|
||||||
|
def do(self):
|
||||||
|
wid=self.getrealwid()
|
||||||
|
wid.setParent(self)
|
||||||
|
wid.adjustSize()
|
||||||
|
wid.setVisible(True)
|
||||||
class ScrollFlow(QWidget):
|
class ScrollFlow(QWidget):
|
||||||
bgclicked = pyqtSignal()
|
bgclicked = pyqtSignal()
|
||||||
|
|
||||||
@ -134,14 +167,40 @@ class ScrollFlow(QWidget):
|
|||||||
|
|
||||||
self.listWidget = qw(self)
|
self.listWidget = qw(self)
|
||||||
# self.listWidget.setFixedWidth(600)
|
# self.listWidget.setFixedWidth(600)
|
||||||
|
self.lazyitems=[]
|
||||||
|
self.lazydoneidx=[]
|
||||||
self.l = FlowLayout()
|
self.l = FlowLayout()
|
||||||
|
|
||||||
self.listWidget.setLayout(self.l)
|
self.listWidget.setLayout(self.l)
|
||||||
|
|
||||||
self.qscrollarea = QScrollArea(self)
|
self.qscrollarea = ScrollArea(self)
|
||||||
self.qscrollarea.setWidgetResizable(True)
|
self.qscrollarea.setWidgetResizable(True)
|
||||||
self.qscrollarea.setWidget(self.listWidget)
|
self.qscrollarea.setWidget(self.listWidget)
|
||||||
|
self.qscrollarea.scrolled.connect(self.doshowlazywidget)
|
||||||
|
def doshowlazywidget(self,region:QRect):
|
||||||
|
try:
|
||||||
|
#print(region)
|
||||||
|
for i,widget in enumerate(self.lazyitems):
|
||||||
|
if i in self.lazydoneidx:
|
||||||
|
continue
|
||||||
|
widget_rect = widget.geometry() #有可能已被delete,必须try
|
||||||
|
#print(widget_rect)
|
||||||
|
if region.intersects(widget_rect):
|
||||||
|
#print(i,widget_rect)
|
||||||
|
self.lazydoneidx.append(i)
|
||||||
|
widget.do()
|
||||||
|
QApplication.processEvents()
|
||||||
|
except:
|
||||||
|
print_exc()
|
||||||
|
@trypass
|
||||||
|
def refreshscroll(self):
|
||||||
|
self.qscrollarea.refreshscroll()
|
||||||
|
@trypass
|
||||||
|
def addwidgetlazy(self,wid,size):
|
||||||
|
wid=lazynotify(wid)
|
||||||
|
self.lazyitems.append(wid)
|
||||||
|
wid.setFixedSize(size)
|
||||||
|
self.l.addWidget(wid)
|
||||||
@trypass
|
@trypass
|
||||||
def addwidget(self, wid):
|
def addwidget(self, wid):
|
||||||
self.l.addWidget(wid)
|
self.l.addWidget(wid)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user