def accept(self, *args, **kwargs): self.updateCurrentState() destination = self.state['destinationPath'] if not isValidPath(destination): showError("Invalid destination.", parent=self) return overwrite = bool(self.state['overwrite']) pluginId = self.state["pluginId"] pluginName = self.state["pluginName"] if overwrite is False and os.path.exists(os.path.join(destination, pluginName)): showError("A plugin named '%s' \n" "already exists at the destination and \n" "Overwrite? is set to %s." % (pluginName, str(overwrite))) return author = self.state["author"] org = self.state["org"] template = self.state['template'] templatePath = self.state['templatePath'] source = get_parent_dirpath(templatePath) try: self.saveSettings() except Exception as e: # IGNORE:W0703 print("E: couldn't save settings: %s" % e) args = ["--verbose", "--create-rootdir", "--source-data=%s" % source, '--destination=%s' % destination, "--org=%s" % org, "--author=%s" % author, "--type=%s" % template, pluginId, pluginName] if overwrite == True: args.insert(2, '--force') # if DEBUG: print("args = %r" % args) result = -1 errMsg = "Unknown error." try: result = c4dplugwiz_main(args, extend=False) except Exception as e: errMsg = "Error: " + str(e) if result == 0: openPath(os.path.realpath(os.path.join(destination, pluginName))) super(PluginWizardGui, self).accept() else: showError("%s.\n\n" "Please double check that the selected data " "directory actually contains some valid templates." % (errMsg))
def validateCurrentPage(self, *args, **kwargs): if self.currentId() == 1: # Details page if self.field('author') == "": self.setField('author', 'Unknown Author') curPage = self.currentPage() pluginIdLabel = curPage.pluginIdLabel pluginNameLabel = curPage.pluginNameLabel idstr = self.field("pluginId") namestr = self.field("pluginName") if not isValidPluginId(idstr): pluginIdLabel.setText(self.colorText(pluginIdLabel.text(), 'red')) return False if not isValidPluginName(namestr): pluginNameLabel.setText(self.colorText(pluginNameLabel.text(), 'red')) return False # everything OK? set color back to no color in case user goes back a page pluginIdLabel.setText(self.uncolorText(pluginIdLabel.text())) pluginNameLabel.setText(self.uncolorText(pluginNameLabel.text())) if self.currentId() == 2: # Template page curPage = self.currentPage() if (curPage.selectedTemplate is None or curPage.getPathForTemplate() is None): #templateTable = curPage.templateTable #curRow = templateTable.currentRow() #curCol = templateTable.currentColumn() #if curPage.updateSelectedTemplate(curRow, curCol) is True: # return True templateTree = curPage.templateTree curIdx = templateTree.currentIndex() if curPage.updateSelectedTemplate(curIdx) is True: return True return False if self.currentId() == 3: # Conclusion page curPage = self.currentPage() if not isValidPath(curPage.destinationPath): return False return QtGui.QWizard.validateCurrentPage(self, *args, **kwargs)
def destDirTextEdited(self, *args, **kwargs): newDir = args[0] if isValidPath(newDir): self.updatePath(newDir) self.updateBrowserText() self.updateComboBox(self.directoryComboBox)
def updatePath(self, path): if isValidPath(path): self.destinationPath = os.path.realpath(path) self.destinationDir = QtCore.QDir(self.destinationPath)
def dataDirTextEdited(self, *args, **kwargs): newDir = args[0] if isValidPath(newDir): self.updatePath(newDir) self.updateTemplateTable() self.updateComboBox(self.directoryComboBox, newValue=newDir)
def updatePath(self, path): isValid = isValidPath(path) if isValid: self.currentPath = os.path.realpath(path) self.currentDir = QtCore.QDir(self.currentPath)
def __init__(self, parent=None): super(TemplatePage, self).__init__(parent) self.setTitle("Template Selector") self.setSubTitle("Select the template to use from the data directory. " "By default the data directory is in the same location " "as this wizard but you can select a different directory below.") self.state = PluginWizardGui.loadSettings() self.selectedTemplate = None self.selectedTemplatePath = None self.currentPath = None self.currentDir = None self.showTemplatePaths = False # show full paths in a second column in templates table? if isValidPath(RESPATH): self.updatePath(RESPATH) browseButton = self.createButton("&Browse...", self.browse) browseButton.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) directoryLabel = QtGui.QLabel("Data Directory:") directoryLabel.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) self.directoryComboBox = self.createDirectoryComboBox() self.directoryComboBox.setSizeAdjustPolicy(2) self.helpButton = self.createButton("Template Help", self.help) self.helpButton.setSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) spacer = QtGui.QSpacerItem(40, 20) self.fileSystemModel = QtGui.QFileSystemModel() self.fileSystemModel.setReadOnly(True) self.fileSystemModel.setRootPath(self.currentPath) self.fileSystemModel.setFilter(QtCore.QDir.Dirs | QtCore.QDir.NoDotAndDotDot) self.templateTree = self.createTemplateTree() self.templatesFoundLabel = QtGui.QLabel() self.templatesFoundLabel.setText("Select template folder (double click entry to open it)") self.registerField("dataDir", self.directoryComboBox) mainLayout = QtGui.QVBoxLayout() gridLayout = QtGui.QGridLayout() gridLayout.addItem(spacer, 0, 0) gridLayout.addWidget(directoryLabel, 1, 0) gridLayout.addWidget(self.directoryComboBox, 1, 1) gridLayout.addWidget(browseButton, 1, 2) mainLayout.insertLayout(0, gridLayout) mainLayout.addWidget(self.templateTree) bottomLayout = QtGui.QHBoxLayout() bottomLayout.addWidget(self.templatesFoundLabel) bottomLayout.addWidget(self.helpButton) mainLayout.addLayout(bottomLayout) self.setLayout(mainLayout) self.updateTemplateTree()