mirror of
https://github.com/Escartem/AnimeWwise.git
synced 2026-06-08 09:36:23 +08:00
refactor code
This commit is contained in:
66
app.py
66
app.py
@@ -65,6 +65,13 @@ class AnimeWwise(QMainWindow):
|
|||||||
# utils
|
# utils
|
||||||
self.selectFolder = lambda: QFileDialog.getExistingDirectory(self, "Select Folder")
|
self.selectFolder = lambda: QFileDialog.getExistingDirectory(self, "Select Folder")
|
||||||
|
|
||||||
|
def getMaps(self):
|
||||||
|
with open("maps/index.json", "r") as f:
|
||||||
|
maps = json.loads(f.read())
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
return maps
|
||||||
|
|
||||||
def setFolder(self, elem, folder):
|
def setFolder(self, elem, folder):
|
||||||
path = self.selectFolder()
|
path = self.selectFolder()
|
||||||
self.folders[folder] = path
|
self.folders[folder] = path
|
||||||
@@ -86,13 +93,10 @@ class AnimeWwise(QMainWindow):
|
|||||||
self.actionClearTreeView.triggered.connect(lambda: self.resetTreeWidget())
|
self.actionClearTreeView.triggered.connect(lambda: self.resetTreeWidget())
|
||||||
self.actionExit.triggered.connect(lambda: self.close())
|
self.actionExit.triggered.connect(lambda: self.close())
|
||||||
|
|
||||||
def getMaps(self):
|
self.actionExtractSelected.triggered.connect(lambda: self.extractItems(False))
|
||||||
with open("maps/index.json", "r") as f:
|
self.actionExtractAll.triggered.connect(lambda: self.extractItems(True))
|
||||||
maps = json.loads(f.read())
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
return maps
|
|
||||||
|
|
||||||
|
# workers
|
||||||
@pyqtSlot(list)
|
@pyqtSlot(list)
|
||||||
def progressBarSlot(self, progress):
|
def progressBarSlot(self, progress):
|
||||||
if progress[0] == "total":
|
if progress[0] == "total":
|
||||||
@@ -100,6 +104,16 @@ class AnimeWwise(QMainWindow):
|
|||||||
elif progress[0] == "task":
|
elif progress[0] == "task":
|
||||||
self.taskProgress.setValue(progress[1])
|
self.taskProgress.setValue(progress[1])
|
||||||
|
|
||||||
|
@pyqtSlot(dict)
|
||||||
|
def handleFinished(self, data):
|
||||||
|
if data["action"] == "load":
|
||||||
|
self.fileStructure = data["content"]
|
||||||
|
self.updateTreeWidget()
|
||||||
|
self.tabs.setTabEnabled(0, True)
|
||||||
|
self.tabs.setTabEnabled(1, True)
|
||||||
|
self.tabs.setCurrentIndex(1)
|
||||||
|
|
||||||
|
# page 1 - config
|
||||||
def start(self):
|
def start(self):
|
||||||
if "" in [self.folders["input"], self.folders["output"]]:
|
if "" in [self.folders["input"], self.folders["output"]]:
|
||||||
QMessageBox.warning(None, "Warning", "Missing input/output folder !", QMessageBox.Ok)
|
QMessageBox.warning(None, "Warning", "Missing input/output folder !", QMessageBox.Ok)
|
||||||
@@ -126,22 +140,7 @@ class AnimeWwise(QMainWindow):
|
|||||||
self.extractWorker.progress.connect(self.progressBarSlot)
|
self.extractWorker.progress.connect(self.progressBarSlot)
|
||||||
self.extractThread.start()
|
self.extractThread.start()
|
||||||
|
|
||||||
@pyqtSlot(dict)
|
# page 2 - browsing
|
||||||
def handleFinished(self, data):
|
|
||||||
if data["action"] == "load":
|
|
||||||
self.fileStructure = data["content"]
|
|
||||||
self.updateTreeWidget()
|
|
||||||
self.tabs.setTabEnabled(0, True)
|
|
||||||
self.tabs.setTabEnabled(1, True)
|
|
||||||
self.tabs.setCurrentIndex(1)
|
|
||||||
|
|
||||||
def _appendText(self, text):
|
|
||||||
cursor = self.console.textCursor()
|
|
||||||
cursor.movePosition(cursor.End)
|
|
||||||
cursor.insertText(text)
|
|
||||||
self.console.setTextCursor(cursor)
|
|
||||||
self.console.ensureCursorVisible()
|
|
||||||
|
|
||||||
def resetTreeWidget(self):
|
def resetTreeWidget(self):
|
||||||
self.treeWidget.clear()
|
self.treeWidget.clear()
|
||||||
self.tabs.setTabEnabled(1, False)
|
self.tabs.setTabEnabled(1, False)
|
||||||
@@ -183,6 +182,29 @@ class AnimeWwise(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
parent.addChild(file_item)
|
parent.addChild(file_item)
|
||||||
|
|
||||||
|
# page 3 - extraction
|
||||||
|
def extractItems(self, _all):
|
||||||
|
checked_items = []
|
||||||
|
|
||||||
|
def check_items(item, _all):
|
||||||
|
if item.checkState(0) == Qt.Checked or _all:
|
||||||
|
checked_items.append([item.text(column) for column in range(item.columnCount())])
|
||||||
|
for i in range(item.childCount()):
|
||||||
|
check_items(item.child(i), _all)
|
||||||
|
|
||||||
|
for i in range(self.treeWidget.topLevelItemCount()):
|
||||||
|
check_items(self.treeWidget.topLevelItem(i), _all)
|
||||||
|
|
||||||
|
print(checked_items)
|
||||||
|
|
||||||
|
# misc
|
||||||
|
def _appendText(self, text):
|
||||||
|
cursor = self.console.textCursor()
|
||||||
|
cursor.movePosition(cursor.End)
|
||||||
|
cursor.insertText(text)
|
||||||
|
self.console.setTextCursor(cursor)
|
||||||
|
self.console.ensureCursorVisible()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = AnimeWwise()
|
window = AnimeWwise()
|
||||||
|
|||||||
Reference in New Issue
Block a user