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

Cuesubmit browse widget #1281

Closed
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions cuesubmit/cuesubmit/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
BLENDER_RENDER_CMD = config.get('BLENDER_RENDER_CMD', 'blender')
FRAME_TOKEN = config.get('FRAME_TOKEN', '#IFRAME#')

MAYA_FILE_FILTERS = [
'Maya Ascii file (*.ma)',
'Maya Binary file (*.mb)',
'Maya file (*.ma *.mb)'
]
NUKE_FILE_FILTERS = ['Nuke script file (*.nk)']
BLENDER_FILE_FILTERS = ['Blender file (*.blend)']


BLENDER_FORMATS = ['', 'AVIJPEG', 'AVIRAW', 'BMP', 'CINEON', 'DPX', 'EXR', 'HDR', 'IRIS', 'IRIZ',
'JP2', 'JPEG', 'MPEG', 'MULTILAYER', 'PNG', 'RAWTGA', 'TGA', 'TIFF']
BLENDER_OUTPUT_OPTIONS_URL = \
Expand Down
20 changes: 20 additions & 0 deletions cuesubmit/cuesubmit/ui/SettingsWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ class InMayaSettings(BaseSettingsWidget):
def __init__(self, cameras=None, filename=None, parent=None, *args, **kwargs):
super(InMayaSettings, self).__init__(parent=parent)
self.mayaFileInput = Widgets.CueLabelLineEdit('Maya File:', filename)
self.fileFilters = Constants.MAYA_FILE_FILTERS
self.cameraSelector = Widgets.CueSelectPulldown('Render Cameras', options=cameras)
self.selectorLayout = QtWidgets.QHBoxLayout()
self.setupUi()
self.setupConnections()

def setupUi(self):
"""Creates the Maya-specific widget layout."""
Expand All @@ -65,6 +67,11 @@ def setupUi(self):
self.selectorLayout.addSpacerItem(Widgets.CueSpacerItem(Widgets.SpacerTypes.HORIZONTAL))
self.mainLayout.addLayout(self.selectorLayout)

def setupConnections(self):
"""Sets up widget signals."""
self.mayaFileInput.lineEdit.textChanged.connect(self.dataChanged.emit) # pylint: disable=no-member
self.mayaFileInput.setFileBrowsable(fileFilter=self.fileFilters)

def setCommandData(self, commandData):
self.mayaFileInput.setText(commandData.get('mayaFile', ''))
self.cameraSelector.setChecked(commandData.get('camera', '').split(','))
Expand All @@ -83,6 +90,7 @@ class BaseMayaSettings(BaseSettingsWidget):
def __init__(self, parent=None, *args, **kwargs):
super(BaseMayaSettings, self).__init__(parent=parent)
self.mayaFileInput = Widgets.CueLabelLineEdit('Maya File:')
self.fileFilters = Constants.MAYA_FILE_FILTERS
self.setupUi()
self.setupConnections()

Expand All @@ -93,6 +101,7 @@ def setupUi(self):
def setupConnections(self):
"""Sets up widget signals."""
self.mayaFileInput.lineEdit.textChanged.connect(self.dataChanged.emit) # pylint: disable=no-member
self.mayaFileInput.setFileBrowsable(fileFilter=self.fileFilters)

def setCommandData(self, commandData):
self.mayaFileInput.setText(commandData.get('mayaFile', ''))
Expand All @@ -110,10 +119,12 @@ class InNukeSettings(BaseSettingsWidget):
def __init__(self, writeNodes=None, filename=None, parent=None, *args, **kwargs):
super(InNukeSettings, self).__init__(parent=parent)
self.fileInput = Widgets.CueLabelLineEdit('Nuke File:', filename)
self.fileFilters = Constants.NUKE_FILE_FILTERS
self.writeNodeSelector = Widgets.CueSelectPulldown('Write Nodes:', emptyText='[All]',
options=writeNodes)
self.selectorLayout = QtWidgets.QHBoxLayout()
self.setupUi()
self.setupConnections()

def setupUi(self):
"""Creates the Nuke-specific widget layout."""
Expand All @@ -122,6 +133,11 @@ def setupUi(self):
self.selectorLayout.addSpacerItem(Widgets.CueSpacerItem(Widgets.SpacerTypes.HORIZONTAL))
self.mainLayout.addLayout(self.selectorLayout)

def setupConnections(self):
"""Sets up widget signals."""
self.fileInput.lineEdit.textChanged.connect(self.dataChanged.emit) # pylint: disable=no-member
self.fileInput.setFileBrowsable(fileFilter=self.fileFilters)

def setCommandData(self, commandData):
self.fileInput.setText(commandData.get('nukeFile', ''))
self.writeNodeSelector.setChecked(commandData.get('writeNodes', '').split(','))
Expand All @@ -140,6 +156,7 @@ class BaseNukeSettings(BaseSettingsWidget):
def __init__(self, parent=None, *args, **kwargs):
super(BaseNukeSettings, self).__init__(parent=parent)
self.fileInput = Widgets.CueLabelLineEdit('Nuke File:')
self.fileFilters = Constants.NUKE_FILE_FILTERS
self.setupUi()
self.setupConnections()

Expand All @@ -150,6 +167,7 @@ def setupUi(self):
def setupConnections(self):
"""Sets up widget signals."""
self.fileInput.lineEdit.textChanged.connect(self.dataChanged.emit) # pylint: disable=no-member
self.fileInput.setFileBrowsable(fileFilter=self.fileFilters)

def setCommandData(self, commandData):
self.fileInput.setText(commandData.get('nukeFile', ''))
Expand Down Expand Up @@ -193,6 +211,7 @@ class BaseBlenderSettings(BaseSettingsWidget):
# pylint: disable=keyword-arg-before-vararg,unused-argument
def __init__(self, parent=None, *args, **kwargs):
super(BaseBlenderSettings, self).__init__(parent=parent)
self.fileFilters = Constants.BLENDER_FILE_FILTERS
self.fileInput = Widgets.CueLabelLineEdit('Blender File:')
self.outputPath = Widgets.CueLabelLineEdit(
'Output Path (Optional):',
Expand All @@ -217,6 +236,7 @@ def setupConnections(self):
# pylint: disable=no-member
self.fileInput.lineEdit.textChanged.connect(self.dataChanged.emit)
self.outputPath.lineEdit.textChanged.connect(self.dataChanged.emit)
self.fileInput.setFileBrowsable(fileFilter=self.fileFilters)
# pylint: enable=no-member

def setCommandData(self, commandData):
Expand Down
64 changes: 64 additions & 0 deletions cuesubmit/cuesubmit/ui/Widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from __future__ import absolute_import

from builtins import object
from functools import partial
from PySide2 import QtCore, QtGui, QtWidgets

from cuesubmit import Constants
Expand Down Expand Up @@ -53,6 +54,7 @@ def __init__(self, labelText=None, defaultText='', tooltip=None, validators=None
self.label.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.lineEdit = CueLineEdit(defaultText, completerStrings=completers)
self.lineEdit.setToolTip(tooltip)
self.browseButton = QtWidgets.QPushButton(text='Browse')
self.horizontalLine = CueHLine()
self.validators = validators or []
self.setupUi()
Expand All @@ -64,6 +66,7 @@ def setupUi(self):
self.setLayout(self.mainLayout)
self.mainLayout.addWidget(self.label, 0, 0, 1, 1)
self.mainLayout.addWidget(self.lineEdit, 1, 0, 1, 4)
self.browseButton.setVisible(False)
self.mainLayout.addWidget(self.horizontalLine, 2, 0, 1, 4)
self.label.setStyleSheet(Style.LABEL_TEXT)

Expand All @@ -74,6 +77,32 @@ def setupConnections(self):
self.lineEdit.focusChange.connect(self.textFocusChange)
# pylint: enable=no-member

def setFileBrowsable(self, fileFilter=None):
""" Displays the Browse button and hook it to a fileBrowser with optional file filters

:param fileFilter: single or multiple file filters (ex: 'Maya Ascii File (*.ma)')
:type fileFilter: str or list
"""
self._showBrowseButton()
if isinstance(fileFilter, (list, tuple)):
fileFilter = ';;'.join(fileFilter)
self.browseButton.clicked.connect(partial(_setBrowseFileText,
widget_setter=self.setter,
fileFilter=fileFilter))

def setFolderBrowsable(self):
""" Displays the Browse button and hook it to a folderBrowser """
self._showBrowseButton()
self.browseButton.clicked.connect(partial(_setBrowseFolderText,
widget_setter=self.setter))

def _showBrowseButton(self):
""" Re-layout lineEdit and browse button and display it """
self.mainLayout.removeWidget(self.lineEdit)
self.mainLayout.addWidget(self.lineEdit, 1, 0, 1, 3)
self.mainLayout.addWidget(self.browseButton, 1, 3, 1, 1)
self.browseButton.setVisible(True)

def setText(self, text):
"""Set the text to the given value.
@type text: str
Expand Down Expand Up @@ -448,6 +477,41 @@ def separatorLine():
line.setStyleSheet(Style.SEPARATOR_LINE)
return line

def getFile(fileFilter=None):
""" Opens a file browser and returns the result
:param fileFilter: optional filters (ex: "Maya Ascii File (*.ma);;Maya Binary File (*.mb);;Maya Files (*.ma *.mb)")
:type fileFilter: str
:returns: Name of the file
:rtype: str
"""
filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption='Select file', dir='.', filter=fileFilter)
return filename

def getFolder():
""" Opens a folder browser and returns the result
:returns: Name of the folder
:rtype: str
"""
folder = QtWidgets.QFileDialog.getExistingDirectory(caption='Select folder', dir='.', filter='')
return folder

def _setBrowseFileText(widget_setter, fileFilter, *args, **kwargs):
""" wrapper function to open a fileBrowser and set its result back in the widget
:param widget_setter: widget's function to set its text
:type widget_setter: function
:param fileFilter: optional filters (ex: "Maya Ascii File (*.ma);;Maya Binary File (*.mb);;Maya Files (*.ma *.mb)")
:type fileFilter: str
"""
result = getFile(fileFilter)
widget_setter(result)

def _setBrowseFolderText(widget_setter, *args, **kwargs):
""" wrapper function to open a folderBrowser and set its result back in the widget
:param widget_setter: widget's function to set its text
:type widget_setter: function
"""
result = getFolder()
widget_setter(result)

class CueMessageBox(QtWidgets.QMessageBox):
"""A QMessageBox with message and OK button."""
Expand Down