lambda/src/ui/settings.py

65 lines
2.1 KiB
Python

import sys
from PySide6 import QtWidgets
from utils.config import UserConfig, TransactionLevel
class SettingsDialog(QtWidgets.QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Settings")
self.setMinimumSize(400, 100)
# Position the dialog relative to the parent (main window)
if parent:
x = parent.geometry().x() + parent.geometry().width() // 2 - self.width() // 2
y = parent.geometry().y() + parent.geometry().height() // 2 - self.height() // 2
self.move(x, y)
# Create layout
layout = QtWidgets.QVBoxLayout(self)
data_mode_layout = QtWidgets.QHBoxLayout()
self.data_mode_label = QtWidgets.QLabel("Data mode:")
data_mode_layout.addWidget(self.data_mode_label)
self.data_mode_dropdown = QtWidgets.QComboBox()
for tl in TransactionLevel:
self.data_mode_dropdown.addItem(tl.name.capitalize(), tl.value)
data_mode_layout.addWidget(self.data_mode_dropdown)
layout.addLayout(data_mode_layout)
# Set the currently selected mode to the mode in UserConfig
config = UserConfig()
current_level = config.transaction_level
index = self.data_mode_dropdown.findData(current_level)
if index != -1:
self.data_mode_dropdown.setCurrentIndex(index)
# Buttons
button_layout = QtWidgets.QHBoxLayout()
self.save_button = QtWidgets.QPushButton("Save")
self.save_button.clicked.connect(self.save_settings)
button_layout.addWidget(self.save_button)
self.cancel_button = QtWidgets.QPushButton("Cancel")
self.cancel_button.clicked.connect(self.reject)
button_layout.addWidget(self.cancel_button)
layout.addLayout(button_layout)
def save_settings(self):
data_mode = self.data_mode_dropdown.currentData()
config = UserConfig()
config.transaction_level = data_mode
print("Settings Saved:")
print(f"Data Mode: {config.transaction_level}")
self.accept()