def connect(self): devices = load_device_data() if not devices: return self.connect_to_device(devices[self.get_list_index()])
def remove_device(self): devices = load_device_data() if not devices: return devices.pop(self.get_list_index()) save_device_data(devices) self.load_device_data()
def load_device_data(self, autoload=False): devices = load_device_data() lst = self.ids.deviceList lst.clear() for device in devices: lst.addItem('%s (%s)' % (device['name'], device['host'])) if autoload and len(devices) == 1: self.connect_to_device(devices[0])
def add_new_device(self): device = { 'key': uuid.uuid4().hex, 'name': self.ids.deviceName.text(), 'host': self.ids.host.text(), 'username': self.ids.username.text(), 'password': self.ids.password.text(), 'params': {} } devices = load_device_data() + [device] save_device_data(devices)
def selected_device_changed(self): idx = self.get_list_index() disable_buttons = True if idx >= 0: devices = load_device_data() if devices: disable_buttons = False for btn in [self.ids.connectButton, self.ids.removeButton]: btn.setEnabled(not disable_buttons)