Skip to content

Commit c5e1313

Browse files
committed
feat(ui): add menubar
- add basic menu bar showing Close and About areas - add program version in localizations.py - refactor functions out of AutoGGUF.py and move to ui_update.py
1 parent f5e0bca commit c5e1313

File tree

3 files changed

+254
-153
lines changed

3 files changed

+254
-153
lines changed

src/AutoGGUF.py

+39-83
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import psutil
77
import requests
8+
from functools import partial
89
from PySide6.QtCore import *
910
from PySide6.QtGui import *
1011
from PySide6.QtWidgets import *
@@ -19,6 +20,7 @@
1920
from error_handling import show_error, handle_error
2021
from imports_and_globals import ensure_directory, open_file_safe, resource_path
2122
from localizations import *
23+
from ui_update import *
2224

2325

2426
class AutoGGUF(QMainWindow):
@@ -34,6 +36,19 @@ def __init__(self):
3436
ensure_directory(os.path.abspath("quantized_models"))
3537
ensure_directory(os.path.abspath("models"))
3638

39+
# References
40+
self.update_base_model_visibility = partial(update_base_model_visibility, self)
41+
self.update_assets = update_assets.__get__(self)
42+
self.update_cuda_option = update_cuda_option.__get__(self)
43+
self.update_cuda_backends = update_cuda_backends.__get__(self)
44+
self.update_threads_spinbox = partial(update_threads_spinbox, self)
45+
self.update_threads_slider = partial(update_threads_slider, self)
46+
self.update_gpu_offload_spinbox = partial(update_gpu_offload_spinbox, self)
47+
self.update_gpu_offload_slider = partial(update_gpu_offload_slider, self)
48+
self.update_model_info = partial(update_model_info, self.logger, self)
49+
self.update_system_info = partial(update_system_info, self)
50+
self.update_download_progress = partial(update_download_progress, self)
51+
3752
# Create a central widget and main layout
3853
central_widget = QWidget()
3954
main_layout = QHBoxLayout(central_widget)
@@ -52,6 +67,23 @@ def __init__(self):
5267
left_widget.setMinimumWidth(800)
5368
right_widget.setMinimumWidth(400)
5469

70+
menubar = QMenuBar(self)
71+
self.layout().setMenuBar(menubar)
72+
73+
# File menu
74+
file_menu = menubar.addMenu("&File")
75+
close_action = QAction("&Close", self)
76+
close_action.setShortcut(QKeySequence.Quit)
77+
close_action.triggered.connect(self.close)
78+
file_menu.addAction(close_action)
79+
80+
# Help menu
81+
help_menu = menubar.addMenu("&Help")
82+
about_action = QAction("&About", self)
83+
about_action.setShortcut(QKeySequence("Ctrl+Q"))
84+
about_action.triggered.connect(self.show_about)
85+
help_menu.addAction(about_action)
86+
5587
left_layout = QVBoxLayout(left_widget)
5688
right_layout = QVBoxLayout(right_widget)
5789

@@ -679,9 +711,13 @@ def refresh_backends(self):
679711
self.backend_combo.setEnabled(False)
680712
self.logger.info(FOUND_VALID_BACKENDS.format(self.backend_combo.count()))
681713

682-
def update_base_model_visibility(self, index):
683-
is_gguf = self.lora_output_type_combo.itemText(index) == "GGUF"
684-
self.base_model_wrapper.setVisible(is_gguf)
714+
def show_about(self):
715+
about_text = (
716+
"AutoGGUF\n\n"
717+
f"Version: {AUTOGGUF_VERSION}\n\n"
718+
"A tool for managing and converting GGUF models."
719+
)
720+
QMessageBox.about(self, "About AutoGGUF", about_text)
685721

686722
def save_preset(self):
687723
self.logger.info(SAVING_PRESET)
@@ -1174,20 +1210,6 @@ def refresh_releases(self):
11741210
except requests.exceptions.RequestException as e:
11751211
show_error(self.logger, ERROR_FETCHING_RELEASES.format(str(e)))
11761212

1177-
def update_assets(self):
1178-
self.logger.debug(UPDATING_ASSET_LIST)
1179-
self.asset_combo.clear()
1180-
release = self.release_combo.currentData()
1181-
if release:
1182-
if "assets" in release:
1183-
for asset in release["assets"]:
1184-
self.asset_combo.addItem(asset["name"], userData=asset)
1185-
else:
1186-
show_error(
1187-
self.logger, NO_ASSETS_FOUND_FOR_RELEASE.format(release["tag_name"])
1188-
)
1189-
self.update_cuda_option()
1190-
11911213
def download_llama_cpp(self):
11921214
self.logger.info(STARTING_LLAMACPP_DOWNLOAD)
11931215
asset = self.asset_combo.currentData()
@@ -1209,45 +1231,6 @@ def download_llama_cpp(self):
12091231
self.download_button.setEnabled(False)
12101232
self.download_progress.setValue(0)
12111233

1212-
def update_cuda_option(self):
1213-
self.logger.debug(UPDATING_CUDA_OPTIONS)
1214-
asset = self.asset_combo.currentData()
1215-
1216-
# Handle the case where asset is None
1217-
if asset is None:
1218-
self.logger.warning(NO_ASSET_SELECTED_FOR_CUDA_CHECK)
1219-
self.cuda_extract_checkbox.setVisible(False)
1220-
self.cuda_backend_label.setVisible(False)
1221-
self.backend_combo_cuda.setVisible(False)
1222-
return # Exit the function early
1223-
1224-
is_cuda = asset and "cudart" in asset["name"].lower()
1225-
self.cuda_extract_checkbox.setVisible(is_cuda)
1226-
self.cuda_backend_label.setVisible(is_cuda)
1227-
self.backend_combo_cuda.setVisible(is_cuda)
1228-
if is_cuda:
1229-
self.update_cuda_backends()
1230-
1231-
def update_cuda_backends(self):
1232-
self.logger.debug(UPDATING_CUDA_BACKENDS)
1233-
self.backend_combo_cuda.clear()
1234-
llama_bin = os.path.abspath("llama_bin")
1235-
if os.path.exists(llama_bin):
1236-
for item in os.listdir(llama_bin):
1237-
item_path = os.path.join(llama_bin, item)
1238-
if os.path.isdir(item_path) and "cudart-llama" not in item.lower():
1239-
if "cu1" in item.lower(): # Only include CUDA-capable backends
1240-
self.backend_combo_cuda.addItem(item, userData=item_path)
1241-
1242-
if self.backend_combo_cuda.count() == 0:
1243-
self.backend_combo_cuda.addItem(NO_SUITABLE_CUDA_BACKENDS)
1244-
self.backend_combo_cuda.setEnabled(False)
1245-
else:
1246-
self.backend_combo_cuda.setEnabled(True)
1247-
1248-
def update_download_progress(self, progress):
1249-
self.download_progress.setValue(progress)
1250-
12511234
def download_finished(self, extract_dir):
12521235
self.download_button.setEnabled(True)
12531236
self.download_progress.setValue(100)
@@ -1335,18 +1318,6 @@ def show_task_properties(self, item):
13351318
model_info_dialog.exec()
13361319
break
13371320

1338-
def update_threads_spinbox(self, value):
1339-
self.threads_spinbox.setValue(value)
1340-
1341-
def update_threads_slider(self, value):
1342-
self.threads_slider.setValue(value)
1343-
1344-
def update_gpu_offload_spinbox(self, value):
1345-
self.gpu_offload_spinbox.setValue(value)
1346-
1347-
def update_gpu_offload_slider(self, value):
1348-
self.gpu_offload_slider.setValue(value)
1349-
13501321
def toggle_gpu_offload_auto(self, state):
13511322
is_auto = state == Qt.CheckState.Checked
13521323
self.gpu_offload_slider.setEnabled(not is_auto)
@@ -1483,17 +1454,6 @@ def validate_quantization_inputs(self):
14831454
if errors:
14841455
raise ValueError("\n".join(errors))
14851456

1486-
def update_system_info(self):
1487-
ram = psutil.virtual_memory()
1488-
cpu = psutil.cpu_percent()
1489-
self.ram_bar.setValue(int(ram.percent))
1490-
self.ram_bar.setFormat(
1491-
RAM_USAGE_FORMAT.format(
1492-
ram.percent, ram.used // 1024 // 1024, ram.total // 1024 // 1024
1493-
)
1494-
)
1495-
self.cpu_label.setText(CPU_USAGE_FORMAT.format(cpu))
1496-
14971457
def add_kv_override(self, override_string=None):
14981458
entry = KVOverrideEntry()
14991459
entry.deleted.connect(self.remove_kv_override)
@@ -1679,10 +1639,6 @@ def quantize_model(self):
16791639
except Exception as e:
16801640
show_error(self.logger, ERROR_STARTING_QUANTIZATION.format(str(e)))
16811641

1682-
def update_model_info(self, model_info):
1683-
self.logger.debug(UPDATING_MODEL_INFO.format(model_info))
1684-
pass
1685-
16861642
def parse_progress(self, line, task_item):
16871643
# Parses the output line for progress information and updates the task item.
16881644
match = re.search(r"\[(\d+)/(\d+)\]", line)

0 commit comments

Comments
 (0)