Compare commits

...

5 Commits

2 changed files with 81 additions and 24 deletions
+31 -9
View File
@@ -12,7 +12,9 @@ from PySide6.QtWidgets import (
QHBoxLayout,
QSpinBox,
QCheckBox,
)
QFileDialog,
)
import platform
def settings_dialog(self):
@@ -32,14 +34,16 @@ def settings_dialog(self):
update_checkbox_layout = QHBoxLayout()
# ignore updates checkbox
update_checkbox = QCheckBox()
update_checkbox_container.setLayout(update_checkbox_layout)
update_checkbox_layout.addWidget(QLabel("Ignore Updates: "))
update_checkbox_layout.addStretch()
update_checkbox.setChecked(state.ignore_updates)
update_checkbox.toggled.connect(lambda checked: setattr(state, 'ignore_updates', checked))
update_checkbox_layout.addWidget(update_checkbox)
dialog.layout().addWidget(update_checkbox_container)
if platform.system() == "Windows":
update_checkbox = QCheckBox()
update_checkbox_container.setLayout(update_checkbox_layout)
update_checkbox_layout.addWidget(QLabel("Ignore Updates: "))
update_checkbox_layout.addStretch()
update_checkbox.setChecked(state.ignore_updates)
update_checkbox.toggled.connect(lambda checked: setattr(state, 'ignore_updates', checked))
update_checkbox_layout.addWidget(update_checkbox)
dialog.layout().addWidget(update_checkbox_container)
# auto-resume downloads checkbox
@@ -111,6 +115,15 @@ def settings_dialog(self):
download_path.setText(state.download_path)
dialog.layout().addWidget(download_path_container)
def browse_download_path():
dir_path = QFileDialog.getExistingDirectory(dialog, "Select Download Directory", state.download_path)
if dir_path:
download_path.setText(dir_path)
browse_button = QPushButton("📁")
download_path_layout.addWidget(browse_button)
browse_button.clicked.connect(browse_download_path)
##################
# SPEED LIMITING #
##################
@@ -144,6 +157,15 @@ def settings_dialog(self):
image_path.setText(state.image_path)
dialog.layout().addWidget(image_path_container)
def browse_image_path():
file_path = QFileDialog.getOpenFileName(dialog, "Select Image File", state.image_path, "Image Files (*.png *.jpg)")[0]
if file_path:
image_path.setText(file_path)
browse_button = QPushButton("📁")
image_path_layout.addWidget(browse_button)
browse_button.clicked.connect(browse_image_path)
###############
# SAVE/CANCEL #
###############
+50 -15
View File
@@ -20,7 +20,7 @@ from PySide6.QtWidgets import (
QStyleOptionButton,
QStyledItemDelegate,
QApplication,
)
)
from PySide6.QtGui import QIcon, QAction, QCloseEvent, QImage, QPixmap
import darkdetect
@@ -223,6 +223,23 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
def toggle_pause_resume(self, row):
download = state.downloads[row]
if download.progress == 100:
if state.download_path is not None and os.path.exists(state.download_path):
if platform.system() == "Windows":
os.startfile(os.path.normpath(state.download_path))
elif platform.system() == "Linux":
subprocess.Popen(["xdg-open", state.download_path])
elif platform.system() == "Darwin":
subprocess.Popen(["open", state.download_path])
else:
if platform.system() == "Windows":
os.startfile(os.path.normpath(os.getcwd()))
elif platform.system() == "Linux":
subprocess.Popen(["xdg-open", os.getcwd()])
elif platform.system() == "Darwin":
subprocess.Popen(["open", os.getcwd()])
return
if download.is_paused:
download.resume()
consoleLog(f"Resumed download: {download.name}", True)
@@ -230,26 +247,40 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
download.pause()
consoleLog(f"Paused download: {download.name}", True)
idx = self.index(row, 0)
self.dataChanged.emit(idx, idx, [Qt.DisplayRole, Qt.UserRole])
self.dataChanged.emit(idx, idx, [Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.UserRole])
class PauseResumeDelegate(QStyledItemDelegate):
clicked = Signal(int)
def paint(self, painter, option, index):
if index.column() != 0:
super().paint(painter, option, index)
return
def setEditorData(self, editor, index):
download = state.downloads[index.row()]
button = editor.findChild(QtWidgets.QPushButton)
paused = index.data(Qt.UserRole)
if button:
if download.progress == 100:
button.setText("📁")
else:
button.setText("▶︎" if download.is_paused else "⏸︎")
button = QStyleOptionButton()
button.rect = option.rect
button.text = "▶︎" if paused else "⏸︎"
button.state = QStyle.State_Enabled
QApplication.style().drawControl(
QStyle.CE_PushButton, button, painter
)
def createEditor(self, parent, option, index):
download = state.downloads[index.row()]
widget = QWidget(parent)
widget.setStyleSheet("border: none;")
layout = QHBoxLayout(widget)
layout.setContentsMargins(0, 0, 0, 0)
if download.progress == 100:
btnPause = QtWidgets.QPushButton("📁")
else:
btnPause = QtWidgets.QPushButton("▶︎" if download.is_paused else "⏸︎")
btnPause.setFixedSize(40, 30)
btnPause.clicked.connect(lambda: self.clicked.emit(index.row()))
layout.addStretch()
layout.addWidget(btnPause)
layout.addStretch()
widget.setLayout(layout)
return widget
def editorEvent(self, event, model, option, index):
if index.column() == 0 and event.type() == QEvent.Type.MouseButtonPress:
@@ -341,7 +372,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
self.progress_timer.start(1000)
self.download_timer = QTimer()
self.download_timer.timeout.connect(lambda: run_thread(threading.Thread(target=self.download_list_update)))
self.download_timer.timeout.connect(self.download_list_update)
self.download_timer.start(500)
self.active_timer = QTimer()
@@ -370,6 +401,10 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
if self.download_model:
self.download_model.layoutAboutToBeChanged.emit()
self.download_model.layoutChanged.emit()
for row in range(self.download_model.rowCount()):
idx = self.download_model.index(row, 0)
self.downloadList.closePersistentEditor(idx)
self.downloadList.openPersistentEditor(idx)
def closeEvent(self, event: QCloseEvent):