Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2001 from pypeclub/feature/1999_number_with_confi…
Browse files Browse the repository at this point in the history
…gurable_steps

Settings UI: Number with configurable steps
  • Loading branch information
iLLiCiTiT authored Sep 9, 2021
2 parents fcd3df0 + 40a6712 commit a46d1d8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions openpype/settings/entities/input_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ def _item_initalization(self):

# UI specific attributes
self.show_slider = self.schema_data.get("show_slider", False)
steps = self.schema_data.get("steps", None)
# Make sure that steps are not set to `0`
if steps == 0:
steps = None
self.steps = steps

def _convert_to_valid_type(self, value):
if isinstance(value, str):
Expand Down
1 change: 1 addition & 0 deletions openpype/settings/entities/schemas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ How output of the schema could look like on save:
- key `"decimal"` defines how many decimal places will be used, 0 is for integer input (Default: `0`)
- key `"minimum"` as minimum allowed number to enter (Default: `-99999`)
- key `"maxium"` as maximum allowed number to enter (Default: `99999`)
- key `"steps"` will change single step value of UI inputs (using arrows and wheel scroll)
- for UI it is possible to show slider to enable this option set `show_slider` to `true`
```
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"type": "number",
"key": "AVALON_TIMEOUT",
"minimum": 0,
"label": "Avalon Mongo Timeout (ms)"
"label": "Avalon Mongo Timeout (ms)",
"steps": 100
},
{
"type": "path",
Expand Down
7 changes: 6 additions & 1 deletion openpype/tools/settings/settings/item_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ def _add_inputs_to_layout(self):
kwargs = {
"minimum": self.entity.minimum,
"maximum": self.entity.maximum,
"decimal": self.entity.decimal
"decimal": self.entity.decimal,
"steps": self.entity.steps
}
self.input_field = NumberSpinBox(self.content_widget, **kwargs)
input_field_stretch = 1
Expand All @@ -426,6 +427,10 @@ def _add_inputs_to_layout(self):
int(self.entity.minimum * slider_multiplier),
int(self.entity.maximum * slider_multiplier)
)
if self.entity.steps is not None:
slider_widget.setSingleStep(
self.entity.steps * slider_multiplier
)

self.content_layout.addWidget(slider_widget, 1)

Expand Down
4 changes: 4 additions & 0 deletions openpype/tools/settings/settings/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ def __init__(self, *args, **kwargs):
min_value = kwargs.pop("minimum", -99999)
max_value = kwargs.pop("maximum", 99999)
decimals = kwargs.pop("decimal", 0)
steps = kwargs.pop("steps", None)

super(NumberSpinBox, self).__init__(*args, **kwargs)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.setDecimals(decimals)
self.setMinimum(min_value)
self.setMaximum(max_value)
if steps is not None:
self.setSingleStep(steps)

def focusInEvent(self, event):
super(NumberSpinBox, self).focusInEvent(event)
Expand Down

0 comments on commit a46d1d8

Please sign in to comment.