Skip to content

Commit

Permalink
Client Improvement
Browse files Browse the repository at this point in the history
1. [GUI] Add ParamsManager class to simplify the config management
2. [GUI] Support import&export params settings of each tool page
3. [GUI] Change the way how LineEdits display alert info
4. [GUI] Widget library update (see details in 'QSimpleWidget' repo)
  • Loading branch information
Spr-Aachen committed May 15, 2024
1 parent 78864eb commit c932146
Show file tree
Hide file tree
Showing 4 changed files with 1,603 additions and 802 deletions.
14 changes: 9 additions & 5 deletions EVT_GUI/Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, parent: QWidget = None):
lambda: self.ValueChanged.emit(self.GetValue())
)

def AddRow(self, Param: Optional[tuple] = None, FileType: Optional[str] = None):
def AddRow(self, Param: Optional[tuple] = None):
RowHeight = 30
ButtonStyle = '''
QPushButton {
Expand Down Expand Up @@ -186,7 +186,7 @@ def SetColumnLayout(ColumnLayout):
LineEdit1 = LineEditBase()
LineEdit1.ClearDefaultStyleSheet()
LineEdit1.setStyleSheet(LineEdit1.styleSheet() + 'LineEditBase {border-radius: 0px;}')
LineEdit1.SetFileDialog("SelectFile", FileType)
#LineEdit1.SetFileDialog("SelectFile", FileType)
Function_SetText(LineEdit1, Param[1] if Param else '', SetPlaceholderText = True)
LineEdit1.textChanged.connect(
lambda: self.ValueChanged.emit(self.GetValue())
Expand Down Expand Up @@ -217,14 +217,18 @@ def SetColumnLayout(ColumnLayout):
RowHeight
)

def SetValue(self, Params: dict = {'%Speaker%': '%Path%'}, FileType: Optional[str] = None):
def SetValue(self, Params: dict = {'%Speaker%': '%Path%'}):
self.ClearRows()
ParamDict = ToIterable(Params)
ParamDict = ToIterable(Params if Params is None or len(Params) != 0 else {'': ''})
for Key, Value in ParamDict.items():
QApplication.processEvents()
Param = (Key, Value)
#Index = next((i for i, key in enumerate(ParamDict) if key == Key), None)
self.AddRow(Param, FileType)
self.AddRow(Param)

def SetFileDialog(self, FileType: Optional[str] = None):
for RowCount in range(self.rowCount()):
self.cellWidget(RowCount, 1).findChild(LineEditBase).SetFileDialog("SelectFile", FileType)

def GetValue(self):
ValueDict = {}
Expand Down
108 changes: 106 additions & 2 deletions EVT_GUI/Functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .Window import *

##############################################################################################################################

"""
def Function_InsertUI(
ParentUI: QWidget,
InsertType: object,
Expand Down Expand Up @@ -74,7 +74,7 @@ def Function_InsertUI(
InsertUI.setToolTip(UIToolTip)
return InsertUI

"""

def Function_ScrollToWidget(
Trigger: QWidget,
Expand Down Expand Up @@ -155,6 +155,30 @@ def Function_SetTreeView(
TreeView.header().setOrientation(Qt.Vertical)
'''

def Function_SetChildWidgetsVisibility(
Container: QWidget,
ChildWidgets: list[Optional[QWidget]],
SetVisible: bool,
AdjustContainer: bool = True
):
'''
Function to set the visibility of child-widgets
'''
ChildWidgets = [ChildWidget for ChildWidget in ChildWidgets if ChildWidget is not None]
for ChildWidget in ChildWidgets:
ChildWidget.setVisible(SetVisible)
if AdjustContainer:
CurrentHeight = Container.height()
#Container.updateGeometry()
AdjustedHeight = Container.minimumSizeHint().height()
Function_AnimateFrame(
Frame = Container,
MinHeight = CurrentHeight if SetVisible else AdjustedHeight,
MaxHeight = AdjustedHeight if SetVisible else CurrentHeight,
Mode = 'Extend' if SetVisible else 'Reduce'
)


def Function_ConfigureCheckBox(
CheckBox: QCheckBox,
CheckedText: Optional[str] = None,
Expand Down Expand Up @@ -246,6 +270,7 @@ def Function_ShowMessageBox(

ButtonEvents[Result]() if Result in list(ButtonEvents.keys()) else None

##############################################################################################################################

def Function_ParamsHandler(
UI: QObject,
Expand Down Expand Up @@ -366,6 +391,7 @@ def Function_ParamsChecker(

return Args

##############################################################################################################################

def Function_AnimateStackedWidget(
StackedWidget: QStackedWidget,
Expand Down Expand Up @@ -439,4 +465,82 @@ def Function_AnimateProgressBar(
ProgressBar.setRange(MinValue, MaxValue)
ProgressBar.setValue(MaxValue)

##############################################################################################################################

def Function_SetWidgetValue(
Widget: QWidget,
Config: ManageConfig,
Section: str = ...,
Option: str = ...,
Value = ...,
Times: Union[int, float] = 1,
SetPlaceholderText: bool = False,
PlaceholderText: Optional[str] = None
):
if isinstance(Widget, (QLineEdit, LineEditBase, QPlainTextEdit)):
Function_SetText(Widget, Value, SetPlaceholderText = SetPlaceholderText, PlaceholderText = PlaceholderText)
Widget.textChanged.connect(lambda Value: Config.EditConfig(Section, Option, str(Value)))
if isinstance(Widget, QComboBox):
Widget.setCurrentText(str(Value))
Widget.currentTextChanged.connect(lambda Value: Config.EditConfig(Section, Option, str(Value)))
if isinstance(Widget, (QSlider, QSpinBox)):
Widget.setValue(int(eval(str(Value)) * Times))
Widget.valueChanged.connect(lambda Value: Config.EditConfig(Section, Option, str(eval(str(Value)) / Times)))
if isinstance(Widget, QDoubleSpinBox):
Widget.setValue(float(eval(str(Value)) * Times))
Widget.valueChanged.connect(lambda Value: Config.EditConfig(Section, Option, str(eval(str(Value)) / Times)))
if isinstance(Widget, (QCheckBox, QRadioButton)):
Widget.setChecked(eval(str(Value)))
Widget.toggled.connect(lambda Value: Config.EditConfig(Section, Option, str(Value)))
if isinstance(Widget, Table_EditAudioSpeaker):
Widget.SetValue(eval(str(Value)))
Widget.ValueChanged.connect(lambda Value: Config.EditConfig(Section, Option, str(Value)))


class ParamsManager:
def __init__(self,
ConfigPath: str,
):
self.ConfigPath = ConfigPath
self.Config = ManageConfig(ConfigPath)

self.RegistratedWidgets = {}

def Registrate(self, Widget: QWidget, value: tuple):
self.RegistratedWidgets[Widget] = value

def SetParam(self,
Widget: QWidget,
Section: str = ...,
Option: str = ...,
DefaultValue = None,
Times: Union[int, float] = 1,
SetPlaceholderText: bool = False,
PlaceholderText: Optional[str] = None,
Registrate: bool = True
):
Value = self.Config.GetValue(Section, Option, str(DefaultValue))
Function_SetWidgetValue(Widget, self.Config, Section, Option, Value, Times, SetPlaceholderText, PlaceholderText)
self.Registrate(Widget, (Section, Option, DefaultValue, Times, SetPlaceholderText, PlaceholderText)) if Registrate else None

def ResetParam(self, Widget: QWidget):
value = self.RegistratedWidgets[Widget]
Function_SetWidgetValue(Widget, self.Config, *value)

def ResetSettings(self):
for Widget in list(self.RegistratedWidgets.keys()):
self.ResetParam(Widget)

def ImportSettings(self, ReadPath: str):
ConfigParser = ManageConfig(ReadPath).ReadConfig()
with open(self.ConfigPath, 'w') as Config:
ConfigParser.write(Config)
for Widget, value in list(self.RegistratedWidgets.items()):
self.SetParam(Widget, *value)

def ExportSettings(self, SavePath: str):
ConfigParser = self.Config.ReadConfig()
with open(SavePath, 'w') as Config:
ConfigParser.write(Config)

##############################################################################################################################
Loading

0 comments on commit c932146

Please sign in to comment.