I am creating some buttons and assigning click events to them. Each button is assigned to a dialog window where data can be entered. After entering that data it’s sent to a flask server, flask server emits that data back to the client python application.
In the socket event, I am disconnecting the button and connecting a new click event. The disconnect seems to work fine, but connecting the button again doesn’t seem to work.
# Here is where I first create and connect the buttons
def create_flow_layout(self):
frame = self.ui.receivingFlowLayoutHolder
flow_layout = FlowLayout(frame)
self.data_obj = self._api.get_receiving_data()
print(f"data: {self.data_obj}")
for location in self.locations:
button = QPushButton(location)
self.buttons_by_location[location] = button
if location in self.data_obj:
if self.data_obj[location]['type'] == "logPallet1week":
color = 'green'
self.buttons_by_location[location].clicked.connect(lambda checked, loc=location: self.open_dialog_logged_pallet(loc))
else:
color = 'grey'
self.buttons_by_location[location].clicked.connect(lambda checked, loc=location, but=button: self.open_dialog_empty_location(loc, but))
else:
color = 'grey'
self.buttons_by_location[location].clicked.connect(lambda checked, loc=location, but=button: self.open_dialog_empty_location(loc, but))
self.buttons_by_location[location].setStyleSheet(f"background-color: {color}; color: white; font-size: 16px; font-weight: bold;")
self.buttons_by_location[location].setFixedSize(200, 50)
flow_layout.addWidget(self.buttons_by_location[location])
# HERE IS WHERE I UPDATE THE BUTTON after receiving the socket event
def update_buttons(self, data):
print(data)
for location, values in data['data'].items():
self.data_obj[location] = {
'date': values['date'],
'supplier': values['supplier'],
'deliveryNumber': values['deliveryNumber'],
'palletNumber': values['palletNumber'],
'type': values['type'],
'sku': values['sku'],
'totalNumberPallets': values['totalNumberPallets']
}
button = self.buttons_by_location[location]
button.clicked.disconnect()
button.clicked.connect(lambda checked, loc=location: self.open_dialog_logged_pallet(loc))
I tried experimenting with different things. I considered not allowing the flask server emit to self, but would be nice to get this functionality working.