mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
cleanup gui file, splitting and general improvements
This commit is contained in:
@@ -0,0 +1,123 @@
|
|||||||
|
from core.utils.config.settings import save_settings
|
||||||
|
from core.utils.data.state import state
|
||||||
|
from PySide6 import QtWidgets
|
||||||
|
from PySide6.QtWidgets import (
|
||||||
|
QLineEdit,
|
||||||
|
QPushButton,
|
||||||
|
QWidget,
|
||||||
|
QVBoxLayout,
|
||||||
|
QDialog,
|
||||||
|
QLabel,
|
||||||
|
QHBoxLayout,
|
||||||
|
QSpinBox,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def settings_dialog(self):
|
||||||
|
|
||||||
|
if state.debug:
|
||||||
|
print("Settings dialog opened")
|
||||||
|
dialog = QDialog(self)
|
||||||
|
dialog.setWindowTitle("Settings")
|
||||||
|
dialog.setFixedSize(800, 400)
|
||||||
|
|
||||||
|
dialog.setLayout(QVBoxLayout())
|
||||||
|
dialog.layout().addWidget(QLabel("Settings"))
|
||||||
|
|
||||||
|
def close_settings():
|
||||||
|
dialog.reject()
|
||||||
|
|
||||||
|
##################
|
||||||
|
# THREAD SETTING #
|
||||||
|
##################
|
||||||
|
thread_box = QSpinBox()
|
||||||
|
thread_box.setMinimum(1)
|
||||||
|
thread_box.setMaximum(16)
|
||||||
|
thread_box.setValue(state.aria2_threads)
|
||||||
|
|
||||||
|
|
||||||
|
# container for tight space
|
||||||
|
thread_container = QWidget()
|
||||||
|
thread_layout = QHBoxLayout()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
##################
|
||||||
|
# SERVER SETTING #
|
||||||
|
##################
|
||||||
|
|
||||||
|
api_url_container = QWidget()
|
||||||
|
api_url_layout = QHBoxLayout()
|
||||||
|
|
||||||
|
api_url = QLineEdit()
|
||||||
|
api_url_layout.addWidget(QLabel("API Server URL:"))
|
||||||
|
api_url_layout.addWidget(api_url)
|
||||||
|
api_url_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
||||||
|
api_url_container.setLayout(api_url_layout)
|
||||||
|
api_url.setText(state.api_url)
|
||||||
|
dialog.layout().addWidget(api_url_container)
|
||||||
|
|
||||||
|
#################
|
||||||
|
# DOWNLOAD PATH #
|
||||||
|
#################
|
||||||
|
|
||||||
|
download_path_container = QWidget()
|
||||||
|
download_path_layout = QHBoxLayout()
|
||||||
|
|
||||||
|
download_path = QLineEdit()
|
||||||
|
download_path_layout.addWidget(QLabel("Download Path:"))
|
||||||
|
download_path_layout.addWidget(download_path)
|
||||||
|
download_path_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
||||||
|
download_path_container.setLayout(download_path_layout)
|
||||||
|
download_path.setText(state.download_path)
|
||||||
|
dialog.layout().addWidget(download_path_container)
|
||||||
|
|
||||||
|
##################
|
||||||
|
# SPEED LIMITING #
|
||||||
|
##################
|
||||||
|
|
||||||
|
speed_limit_container = QWidget()
|
||||||
|
speed_limit_layout = QHBoxLayout()
|
||||||
|
|
||||||
|
speed_limit_layout.addWidget(QLabel("Max Download Speed (KiB, 0 for unlimited): "))
|
||||||
|
speed_limit = QSpinBox()
|
||||||
|
speed_limit.setMinimum(0)
|
||||||
|
speed_limit.setMaximum(10000000)
|
||||||
|
speed_limit.setValue(state.speed_limit)
|
||||||
|
speed_limit_container.setLayout(speed_limit_layout)
|
||||||
|
speed_limit_layout.addWidget(speed_limit)
|
||||||
|
speed_limit.setFixedWidth(180)
|
||||||
|
speed_limit.setFixedHeight(30)
|
||||||
|
dialog.layout().addWidget(speed_limit_container)
|
||||||
|
|
||||||
|
###############
|
||||||
|
# SAVE/CANCEL #
|
||||||
|
###############
|
||||||
|
|
||||||
|
layout = QHBoxLayout()
|
||||||
|
|
||||||
|
save_btn = QPushButton("Save")
|
||||||
|
cancel_btn = QPushButton("Cancel")
|
||||||
|
save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, api_url.text(), download_path.text(), speed_limit.value()))
|
||||||
|
|
||||||
|
cancel_btn.clicked.connect(dialog.reject)
|
||||||
|
print(thread_box.value())
|
||||||
|
layout.addWidget(cancel_btn)
|
||||||
|
layout.addWidget(save_btn)
|
||||||
|
|
||||||
|
dialog.layout().addLayout(layout)
|
||||||
|
|
||||||
|
dialog.exec()
|
||||||
+6
-153
@@ -2,34 +2,29 @@ from PySide6 import QtWidgets
|
|||||||
from PySide6.QtCore import Qt, QTimer
|
from PySide6.QtCore import Qt, QTimer
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QLineEdit,
|
QLineEdit,
|
||||||
QPushButton,
|
|
||||||
QWidget,
|
QWidget,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QListWidget,
|
QListWidget,
|
||||||
QToolBar,
|
QToolBar,
|
||||||
QDialog,
|
|
||||||
QLabel,
|
QLabel,
|
||||||
QHBoxLayout,
|
QHBoxLayout,
|
||||||
QComboBox,
|
QComboBox,
|
||||||
QSpinBox,
|
|
||||||
QTabWidget,
|
QTabWidget,
|
||||||
QProgressBar,
|
QProgressBar,
|
||||||
)
|
)
|
||||||
from PySide6.QtGui import QIcon, QAction
|
from PySide6.QtGui import QIcon, QAction
|
||||||
import darkdetect
|
import darkdetect
|
||||||
import threading
|
import threading
|
||||||
import asyncio
|
|
||||||
from core.data.scrapers.uztracker import scrape_uztracker
|
|
||||||
from core.data.scrapers.rutracker import scrape_rutracker
|
|
||||||
from core.utils.wrappers import run_thread
|
from core.utils.wrappers import run_thread
|
||||||
from core.utils.config.settings import save_settings
|
|
||||||
from core.utils.data.state import state
|
from core.utils.data.state import state
|
||||||
from core.utils.network.jsonhandler import split_data, format_data
|
|
||||||
from core.utils.network.download import download_selected
|
from core.utils.network.download import download_selected
|
||||||
from core.interface.utils.guihelper import create_tab
|
from core.interface.utils.tabhelper import create_tab
|
||||||
|
from core.interface.utils.searchhelper import return_pressed
|
||||||
|
from core.interface.dialogs.settings import settings_dialog
|
||||||
from core.network.aria2_integration import dlprogress
|
from core.network.aria2_integration import dlprogress
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -46,7 +41,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
self.searchbar.setPlaceholderText("Search for software...")
|
self.searchbar.setPlaceholderText("Search for software...")
|
||||||
self.searchbar.setClearButtonEnabled(True)
|
self.searchbar.setClearButtonEnabled(True)
|
||||||
self.searchbar.setMinimumHeight(30)
|
self.searchbar.setMinimumHeight(30)
|
||||||
self.searchbar.returnPressed.connect(lambda: run_thread(threading.Thread(target=self.return_pressed))) # Triggers data function thread on enter
|
self.searchbar.returnPressed.connect(lambda: run_thread(threading.Thread(target=return_pressed, args=(self,)))) # Triggers data function thread on enter
|
||||||
|
|
||||||
self.dlbutton = QtWidgets.QPushButton("Download")
|
self.dlbutton = QtWidgets.QPushButton("Download")
|
||||||
self.softwareList = QListWidget()
|
self.softwareList = QListWidget()
|
||||||
@@ -100,7 +95,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
else:
|
else:
|
||||||
settings_action = QAction(QIcon("core/interface/assets/settings.png"), "Settings", self)
|
settings_action = QAction(QIcon("core/interface/assets/settings.png"), "Settings", self)
|
||||||
|
|
||||||
settings_action.triggered.connect(self.settings_dialog)
|
settings_action.triggered.connect(lambda: settings_dialog(self))
|
||||||
toolbar.addAction(settings_action)
|
toolbar.addAction(settings_action)
|
||||||
toolbar.addWidget(self.tracker_list)
|
toolbar.addWidget(self.tracker_list)
|
||||||
|
|
||||||
@@ -116,148 +111,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 settings_dialog(self):
|
|
||||||
|
|
||||||
if state.debug:
|
|
||||||
print("Settings dialog opened")
|
|
||||||
dialog = QDialog(self)
|
|
||||||
dialog.setWindowTitle("Settings")
|
|
||||||
dialog.setFixedSize(800, 400)
|
|
||||||
|
|
||||||
dialog.setLayout(QVBoxLayout())
|
|
||||||
dialog.layout().addWidget(QLabel("Settings"))
|
|
||||||
|
|
||||||
def close_settings():
|
|
||||||
dialog.reject()
|
|
||||||
|
|
||||||
##################
|
|
||||||
# THREAD SETTING #
|
|
||||||
##################
|
|
||||||
thread_box = QSpinBox()
|
|
||||||
thread_box.setMinimum(1)
|
|
||||||
thread_box.setMaximum(16)
|
|
||||||
thread_box.setValue(state.aria2_threads)
|
|
||||||
|
|
||||||
|
|
||||||
# container for tight space
|
|
||||||
thread_container = QWidget()
|
|
||||||
thread_layout = QHBoxLayout()
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
##################
|
|
||||||
# SERVER SETTING #
|
|
||||||
##################
|
|
||||||
|
|
||||||
api_url_container = QWidget()
|
|
||||||
api_url_layout = QHBoxLayout()
|
|
||||||
|
|
||||||
api_url = QLineEdit()
|
|
||||||
api_url_layout.addWidget(QLabel("API Server URL:"))
|
|
||||||
api_url_layout.addWidget(api_url)
|
|
||||||
api_url_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
|
||||||
api_url_container.setLayout(api_url_layout)
|
|
||||||
api_url.setText(state.api_url)
|
|
||||||
dialog.layout().addWidget(api_url_container)
|
|
||||||
|
|
||||||
#################
|
|
||||||
# DOWNLOAD PATH #
|
|
||||||
#################
|
|
||||||
|
|
||||||
download_path_container = QWidget()
|
|
||||||
download_path_layout = QHBoxLayout()
|
|
||||||
|
|
||||||
download_path = QLineEdit()
|
|
||||||
download_path_layout.addWidget(QLabel("Download Path:"))
|
|
||||||
download_path_layout.addWidget(download_path)
|
|
||||||
download_path_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
|
||||||
download_path_container.setLayout(download_path_layout)
|
|
||||||
download_path.setText(state.download_path)
|
|
||||||
dialog.layout().addWidget(download_path_container)
|
|
||||||
|
|
||||||
##################
|
|
||||||
# SPEED LIMITING #
|
|
||||||
##################
|
|
||||||
|
|
||||||
speed_limit_container = QWidget()
|
|
||||||
speed_limit_layout = QHBoxLayout()
|
|
||||||
|
|
||||||
speed_limit_layout.addWidget(QLabel("Max Download Speed (KiB, 0 for unlimited): "))
|
|
||||||
speed_limit = QSpinBox()
|
|
||||||
speed_limit.setMinimum(0)
|
|
||||||
speed_limit.setMaximum(10000000)
|
|
||||||
speed_limit.setValue(state.speed_limit)
|
|
||||||
speed_limit_container.setLayout(speed_limit_layout)
|
|
||||||
speed_limit_layout.addWidget(speed_limit)
|
|
||||||
speed_limit.setFixedWidth(180)
|
|
||||||
speed_limit.setFixedHeight(30)
|
|
||||||
dialog.layout().addWidget(speed_limit_container)
|
|
||||||
|
|
||||||
###############
|
|
||||||
# SAVE/CANCEL #
|
|
||||||
###############
|
|
||||||
|
|
||||||
layout = QHBoxLayout()
|
|
||||||
|
|
||||||
save_btn = QPushButton("Save")
|
|
||||||
cancel_btn = QPushButton("Cancel")
|
|
||||||
save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, api_url.text(), download_path.text(), speed_limit.value()))
|
|
||||||
|
|
||||||
cancel_btn.clicked.connect(dialog.reject)
|
|
||||||
print(thread_box.value())
|
|
||||||
layout.addWidget(cancel_btn)
|
|
||||||
layout.addWidget(save_btn)
|
|
||||||
|
|
||||||
dialog.layout().addLayout(layout)
|
|
||||||
|
|
||||||
dialog.exec()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def return_pressed(self):
|
|
||||||
search_text = self.searchbar.text()
|
|
||||||
if search_text == "":
|
|
||||||
if state.debug:
|
|
||||||
print("Error: Can't search for nothing")
|
|
||||||
return
|
|
||||||
if state.debug:
|
|
||||||
print("User searched for:", search_text)
|
|
||||||
if state.tracker == "uztracker":
|
|
||||||
response = asyncio.run(scrape_uztracker(search_text))
|
|
||||||
if state.tracker == "rutracker":
|
|
||||||
response = scrape_rutracker(search_text)
|
|
||||||
if response:
|
|
||||||
if state.tracker == "uztracker":
|
|
||||||
state.post_titles, state.post_urls, = response
|
|
||||||
self.softwareList.clear()
|
|
||||||
if state.post_titles:
|
|
||||||
self.softwareList.addItems(state.post_titles)
|
|
||||||
self.post_author_list.addItems(state.post_author)
|
|
||||||
if state.tracker == "rutracker":
|
|
||||||
_, state.posts, _, _, cached = split_data(response)
|
|
||||||
state.post_titles, _, state.post_author = format_data(state.posts)
|
|
||||||
self.post_author_list.clear()
|
|
||||||
self.post_author_list.addItems(state.post_author)
|
|
||||||
self.softwareList.clear()
|
|
||||||
self.softwareList.addItems(state.post_titles)
|
|
||||||
if state.debug == True:
|
|
||||||
print(f"Cached: {cached}")
|
|
||||||
if not response:
|
|
||||||
if state.debug:
|
|
||||||
print(f"No Results found for \"{search_text}\"")
|
|
||||||
self.softwareList.clear()
|
|
||||||
self.softwareList.addItem("No Results") # replace with no results text in center
|
|
||||||
|
|
||||||
|
|
||||||
def update_progress(self):
|
def update_progress(self):
|
||||||
progress = dlprogress()
|
progress = dlprogress()
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import asyncio
|
||||||
|
from core.data.scrapers.uztracker import scrape_uztracker
|
||||||
|
from core.data.scrapers.rutracker import scrape_rutracker
|
||||||
|
from core.utils.network.jsonhandler import split_data, format_data
|
||||||
|
from core.utils.data.state import state
|
||||||
|
|
||||||
|
def return_pressed(self):
|
||||||
|
search_text = self.searchbar.text()
|
||||||
|
if search_text == "":
|
||||||
|
if state.debug:
|
||||||
|
print("Error: Can't search for nothing")
|
||||||
|
return
|
||||||
|
if state.debug:
|
||||||
|
print("User searched for:", search_text)
|
||||||
|
if state.tracker == "uztracker":
|
||||||
|
response = asyncio.run(scrape_uztracker(search_text))
|
||||||
|
if state.tracker == "rutracker":
|
||||||
|
response = scrape_rutracker(search_text)
|
||||||
|
if response:
|
||||||
|
if state.tracker == "uztracker":
|
||||||
|
state.post_titles, state.post_urls, = response
|
||||||
|
self.softwareList.clear()
|
||||||
|
if state.post_titles:
|
||||||
|
self.softwareList.addItems(state.post_titles)
|
||||||
|
self.post_author_list.addItems(state.post_author)
|
||||||
|
if state.tracker == "rutracker":
|
||||||
|
_, state.posts, _, _, cached = split_data(response)
|
||||||
|
state.post_titles, _, state.post_author = format_data(state.posts)
|
||||||
|
self.post_author_list.clear()
|
||||||
|
self.post_author_list.addItems(state.post_author)
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.softwareList.addItems(state.post_titles)
|
||||||
|
if state.debug == True:
|
||||||
|
print(f"Cached: {cached}")
|
||||||
|
if not response:
|
||||||
|
if state.debug:
|
||||||
|
print(f"No Results found for \"{search_text}\"")
|
||||||
|
self.softwareList.clear()
|
||||||
|
self.softwareList.addItem("No Results") # replace with no results text in center
|
||||||
Reference in New Issue
Block a user