feat: ProjectEntry_Samples

This commit is contained in:
283375 2023-09-24 02:07:42 +08:00
parent 0ae960a405
commit bd69c32098
Signed by: 283375
SSH Key Fingerprint: SHA256:UcX0qg6ZOSDOeieKPGokA5h7soykG61nz2uxuQgVLSk
6 changed files with 240 additions and 2 deletions

View File

@ -17,6 +17,7 @@ class ProjectEntry(Ui_ProjectEntry, QWidget):
self.project = project
self.tabManage.setProject(project)
self.tabClassify.setProject(project)
self.tabSamples.setProject(project)
def reloadProject(self):
self.project.reload()

View File

@ -29,7 +29,7 @@
<string>Classify</string>
</attribute>
</widget>
<widget class="QWidget" name="tabSamples">
<widget class="ProjectEntry_Samples" name="tabSamples">
<attribute name="title">
<string>Samples</string>
</attribute>
@ -51,6 +51,12 @@
<header>ui.components.projectEntry_Classify</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ProjectEntry_Samples</class>
<extends>QWidget</extends>
<header>ui.components.projectEntry_Samples</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@ -0,0 +1,64 @@
import logging
from PySide6.QtCore import Qt, Slot
from PySide6.QtWidgets import QListWidgetItem, QWidget
from project import Project
from ..extends.samplesListWidget import SamplesListWidget
from .blockLabelDialog import BlockLabelDialog
from .projectEntry_Samples_ui import Ui_ProjectEntry_Samples
logger = logging.getLogger(__name__)
class ProjectEntry_Samples(Ui_ProjectEntry_Samples, QWidget):
TagRole = Qt.ItemDataRole.UserRole + 1
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.samplesListWidget.setDragEnabled(False)
self.project = None
def setProject(self, project: Project):
self.project = project
self.updateSampleTags()
def updateSampleTags(self):
self.tagsListWidget.clear()
with BlockLabelDialog(self) as block:
block.setText(f"{self.project.name}<br>Loading tags")
block.show()
for tag in self.project.tags + ["ignored"]:
samples = self.project.samplesByTag(tag)
item = QListWidgetItem(f"{tag} ({len(samples)} samples)")
item.setData(self.TagRole, tag)
self.tagsListWidget.addItem(item)
@Slot()
def on_loadSamplesButton_clicked(self):
tag = self.tagsListWidget.currentItem().data(self.TagRole)
samples = self.project.samplesByTag(tag)
self.samplesListWidget.setSamples(samples, cancellable=False)
@Slot()
def on_reloadButton_clicked(self):
self.updateSampleTags()
@Slot()
def on_unclassifyButton_clicked(self):
selectedSampleItems = self.samplesListWidget.selectedItems()
paths = [
item.data(SamplesListWidget.PathlibPathRole) for item in selectedSampleItems
]
for item, path in zip(selectedSampleItems, paths):
try:
self.project.unclassify(path)
index = self.samplesListWidget.indexFromItem(item)
self.samplesListWidget.model().removeRow(index.row())
except Exception:
logger.exception(f"cannot unclassify {path}")

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProjectEntry_Samples</class>
<widget class="QWidget" name="ProjectEntry_Samples">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>648</width>
<height>504</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">ProjectEntry_Samples</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="tagsListWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="loadSamplesButton">
<property name="text">
<string>Load &gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reloadButton">
<property name="text">
<string>Reload</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="SamplesListWidget" name="samplesListWidget"/>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="unclassifyButton">
<property name="text">
<string>Unclassify</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SamplesListWidget</class>
<extends>QListWidget</extends>
<header>ui.extends.samplesListWidget</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'projectEntry_Samples.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, QFrame, QHBoxLayout, QListWidget,
QListWidgetItem, QPushButton, QSizePolicy, QVBoxLayout,
QWidget)
from ui.extends.samplesListWidget import SamplesListWidget
class Ui_ProjectEntry_Samples(object):
def setupUi(self, ProjectEntry_Samples):
if not ProjectEntry_Samples.objectName():
ProjectEntry_Samples.setObjectName(u"ProjectEntry_Samples")
ProjectEntry_Samples.resize(648, 504)
ProjectEntry_Samples.setWindowTitle(u"ProjectEntry_Samples")
self.horizontalLayout = QHBoxLayout(ProjectEntry_Samples)
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.verticalLayout_2 = QVBoxLayout()
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.tagsListWidget = QListWidget(ProjectEntry_Samples)
self.tagsListWidget.setObjectName(u"tagsListWidget")
sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.tagsListWidget.sizePolicy().hasHeightForWidth())
self.tagsListWidget.setSizePolicy(sizePolicy)
self.verticalLayout_2.addWidget(self.tagsListWidget)
self.loadSamplesButton = QPushButton(ProjectEntry_Samples)
self.loadSamplesButton.setObjectName(u"loadSamplesButton")
self.verticalLayout_2.addWidget(self.loadSamplesButton)
self.reloadButton = QPushButton(ProjectEntry_Samples)
self.reloadButton.setObjectName(u"reloadButton")
self.verticalLayout_2.addWidget(self.reloadButton)
self.horizontalLayout.addLayout(self.verticalLayout_2)
self.samplesListWidget = SamplesListWidget(ProjectEntry_Samples)
self.samplesListWidget.setObjectName(u"samplesListWidget")
self.horizontalLayout.addWidget(self.samplesListWidget)
self.frame = QFrame(ProjectEntry_Samples)
self.frame.setObjectName(u"frame")
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.verticalLayout = QVBoxLayout(self.frame)
self.verticalLayout.setObjectName(u"verticalLayout")
self.unclassifyButton = QPushButton(self.frame)
self.unclassifyButton.setObjectName(u"unclassifyButton")
self.verticalLayout.addWidget(self.unclassifyButton)
self.horizontalLayout.addWidget(self.frame)
self.retranslateUi(ProjectEntry_Samples)
QMetaObject.connectSlotsByName(ProjectEntry_Samples)
# setupUi
def retranslateUi(self, ProjectEntry_Samples):
self.loadSamplesButton.setText(QCoreApplication.translate("ProjectEntry_Samples", u"Load >", None))
self.reloadButton.setText(QCoreApplication.translate("ProjectEntry_Samples", u"Reload", None))
self.unclassifyButton.setText(QCoreApplication.translate("ProjectEntry_Samples", u"Unclassify", None))
pass
# retranslateUi

View File

@ -20,6 +20,7 @@ from PySide6.QtWidgets import (QApplication, QSizePolicy, QTabWidget, QVBoxLayou
from ui.components.projectEntry_Classify import ProjectEntry_Classify
from ui.components.projectEntry_Manage import ProjectEntry_Manage
from ui.components.projectEntry_Samples import ProjectEntry_Samples
class Ui_ProjectEntry(object):
def setupUi(self, ProjectEntry):
@ -36,7 +37,7 @@ class Ui_ProjectEntry(object):
self.tabClassify = ProjectEntry_Classify()
self.tabClassify.setObjectName(u"tabClassify")
self.tabWidget.addTab(self.tabClassify, "")
self.tabSamples = QWidget()
self.tabSamples = ProjectEntry_Samples()
self.tabSamples.setObjectName(u"tabSamples")
self.tabWidget.addTab(self.tabSamples, "")