def create_item(parent, type, path): padding_size = 3 icon_path = resources.getIconPath() formats = resources.getFormats() images = resources.getImages() format = os.path.splitext(path)[-1] if format not in formats[type]: warnings.warn( 'wrong file, please check the file extension', Warning ) return item = QtGui.QTreeWidgetItem(parent) item.setText(1, os.path.basename(path)) item.setToolTip(1, path) current_icon = os.path.join( icon_path, '%s.png' % images[format]) icon = QtGui.QIcon() icon.addPixmap( QtGui.QPixmap(current_icon), QtGui.QIcon.Normal, QtGui.QIcon.Off ) item.setIcon(1, icon) if not os.path.isfile(path): item.setFlags(QtCore.Qt.ItemIsDragEnabled) item_count = parent.topLevelItemCount() zeros = padding(item_count, padding_size) current_number = '%s%s' % (zeros, item_count) item.setText(0, current_number)
def set_maya_version(path, *args): input_data = generic.read_preset(path) if not input_data: return maya_version = input_data['current_version']['name'] args[0].setPixmap(QtGui.QPixmap( os.path.join(resources.getIconPath(), 'maya%s.png' % maya_version))) args[0].setScaledContents(True) args[0].setMinimumSize(QtCore.QSize(32, 32)) args[0].setMaximumSize(QtCore.QSize(32, 32)) args[1].setText('Autodesk Maya %s' % maya_version)
def modify_widgets(self): icon_path = resources.getIconPath() icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(os.path.join(icon_path, 'title.png'))) self.setWindowIcon(icon) qactions = self.findChildren(QtGui.QAction) for qaction in qactions: icon = QtGui.QIcon() label = str(qaction.objectName()).split('action_')[-1] if not label: continue icon.addPixmap( QtGui.QPixmap(os.path.join(icon_path, '%s.png' % label)), QtGui.QIcon.Normal, QtGui.QIcon.Off) qaction.setIcon(icon)
def setup_ui(self): self.setObjectName('maya_mainwindow') self.setStyleSheet(self.style) self.setWindowTitle('{} {}'.format(self.label, self.version)) self.resize(self.width, self.height) self.centralwidget = QtGui.QWidget(self) self.centralwidget.setObjectName('centralwidget') self.setCentralWidget(self.centralwidget) self.verticallayout = QtGui.QVBoxLayout(self.centralwidget) self.verticallayout.setObjectName('verticallayout') self.verticallayout.setSpacing(10) self.verticallayout.setContentsMargins(10, 10, 10, 10) self.groupbox_bar = QtGui.QGroupBox(self.centralwidget) self.groupbox_bar.setObjectName('groupbox_bar') sizepolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) self.groupbox_bar.setSizePolicy(sizepolicy) self.verticallayout.addWidget(self.groupbox_bar) self.horizontallayout_bar = QtGui.QHBoxLayout(self.groupbox_bar) self.horizontallayout_bar.setObjectName('horizontallayout_toolbar') self.horizontallayout_bar.setSpacing(10) self.horizontallayout_bar.setContentsMargins(2, 2, 2, 2) self.label_mayalogo = QtGui.QLabel(self.centralwidget) self.label_mayalogo.setObjectName('label_mayalogo') sizepolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) self.label_mayalogo.setSizePolicy(sizepolicy) self.label_maya = QtGui.QLabel(self.centralwidget) self.label_maya.setObjectName('label_maya') self.label_maya.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.label_maya.setSizePolicy(sizepolicy) self.splitter = QtGui.QSplitter(self.centralwidget) self.splitter.setObjectName('splitter') self.splitter.setOrientation(QtCore.Qt.Vertical) self.splitter.setHandleWidth(5) self.verticallayout.addWidget(self.splitter) self.groupbox_input = QtGui.QGroupBox(self.splitter) self.groupbox_input.setObjectName('groupbox_input') self.horizontallayout_input = QtGui.QHBoxLayout(self.groupbox_input) self.horizontallayout_input.setObjectName('horizontallayout_input') self.horizontallayout_input.setSpacing(10) self.horizontallayout_input.setContentsMargins(2, 2, 2, 2) self.splitter_input = QtGui.QSplitter(self.groupbox_input) self.splitter_input.setObjectName('splitter_input') self.splitter_input.setOrientation(QtCore.Qt.Horizontal) self.splitter_input.setHandleWidth(5) self.horizontallayout_input.addWidget(self.splitter_input) self.textedit_output = QtGui.QTextEdit(self.splitter) self.textedit_output.setObjectName('textedit_output') self.textedit_output.setLineWrapMode(QtGui.QTextEdit.WidgetWidth) self.textedit_output.setStyleSheet('font: 11pt') self.textedit_output.setReadOnly(True) self.progressbar = QtGui.QProgressBar(self.centralwidget) self.progressbar.setObjectName('progressbar') self.progressbar.setMinimumSize(QtCore.QSize(0, 10)) self.progressbar.setMaximumSize(QtCore.QSize(16777215, 10)) self.progressbar.setValue(0) self.progressbar.setFormat('%p%') self.progressbar.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.progressbar.hide() self.verticallayout.addWidget(self.progressbar) self.horizontallayout_credit = QtGui.QHBoxLayout(None) self.horizontallayout_credit.setObjectName('horizontallayout_credit') self.horizontallayout_credit.setSpacing(10) self.horizontallayout_credit.setContentsMargins(5, 5, 5, 5) self.verticallayout.addLayout(self.horizontallayout_credit) spacer_item = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontallayout_credit.addItem(spacer_item) self.button_logo = QtGui.QPushButton(self.centralwidget) self.button_logo.setObjectName('button_logo') self.button_logo.setFlat(True) log_path = os.path.join(resources.getIconPath(), 'studio_maya_logo.png') icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(log_path), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.button_logo.setIcon(icon) self.button_logo.setIconSize(QtCore.QSize(341, 90)) self.button_logo.setMinimumSize(QtCore.QSize(341, 90)) self.button_logo.setMaximumSize(QtCore.QSize(341, 90)) self.horizontallayout_credit.addWidget(self.button_logo) self.label_sign = QtGui.QLabel(self.centralwidget) self.label_sign.setObjectName('label_sign') self.label_sign.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.label_sign.setText('www.subin-toolkits.com\[email protected]') self.label_sign.setStyleSheet('font: 10pt;') self.verticallayout.addWidget(self.label_sign) self.menubar = QtGui.QMenuBar(self) self.menubar.setObjectName('menubar') self.setMenuBar(self.menubar) self.menu_file = QtGui.QMenu(self.menubar) self.menu_file.setObjectName('menu_file') self.menu_file.setTitle('File') self.menu_edit = QtGui.QMenu(self.menubar) self.menu_edit.setObjectName('menu_edit') self.menu_edit.setTitle('Edit') self.menu_settings = QtGui.QMenu(self.menubar) self.menu_settings.setObjectName('menu_settings') self.menu_settings.setTitle('Settings') self.menu_run = QtGui.QMenu(self.menubar) self.menu_run.setObjectName('menu_run') self.menu_run.setTitle('Run') self.menu_help = QtGui.QMenu(self.menubar) self.menu_help.setObjectName('menu_help') self.menu_help.setTitle('Help') self.action_new = QtGui.QAction(self) self.action_new.setObjectName('action_new') self.action_new.setText('New') self.action_open = QtGui.QAction(self) self.action_open.setObjectName('action_open') self.action_open.setText('Open') self.action_save = QtGui.QAction(self) self.action_save.setObjectName('action_save') self.action_save.setText('Save') self.action_saveAs = QtGui.QAction(self) self.action_saveAs.setObjectName('action_saveAs') self.action_saveAs.setText('Save As...') self.action_quit = QtGui.QAction(self) self.action_quit.setObjectName('action_quit') self.action_quit.setText('Quit') self.action_import_maya = QtGui.QAction(self) self.action_import_maya.setObjectName('action_import_maya') self.action_import_maya.setText('Import Maya File') self.action_import_code = QtGui.QAction(self) self.action_import_code.setObjectName('action_import_code') self.action_import_code.setText('Import Mel/Python') self.action_import_sample = QtGui.QAction(self) self.action_import_sample.setObjectName('action_import_sample') self.action_import_sample.setText('Import Sample Scripts') self.action_preference = QtGui.QAction(self) self.action_preference.setObjectName('action_preference') self.action_preference.setText('Preference') self.action_execute = QtGui.QAction(self) self.action_execute.setObjectName('action_execute') self.action_execute.setText('Start To Execute') self.action_pause = QtGui.QAction(self) self.action_pause.setObjectName('action_pause') self.action_pause.setText('Pause') self.action_pause.setVisible(False) self.action_stop = QtGui.QAction(self) self.action_stop.setObjectName('action_stop') self.action_stop.setText('Stop') self.action_stop.setVisible(False) self.action_about = QtGui.QAction(self) self.action_about.setObjectName('action_about') self.action_about.setText('About Application') self.menu_file.addAction(self.action_new) self.menu_file.addAction(self.action_open) self.menu_file.addAction(self.action_save) self.menu_file.addAction(self.action_saveAs) self.menu_file.addSeparator() self.menu_file.addSeparator() self.menu_file.addAction(self.action_quit) self.menu_edit.addAction(self.action_import_maya) self.menu_edit.addSeparator() self.menu_edit.addAction(self.action_import_code) self.menu_edit.addSeparator() self.menu_edit.addAction(self.action_import_sample) self.menu_settings.addAction(self.action_preference) self.menu_help.addAction(self.action_about) self.menu_run.addAction(self.action_execute) self.menu_run.addAction(self.action_pause) self.menu_run.addAction(self.action_stop) self.menubar.addAction(self.menu_file.menuAction()) self.menubar.addAction(self.menu_edit.menuAction()) self.menubar.addAction(self.menu_settings.menuAction()) self.menubar.addAction(self.menu_run.menuAction()) self.menubar.addAction(self.menu_help.menuAction()) self.action_remove = QtGui.QAction(self) self.action_remove.setObjectName('action_remove') self.action_remove.setText('Remove') self.action_clear = QtGui.QAction(self) self.action_clear.setObjectName('action_clear') self.action_clear.setText('Clear') self.action_edit = QtGui.QAction(self) self.action_edit.setObjectName('action_edit') self.action_edit.setText('Edit') self.treewidget_maya = drag.DropArea(type='maya') self.treewidget_maya.setObjectName('treewidget_maya') self.treewidget_maya.headerItem().setText(0, 'No') self.treewidget_maya.headerItem().setText(1, 'Maya Files') self.treewidget_maya.setSelectionMode( QtGui.QAbstractItemView.ExtendedSelection) self.treewidget_maya.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.treewidget_maya.customContextMenuRequested.connect( partial(self.on_context_menu, self.treewidget_maya, 'maya')) self.splitter_input.addWidget(self.treewidget_maya) self.treewidget_code = drag.DropArea(type='code') self.treewidget_code.setObjectName('treewidget_code') self.treewidget_code.headerItem().setText(0, 'No') self.treewidget_code.headerItem().setText(1, 'Scripts') self.treewidget_code.setSelectionMode( QtGui.QAbstractItemView.SingleSelection) self.treewidget_code.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.treewidget_code.customContextMenuRequested.connect( partial(self.on_context_menu, self.treewidget_code, 'code')) self.splitter_input.addWidget(self.treewidget_code) self.treewidget_maya.header().resizeSection(0, 80) self.treewidget_maya.header().resizeSection(1, 80) self.treewidget_code.header().resizeSection(0, 80) self.treewidget_code.header().resizeSection(1, 80) self.splitter.setSizes([468, 175]) self.action_new.triggered.connect(self.new) self.action_open.triggered.connect(self.open) self.action_save.triggered.connect(self.save) self.action_saveAs.triggered.connect(self.save_as) self.action_quit.triggered.connect(self.quit) self.action_execute.triggered.connect(self.execute) self.action_pause.triggered.connect(self.set_pause) self.action_stop.triggered.connect(self.set_stop) self.action_about.triggered.connect(self.about) self.action_import_maya.triggered.connect( partial(self.import_source, 'maya')) self.action_import_code.triggered.connect( partial(self.import_source, 'code')) self.action_import_sample.triggered.connect( partial(self.import_samples, self.treewidget_code)) self.action_preference.triggered.connect(self.show_preference) self.action_remove.triggered.connect(partial(self.remove, 'selected')) self.action_clear.triggered.connect(partial(self.remove, 'all')) self.action_edit.triggered.connect( partial(self.edit_code, self.treewidget_code)) self.button_logo.clicked.connect(self.subin_toolkit)