Esempio n. 1
0
class ServerForm(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.connect_handlers()

        self.main_window = None
        self.entry_id = None

    def set_main_window(self, main_win):
        self.main_window = main_win

    def set_entry_id(self, id):
        self.entry_id = id
        entry = self.main_window.data[id]

        self.ui.serverAddress.setText(entry['address'])
        self.ui.serverName.setText(entry['name'])


    def connect_handlers(self):
        self.ui.okButton.clicked.connect(self.handle_ok_events)
        self.ui.cancelButton.clicked.connect(self.handle_cancel_events)


    def handle_ok_events(self):
        server_addr = self.ui.serverAddress.text()
        server_name = self.ui.serverName.text()
        server = {'name': server_name, 'address': server_addr}

        if self.entry_id is None:
            self.main_window.data.append(server)
        else:
            self.main_window.data[self.entry_id] = server

        self.main_window.update_list()
        self.main_window.refresh_list()

        self.main_window.show()
        self.hide()

        self.set_default_texts()

    def handle_cancel_events(self):
        self.main_window.show()
        self.hide()

        self.set_default_texts()

    def set_default_texts(self):
        self.ui.serverAddress.setText('example.com:27960')
        self.ui.serverName.setText('Server Name')
Esempio n. 2
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.connect_handlers()

        self.main_window = None
        self.entry_id = None