Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add discover_gui (without introducing ui dependencies !) #389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pyblish/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pyblish.api


def show(parent=None):
"""Try showing the most desirable GUI
This function cycles through the currently registered
graphical user interfaces, if any, and presents it to
the user.

parent (QWidget): the Parent widget to pass to GUI, preferably parented under QApplication
to avoid any dependencies on Qt, pyside2, or your favorite QT wrapper:
if you don't have a QApplication instance, instantiate one yourself

return a QWidget instance
"""
gui_show = _discover_gui()

if gui_show is None:
raise RuntimeError("No GUI found")
else:
return gui_show(parent)


def _discover_gui():
"""Return the most desirable of the currently registered GUIs"""

# Prefer last registered
guis = reversed(pyblish.api.registered_guis())

for gui in guis:
try:
gui_show = __import__(gui).show
except (ImportError, AttributeError) as e:
print("Failed to import GUI: %s" % gui, e)
continue
else:
return gui_show