create files with abstract model class
This commit is contained in:
committed by
Thomas Peetz
parent
954dab289a
commit
3f0a37ff19
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Boolean, Column, DateTime, Integer, String
|
||||
from sqlalchemy import Column, DateTime, Integer, String
|
||||
from sqlalchemy.dialects.mysql import BIT
|
||||
|
||||
from database.base import Base
|
||||
@@ -13,10 +13,10 @@ class MediaFile(Base):
|
||||
cloud_link = Column(String(255))
|
||||
file_name = Column(String(255))
|
||||
path = Column(String(255))
|
||||
review = Column(BIT(1), default=True)
|
||||
review = Column(BIT(1))
|
||||
title = Column(String(255))
|
||||
url = Column(String(255))
|
||||
should_download = Column(Boolean, default=True)
|
||||
should_download = Column(BIT(1))
|
||||
|
||||
def __repr__(self):
|
||||
return f'MediaFile({self.id} {self.title} {self.title})'
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Boolean, Column, DateTime, Integer, String, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy import Column, DateTime, Integer, String, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.dialects.mysql import BIT
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class DataViewMeta(ABC):
|
||||
@abstractmethod
|
||||
def get_header(self):
|
||||
pass
|
||||
|
||||
|
||||
class ComicView(DataViewMeta):
|
||||
def get_header(self):
|
||||
pass
|
||||
@@ -0,0 +1,33 @@
|
||||
from typing import List
|
||||
|
||||
from PyQt5.QtCore import QAbstractTableModel
|
||||
from PySide6.QtCore import QModelIndex
|
||||
from PySide6.QtGui import Qt
|
||||
|
||||
from gui.data_view import DataViewMeta
|
||||
|
||||
|
||||
class DataViewModel(QAbstractTableModel):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.main_window = None
|
||||
self._config = None
|
||||
self._data = List[DataViewMeta]
|
||||
|
||||
def rowCount(self, parent = QModelIndex()):
|
||||
return len(self._data)
|
||||
|
||||
def columnCount(self, parent = QModelIndex()):
|
||||
return 0
|
||||
|
||||
def headerData(self, section, orientation, role = Qt.ItemDataRole.DisplayRole):
|
||||
return None
|
||||
|
||||
def data(self, index, role = Qt.ItemDataRole.DisplayRole):
|
||||
return None
|
||||
|
||||
def setData(self, index, value, role = Qt.ItemDataRole.EditRole):
|
||||
return False
|
||||
|
||||
def flags(self, index):
|
||||
return None
|
||||
+10
-5
@@ -45,8 +45,8 @@ class KontorTableModel(QAbstractTableModel):
|
||||
if self._data is None:
|
||||
return None
|
||||
value = self._data[index.row()][index.column()]
|
||||
if role == Qt.ItemDataRole.DisplayRole:
|
||||
# print('{}: {}'.format(value, type(value)))
|
||||
# print('{}:: {}:: {}: {}'.format(index, role, value, type(value)))
|
||||
if role == Qt.ItemDataRole.DisplayRole or role == Qt.ItemDataRole.EditRole:
|
||||
if isinstance(value, datetime):
|
||||
return value.strftime("%Y-%m-%d %M:%M:%S")
|
||||
if isinstance(value, str):
|
||||
@@ -57,6 +57,7 @@ class KontorTableModel(QAbstractTableModel):
|
||||
else:
|
||||
return self._main_window.cross
|
||||
if isinstance(value, int):
|
||||
print('{}:: {}: {}'.format(index, value, type(value)))
|
||||
if value == 1:
|
||||
return self._main_window.tick
|
||||
else:
|
||||
@@ -69,7 +70,6 @@ class KontorTableModel(QAbstractTableModel):
|
||||
return str(value)
|
||||
if role == Qt.ItemDataRole.DecorationRole:
|
||||
if isinstance(value, bytes):
|
||||
# print('{}: {}'.format(value, type(value)))
|
||||
if value == b'\x01':
|
||||
return self._main_window.tick
|
||||
else:
|
||||
@@ -91,13 +91,18 @@ class KontorTableModel(QAbstractTableModel):
|
||||
# print(f"Header count: {len(self._config.get_header())}")
|
||||
return len(self._config.header)
|
||||
|
||||
def setData(self, index, value, role=Qt.ItemDataRole.EditRole):
|
||||
def setData(self, index, value, role: int) -> bool:
|
||||
print(index, role)
|
||||
if role == Qt.ItemDataRole.EditRole:
|
||||
self._data[index.row()][index.column()] = value
|
||||
print(self._data[index.row()][index.column()])
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
if role == Qt.ItemDataRole.CheckStateRole:
|
||||
print("role == Qt.ItemDataRole.CheckStateRole")
|
||||
checked = value == Qt.CheckState.Checked
|
||||
self._data[index.row()][index.column()] = checked
|
||||
return True
|
||||
return False
|
||||
|
||||
def flags(self, index):
|
||||
return Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsEditable | Qt.ItemFlag.ItemIsUserTristate
|
||||
|
||||
Reference in New Issue
Block a user