I am currently developing a small GUI for a project at university. Basically the GUI is supposed to be able to display some info about a process, and have a progressbar.
For some reason the first sequence of methods works well – the text label gets updated, the progressbar works. However when I press the second button, no updates are shown on the screen anymore. When I debug the code, I can see, that all the updates are working in the background – just – for whatever reason, these updates are not shown on screen. Can anyone help me?
When pressing the start button I want to clear the progressbar and eventually update some textlabels. For debugging reasons I am currently only working on clearing the progressbar, since none of these tasks seem to work so far.
The homing sequence (from home_rebuilder until home_stop) works perfectly well. I don’t understand, why after pressing start() nothing works anymore.
I inserted Debugging messages all over my code. These show that the code is working fine in the background, however my screen doesn’t want to show these updates:
I have also started to make some global variables. This helps some, but doesn’t solve all my issues with the code
#Queues
queues: SystemQueues = SystemQueues()
bilderkennung_to_gui = queues.gui_bilderkennung_rx
gui_to_bilderkennung = queues.gui_bilderkennung_tx
pathing_to_gui = queues.gui_pathing_rx
gui_to_pathing = queues.gui_pathing_tx
home_started = False
progress_count = 1
def __init__(self, **kwargs):
super().__init__(**kwargs)
#initialize variables
self.time_started = False
self.time_seconds = 0
self.progress_started = False
self.energy_started = False
#Reset counter
#Schedule Queue Handler
Clock.schedule_interval(self.queue_handler, 1)
"""if GuiWindow.pathing is None:
GuiWindow.pathing = PathingFactory.setup_pathing(self.queues)
#initialize threads
GuiWindow.pathing_thread = Process(target=self.pathing.run)
GuiWindow.cube_detection_thread = Process(target=init_cube_detection, args=(self.queues, ))"""
def queue_handler(self, get_pathing):
try:
# check for object in pathing queue
if not GuiWindow.pathing_to_gui.empty():
get_pathing = GuiWindow.pathing_to_gui.get_nowait()
else:
get_pathing = None
prev_get_pathing = None
#Debug Logger entry, if Pathing-Queue updated
if get_pathing == prev_get_pathing:
pass
else:
prev_get_pathing = get_pathing
Logger.info(f"Pathing to gui = {get_pathing}")
# Check if object in cubedetector queue
if not GuiWindow.bilderkennung_to_gui.empty():
get_bildanalyse = GuiWindow.bilderkennung_to_gui.get_nowait()
else:
get_bildanalyse = None
# Debug Logger entry, if CubeDetector Queue updated
prev_get_bildanalyse = None
if get_bildanalyse == prev_get_bildanalyse:
pass
else:
prev_get_bildanalyse = get_bildanalyse
Logger.info(f"Bildanalyse to gui = {get_bildanalyse}")
if isinstance(get_pathing, Setup):
self.home_update(get_pathing)
elif isinstance(get_pathing, MeasureResults):
self.energy_update(get_pathing)
elif isinstance(get_pathing, Build) or isinstance(get_bildanalyse, Analyse):
self.start_update(get_pathing, get_bildanalyse)
elif isinstance(get_pathing, Reset):
self.reset_update(get_pathing)
elif isinstance(get_pathing, Emergency):
self.emergency(get_pathing)
except Empty:
Logger.debug("Die Queue ist leer")
except Exception as e:
Logger.debug(f"Fehler aufgetreten {e}")
#automatic homing when starting 3drebuilder the first time
def home_rebuilder(self):
GuiWindow.home_started = True
Logger.info(f”Homing started {self.home_started}”)
command = Setup(“home”)
GuiWindow.gui_to_pathing.put(command)
Clock.schedule_once(self.fake_homing,1)
#Fake homing_answer
def fake_homing(self, dt):
command = Setup(None, "ack")
GuiWindow.pathing_to_gui.put(command)
Clock.schedule_once(self.fake_homing_two, 9)
def fake_homing_two(self, dt):
command = Setup(None, "done")
GuiWindow.pathing_to_gui.put(command)
def home_update(self, get_pathing: Setup):
Logger.info("Home_update called")
if GuiWindow.home_started:
if get_pathing.ans == "ack":
self.update_progress_label("Bitte warten..")
zeiten = [0.1, 1.5, 2.2, 3.9, 5.2, 6.7, 8, 9.4]
for zeit in zeiten:
Clock.schedule_once(self.update_progress_bar, zeit)
elif get_pathing.ans == "done":
self.update_progress_label("Gerät ist betriebsbereit.")
Clock.schedule_once(self.update_progress_bar, 0)
self.ids.start.disabled = False
self.ids.reset.disabled = False
self.home_stop()
def home_stop(self):
if GuiWindow.home_started:
GuiWindow.home_started = False
Logger.info(f"Home started {GuiWindow.home_started}")
def update_progress_label(self, text):
self.ids.progress_label.text = text
Logger.info(f"Progress_Label zeigt: {self.ids.progress_label.text}")
def update_progress_bar(self, dt):
Logger.info("Update Progressbar called")
if GuiWindow.progress_count <= 9:
cube_id = "p"+str(self.progress_count)
cube = self.ids.get(cube_id, None)
cube.status = "highlight"
GuiWindow.progress_count +=1
else:
pass
def clear_progress_bar(self): #FDoesn't work smh..
Logger.info("Clear Progressbar called")
GuiWindow.progress_count = 1
Logger.info(f"Progress count {GuiWindow.progress_count}")
self.update_gui()
for i in range(1,10):
cube_id = "p"+str(i)
cube = self.ids.get(cube_id, None)
Logger.info(f"Cube status {cube.status}")
if cube:
Cube.on_status_change(self, cube, None)
else:
Logger.error("Cube nicht erkannt")
self.update_gui()
#Start_Button pressed
def start(self):
if not GuiWindow.home_started:
#clear progressbar
self.clear_progress_bar()
else:
Logger.info("Es laufen noch Hintergrundprozesse. Start wird zurückgestellt.")
#Clock.schedule_once(self.start_zwei)
#Clock.schedule_once(self.start_drei)
#Clock.schedule_once(self.start_vier)
#is currently deactivated - but just to show what I would like to implement
def start_zwei(self, dt):
Logger.info("Start_zwei was called")
#ask for measurements of current
command = Control("start")
GuiWindow.gui_to_pathing.put(command)
GuiWindow.gui_to_bilderkennung.put(command)
#Label update
self.update_progress_label("Bildanalyse initialisieren")
This is what it should look like (–> picture from going through the “homing” sequence)
homing sequence
After pressing start: no clearing of progressbar – no update of labels (text, timer, measurements) when activated in the code
enter image description here
newb is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.