From 08e97ab03edc027ca8d7849a21c17970d3b2e775 Mon Sep 17 00:00:00 2001 From: 283375 Date: Thu, 14 Sep 2023 03:14:01 +0800 Subject: [PATCH] wip: ui --- ui/components/projectEntry.py | 23 ++--- ui/components/projectEntry.ui | 57 ++----------- ui/components/projectEntry_Manage.py | 108 ++++++++++++++++++++++++ ui/components/projectEntry_Manage.ui | 68 +++++++++++++++ ui/components/projectEntry_Manage_ui.py | 70 +++++++++++++++ ui/components/projectEntry_ui.py | 42 +-------- ui/components/yieldProgress.py | 9 ++ ui/components/yieldProgress.ui | 87 +++++++++++++++++++ ui/components/yieldProgress_ui.py | 78 +++++++++++++++++ 9 files changed, 437 insertions(+), 105 deletions(-) create mode 100644 ui/components/projectEntry_Manage.py create mode 100644 ui/components/projectEntry_Manage.ui create mode 100644 ui/components/projectEntry_Manage_ui.py create mode 100644 ui/components/yieldProgress.py create mode 100644 ui/components/yieldProgress.ui create mode 100644 ui/components/yieldProgress_ui.py diff --git a/ui/components/projectEntry.py b/ui/components/projectEntry.py index 0105a9f..f60d48b 100644 --- a/ui/components/projectEntry.py +++ b/ui/components/projectEntry.py @@ -11,23 +11,12 @@ class ProjectEntry(Ui_ProjectEntry, QWidget): self.setupUi(self) self.project = None + self.tabManage.reloadProject.connect(self.reloadProject) + def setProject(self, project: Project): self.project = project - self.updateLabels() + self.tabManage.setProject(project) - def updateLabels(self): - if not self.project: - self.projectNameLabel.setText("-") - self.projectDescriptionLabel.setText("-") - return - - self.projectNameLabel.setText(self.project.name) - self.projectDescriptionLabel.setText( - "
".join( - [ - str(self.project.path.resolve()), - f"{len(self.project.sources)} sources", - f"{len(self.project.samples)} samples ({len(self.project.samplesUnclassified)} unclassified)", - ] - ) - ) + def reloadProject(self): + self.project.reload() + self.setProject(self.project) diff --git a/ui/components/projectEntry.ui b/ui/components/projectEntry.ui index 2edb353..66028fa 100644 --- a/ui/components/projectEntry.ui +++ b/ui/components/projectEntry.ui @@ -19,59 +19,10 @@ 0 - + Manage - - - - - Extract - - - - - - - - 14 - true - - - - - - - - - - - - ... - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - @@ -110,6 +61,12 @@ QListWidget
ui.components.samplesListWidget
+ + ProjectEntry_Manage + QWidget +
ui.components.projectEntry_Manage
+ 1 +
diff --git a/ui/components/projectEntry_Manage.py b/ui/components/projectEntry_Manage.py new file mode 100644 index 0000000..e4b24ea --- /dev/null +++ b/ui/components/projectEntry_Manage.py @@ -0,0 +1,108 @@ +from PySide6.QtCore import Qt, Signal, Slot +from PySide6.QtWidgets import QApplication, QWidget + +from project import Project + +from .projectEntry_Manage_ui import Ui_ProjectEntry_Manage +from .yieldProgress import YieldProgress + + +class ProjectEntry_Manage(Ui_ProjectEntry_Manage, QWidget): + reloadProject = Signal() + + def __init__(self, parent=None): + super().__init__(parent) + self.setupUi(self) + self.project = None + self.abort = False + + def setProject(self, project: Project): + self.project = project + self.updateLabels() + + def updateLabels(self): + if not self.project: + self.projectNameLabel.setText("-") + self.projectDescriptionLabel.setText("-") + return + + self.projectNameLabel.setText(self.project.name) + self.projectDescriptionLabel.setText( + "
".join( + [ + str(self.project.path.resolve()), + f"{len(self.project.sources)} sources", + f"{len(self.project.samples)} samples ({len(self.project.samplesUnclassified)} unclassified)", + ] + ) + ) + + def setAbort(self, b: bool): + self.abort = b + + @Slot() + def on_extractButton_clicked(self): + if not self.project: + return + + progressDialog = YieldProgress(self) + progressDialog.setWindowModality(Qt.WindowModality.ApplicationModal) + + self.abort = False + progressDialog.abortButton.clicked.connect(lambda: self.setAbort(True)) + + progressDialog.show() + + iterator = iter(self.project.extractSamplesYield()) + progressDialog.progressBar.setMinimum(0) + while not self.abort: + try: + path, i, total = next(iterator) + progressDialog.label.setText(path.name) + progressDialog.progressBar.setValue(i) + if i <= 2: + progressDialog.progressBar.setMaximum(total) + + if total > 10 and i % 10 == 0 or total <= 10: + progressDialog.update() + QApplication.processEvents() + except StopIteration: + break + + self.abort = False + self.reloadProject.emit() + progressDialog.close() + progressDialog.deleteLater() + + @Slot() + def on_redactSourcesButton_clicked(self): + if not self.project: + return + + progressDialog = YieldProgress(self) + progressDialog.setWindowModality(Qt.WindowModality.ApplicationModal) + + self.abort = False + progressDialog.abortButton.clicked.connect(lambda: self.setAbort(True)) + + progressDialog.show() + + iterator = iter(self.project.redactSourcesYield()) + progressDialog.progressBar.setMinimum(0) + while not self.abort: + try: + path, i, total = next(iterator) + progressDialog.label.setText(path.name) + progressDialog.progressBar.setValue(i) + if i <= 2: + progressDialog.progressBar.setMaximum(total) + + if total > 10 and i % 10 == 0 or total <= 10: + progressDialog.update() + QApplication.processEvents() + except StopIteration: + break + + self.abort = False + progressDialog.close() + progressDialog.deleteLater() diff --git a/ui/components/projectEntry_Manage.ui b/ui/components/projectEntry_Manage.ui new file mode 100644 index 0000000..35878c8 --- /dev/null +++ b/ui/components/projectEntry_Manage.ui @@ -0,0 +1,68 @@ + + + ProjectEntry_Manage + + + + 0 + 0 + 500 + 400 + + + + ProjectEntry_Manage + + + + + + Redact sources + + + + + + + - + + + + + + + + 14 + true + + + + - + + + + + + + Extract + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/ui/components/projectEntry_Manage_ui.py b/ui/components/projectEntry_Manage_ui.py new file mode 100644 index 0000000..64809e8 --- /dev/null +++ b/ui/components/projectEntry_Manage_ui.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file 'projectEntry_Manage.ui' +## +## Created by: Qt User Interface Compiler version 6.5.2 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QGridLayout, QLabel, QPushButton, + QSizePolicy, QSpacerItem, QWidget) + +class Ui_ProjectEntry_Manage(object): + def setupUi(self, ProjectEntry_Manage): + if not ProjectEntry_Manage.objectName(): + ProjectEntry_Manage.setObjectName(u"ProjectEntry_Manage") + ProjectEntry_Manage.resize(500, 400) + ProjectEntry_Manage.setWindowTitle(u"ProjectEntry_Manage") + self.gridLayout = QGridLayout(ProjectEntry_Manage) + self.gridLayout.setObjectName(u"gridLayout") + self.redactSourcesButton = QPushButton(ProjectEntry_Manage) + self.redactSourcesButton.setObjectName(u"redactSourcesButton") + + self.gridLayout.addWidget(self.redactSourcesButton, 2, 1, 1, 1) + + self.projectDescriptionLabel = QLabel(ProjectEntry_Manage) + self.projectDescriptionLabel.setObjectName(u"projectDescriptionLabel") + + self.gridLayout.addWidget(self.projectDescriptionLabel, 1, 0, 1, 2) + + self.projectNameLabel = QLabel(ProjectEntry_Manage) + self.projectNameLabel.setObjectName(u"projectNameLabel") + font = QFont() + font.setPointSize(14) + font.setBold(True) + self.projectNameLabel.setFont(font) + + self.gridLayout.addWidget(self.projectNameLabel, 0, 0, 1, 2) + + self.extractButton = QPushButton(ProjectEntry_Manage) + self.extractButton.setObjectName(u"extractButton") + + self.gridLayout.addWidget(self.extractButton, 2, 0, 1, 1) + + self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) + + self.gridLayout.addItem(self.verticalSpacer, 3, 0, 1, 2) + + + self.retranslateUi(ProjectEntry_Manage) + + QMetaObject.connectSlotsByName(ProjectEntry_Manage) + # setupUi + + def retranslateUi(self, ProjectEntry_Manage): + self.redactSourcesButton.setText(QCoreApplication.translate("ProjectEntry_Manage", u"Redact sources", None)) + self.projectDescriptionLabel.setText(QCoreApplication.translate("ProjectEntry_Manage", u"-", None)) + self.projectNameLabel.setText(QCoreApplication.translate("ProjectEntry_Manage", u"-", None)) + self.extractButton.setText(QCoreApplication.translate("ProjectEntry_Manage", u"Extract", None)) + pass + # retranslateUi + diff --git a/ui/components/projectEntry_ui.py b/ui/components/projectEntry_ui.py index 78bb438..edec07f 100644 --- a/ui/components/projectEntry_ui.py +++ b/ui/components/projectEntry_ui.py @@ -15,10 +15,10 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QGradient, QIcon, QImage, QKeySequence, QLinearGradient, QPainter, QPalette, QPixmap, QRadialGradient, QTransform) -from PySide6.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, QLabel, - QListWidget, QListWidgetItem, QPushButton, QSizePolicy, - QSpacerItem, QTabWidget, QVBoxLayout, QWidget) +from PySide6.QtWidgets import (QApplication, QHBoxLayout, QListWidget, QListWidgetItem, + QSizePolicy, QTabWidget, QVBoxLayout, QWidget) +from ui.components.projectEntry_Manage import ProjectEntry_Manage from ui.components.samplesListWidget import SamplesListWidget class Ui_ProjectEntry(object): @@ -30,38 +30,8 @@ class Ui_ProjectEntry(object): self.verticalLayout.setObjectName(u"verticalLayout") self.tabWidget = QTabWidget(ProjectEntry) self.tabWidget.setObjectName(u"tabWidget") - self.tabManage = QWidget() + self.tabManage = ProjectEntry_Manage() self.tabManage.setObjectName(u"tabManage") - self.gridLayout = QGridLayout(self.tabManage) - self.gridLayout.setObjectName(u"gridLayout") - self.pushButton = QPushButton(self.tabManage) - self.pushButton.setObjectName(u"pushButton") - - self.gridLayout.addWidget(self.pushButton, 2, 0, 1, 1) - - self.projectNameLabel = QLabel(self.tabManage) - self.projectNameLabel.setObjectName(u"projectNameLabel") - font = QFont() - font.setPointSize(14) - font.setBold(True) - self.projectNameLabel.setFont(font) - - self.gridLayout.addWidget(self.projectNameLabel, 0, 0, 1, 2) - - self.pushButton_2 = QPushButton(self.tabManage) - self.pushButton_2.setObjectName(u"pushButton_2") - - self.gridLayout.addWidget(self.pushButton_2, 2, 1, 1, 1) - - self.projectDescriptionLabel = QLabel(self.tabManage) - self.projectDescriptionLabel.setObjectName(u"projectDescriptionLabel") - - self.gridLayout.addWidget(self.projectDescriptionLabel, 1, 0, 1, 2) - - self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) - - self.gridLayout.addItem(self.verticalSpacer, 3, 0, 1, 2) - self.tabWidget.addTab(self.tabManage, "") self.tabClassify = QWidget() self.tabClassify.setObjectName(u"tabClassify") @@ -107,10 +77,6 @@ class Ui_ProjectEntry(object): def retranslateUi(self, ProjectEntry): ProjectEntry.setWindowTitle(QCoreApplication.translate("ProjectEntry", u"projectEntry", None)) - self.pushButton.setText(QCoreApplication.translate("ProjectEntry", u"Extract", None)) - self.projectNameLabel.setText(QCoreApplication.translate("ProjectEntry", u"-", None)) - self.pushButton_2.setText(QCoreApplication.translate("ProjectEntry", u"...", None)) - self.projectDescriptionLabel.setText(QCoreApplication.translate("ProjectEntry", u"-", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabManage), QCoreApplication.translate("ProjectEntry", u"Manage", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabClassify), QCoreApplication.translate("ProjectEntry", u"Classify", None)) # retranslateUi diff --git a/ui/components/yieldProgress.py b/ui/components/yieldProgress.py new file mode 100644 index 0000000..fdced78 --- /dev/null +++ b/ui/components/yieldProgress.py @@ -0,0 +1,9 @@ +from PySide6.QtWidgets import QDialog + +from .yieldProgress_ui import Ui_YieldProgress + + +class YieldProgress(Ui_YieldProgress, QDialog): + def __init__(self, parent=None): + super().__init__(parent) + self.setupUi(self) diff --git a/ui/components/yieldProgress.ui b/ui/components/yieldProgress.ui new file mode 100644 index 0000000..36772c4 --- /dev/null +++ b/ui/components/yieldProgress.ui @@ -0,0 +1,87 @@ + + + YieldProgress + + + + 0 + 0 + 450 + 200 + + + + YieldProgress + + + + + + + 0 + 0 + + + + ... + + + Qt::AlignCenter + + + + + + + 0 + + + Qt::AlignCenter + + + %v/%m %p% + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Abort + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/ui/components/yieldProgress_ui.py b/ui/components/yieldProgress_ui.py new file mode 100644 index 0000000..5cab283 --- /dev/null +++ b/ui/components/yieldProgress_ui.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file 'yieldProgress.ui' +## +## Created by: Qt User Interface Compiler version 6.5.2 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QDialog, QHBoxLayout, QLabel, + QProgressBar, QPushButton, QSizePolicy, QSpacerItem, + QVBoxLayout, QWidget) + +class Ui_YieldProgress(object): + def setupUi(self, YieldProgress): + if not YieldProgress.objectName(): + YieldProgress.setObjectName(u"YieldProgress") + YieldProgress.resize(450, 200) + YieldProgress.setWindowTitle(u"YieldProgress") + self.verticalLayout = QVBoxLayout(YieldProgress) + self.verticalLayout.setObjectName(u"verticalLayout") + self.label = QLabel(YieldProgress) + self.label.setObjectName(u"label") + sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) + self.label.setSizePolicy(sizePolicy) + self.label.setAlignment(Qt.AlignCenter) + + self.verticalLayout.addWidget(self.label) + + self.progressBar = QProgressBar(YieldProgress) + self.progressBar.setObjectName(u"progressBar") + self.progressBar.setMaximum(0) + self.progressBar.setAlignment(Qt.AlignCenter) + self.progressBar.setFormat(u"%v/%m %p%") + + self.verticalLayout.addWidget(self.progressBar) + + self.horizontalLayout = QHBoxLayout() + self.horizontalLayout.setObjectName(u"horizontalLayout") + self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) + + self.horizontalLayout.addItem(self.horizontalSpacer) + + self.abortButton = QPushButton(YieldProgress) + self.abortButton.setObjectName(u"abortButton") + + self.horizontalLayout.addWidget(self.abortButton) + + self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) + + self.horizontalLayout.addItem(self.horizontalSpacer_2) + + + self.verticalLayout.addLayout(self.horizontalLayout) + + + self.retranslateUi(YieldProgress) + + QMetaObject.connectSlotsByName(YieldProgress) + # setupUi + + def retranslateUi(self, YieldProgress): + self.label.setText(QCoreApplication.translate("YieldProgress", u"...", None)) + self.abortButton.setText(QCoreApplication.translate("YieldProgress", u"Abort", None)) + pass + # retranslateUi +