mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
add threads setting in settings menu + add aria2c restart function in gui.py
This commit is contained in:
@@ -15,6 +15,15 @@ def run_aria2p():
|
||||
|
||||
return aria2
|
||||
|
||||
t = 4 # default value
|
||||
|
||||
def set_threads(threads):
|
||||
global t
|
||||
t = threads
|
||||
|
||||
|
||||
|
||||
|
||||
def aria2server():
|
||||
downloads_dir = os.path.join(os.path.expanduser("~"), "Downloads")
|
||||
|
||||
@@ -24,7 +33,9 @@ def aria2server():
|
||||
"--disable-ipv6", # added this since it caused problems with vpns
|
||||
"--rpc-listen-all",
|
||||
"--rpc-listen-port=6800",
|
||||
f"--dir={downloads_dir}"
|
||||
f"--dir={downloads_dir}",
|
||||
"-x", str(t),
|
||||
"-s", str(t),
|
||||
]
|
||||
|
||||
|
||||
|
||||
+95
-19
@@ -1,14 +1,30 @@
|
||||
from PySide6 import QtWidgets
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QLineEdit, QPushButton, QWidget, QVBoxLayout, QListWidget, QToolBar, QDialog, QVBoxLayout, QLabel, QHBoxLayout,QComboBox
|
||||
from PySide6.QtWidgets import (
|
||||
QLineEdit,
|
||||
QPushButton,
|
||||
QWidget,
|
||||
QVBoxLayout,
|
||||
QListWidget,
|
||||
QToolBar,
|
||||
QDialog,
|
||||
QLabel,
|
||||
QHBoxLayout,
|
||||
QComboBox,
|
||||
QSpinBox,
|
||||
)
|
||||
from PySide6.QtGui import QIcon, QAction
|
||||
import darkdetect
|
||||
import threading
|
||||
import time
|
||||
from core.scraping.uztracker_scraper import scrape_uztracker
|
||||
from core.scraping.rutracker_scraper import scrape_rutracker
|
||||
from core.scraping.utils import get_magnet_link
|
||||
from core.downloading.download import start_client
|
||||
from core.downloading.download import add_magnet
|
||||
from core.downloading.aria2p_server import set_threads
|
||||
|
||||
|
||||
|
||||
def state_debug(setting):
|
||||
global debug
|
||||
@@ -17,10 +33,18 @@ def state_debug(setting):
|
||||
else:
|
||||
debug = False
|
||||
|
||||
|
||||
def pass_aria(aria):
|
||||
global aria2process
|
||||
aria2process = aria
|
||||
|
||||
|
||||
|
||||
global tracker
|
||||
tracker = "rutracker" # default tracker
|
||||
|
||||
|
||||
|
||||
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
def __init__(self):
|
||||
global settings_action
|
||||
@@ -38,10 +62,6 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
self.searchbar.setPlaceholderText("Search for software...")
|
||||
self.searchbar.setClearButtonEnabled(True)
|
||||
self.searchbar.setMinimumHeight(30)
|
||||
|
||||
|
||||
thread_search = threading.Thread(target=self.return_pressed)
|
||||
|
||||
|
||||
|
||||
self.searchbar.returnPressed.connect(lambda: self.run_search(threading.Thread(target=self.return_pressed))) # Triggers scraping function thread on enter
|
||||
@@ -90,37 +110,93 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
tracker = self.tracker_list.currentText()
|
||||
|
||||
def settings_dialog(self):
|
||||
|
||||
|
||||
|
||||
if debug:
|
||||
print("Settings dialog opened")
|
||||
dialog = QDialog(self)
|
||||
dialog.setWindowTitle("Settings")
|
||||
dialog.setFixedSize(400, 300)
|
||||
dialog.setFixedSize(400, 200)
|
||||
|
||||
|
||||
dialog.setLayout(QVBoxLayout())
|
||||
label = QLabel("This is a settings dialog.")
|
||||
QtWidgets.QPushButton("Close", clicked=dialog.close)
|
||||
# close button
|
||||
dialog.layout().addWidget(label)
|
||||
dialog.layout().addWidget(QtWidgets.QPushButton("Close", clicked=dialog.close))
|
||||
dialog.layout().addWidget(QLabel("Settings"))
|
||||
|
||||
layout = QHBoxLayout()
|
||||
def close_settings():
|
||||
dialog.reject()
|
||||
|
||||
##################
|
||||
# THREAD SETTING #
|
||||
##################
|
||||
thread_box = QSpinBox()
|
||||
thread_box.setMinimum(1)
|
||||
thread_box.setMaximum(16)
|
||||
thread_box.setValue(4)
|
||||
|
||||
|
||||
# container for tight space
|
||||
thread_container = QWidget()
|
||||
thread_layout = QVBoxLayout()
|
||||
|
||||
thread_layout.addWidget(QLabel("Threads:"))
|
||||
thread_layout.addWidget(thread_box)
|
||||
thread_container.setLayout(thread_layout)
|
||||
thread_container.setMaximumHeight(80)
|
||||
|
||||
|
||||
# Dimensions
|
||||
thread_box.setFixedWidth(90)
|
||||
thread_box.setFixedHeight(30)
|
||||
|
||||
dialog.layout().addWidget(thread_container)
|
||||
|
||||
|
||||
|
||||
|
||||
# dialog.layout().addWidget(QtWidgets.QPushButton("Close", clicked=dialog.close))
|
||||
|
||||
layout = QHBoxLayout() # layout for buttons
|
||||
|
||||
save_btn = QPushButton("Save")
|
||||
cancel_btn = QPushButton("Cancel")
|
||||
save_btn.clicked.connect(self.save_settings)
|
||||
cancel_btn.clicked.connect(dialog.reject)
|
||||
layout.addWidget(save_btn)
|
||||
layout.addWidget(cancel_btn)
|
||||
save_btn.clicked.connect(lambda: self.save_settings(thread_box.value(), close_settings))
|
||||
|
||||
|
||||
|
||||
cancel_btn.clicked.connect(dialog.reject)
|
||||
print(thread_box.value())
|
||||
layout.addWidget(cancel_btn)
|
||||
layout.addWidget(save_btn)
|
||||
|
||||
|
||||
self.setLayout(QVBoxLayout())
|
||||
dialog.layout().addLayout(layout)
|
||||
|
||||
|
||||
dialog.exec()
|
||||
|
||||
def save_settings(self):
|
||||
pass
|
||||
def restart_aria2c(self):
|
||||
import main # had to do this because of circle import :(
|
||||
import signal
|
||||
import atexit
|
||||
global aria2process
|
||||
main.kill_aria2server(aria2process)
|
||||
aria2process.wait()
|
||||
aria2process = main.run_aria2server()
|
||||
signal.signal(signal.SIGINT, main.keyboardinterrupthandler)
|
||||
atexit.unregister(main.kill_aria2server)
|
||||
atexit.register(main.kill_aria2server, aria2process)
|
||||
|
||||
|
||||
|
||||
def save_settings(self, thread_count, close):
|
||||
set_threads(thread_count)
|
||||
self.restart_aria2c()
|
||||
close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def download_selected(self):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from core.ui.gui import MainWindow
|
||||
from core.ui.gui import state_debug
|
||||
from core.ui.gui import pass_aria
|
||||
from core.downloading.aria2p_server import aria2server
|
||||
from PySide6 import QtWidgets
|
||||
import qdarktheme
|
||||
@@ -10,7 +11,6 @@ import atexit
|
||||
import sys
|
||||
|
||||
debug = True
|
||||
aria2process = None
|
||||
|
||||
def run_gui():
|
||||
state_debug(debug)
|
||||
@@ -23,26 +23,34 @@ def run_gui():
|
||||
widget.show()
|
||||
sys.exit(app.exec())
|
||||
|
||||
def kill_aria2server():
|
||||
def run_aria2server():
|
||||
global aria2process
|
||||
aria2process = aria2server()
|
||||
return aria2process
|
||||
|
||||
|
||||
def kill_aria2server(aria2process):
|
||||
if aria2process:
|
||||
aria2process.kill()
|
||||
if debug:
|
||||
print("\nKilled Aria2")
|
||||
|
||||
|
||||
def keyboardinterrupthandler(signum, frame):
|
||||
kill_aria2server()
|
||||
global aria2process
|
||||
kill_aria2server(aria2process)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
kill_aria2server()
|
||||
if debug:
|
||||
print("Starting Aria2 Server")
|
||||
aria2process = aria2server()
|
||||
aria2process = run_aria2server()
|
||||
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
||||
atexit.register(kill_aria2server)
|
||||
atexit.register(kill_aria2server, aria2process)
|
||||
if debug:
|
||||
print("Launching GUI")
|
||||
|
||||
pass_aria(aria2process)
|
||||
run_gui()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user