Skip to content

Commit

Permalink
Merge pull request #851 from ynput/feature/hinted-line-edit
Browse files Browse the repository at this point in the history
Widgets: Line edit with hints
  • Loading branch information
iLLiCiTiT authored Aug 21, 2024
2 parents f87a433 + 2e24a6f commit 84b8880
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 100 deletions.
36 changes: 25 additions & 11 deletions client/ayon_core/style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,31 @@ OverlayMessageWidget QWidget {
background: transparent;
}

/* Hinted Line Edit */
HintedLineEditInput {
border-radius: 0.2em;
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border: 1px solid {color:border};
}
HintedLineEditInput:hover {
border-color: {color:border-hover};
}
HintedLineEditInput:focus{
border-color: {color:border-focus};
}
HintedLineEditInput:disabled {
background: {color:bg-inputs-disabled};
}
HintedLineEditButton {
border: none;
border-radius: 0.2em;
border-bottom-left-radius: 0px;
border-top-left-radius: 0px;
padding: 0px;
qproperty-iconSize: 11px 11px;
}

/* Password dialog*/
#PasswordBtn {
border: none;
Expand Down Expand Up @@ -969,17 +994,6 @@ PixmapButton:disabled {
#PublishLogConsole {
font-family: "Noto Sans Mono";
}
#VariantInputsWidget QLineEdit {
border-bottom-right-radius: 0px;
border-top-right-radius: 0px;
}
#VariantInputsWidget QToolButton {
border-bottom-left-radius: 0px;
border-top-left-radius: 0px;
padding-top: 0.5em;
padding-bottom: 0.5em;
width: 0.5em;
}
#VariantInput[state="new"], #VariantInput[state="new"]:focus, #VariantInput[state="new"]:hover {
border-color: {color:publisher:success};
}
Expand Down
98 changes: 22 additions & 76 deletions client/ayon_core/tools/publisher/widgets/create_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
INPUTS_LAYOUT_HSPACING,
INPUTS_LAYOUT_VSPACING,
)
from ayon_core.tools.utils import HintedLineEdit

from .thumbnail_widget import ThumbnailWidget
from .widgets import (
Expand All @@ -28,8 +29,6 @@
from .create_context_widgets import CreateContextWidget
from .precreate_widget import PreCreateWidget

SEPARATORS = ("---separator---", "---")


class ResizeControlWidget(QtWidgets.QWidget):
resized = QtCore.Signal()
Expand Down Expand Up @@ -168,25 +167,9 @@ def __init__(self, controller, parent=None):

product_variant_widget = QtWidgets.QWidget(creator_basics_widget)
# Variant and product input
variant_widget = ResizeControlWidget(product_variant_widget)
variant_widget.setObjectName("VariantInputsWidget")

variant_input = QtWidgets.QLineEdit(variant_widget)
variant_input.setObjectName("VariantInput")
variant_input.setToolTip(VARIANT_TOOLTIP)

variant_hints_btn = QtWidgets.QToolButton(variant_widget)
variant_hints_btn.setArrowType(QtCore.Qt.DownArrow)
variant_hints_btn.setIconSize(QtCore.QSize(12, 12))

variant_hints_menu = QtWidgets.QMenu(variant_widget)
variant_hints_group = QtWidgets.QActionGroup(variant_hints_menu)

variant_layout = QtWidgets.QHBoxLayout(variant_widget)
variant_layout.setContentsMargins(0, 0, 0, 0)
variant_layout.setSpacing(0)
variant_layout.addWidget(variant_input, 1)
variant_layout.addWidget(variant_hints_btn, 0, QtCore.Qt.AlignVCenter)
variant_widget = HintedLineEdit(parent=product_variant_widget)
variant_widget.set_text_widget_object_name("VariantInput")
variant_widget.setToolTip(VARIANT_TOOLTIP)

product_name_input = QtWidgets.QLineEdit(product_variant_widget)
product_name_input.setEnabled(False)
Expand Down Expand Up @@ -262,15 +245,12 @@ def __init__(self, controller, parent=None):
prereq_timer.timeout.connect(self._invalidate_prereq)

create_btn.clicked.connect(self._on_create)
variant_widget.resized.connect(self._on_variant_widget_resize)
creator_basics_widget.resized.connect(self._on_creator_basics_resize)
variant_input.returnPressed.connect(self._on_create)
variant_input.textChanged.connect(self._on_variant_change)
variant_widget.returnPressed.connect(self._on_create)
variant_widget.textChanged.connect(self._on_variant_change)
creators_view.selectionModel().currentChanged.connect(
self._on_creator_item_change
)
variant_hints_btn.clicked.connect(self._on_variant_btn_click)
variant_hints_menu.triggered.connect(self._on_variant_action)
context_widget.folder_changed.connect(self._on_folder_change)
context_widget.task_changed.connect(self._on_task_change)
thumbnail_widget.thumbnail_created.connect(self._on_thumbnail_create)
Expand All @@ -291,10 +271,7 @@ def __init__(self, controller, parent=None):

self.product_name_input = product_name_input

self.variant_input = variant_input
self.variant_hints_btn = variant_hints_btn
self.variant_hints_menu = variant_hints_menu
self.variant_hints_group = variant_hints_group
self._variant_widget = variant_widget

self._creators_model = creators_model
self._creators_sort_model = creators_sort_model
Expand All @@ -314,6 +291,7 @@ def __init__(self, controller, parent=None):
self._last_current_context_folder_path = None
self._last_current_context_task = None
self._use_current_context = True
self._current_creator_variant_hints = []

def get_current_folder_path(self):
return self._controller.get_current_folder_path()
Expand Down Expand Up @@ -438,8 +416,7 @@ def _invalidate_prereq(self):

self._create_btn.setEnabled(prereq_available)

self.variant_input.setEnabled(prereq_available)
self.variant_hints_btn.setEnabled(prereq_available)
self._variant_widget.setEnabled(prereq_available)

tooltip = ""
if creator_btn_tooltips:
Expand Down Expand Up @@ -611,35 +588,15 @@ def _set_creator(self, creator_item):
if not default_variant:
default_variant = default_variants[0]

for action in tuple(self.variant_hints_menu.actions()):
self.variant_hints_menu.removeAction(action)
action.deleteLater()

for variant in default_variants:
if variant in SEPARATORS:
self.variant_hints_menu.addSeparator()
elif variant:
self.variant_hints_menu.addAction(variant)
self._current_creator_variant_hints = list(default_variants)
self._variant_widget.set_options(default_variants)

variant_text = default_variant or DEFAULT_VARIANT_VALUE
# Make sure product name is updated to new plugin
if variant_text == self.variant_input.text():
if variant_text == self._variant_widget.text():
self._on_variant_change()
else:
self.variant_input.setText(variant_text)

def _on_variant_widget_resize(self):
self.variant_hints_btn.setFixedHeight(self.variant_input.height())

def _on_variant_btn_click(self):
pos = self.variant_hints_btn.rect().bottomLeft()
point = self.variant_hints_btn.mapToGlobal(pos)
self.variant_hints_menu.popup(point)

def _on_variant_action(self, action):
value = action.text()
if self.variant_input.text() != value:
self.variant_input.setText(value)
self._variant_widget.setText(variant_text)

def _on_variant_change(self, variant_value=None):
if not self._prereq_available:
Expand All @@ -652,7 +609,7 @@ def _on_variant_change(self, variant_value=None):
return

if variant_value is None:
variant_value = self.variant_input.text()
variant_value = self._variant_widget.text()

if not self._compiled_name_pattern.match(variant_value):
self._create_btn.setEnabled(False)
Expand Down Expand Up @@ -707,20 +664,12 @@ def _validate_product_name(self, product_name, variant_value):
if _result:
variant_hints |= set(_result.groups())

# Remove previous hints from menu
for action in tuple(self.variant_hints_group.actions()):
self.variant_hints_group.removeAction(action)
self.variant_hints_menu.removeAction(action)
action.deleteLater()

# Add separator if there are hints and menu already has actions
if variant_hints and self.variant_hints_menu.actions():
self.variant_hints_menu.addSeparator()

options = list(self._current_creator_variant_hints)
if options:
options.append("---")
options.extend(variant_hints)
# Add hints to actions
for variant_hint in variant_hints:
action = self.variant_hints_menu.addAction(variant_hint)
self.variant_hints_group.addAction(action)
self._variant_widget.set_options(options)

# Indicate product existence
if not variant_value:
Expand All @@ -741,10 +690,7 @@ def _validate_product_name(self, product_name, variant_value):
self._create_btn.setEnabled(variant_is_valid)

def _set_variant_state_property(self, state):
current_value = self.variant_input.property("state")
if current_value != state:
self.variant_input.setProperty("state", state)
self.variant_input.style().polish(self.variant_input)
self._variant_widget.set_text_widget_property("state", state)

def _on_first_show(self):
width = self.width()
Expand Down Expand Up @@ -776,7 +722,7 @@ def _on_create(self):
index = indexes[0]
creator_identifier = index.data(CREATOR_IDENTIFIER_ROLE)
product_type = index.data(PRODUCT_TYPE_ROLE)
variant = self.variant_input.text()
variant = self._variant_widget.text()
# Care about product name only if context change is enabled
product_name = None
folder_path = None
Expand Down Expand Up @@ -810,7 +756,7 @@ def _on_create(self):

if success:
self._set_creator(self._selected_creator)
self.variant_input.setText(variant)
self._variant_widget.setText(variant)
self._controller.emit_card_message("Creation finished...")
self._last_thumbnail_path = None
self._thumbnail_widget.set_current_thumbnails()
2 changes: 2 additions & 0 deletions client/ayon_core/tools/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ComboBox,
CustomTextComboBox,
PlaceholderLineEdit,
HintedLineEdit,
ExpandingTextEdit,
BaseClickableFrame,
ClickableFrame,
Expand Down Expand Up @@ -88,6 +89,7 @@
"ComboBox",
"CustomTextComboBox",
"PlaceholderLineEdit",
"HintedLineEdit",
"ExpandingTextEdit",
"BaseClickableFrame",
"ClickableFrame",
Expand Down
Loading

0 comments on commit 84b8880

Please sign in to comment.