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

feat: port location selector from previus repo #205

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
import sys
import logging

logger = logging.getLogger('ftrack-connect.widget.PublisherWidget')

cwd = os.path.dirname(__file__)
sources = os.path.abspath(os.path.join(cwd, '..', 'dependencies'))
sys.path.append(sources)

import platform
import ftrack_api
from ftrack_connect.util import get_connect_plugin_version
from ftrack_connect.qt import QtWidgets, QtCore, QtGui
import qtawesome as qta
import ftrack_connect.ui.application

import ftrack_connect.ui.application
Expand Down Expand Up @@ -80,6 +88,8 @@ def _onPublishStarted(self):
def _onPublishFinished(self, success):
'''Callback for publish finished signal.'''
self.busyOverlay.hide()
selected_location = self.publishView.location_selector.selected_location
location_name = selected_location.get('label', selected_location['name'])
if success:
self.blockingOverlay.message = (
'Publish finished!\n \n'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# :coding: utf-8
# :copyright: Copyright (c) 2014-2023 ftrack

from ftrack_connect.qt import QtWidgets
from ftrack_connect.qt import QtCore
from ftrack_connect.qt import QtGui

class AdvancedOptionGroup(QtWidgets.QGroupBox):

def collapse(self, status):
self.content.setVisible(status)

def __init__(self, parent=None):
super(AdvanceOptionGroup, self).__init__(parent=parent)
self.setTitle('Advanced options')
self.setCheckable(True)
self.setFlat(True)
self.setChecked(False)
main_layout = QtWidgets.QVBoxLayout()
self.setLayout(main_layout)
self.content = QtWidgets.QWidget()
self.content_layout = QtWidgets.QFormLayout()
self.content.setLayout(self.content_layout)
main_layout.addWidget(self.content)
self.clicked.connect(self.collapse)
self.clicked.emit()
def addRow(self, name, widget):
self.content_layout.addRow(name, widget)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# :coding: utf-8
# :copyright: Copyright (c) 2014-2023 ftrack

from ftrack_connect.ui.widget import item_selector as _item_selector

import ftrack_connect.asynchronous

from ftrack_connect.qt import QtWidgets
from ftrack_connect.qt import QtCore
from ftrack_connect.qt import QtGui


class LocationSelector(_item_selector.ItemSelector):
excluded_locations = ['ftrack.origin', 'ftrack.review']

def _update_description(self, index):
location = self.itemData(index)
self.setItemData(
index, location.get('description', 'No Description Provided'),
QtCore.Qt.ToolTipRole
)

def reset(self):
current_location = self.session.pick_location()
current_location_index = self.findText(
current_location.get('label', current_location['name'])
)
self.setCurrentIndex(current_location_index)

@property
def selected_location(self):
return self.currentItem()

def __init__(self, *args, **kwargs):
'''Instantiate the asset type selector.'''
self.default_icon = QtGui.QIcon(
QtGui.QPixmap(':ftrack/image/light/object_type/info-outline')
)
super(LocationSelector, self).__init__(
labelField='label',
defaultLabel=None,
emptyLabel=None,
**kwargs
)
self.loadLocations()
self.reset()

@ftrack_connect.asynchronous.asynchronous
def loadLocations(self):
'''Load asset types and add to selector.'''
locations = self.session.query('Location').all()
sorted_locations = sorted(
locations,
key=lambda location: location.priority
)
filtered_locations = [
location for location in sorted_locations if (
(location.accessor and location.structure) and
location['name'] not in self.excluded_locations)
]
for index, location in enumerate(filtered_locations):
self.insertItem(index, location.get('label', location['name']), location)
self.setItemData(index, location.get('description', 'No Description Provided'), QtCore.Qt.ToolTipRole)
self.setItemIcon(index, self.default_icon)

self.currentIndexChanged.connect(self._update_description)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
)
from ftrack_connect.ui.widget import asset_options as _asset_options
from ftrack_connect.ui.widget import entity_selector
from ftrack_connect_publisher_widget import advanced_option_group
from ftrack_connect_publisher_widget import location_selector

from ftrack_utils.decorators import asynchronous
import ftrack_connect.error
Expand Down Expand Up @@ -115,6 +117,13 @@ def __init__(self, session, parent=None):
self.thumbnailDropZone = _thumbnail_drop_zone.ThumbnailDropZone()
formLayout.addRow('Thumbnail', self.thumbnailDropZone)

# add location selector
self.advance_options_grp = advanced_option_group.AdvancedOptionGroup()
self.location_selector = location_selector.LocationSelector(session=self.session)
self.advance_options_grp.addRow('Location', self.location_selector)
self.advance_options_grp.clicked.connect(self.location_selector.reset)
self.layout().addWidget(self.advance_options_grp)

# Add version description component.
self.versionDescription = QtWidgets.QTextEdit()
formLayout.addRow('Description', self.versionDescription)
Expand Down Expand Up @@ -176,7 +185,7 @@ def publish(self):
taskId = entity['id']
entity = entity['parent']

componentLocation = self.session.pick_location()
componentLocation = self.location_selector.selected_location

components = []
for component in self.componentsList.items():
Expand Down
Loading