Skip to content

Commit

Permalink
Scrollbar for long parameter list #1340
Browse files Browse the repository at this point in the history
(splitter sort of worked but had various small annoying problems)
  • Loading branch information
Acly committed Oct 29, 2024
1 parent 15358e6 commit 1c91eb4
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions ai_diffusion/ui/custom_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def _create_param_widget(param: CustomParam, parent: QWidget) -> CustomParamWidg
class WorkflowParamsWidget(QWidget):
value_changed = pyqtSignal()

def __init__(self, params: list[CustomParam], parent: QWidget):
def __init__(self, params: list[CustomParam], parent: QWidget | None = None):
super().__init__(parent)
self._widgets: dict[str, CustomParamWidget] = {}

Expand Down Expand Up @@ -553,7 +553,11 @@ def __init__(self):
self._workflow_edit_widgets, theme.icon("cancel"), _("Cancel"), self._cancel_name
)

self._params_widget = WorkflowParamsWidget([], self)
self._params_widget: WorkflowParamsWidget | None = None
self._params_scroll = QScrollArea(self)
self._params_scroll.setWidgetResizable(True)
self._params_scroll.setFrameShape(QFrame.Shape.NoFrame)
self._params_scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)

self._generate_button = GenerateButton(JobKind.diffusion, self)
self._generate_button.clicked.connect(self._generate)
Expand Down Expand Up @@ -611,7 +615,7 @@ def __init__(self):
header_layout.addWidget(self._workflow_select_widgets)
header_layout.addWidget(self._workflow_edit_widgets)
self._layout.addLayout(header_layout)
self._layout.addWidget(self._params_widget)
self._layout.addWidget(self._params_scroll)
actions_layout = QHBoxLayout()
actions_layout.setSpacing(0)
actions_layout.addWidget(self._generate_button)
Expand Down Expand Up @@ -713,17 +717,28 @@ def _update_current_workflow(self):
self.model.custom.workflow.source is WorkflowSource.local
)

self._params_widget.deleteLater()
self._params_widget = WorkflowParamsWidget(self.model.custom.metadata, self)
self._params_widget.value = self.model.custom.params
self._layout.insertWidget(1, self._params_widget)
self._params_widget.value_changed.connect(self._change_params)
if self._params_widget:
self._params_scroll.setWidget(None)
self._params_widget.deleteLater()
self._params_widget = None
if len(self.model.custom.metadata) > 0:
self._params_widget = WorkflowParamsWidget(self.model.custom.metadata, self)
self._params_widget.value = self.model.custom.params
self._params_widget.value_changed.connect(self._change_params)

self._params_scroll.setWidget(self._params_widget)
widget_size = self._params_scroll.viewportSizeHint().height() + 4
params_size = min(self.height() // 2, widget_size)
self._params_scroll.setFixedHeight(params_size)
else:
self._params_scroll.setFixedHeight(0)

def _change_workflow(self):
self.model.custom.workflow_id = self._workflow_select.currentData()

def _change_params(self):
self.model.custom.params = self._params_widget.value
if self._params_widget:
self.model.custom.params = self._params_widget.value

def apply_result(self, item: QListWidgetItem):
job_id, index = self._history.item_info(item)
Expand Down

0 comments on commit 1c91eb4

Please sign in to comment.