refresh table when updated
@@ -6,8 +6,7 @@ from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from PySide6.QtGui import QAction, QIcon
|
||||
from PySide6.QtSql import QSqlDatabase
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QMenu, QMessageBox, QTabWidget, QTableView
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QMenu, QMessageBox, QTabWidget, QTableView, QHBoxLayout, QCheckBox
|
||||
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow
|
||||
from platformdirs import PlatformDirs
|
||||
|
||||
@@ -21,11 +20,11 @@ class MainWindow(QMainWindow):
|
||||
def __init__(self, config):
|
||||
super().__init__()
|
||||
|
||||
self.tick = QIcon('tick.png')
|
||||
self.cross = QIcon('cross.png')
|
||||
self.import_icon = QIcon("application-import.png")
|
||||
self.export_icon = QIcon("application-export.png")
|
||||
self.circle_icon = QIcon("arrow-circle-double.png")
|
||||
self.tick = QIcon('res/tick.png')
|
||||
self.cross = QIcon('res/cross.png')
|
||||
self.import_icon = QIcon("res/application-import.png")
|
||||
self.export_icon = QIcon("res/application-export.png")
|
||||
self.circle_icon = QIcon("res/arrow-circle-double.png")
|
||||
|
||||
self.setWindowTitle("Kontor")
|
||||
self.setMinimumSize(800, 500)
|
||||
@@ -35,6 +34,7 @@ class MainWindow(QMainWindow):
|
||||
self._createStatusBar()
|
||||
|
||||
self.data = []
|
||||
self.filter = {}
|
||||
self.central_widget = QWidget()
|
||||
parent_layout = QVBoxLayout()
|
||||
self.central_widget.setLayout(parent_layout)
|
||||
@@ -111,11 +111,24 @@ class MainWindow(QMainWindow):
|
||||
def generate_tab_media_file(self, db_configuration):
|
||||
media_file_tab = QWidget()
|
||||
layout = QVBoxLayout()
|
||||
filter_layout = QHBoxLayout()
|
||||
download_checkbox = QCheckBox()
|
||||
download_checkbox.setText("Download")
|
||||
download_checkbox.checkStateChanged.connect(self.refresh)
|
||||
self.filter["download"] = download_checkbox
|
||||
review_checkbox = QCheckBox()
|
||||
review_checkbox.setText("Review")
|
||||
review_checkbox.checkStateChanged.connect(self.refresh)
|
||||
self.filter["review"] = review_checkbox
|
||||
filter_layout.addWidget(review_checkbox)
|
||||
filter_layout.addWidget(download_checkbox)
|
||||
filter_layout.addStretch()
|
||||
model = MediaFileTableModel(db_configuration, self)
|
||||
self.data.append(model)
|
||||
media_file_tab.setLayout(layout)
|
||||
table_view = QTableView()
|
||||
table_view.setModel(model)
|
||||
layout.addLayout(filter_layout)
|
||||
layout.addWidget(table_view)
|
||||
return media_file_tab
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ class MediaFileTableModel(QAbstractTableModel):
|
||||
super().__init__()
|
||||
self.main_window = main_window
|
||||
self._data = []
|
||||
self.status_bar = main_window.statusBar
|
||||
self.mariadb_conn = mariadb.connect(
|
||||
host=db_config['mariadb']['host'],
|
||||
port=db_config['mariadb']['port'],
|
||||
@@ -24,12 +23,37 @@ class MediaFileTableModel(QAbstractTableModel):
|
||||
def refresh(self):
|
||||
data = []
|
||||
cursor = self.mariadb_conn.cursor()
|
||||
cursor.execute("SELECT id, url, review, should_download, file_name, cloud_link FROM media_file")
|
||||
filter_rule = ""
|
||||
print(self.main_window.filter["download"].isChecked())
|
||||
if self.main_window.filter["download"].isChecked():
|
||||
print(self.main_window.filter["download"].isChecked())
|
||||
filter_rule = "WHERE should_download is true"
|
||||
if self.main_window.filter["review"].isChecked():
|
||||
if len(filter_rule) > 0:
|
||||
filter_rule += " AND "
|
||||
else:
|
||||
filter_rule += "WHERE "
|
||||
filter_rule += "review is true"
|
||||
print(f"{filter_rule=}")
|
||||
try:
|
||||
cursor.execute(f"SELECT id, url, review, should_download, file_name, cloud_link FROM media_file {filter_rule}")
|
||||
except mariadb.Error as error:
|
||||
print(error)
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
data.append(list(row))
|
||||
self.status_bar.showMessage(f"{len(rows)} Einträge geladen", 3000)
|
||||
self._data = data
|
||||
print(len(rows))
|
||||
if len(rows) > 0:
|
||||
self.beginResetModel()
|
||||
for row in rows:
|
||||
data.append(list(row))
|
||||
self._data = data
|
||||
self.endResetModel()
|
||||
else:
|
||||
self._data = None
|
||||
try:
|
||||
self.layoutChanged.emit()
|
||||
except:
|
||||
|
||||
self.main_window.statusBar.showMessage(f"{len(rows)} Einträge geladen", 3000)
|
||||
|
||||
def rowCount(self, parent=QModelIndex()):
|
||||
# The length of the outer list.
|
||||
|
||||
|
Before Width: | Height: | Size: 513 B After Width: | Height: | Size: 513 B |
|
Before Width: | Height: | Size: 524 B After Width: | Height: | Size: 524 B |
|
Before Width: | Height: | Size: 836 B After Width: | Height: | Size: 836 B |
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 544 B |
|
Before Width: | Height: | Size: 634 B After Width: | Height: | Size: 634 B |