def __init__(self, butData, parent=None, name=None): super(CWButtonDialog, self).__init__(parent) # Formality self.ui = Ui_ButtonDialog() self.ui.setupUi(self) self.ui.outputButton.clicked.connect(self.openCommandBoxChoiceDialog) if butData == None: self.ui.confirmButton.clicked.connect(self.saveSettings) self.ui.outputText.setText("Main Command Box") butData = ButData() else: self.ui.confirmButton.clicked.connect(self.updateSettings) self.ui.nameText.setText(butData.name) if type(butData.command) is str: self.ui.commandText.setText(butData.command) else: self.ui.commandText.setText("".join(butData.command)) self.ui.outputText.setText(butData.outputLoc.name) self.data = butData
class CWButtonDialog(QDialog): # --------------------------------------------- def __init__(self, butData, parent=None, name=None): super(CWButtonDialog, self).__init__(parent) # Formality self.ui = Ui_ButtonDialog() self.ui.setupUi(self) self.ui.outputButton.clicked.connect(self.openCommandBoxChoiceDialog) if butData == None: self.ui.confirmButton.clicked.connect(self.saveSettings) self.ui.outputText.setText("Main Command Box") butData = ButData() else: self.ui.confirmButton.clicked.connect(self.updateSettings) self.ui.nameText.setText(butData.name) if type(butData.command) is str: self.ui.commandText.setText(butData.command) else: self.ui.commandText.setText("".join(butData.command)) self.ui.outputText.setText(butData.outputLoc.name) self.data = butData def saveSettings(self): global butList, butDict if self.ui.nameText.text() == "" or self.ui.commandText.text() == "": self.errorPopup = CWErrorDialog("Error: All fields must have appropriate values.") self.errorPopup.show() else: self.data.name = self.ui.nameText.text() self.data.command = self.ui.commandText.text() self.data.outputLoc = boxDict[self.ui.outputText.text()] newButton = CWButton() newButton.data = self.data newButton.setObjectName(self.data.name) newButton.setText(self.data.name) newButton.data.buttonObj = newButton window.ui.buttonDock.addWidget(newButton) butDict[self.data.name] = self.data butList.append(self.data) self.close() def updateSettings(self): global butDict, butList if butDict.get(self.ui.nameText.text()) != None and self.data.name != self.ui.nameText.text(): self.errorPopup = CWErrorDialog("Error: Another button has this name") self.errorPopup.show() elif self.ui.commandText.text() == "": self.errorPopup = CWErrorDialog("Error: Cannot have a button without a command.") self.errorPopup.show() elif boxDict.get(self.ui.outputText.text()) == None: self.errorPopup = CWErrorDialog("Error: Not a valid command box") self.errorPopup.show() else: self.close() # Saving the name for later removal of the shortcut oldname = self.data.name oldButtonObj = self.data.buttonObj # Removing the old button data for x in range(len(butList)): if butList[x].name == oldname: del butList[x] break del butDict[oldname] # Creating new button data newData = ButData() newData.name = self.ui.nameText.text() newData.command = self.ui.commandText.text() newData.outputLoc = boxDict[self.ui.outputText.text()] newData.buttonObj = oldButtonObj butList.append(newData) butDict[newData.name] = newData newData.buttonObj.setText(newData.name) # Attaching the data to the Button newData.buttonObj.data = newData # Changing the shortuct for key in shortcutDict.keys(): if shortcutDict[key] == oldname: del shortcutDict[key] shortcutDict[key] = newData.name break for act in window.ui.menuCommands.actions(): if act.text() == oldname: act.setText(newData.name) break def openCommandBoxChoiceDialog(self): self.newCommBoxChoiceDialog = CWCommandBoxChoiceDialog(self) self.newCommBoxChoiceDialog.show()