Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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()