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 #3079 from BigRoy/houdini_popups
Browse files Browse the repository at this point in the history
  • Loading branch information
mkolar authored Apr 25, 2022
2 parents 39d2d11 + 2c9a599 commit 3a3b07a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 48 deletions.
4 changes: 2 additions & 2 deletions openpype/hosts/houdini/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ def validate_fps():
if parent is None:
pass
else:
dialog = popup.Popup(parent=parent)
dialog = popup.PopupUpdateKeys(parent=parent)
dialog.setModal(True)
dialog.setWindowTitle("Houdini scene does not match project FPS")
dialog.setMessage("Scene %i FPS does not match project %i FPS" %
(current_fps, fps))
dialog.setButtonText("Fix")

# on_show is the Fix button clicked callback
dialog.on_clicked.connect(lambda: set_scene_fps(fps))
dialog.on_clicked_state.connect(lambda: set_scene_fps(fps))

dialog.show()

Expand Down
10 changes: 6 additions & 4 deletions openpype/hosts/maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,15 +2210,17 @@ def validate_fps():

parent = get_main_window()

dialog = popup.Popup2(parent=parent)
dialog = popup.PopupUpdateKeys(parent=parent)
dialog.setModal(True)
dialog.setWindowTitle("Maya scene not in line with project")
dialog.setMessage("The FPS is out of sync, please fix")
dialog.setWindowTitle("Maya scene does not match project FPS")
dialog.setMessage("Scene %i FPS does not match project %i FPS" %
(current_fps, fps))
dialog.setButtonText("Fix")

# Set new text for button (add optional argument for the popup?)
toggle = dialog.widgets["toggle"]
update = toggle.isChecked()
dialog.on_show.connect(lambda: set_scene_fps(fps, update))
dialog.on_clicked_state.connect(lambda: set_scene_fps(fps, update))

dialog.show()

Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/maya/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _on_show_inventory():
dialog.setWindowTitle("Maya scene has outdated content")
dialog.setMessage("There are outdated containers in "
"your Maya scene.")
dialog.on_show.connect(_on_show_inventory)
dialog.on_clicked.connect(_on_show_inventory)
dialog.show()


Expand Down
82 changes: 41 additions & 41 deletions openpype/widgets/popup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import sys
import logging
import contextlib


from Qt import QtCore, QtWidgets

log = logging.getLogger(__name__)


class Popup(QtWidgets.QDialog):
"""A Popup that moves itself to bottom right of screen on show event.
The UI contains a message label and a red highlighted button to "show"
or perform another custom action from this pop-up.
"""

on_show = QtCore.Signal()
on_clicked = QtCore.Signal()

def __init__(self, parent=None, *args, **kwargs):
super(Popup, self).__init__(parent=parent, *args, **kwargs)
Expand All @@ -19,40 +22,45 @@ def __init__(self, parent=None, *args, **kwargs):
# Layout
layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(10, 5, 10, 10)

# Increase spacing slightly for readability
layout.setSpacing(10)

message = QtWidgets.QLabel("")
message.setStyleSheet("""
QLabel {
font-size: 12px;
}
""")
show = QtWidgets.QPushButton("Show")
show.setSizePolicy(QtWidgets.QSizePolicy.Maximum,
button = QtWidgets.QPushButton("Show")
button.setSizePolicy(QtWidgets.QSizePolicy.Maximum,
QtWidgets.QSizePolicy.Maximum)
show.setStyleSheet("""QPushButton { background-color: #BB0000 }""")
button.setStyleSheet("""QPushButton { background-color: #BB0000 }""")

layout.addWidget(message)
layout.addWidget(show)
layout.addWidget(button)

# Size
# Default size
self.resize(400, 40)
geometry = self.calculate_window_geometry()
self.setGeometry(geometry)

self.widgets = {
"message": message,
"show": show,
"button": button,
}

# Signals
show.clicked.connect(self._on_show_clicked)
button.clicked.connect(self._on_clicked)

# Set default title
self.setWindowTitle("Popup")

def setMessage(self, message):
self.widgets['message'].setText(message)

def _on_show_clicked(self):
def setButtonText(self, text):
self.widgets["button"].setText(text)

def _on_clicked(self):
"""Callback for when the 'show' button is clicked.
Raises the parent (if any)
Expand All @@ -63,11 +71,19 @@ def _on_show_clicked(self):
self.close()

# Trigger the signal
self.on_show.emit()
self.on_clicked.emit()

if parent:
parent.raise_()

def showEvent(self, event):

# Position popup based on contents on show event
geo = self.calculate_window_geometry()
self.setGeometry(geo)

return super(Popup, self).showEvent(event)

def calculate_window_geometry(self):
"""Respond to status changes
Expand Down Expand Up @@ -104,45 +120,29 @@ def calculate_window_geometry(self):
return QtCore.QRect(x, y, width, height)


class Popup2(Popup):
class PopupUpdateKeys(Popup):
"""Popup with Update Keys checkbox (intended for Maya)"""

on_show = QtCore.Signal()
on_clicked_state = QtCore.Signal(bool)

def __init__(self, parent=None, *args, **kwargs):
Popup.__init__(self, parent=parent, *args, **kwargs)

layout = self.layout()

# Add toggle
# Insert toggle for Update keys
toggle = QtWidgets.QCheckBox("Update Keys")
layout.insertWidget(1, toggle)
self.widgets["toggle"] = toggle

layout.insertStretch(1, 1)

# Update button text
fix = self.widgets["show"]
fix.setText("Fix")

def calculate_window_geometry(self):
"""Respond to status changes
On creation, align window with screen bottom right.
"""
parent_widget = self.parent()
self.on_clicked.connect(self.emit_click_with_state)

desktop = QtWidgets.QApplication.desktop()
if parent_widget:
screen = desktop.screenNumber(parent_widget)
else:
screen = desktop.screenNumber(desktop.cursor().pos())
center_point = desktop.screenGeometry(screen).center()

frame_geo = self.frameGeometry()
frame_geo.moveCenter(center_point)
layout.insertStretch(1, 1)

return frame_geo
def emit_click_with_state(self):
"""Emit the on_clicked_state signal with the toggled state"""
checked = self.widgets["toggle"].isChecked()
self.on_clicked_state.emit(checked)


@contextlib.contextmanager
Expand Down

0 comments on commit 3a3b07a

Please sign in to comment.