mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
add downloads tab functionality
This commit is contained in:
+51
-7
@@ -1,7 +1,9 @@
|
|||||||
from PySide6 import QtWidgets
|
from PySide6 import QtWidgets
|
||||||
from PySide6.QtCore import Qt, QTimer
|
from PySide6 import QtCore
|
||||||
|
from PySide6.QtCore import Qt, QTimer, QModelIndex, QAbstractTableModel
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QLineEdit,
|
QLineEdit,
|
||||||
|
QTableView,
|
||||||
QWidget,
|
QWidget,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QListWidget,
|
QListWidget,
|
||||||
@@ -11,6 +13,7 @@ from PySide6.QtWidgets import (
|
|||||||
QComboBox,
|
QComboBox,
|
||||||
QTabWidget,
|
QTabWidget,
|
||||||
QProgressBar,
|
QProgressBar,
|
||||||
|
QHeaderView,
|
||||||
)
|
)
|
||||||
from PySide6.QtGui import QIcon, QAction, QCloseEvent
|
from PySide6.QtGui import QIcon, QAction, QCloseEvent
|
||||||
import darkdetect
|
import darkdetect
|
||||||
@@ -48,7 +51,8 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
self.softwareList = QListWidget()
|
self.softwareList = QListWidget()
|
||||||
self.post_author_list = QListWidget()
|
self.post_author_list = QListWidget()
|
||||||
self.libraryList = QListWidget()
|
self.libraryList = QListWidget()
|
||||||
self.downloadList = QListWidget()
|
self.download_model = None
|
||||||
|
self.downloadList = QTableView()
|
||||||
self.emptyLibrary = QLabel("No items in library.")
|
self.emptyLibrary = QLabel("No items in library.")
|
||||||
self.emptyDownload = QLabel("No items in downloads.")
|
self.emptyDownload = QLabel("No items in downloads.")
|
||||||
self.progressbar = QProgressBar()
|
self.progressbar = QProgressBar()
|
||||||
@@ -61,6 +65,47 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
containerLayout.addWidget(self.post_author_list)
|
containerLayout.addWidget(self.post_author_list)
|
||||||
self.softwareList.addItems(searchresults)
|
self.softwareList.addItems(searchresults)
|
||||||
|
|
||||||
|
class DownloadModel(QAbstractTableModel):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.headers = ["Name", "Status", "Progress", "Speed", "Size", "Total Size"]
|
||||||
|
|
||||||
|
def rowCount(self, parent=QModelIndex()):
|
||||||
|
return len(state.downloads)
|
||||||
|
|
||||||
|
def columnCount(self, parent=QModelIndex()):
|
||||||
|
return len(self.headers)
|
||||||
|
|
||||||
|
def headerData(self, section, orientation, role=Qt.DisplayRole):
|
||||||
|
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
|
||||||
|
return self.headers[section]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def data(self, index, role=Qt.DisplayRole):
|
||||||
|
if role == Qt.DisplayRole:
|
||||||
|
download = state.downloads[index.row()]
|
||||||
|
col = index.column()
|
||||||
|
|
||||||
|
if col == 0:
|
||||||
|
return download.name
|
||||||
|
elif col == 1:
|
||||||
|
return getattr(download, 'status', 'Downloading')
|
||||||
|
elif col == 2:
|
||||||
|
return f"{int(download.progress)}%"
|
||||||
|
elif col == 3:
|
||||||
|
return f"{download.download_speed_string()}"
|
||||||
|
elif col == 4:
|
||||||
|
pass
|
||||||
|
elif col == 5:
|
||||||
|
return f"{download.total_length_string()}"
|
||||||
|
return None
|
||||||
|
|
||||||
|
self.download_model = DownloadModel()
|
||||||
|
self.downloadList.setModel(self.download_model)
|
||||||
|
self.downloadList.horizontalHeader().setStretchLastSection(False)
|
||||||
|
self.downloadList.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
|
||||||
|
self.downloadList.setSelectionBehavior(QTableView.SelectRows)
|
||||||
|
|
||||||
# download button triggers
|
# download button triggers
|
||||||
self.dlbutton.clicked.connect(lambda: run_thread(threading.Thread(target=download_selected, args=(self.softwareList.currentItem(), state.posts, state.post_titles))))
|
self.dlbutton.clicked.connect(lambda: run_thread(threading.Thread(target=download_selected, args=(self.softwareList.currentItem(), state.posts, state.post_titles))))
|
||||||
|
|
||||||
@@ -111,12 +156,12 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
|
|
||||||
self.download_timer = QTimer()
|
self.download_timer = QTimer()
|
||||||
self.download_timer.timeout.connect(lambda: run_thread(threading.Thread(target=self.download_list_update)))
|
self.download_timer.timeout.connect(lambda: run_thread(threading.Thread(target=self.download_list_update)))
|
||||||
self.download_timer.start(5000)
|
self.download_timer.start(500)
|
||||||
|
|
||||||
def download_list_update(self):
|
def download_list_update(self):
|
||||||
self.downloadList.clear()
|
if self.download_model:
|
||||||
for download in state.downloads:
|
self.download_model.layoutAboutToBeChanged.emit()
|
||||||
self.downloadList.addItem(download.name)
|
self.download_model.layoutChanged.emit()
|
||||||
|
|
||||||
def closeEvent(self, event: QCloseEvent):
|
def closeEvent(self, event: QCloseEvent):
|
||||||
closehelper()
|
closehelper()
|
||||||
@@ -125,7 +170,6 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
def set_tracker(self, _):
|
def set_tracker(self, _):
|
||||||
state.tracker = self.tracker_list.currentText()
|
state.tracker = self.tracker_list.currentText()
|
||||||
|
|
||||||
|
|
||||||
def update_progress(self):
|
def update_progress(self):
|
||||||
progress = dlprogress()
|
progress = dlprogress()
|
||||||
self.progressbar.setValue(progress)
|
self.progressbar.setValue(progress)
|
||||||
|
|||||||
@@ -55,6 +55,17 @@ def dlprogress():
|
|||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
# def dlspeed():
|
||||||
|
# try:
|
||||||
|
# state.downloads = [download for download in state.aria2.get_downloads() if not download.is_metadata]
|
||||||
|
# downloads = state.downloads
|
||||||
|
# if downloads:
|
||||||
|
# for download in downloads:
|
||||||
|
# speed = download.download_speed()
|
||||||
|
# return speed
|
||||||
|
# return "0 B/s"
|
||||||
|
# except:
|
||||||
|
# return "0 B/s"
|
||||||
|
|
||||||
def send_notification(shutdown_event):
|
def send_notification(shutdown_event):
|
||||||
while not shutdown_event.is_set():
|
while not shutdown_event.is_set():
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class AppState:
|
|||||||
post_urls: List[str]
|
post_urls: List[str]
|
||||||
post_author: List[str]
|
post_author: List[str]
|
||||||
downloads: List[str]
|
downloads: List[str]
|
||||||
|
# dl_speed: str = "0 B/s"
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
tracker: str = "rutracker"
|
tracker: str = "rutracker"
|
||||||
api_url: str = "https://api.michijackson.xyz"
|
api_url: str = "https://api.michijackson.xyz"
|
||||||
|
|||||||
Reference in New Issue
Block a user