def addServer(self): dialog = EditSageServerDlg(self) name_collision = True #The while loop needs to run at least once. while name_collision: if not dialog.exec_(): #The user clicked cancel. return #Fetch the data. new_server = dialog.getServerConfiguration() #Check to see if the name is in use. name_collision = ServerConfigurations.getServerByName(new_server["name"]) #If the user set the name to a new name that is already in use, name_collision will #not be None. The loop will continue and the dialog reopened. if name_collision: #The name is already in use. QMessageBox.critical(self, "Name already exists", "A server configuration already exists with that name. Choose a different name.") dialog.txtName.selectAll() dialog.txtName.setFocus() #Add the server configuration to the list. ServerConfigurations.addServer(new_server) item = QListWidgetItem(new_server["name"], self.ServerListView) self.ServerListView.setCurrentItem(item) if new_server["default"]: self.updateListViewDefault()
def doActionSageServer(self): server_list_dialog = ServerListDlg(self) #Get a reference to the WorksheetController associated to this window. wsc = self.webViewController().worksheet_controller #Select the server associated to this window, if there is one. if wsc and wsc.server_configuration: server_list_dialog.selectServer(wsc.server_configuration) #Show the dialog. server_list_dialog.exec_() #It's possible that the user will delete all of the servers. It's not clear how to cleanly handle this case. #We choose to give the user a choice to fix the situation. while not ServerConfigurations.server_list: #No servers? message_text = "Guru needs a Sage server configured in order to evaluate cells. " \ "Add a Sage server configuration in the server configuration dialog?" response = QMessageBox.question(self, "Sage Not Configured", message_text, QMessageBox.Yes, QMessageBox.No) if response == QMessageBox.No: return server_list_dialog.exec_() #Execution only reaches this point if there exists a server. server_name = server_list_dialog.ServerListView.currentItem().text() if wsc: new_config = ServerConfigurations.getServerByName(server_name) try: wsc.useServerConfiguration(new_config) except Exception as e: QMessageBox.critical(self, "Error Switching Servers", "Could not switch servers:\n%s" % e.message)
def editServer(self): #Which server configuration is selected? if not self.ServerListView.currentItem(): #Nothing selected. return name = self.ServerListView.currentItem().text() #Find the corresponding server server_config = ServerConfigurations.getServerByName(name) #Create the dialog. It's only shown when we call dialog.exec_(). dialog = EditSageServerDlg(server_info=server_config) name_collision = True #The while loop needs to run at least once. while name_collision: if not dialog.exec_(): #User clicked cancel. return new_server = dialog.getServerConfiguration() name_collision = False #We check it with the 'if' below. #If the user changed the name to a new name that is already in use, the loop will continue #and the dialog reopened. if new_server["name"] != server_config["name"] and ServerConfigurations.getServerByName(new_server["name"]): #The name is already in use. name_collision = True QMessageBox.critical(self, "Name already exists", "A server configuration already exists with that name. Choose a different name.") dialog.txtName.selectAll() dialog.txtName.setFocus() #Update server_config if server_config != new_server: # Replace server_config with new_server. index = ServerConfigurations.server_list.index(server_config) ServerConfigurations.server_list[index] = new_server self.ServerListView.currentItem().setText(new_server["name"]) #When we set the "default" value, we need to also take care of the font of the item in the ListView. ServerConfigurations.setDefault(new_server, set=new_server["default"]) #Update the ListView to reflect our possibly new default server settings. self.updateListViewDefault()