Exemplo n.º 1
0
    def loadSettings(self):

        #open a file browser dialog for user to name file
        dialog = QtWidgets.QFileDialog(
            None, "Open",
            os.path.join(self.toolsPath,
                         "settings" + os.sep + "importSettings"))
        dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile)
        dialog.setDefaultSuffix("json")
        dialog.exec_()
        fileName = dialog.selectedFiles()

        #open and read the file
        f = open(fileName[0], 'r')
        data = json.load(f)
        f.close()

        #find items in UI
        modules = {}
        for i in range(self.fbxModuleList.count()):
            item = self.fbxModuleList.item(i)
            itemWidget = self.fbxModuleList.itemWidget(item)
            itemModule = itemWidget.property("module")

            children = itemWidget.children()
            for child in children:
                if type(child) == QtWidgets.QComboBox:
                    modules[itemModule] = child

        #loop through data
        keys = modules.keys()
        for each in data:
            if each[0] in keys:
                comboBox = modules.get(each[0])
                comboBox.setCurrentIndex(each[1])
Exemplo n.º 2
0
    def saveSettings(self):

        #loop through each of the modules and read the qComboBox value
        moduleItems = []
        for i in range(self.fbxModuleList.count()):
            item = self.fbxModuleList.item(i)
            itemWidget = self.fbxModuleList.itemWidget(item)
            itemModule = itemWidget.property("module")

            children = itemWidget.children()
            for child in children:
                if type(child) == QtWidgets.QComboBox:
                    importMethod = child.currentIndex()
                    moduleItems.append([itemModule, importMethod])

        #save import settings in the settings folder
        if not os.path.exists(os.path.join(self.toolsPath, "settings")):
            os.makedirs(os.path.join(self.toolsPath, "settings"))

        if not os.path.exists(
                os.path.join(self.toolsPath,
                             "settings" + os.sep + "importSettings")):
            os.makedirs(
                os.path.join(self.toolsPath,
                             "settings" + os.sep + "importSettings"))

        #open a file browser dialog for user to name file
        dialog = QtWidgets.QFileDialog(
            None, "Save",
            os.path.join(self.toolsPath,
                         "settings" + os.sep + "importSettings"))
        dialog.setFileMode(QtWidgets.QFileDialog.AnyFile)
        dialog.setDefaultSuffix("json")
        dialog.exec_()
        fileName = dialog.selectedFiles()

        #write file
        f = open(fileName[0], 'w')
        json.dump(moduleItems, f)
        f.close()