mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-06-02 18:19:33 +00:00
Option for automatically remove disconnected copters from table
This commit is contained in:
@@ -91,7 +91,6 @@ class CopterDataModel(QtCore.QAbstractTableModel):
|
||||
self.beginRemoveRows(QtCore.QModelIndex(), position, position + rows - 1)
|
||||
self.data_contents = self.data_contents[:position] + self.data_contents[position + rows:]
|
||||
self.endRemoveRows()
|
||||
print("removed")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@ logging.basicConfig( # TODO all prints as logs
|
||||
ConfigOption = collections.namedtuple("ConfigOption", ["section", "option", "value"])
|
||||
|
||||
|
||||
class Server:
|
||||
BUFFER_SIZE = 1024
|
||||
|
||||
class Server(messaging.Singleton):
|
||||
def __init__(self, server_id=None, config_path="server_config.ini", on_stop=None):
|
||||
self.id = server_id if server_id else str(random.randint(0, 9999)).zfill(4)
|
||||
self.time_started = 0
|
||||
@@ -65,7 +63,9 @@ class Server:
|
||||
def load_config(self):
|
||||
self.config.read(self.config_path)
|
||||
self.port = int(self.config['SERVER']['port']) # TODO try, init def
|
||||
Server.BUFFER_SIZE = int(self.config['SERVER']['buffer_size'])
|
||||
self.BUFFER_SIZE = int(self.config['SERVER']['buffer_size']) # TODO connect to connection manager
|
||||
|
||||
self.remove_disconnected = self.config.getboolean('SERVER', 'remove_disconnected')
|
||||
|
||||
self.use_broadcast = self.config.getboolean('BROADCAST', 'use_broadcast')
|
||||
self.broadcast_port = int(self.config['BROADCAST']['broadcast_port'])
|
||||
@@ -321,7 +321,6 @@ class Client(messaging.ConnectionManager):
|
||||
if self.connected:
|
||||
self.close()
|
||||
|
||||
print("closed")
|
||||
self.clients.pop(self.addr[0])
|
||||
logging.info("Client {} successfully removed!".format(self.copter_id))
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[SERVER]
|
||||
port = 25000
|
||||
buffer_size = 1024
|
||||
remove_disconnected = True
|
||||
|
||||
[BROADCAST]
|
||||
use_broadcast = True
|
||||
|
||||
@@ -111,9 +111,13 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self.signals.add_client_signal.emit(StatedCopterData(copter_id=client.copter_id, client=client))
|
||||
|
||||
def client_connection_changed(self, client: Client):
|
||||
row = self.model.get_row_by_id(client.copter_id)
|
||||
if row is not None:
|
||||
self.signals.update_data_signal.emit(row, 0, client.connected, ModelStateRole)
|
||||
row_num = self.model.get_row_by_id(client.copter_id)
|
||||
if row_num is not None:
|
||||
if Server().remove_disconnected:
|
||||
client.remove()
|
||||
self.signals.remove_client_signal.emit(row_num)
|
||||
else:
|
||||
self.signals.update_data_signal.emit(row_num, 0, client.connected, ModelStateRole)
|
||||
|
||||
def init_ui(self):
|
||||
# Connecting
|
||||
@@ -208,13 +212,9 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
def remove_selected(self):
|
||||
for copter in self.model.user_selected():
|
||||
row_num = self.model.data_contents.index(copter)
|
||||
|
||||
print(1)
|
||||
copter.client.remove()
|
||||
print(2)
|
||||
|
||||
self.signals.remove_client_signal.emit(row_num)
|
||||
print(3)
|
||||
logging.info("Client removed from table!")
|
||||
|
||||
@pyqtSlot()
|
||||
@confirmation_required("This operation will takeoff selected copters with delay and start animation. Proceed?")
|
||||
|
||||
Reference in New Issue
Block a user