From 03c8a23e07600a18c281a8fa0ae8a6c9d869304b Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 17 Aug 2024 13:24:37 -0700 Subject: [PATCH] feat(ui): use Unicode for X button - use Unicode for X button in KV Overrides box - move CustomTitleBar to separate file --- src/AutoGGUF.py | 61 +--------------------------------- src/CustomTitleBar.py | 75 ++++++++++++++++++++++++++++++++++++++++++ src/KVOverrideEntry.py | 2 +- src/ui_update.py | 6 +++- 4 files changed, 82 insertions(+), 62 deletions(-) create mode 100644 src/CustomTitleBar.py diff --git a/src/AutoGGUF.py b/src/AutoGGUF.py index ddf8475..77dde6e 100644 --- a/src/AutoGGUF.py +++ b/src/AutoGGUF.py @@ -12,6 +12,7 @@ from KVOverrideEntry import KVOverrideEntry from Logger import Logger from ModelInfoDialog import ModelInfoDialog +from CustomTitleBar import CustomTitleBar from error_handling import show_error, handle_error from TaskListItem import TaskListItem from QuantizationThread import QuantizationThread @@ -28,66 +29,6 @@ import utils -class CustomTitleBar(QWidget): - def __init__(self, parent=None): - super().__init__(parent) - self.parent = parent - layout = QHBoxLayout(self) - layout.setContentsMargins(10, 5, 10, 5) - - # Add your logo or app name here - self.title = QLabel("AutoGGUF") - layout.addWidget(self.title) - - layout.addStretch(1) # This pushes the buttons to the right - - # Add minimize and close buttons - self.minimize_button = QPushButton("—") - self.close_button = QPushButton("✕") - - for button in (self.minimize_button, self.close_button): - button.setFixedSize(30, 30) - button.setStyleSheet( - """ - QPushButton { - border: none; - background-color: transparent; - } - QPushButton:hover { - background-color: rgba(255, 255, 255, 0.1); - } - """ - ) - - layout.addWidget(self.minimize_button) - layout.addWidget(self.close_button) - - self.minimize_button.clicked.connect(self.parent.showMinimized) - self.close_button.clicked.connect(self.parent.close) - - self.start = QPoint(0, 0) - self.pressing = False - - def mousePressEvent(self, event): - self.start = self.mapToGlobal(event.pos()) - self.pressing = True - - def mouseMoveEvent(self, event): - if self.pressing: - end = self.mapToGlobal(event.pos()) - movement = end - self.start - self.parent.setGeometry( - self.parent.x() + movement.x(), - self.parent.y() + movement.y(), - self.parent.width(), - self.parent.height(), - ) - self.start = end - - def mouseReleaseEvent(self, event): - self.pressing = False - - class AutoGGUF(QMainWindow): def __init__(self): super().__init__() diff --git a/src/CustomTitleBar.py b/src/CustomTitleBar.py new file mode 100644 index 0000000..46398eb --- /dev/null +++ b/src/CustomTitleBar.py @@ -0,0 +1,75 @@ +from PySide6.QtCore import QPoint +from PySide6.QtGui import QPixmap +from PySide6.QtWidgets import QHBoxLayout, QLabel, QMenuBar, QPushButton, QWidget + +from imports_and_globals import resource_path + + +class CustomTitleBar(QWidget): + def __init__(self, parent=None): + super().__init__(parent) + self.parent = parent + layout = QHBoxLayout(self) + layout.setContentsMargins(10, 5, 10, 5) + + # Add the favicon + # TODO: uncomment this + # self.icon_label = QLabel() + # self.icon_label.setPixmap(QPixmap(resource_path("assets/favicon.ico"))) + # layout.addWidget(self.icon_label) + + # Add app title (bolded) + self.title = QLabel("AutoGGUF") # Use HTML tags for bolding + layout.addWidget(self.title) + + # Add menubar here + self.menubar = QMenuBar() + layout.addWidget(self.menubar) # Add menubar to the layout + + layout.addStretch(1) # This pushes the buttons to the right + + # Add minimize and close buttons + self.minimize_button = QPushButton("—") + self.close_button = QPushButton("✕") + + for button in (self.minimize_button, self.close_button): + button.setFixedSize(30, 30) + button.setStyleSheet( + """ + QPushButton { + border: none; + background-color: transparent; + } + QPushButton:hover { + background-color: rgba(255, 255, 255, 0.1); + } + """ + ) + + layout.addWidget(self.minimize_button) + layout.addWidget(self.close_button) + + self.minimize_button.clicked.connect(self.parent.showMinimized) + self.close_button.clicked.connect(self.parent.close) + + self.start = QPoint(0, 0) + self.pressing = False + + def mousePressEvent(self, event): + self.start = self.mapToGlobal(event.pos()) + self.pressing = True + + def mouseMoveEvent(self, event): + if self.pressing: + end = self.mapToGlobal(event.pos()) + movement = end - self.start + self.parent.setGeometry( + self.parent.x() + movement.x(), + self.parent.y() + movement.y(), + self.parent.width(), + self.parent.height(), + ) + self.start = end + + def mouseReleaseEvent(self, event): + self.pressing = False diff --git a/src/KVOverrideEntry.py b/src/KVOverrideEntry.py index 2c4b42c..a5cfb7a 100644 --- a/src/KVOverrideEntry.py +++ b/src/KVOverrideEntry.py @@ -31,7 +31,7 @@ def __init__(self, parent=None): self.value_input.setPlaceholderText("Value") layout.addWidget(self.value_input) - delete_button = QPushButton("X") + delete_button = QPushButton("✕") delete_button.setFixedSize(30, 30) delete_button.clicked.connect(self.delete_clicked) layout.addWidget(delete_button) diff --git a/src/ui_update.py b/src/ui_update.py index 3d624f0..cf9e996 100644 --- a/src/ui_update.py +++ b/src/ui_update.py @@ -27,6 +27,7 @@ def update_system_info(self): ) self.cpu_label.setText(CPU_USAGE_FORMAT.format(cpu)) + def animate_bar(self, bar, target_value): current_value = bar.value() difference = target_value - current_value @@ -40,11 +41,14 @@ def animate_bar(self, bar, target_value): timer.timeout.connect(lambda: _animate_step(bar, target_value, step, timer)) timer.start(10) # Adjust the interval for animation speed + def _animate_step(bar, target_value, step, timer): current_value = bar.value() new_value = current_value + step - if (step > 0 and new_value > target_value) or (step < 0 and new_value < target_value): + if (step > 0 and new_value > target_value) or ( + step < 0 and new_value < target_value + ): bar.setValue(target_value) timer.stop() else: