mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 16:44:13 +08:00
delay
This commit is contained in:
parent
7b57274041
commit
3821c7089a
@ -1,6 +1,6 @@
|
|||||||
from PyQt5.QtGui import QMouseEvent
|
from PyQt5.QtGui import QMouseEvent
|
||||||
from qtsymbols import *
|
from qtsymbols import *
|
||||||
import os, functools, uuid
|
import os, functools, uuid, threading
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
import windows, gobject, winsharedutils
|
import windows, gobject, winsharedutils
|
||||||
@ -41,8 +41,10 @@ from gui.usefulwidget import (
|
|||||||
auto_select_webview,
|
auto_select_webview,
|
||||||
Prompt_dialog,
|
Prompt_dialog,
|
||||||
getsimplecombobox,
|
getsimplecombobox,
|
||||||
|
D_getsimpleswitch,
|
||||||
getspinbox,
|
getspinbox,
|
||||||
getcolorbutton,
|
getcolorbutton,
|
||||||
|
D_getcolorbutton,
|
||||||
makesubtab_lazy,
|
makesubtab_lazy,
|
||||||
tabadd_lazy,
|
tabadd_lazy,
|
||||||
getsimpleswitch,
|
getsimpleswitch,
|
||||||
@ -1538,39 +1540,45 @@ def addgamebatch(callback, targetlist):
|
|||||||
|
|
||||||
@Singleton_close
|
@Singleton_close
|
||||||
class dialog_savedgame_integrated(saveposwindow):
|
class dialog_savedgame_integrated(saveposwindow):
|
||||||
def selectlayout(self, type):
|
|
||||||
globalconfig["gamemanager_integrated_internal_layout"] = type
|
|
||||||
klass = [dialog_savedgame_new, dialog_savedgame_v3, dialog_savedgame_lagacy][
|
|
||||||
type
|
|
||||||
]
|
|
||||||
|
|
||||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type) % 3].setEnabled(
|
def selectlayout(self, type):
|
||||||
False
|
try:
|
||||||
)
|
globalconfig["gamemanager_integrated_internal_layout"] = type
|
||||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type + 1) % 3].setEnabled(
|
klass = [
|
||||||
False
|
dialog_savedgame_new,
|
||||||
)
|
dialog_savedgame_v3,
|
||||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type + 2) % 3].setEnabled(
|
dialog_savedgame_lagacy,
|
||||||
False
|
][type]
|
||||||
)
|
|
||||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type + 1) % 3].setChecked(
|
[self.layout1btn, self.layout2btn, self.layout3btn][(type) % 3].setEnabled(
|
||||||
False
|
False
|
||||||
)
|
)
|
||||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type + 2) % 3].setChecked(
|
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||||
False
|
(type + 1) % 3
|
||||||
)
|
].setEnabled(False)
|
||||||
_old = self.internallayout.takeAt(0).widget()
|
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||||
_old.hide()
|
(type + 2) % 3
|
||||||
_ = klass(self)
|
].setEnabled(False)
|
||||||
self.internallayout.addWidget(_)
|
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||||
_.directshow()
|
(type + 1) % 3
|
||||||
_old.deleteLater()
|
].setChecked(False)
|
||||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type + 1) % 3].setEnabled(
|
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||||
True
|
(type + 2) % 3
|
||||||
)
|
].setChecked(False)
|
||||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type + 2) % 3].setEnabled(
|
_old = self.internallayout.takeAt(0).widget()
|
||||||
True
|
_old.hide()
|
||||||
)
|
_ = klass(self)
|
||||||
|
self.internallayout.addWidget(_)
|
||||||
|
_.directshow()
|
||||||
|
_old.deleteLater()
|
||||||
|
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||||
|
(type + 1) % 3
|
||||||
|
].setEnabled(True)
|
||||||
|
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||||
|
(type + 2) % 3
|
||||||
|
].setEnabled(True)
|
||||||
|
except:
|
||||||
|
print_exc()
|
||||||
|
|
||||||
def __init__(self, parent) -> None:
|
def __init__(self, parent) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@ -1693,7 +1701,6 @@ class dialog_savedgame_new(QWidget):
|
|||||||
continue
|
continue
|
||||||
self.newline(k)
|
self.newline(k)
|
||||||
|
|
||||||
|
|
||||||
def showmenu(self, p):
|
def showmenu(self, p):
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
startgame = QAction(_TR("开始游戏"))
|
startgame = QAction(_TR("开始游戏"))
|
||||||
@ -1906,12 +1913,88 @@ class dialog_savedgame_new(QWidget):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class LazyLoadTableView(QTableView):
|
||||||
|
def __init__(self, model: QStandardItemModel) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.widgetfunction = []
|
||||||
|
self.lock = threading.Lock()
|
||||||
|
self.setModel(model)
|
||||||
|
self.started = False
|
||||||
|
|
||||||
|
def starttraceir(self):
|
||||||
|
self.started = True
|
||||||
|
self.model().rowsRemoved.connect(functools.partial(self.insertremove))
|
||||||
|
self.model().rowsInserted.connect(functools.partial(self.insert))
|
||||||
|
|
||||||
|
def resizeEvent(self, e):
|
||||||
|
self.loadVisibleRows()
|
||||||
|
super().resizeEvent(e)
|
||||||
|
|
||||||
|
def insertremove(self, index, start, end):
|
||||||
|
off = end - start + 1
|
||||||
|
with self.lock:
|
||||||
|
collect = []
|
||||||
|
for i in range(len(self.widgetfunction)):
|
||||||
|
if self.widgetfunction[i][0] > end:
|
||||||
|
self.widgetfunction[i][0] -= off
|
||||||
|
elif (
|
||||||
|
self.widgetfunction[i][0] >= start
|
||||||
|
and self.widgetfunction[i][0] <= end
|
||||||
|
):
|
||||||
|
collect.append(i)
|
||||||
|
for i in collect:
|
||||||
|
self.widgetfunction.pop(i)
|
||||||
|
|
||||||
|
self.loadVisibleRows()
|
||||||
|
|
||||||
|
def insert(self, index, start, end):
|
||||||
|
off = end - start + 1
|
||||||
|
with self.lock:
|
||||||
|
for i in range(len(self.widgetfunction)):
|
||||||
|
if self.widgetfunction[i][0] >= start:
|
||||||
|
self.widgetfunction[i][0] += off
|
||||||
|
print(self.widgetfunction[i])
|
||||||
|
|
||||||
|
self.loadVisibleRows()
|
||||||
|
|
||||||
|
def setIndexWidget(self, index: QModelIndex, widgetf):
|
||||||
|
if not self.started:
|
||||||
|
self.widgetfunction.append([index.row(), index.column(), widgetf])
|
||||||
|
return
|
||||||
|
if self.visualRect(index).intersects(self.viewport().rect()):
|
||||||
|
w = widgetf()
|
||||||
|
super().setIndexWidget(index, w)
|
||||||
|
else:
|
||||||
|
with self.lock:
|
||||||
|
self.widgetfunction.append([index.row(), index.column(), widgetf])
|
||||||
|
|
||||||
|
def scrollContentsBy(self, dx, dy):
|
||||||
|
super().scrollContentsBy(dx, dy)
|
||||||
|
self.loadVisibleRows()
|
||||||
|
|
||||||
|
def loadVisibleRows(self):
|
||||||
|
with self.lock:
|
||||||
|
collect = []
|
||||||
|
for i, index in enumerate(self.widgetfunction):
|
||||||
|
row, col, wf = index
|
||||||
|
if self.visualRect(self.model().index(row, col)).intersects(
|
||||||
|
self.viewport().rect()
|
||||||
|
):
|
||||||
|
collect.insert(0, i)
|
||||||
|
|
||||||
|
for i in collect:
|
||||||
|
row, col, wf = self.widgetfunction.pop(i)
|
||||||
|
|
||||||
|
w = wf()
|
||||||
|
super().setIndexWidget(self.model().index(row, col), w)
|
||||||
|
|
||||||
|
|
||||||
class dialog_savedgame_lagacy(QWidget):
|
class dialog_savedgame_lagacy(QWidget):
|
||||||
|
|
||||||
def directshow(self):
|
def directshow(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def showsettingdialog(self, k, item):
|
def showsettingdialog(self, k):
|
||||||
dialog_setting_game(self, k)
|
dialog_setting_game(self, k)
|
||||||
|
|
||||||
def clicked2(self):
|
def clicked2(self):
|
||||||
@ -1935,6 +2018,11 @@ class dialog_savedgame_lagacy(QWidget):
|
|||||||
self, self.model.item(self.table.currentIndex().row(), 2).savetext
|
self, self.model.item(self.table.currentIndex().row(), 2).savetext
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def delayloadicon(self, k):
|
||||||
|
return getcolorbutton(
|
||||||
|
"", "", functools.partial(opendir, k), qicon=getExeIcon(k, cache=True)
|
||||||
|
)
|
||||||
|
|
||||||
def newline(self, row, k):
|
def newline(self, row, k):
|
||||||
keyitem = QStandardItem()
|
keyitem = QStandardItem()
|
||||||
keyitem.savetext = k
|
keyitem.savetext = k
|
||||||
@ -1949,21 +2037,19 @@ class dialog_savedgame_lagacy(QWidget):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.table.setIndexWidget(
|
self.table.setIndexWidget(
|
||||||
self.model.index(row, 0), getsimpleswitch(savehook_new_data[k], "leuse")
|
self.model.index(row, 0), D_getsimpleswitch(savehook_new_data[k], "leuse")
|
||||||
)
|
)
|
||||||
self.table.setIndexWidget(
|
self.table.setIndexWidget(
|
||||||
self.model.index(row, 1),
|
self.model.index(row, 1),
|
||||||
getcolorbutton(
|
functools.partial(self.delayloadicon, k),
|
||||||
"", "", functools.partial(opendir, k), qicon=getExeIcon(k, cache=True)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.table.setIndexWidget(
|
self.table.setIndexWidget(
|
||||||
self.model.index(row, 2),
|
self.model.index(row, 2),
|
||||||
getcolorbutton(
|
D_getcolorbutton(
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
functools.partial(self.showsettingdialog, k, keyitem),
|
functools.partial(self.showsettingdialog, k),
|
||||||
icon="fa.gear",
|
icon="fa.gear",
|
||||||
constcolor="#FF69B4",
|
constcolor="#FF69B4",
|
||||||
),
|
),
|
||||||
@ -1981,7 +2067,7 @@ class dialog_savedgame_lagacy(QWidget):
|
|||||||
|
|
||||||
self.model = model
|
self.model = model
|
||||||
|
|
||||||
table = QTableView()
|
table = LazyLoadTableView(model)
|
||||||
table.horizontalHeader().setSectionResizeMode(
|
table.horizontalHeader().setSectionResizeMode(
|
||||||
QHeaderView.ResizeMode.ResizeToContents
|
QHeaderView.ResizeMode.ResizeToContents
|
||||||
)
|
)
|
||||||
@ -1990,10 +2076,10 @@ class dialog_savedgame_lagacy(QWidget):
|
|||||||
table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
||||||
table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection))
|
table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection))
|
||||||
table.setWordWrap(False)
|
table.setWordWrap(False)
|
||||||
table.setModel(model)
|
|
||||||
self.table = table
|
self.table = table
|
||||||
for row, k in enumerate(savehook_new_list): # 2
|
for row, k in enumerate(savehook_new_list): # 2
|
||||||
self.newline(row, k)
|
self.newline(row, k)
|
||||||
|
self.table.starttraceir()
|
||||||
button = QPushButton()
|
button = QPushButton()
|
||||||
button.setText(_TR("开始游戏"))
|
button.setText(_TR("开始游戏"))
|
||||||
self.button = button
|
self.button = button
|
||||||
@ -2236,7 +2322,9 @@ class dialog_savedgame_v3(QWidget):
|
|||||||
self.stack = stackedlist()
|
self.stack = stackedlist()
|
||||||
self.stack.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
self.stack.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||||
self.stack.customContextMenuRequested.connect(self.stack_showmenu)
|
self.stack.customContextMenuRequested.connect(self.stack_showmenu)
|
||||||
self.stack.setFixedWidth(globalconfig["dialog_savegame_layout"]["listitemwidth"])
|
self.stack.setFixedWidth(
|
||||||
|
globalconfig["dialog_savegame_layout"]["listitemwidth"]
|
||||||
|
)
|
||||||
self.stack.bgclicked.connect(clickitem.clearfocus)
|
self.stack.bgclicked.connect(clickitem.clearfocus)
|
||||||
lay = QHBoxLayout()
|
lay = QHBoxLayout()
|
||||||
self.setLayout(lay)
|
self.setLayout(lay)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user