def message(self, text): msgBox = QtWidgets.QMessageBox() msgBox.setText(text) msgBox.setStyleSheet(style.load_stylesheet()) msgBox.setWindowFlags(msgBox.windowFlags() | QtCore.Qt.FramelessWindowHint) msgBox.exec_()
def open_app(self): if self.context == 'maya': Popen("maya") else: message = QtWidgets.QMessageBox(self) message.setWindowTitle("App is not set") message.setIcon(QtWidgets.QMessageBox.Critical) message.show()
def create_asset(self): name_input = self.data['inputs']['name'] name = name_input.text() test_name = name.replace(' ', '') error_message = None message = QtWidgets.QMessageBox(self) message.setWindowTitle("Some errors has occured") message.setIcon(QtWidgets.QMessageBox.Critical) # TODO: show error messages on any error if self.valid_parent is not True and test_name == '': error_message = "Name is not set and Parent is not selected" elif self.valid_parent is not True: error_message = "Parent is not selected" elif test_name == '': error_message = "Name is not set" if error_message is not None: message.setText(error_message) message.show() return test_name_exists = io.find({ 'type': 'asset', 'name': name }) existing_assets = [x for x in test_name_exists] if len(existing_assets) > 0: message.setText("Entered Asset name is occupied") message.show() return checkbox_app = self.data['inputs']['open_app'] if checkbox_app is not None and checkbox_app.isChecked() is True: task_view = self.data["view"]["tasks"] task_model = self.data["model"]["tasks"] try: index = task_view.selectedIndexes()[0] task_name = task_model.itemData(index)[0] except Exception: message.setText("Please select task") message.show() return # Get ftrack session if self.session is None: session = ftrack_api.Session() self.session = session else: session = self.session # Get Ftrack project entity project_name = io.Session['AVALON_PROJECT'] project_query = 'Project where full_name is "{}"'.format(project_name) try: ft_project = session.query(project_query).one() except Exception: message.setText("Ftrack project was not found") message.show() return # Get Ftrack entity of parent ft_parent = None assets_model = self.data["model"]["assets"] selected = assets_model.get_selected_assets() parent = io.find_one({"_id": selected[0], "type": "asset"}) asset_id = parent.get('data', {}).get('ftrackId', None) asset_entity_type = parent.get('data', {}).get('entityType', None) asset_query = '{} where id is "{}"' if asset_id is not None and asset_entity_type is not None: try: ft_parent = session.query(asset_query.format( asset_entity_type, asset_id) ).one() except Exception: ft_parent = None if ft_parent is None: ft_parent = self.get_ftrack_asset(parent, ft_project) if ft_parent is None: message.setText("Parent's Ftrack entity was not found") message.show() return asset_build_combo = self.data['inputs']['assetbuild'] asset_type_name = asset_build_combo.currentText() asset_type_query = 'Type where name is "{}"'.format(asset_type_name) try: asset_type = session.query(asset_type_query).one() except Exception: message.setText("Selected Asset Build type does not exists") message.show() return for children in ft_parent['children']: if children['name'] == name: message.setText("Entered Asset name is occupied") message.show() return task_template_combo = self.data['inputs']['tasktemplate'] task_template = task_template_combo.currentText() tasks = [] for template in self.config_data['task_templates']: if template['name'] == task_template: tasks = template['task_types'] break available_task_types = [] task_types = ft_project['project_schema']['_task_type_schema'] for task_type in task_types['types']: available_task_types.append(task_type['name']) not_possible_tasks = [] for task in tasks: if task not in available_task_types: not_possible_tasks.append(task) if len(not_possible_tasks) != 0: message.setText(( "These Task types weren't found" " in Ftrack project schema:\n{}").format( ', '.join(not_possible_tasks)) ) message.show() return # Create asset build asset_build_data = { 'name': name, 'project_id': ft_project['id'], 'parent_id': ft_parent['id'], 'type': asset_type } new_entity = session.create('AssetBuild', asset_build_data) task_data = { 'project_id': ft_project['id'], 'parent_id': new_entity['id'] } for task in tasks: type = session.query('Type where name is "{}"'.format(task)).one() task_data['type_id'] = type['id'] task_data['name'] = task session.create('Task', task_data) av_project = io.find_one({'type': 'project'}) hiearchy_items = [] hiearchy_items.extend(self.get_avalon_parent(parent)) hiearchy_items.append(parent['name']) hierarchy = os.path.sep.join(hiearchy_items) new_asset_data = { 'ftrackId': new_entity['id'], 'entityType': new_entity.entity_type, 'visualParent': parent['_id'], 'tasks': tasks, 'parents': hiearchy_items, 'hierarchy': hierarchy } new_asset_info = { 'parent': av_project['_id'], 'name': name, 'schema': "openpype:asset-3.0", 'type': 'asset', 'data': new_asset_data } # Backwards compatibility (add silo from parent if is silo project) if self.silos: new_asset_info["silo"] = parent["silo"] try: schema.validate(new_asset_info) except Exception: message.setText(( 'Asset information are not valid' ' to create asset in avalon database' )) message.show() session.rollback() return io.insert_one(new_asset_info) session.commit() outlink_cb = self.data['inputs']['outlink_cb'] if outlink_cb.isChecked() is True: outlink_input = self.data['inputs']['outlink'] outlink_name = outlink_input.text() outlink_asset = io.find_one({ 'type': 'asset', 'name': outlink_name }) outlink_ft_id = outlink_asset.get('data', {}).get('ftrackId', None) outlink_entity_type = outlink_asset.get( 'data', {} ).get('entityType', None) if outlink_ft_id is not None and outlink_entity_type is not None: try: outlink_entity = session.query(asset_query.format()).one() except Exception: outlink_entity = None if outlink_entity is None: outlink_entity = self.get_ftrack_asset( outlink_asset, ft_project ) if outlink_entity is None: message.setText("Outlink's Ftrack entity was not found") message.show() return link_data = { 'from_id': new_entity['id'], 'to_id': outlink_entity['id'] } session.create('TypedContextLink', link_data) session.commit() if checkbox_app is not None and checkbox_app.isChecked() is True: origin_asset = api.Session.get('AVALON_ASSET', None) origin_task = api.Session.get('AVALON_TASK', None) asset_name = name task_view = self.data["view"]["tasks"] task_model = self.data["model"]["tasks"] try: index = task_view.selectedIndexes()[0] except Exception: message.setText("No task is selected. App won't be launched") message.show() return task_name = task_model.itemData(index)[0] try: api.update_current_task(task=task_name, asset=asset_name) self.open_app() finally: if origin_task is not None and origin_asset is not None: api.update_current_task( task=origin_task, asset=origin_asset ) message.setWindowTitle("Asset Created") message.setText("Asset Created successfully") message.setIcon(QtWidgets.QMessageBox.Information) message.show()
def _show_no_gui(): """ Popup with information about how to register a new GUI In the event of no GUI being registered or available, this information dialog will appear to guide the user through how to get set up with one. """ messagebox = QtWidgets.QMessageBox() messagebox.setIcon(messagebox.Warning) messagebox.setWindowIcon( QtGui.QIcon( os.path.join(os.path.dirname(pyblish.__file__), "icons", "logo-32x32.svg"))) spacer = QtWidgets.QWidget() spacer.setMinimumSize(400, 0) spacer.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) layout = messagebox.layout() layout.addWidget(spacer, layout.rowCount(), 0, 1, layout.columnCount()) messagebox.setWindowTitle("Uh oh") messagebox.setText("No registered GUI found.") if not pyblish.api.registered_guis(): messagebox.setInformativeText( "In order to show you a GUI, one must first be registered. " "Press \"Show details...\" below for information on how to " "do that.") messagebox.setDetailedText( "Pyblish supports one or more graphical user interfaces " "to be registered at once, the next acting as a fallback to " "the previous." "\n" "\n" "For example, to use Pyblish Lite, first install it:" "\n" "\n" "$ pip install pyblish-lite" "\n" "\n" "Then register it, like so:" "\n" "\n" ">>> import pyblish.api\n" ">>> pyblish.api.register_gui(\"pyblish_lite\")" "\n" "\n" "The next time you try running this, Lite will appear." "\n" "See http://api.pyblish.com/register_gui.html for " "more information.") else: messagebox.setInformativeText( "None of the registered graphical user interfaces " "could be found." "\n" "\n" "Press \"Show details\" for more information.") messagebox.setDetailedText("These interfaces are currently registered." "\n" "%s" % "\n".join(pyblish.api.registered_guis())) messagebox.setStandardButtons(messagebox.Ok) messagebox.exec_()