I've created an application in Python GTK and I am also using zeromq to connect with a different program. I am receiving a variable from client program and I store it inside shared_memory. The problem is that even though I successfully print correct variable whenever it varies from a previous one, the markup on the label doesn't change.
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gtk, GObject
from multiprocessing import Process, shared_memory
import zmq
data = shared_memory.ShareableList([0,0,0])
class Application(Gtk.Window):
def __init__(self):
super().__init__(title="boozeBOT")
self.hbox = Gtk.Box(spacing=10)
self.vbox_left = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.vbox_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.hbox.pack_start(self.vbox_left, True, True, 0)
self.hbox.pack_start(self.vbox_right, True, True, 0)
self.label = Gtk.Label()
self.set_markup(1)
self.vbox_left.pack_start(self.label, True, True, 0)
...
markup_task = Process(target=self.markup_loop)
markup_task.start()
GLib.threads_init()
self.add(self.hbox)
def set_markup(self, val):
print("val:", str(val), flush=True)
markup = '<span foreground="blue" font="80" size="x-large">{}</span> \n Detected'.format(val)
#GLib.idle_add(self.label.set_markup, markup)
self.label.set_markup(markup)
def markup_loop(self):
prev_val = 0
while True:
if data[2] != prev_val:
print("new markup", data[2], flush=True)
markup = '<span foreground="blue" font="80" size="x-large">{}</span> \n Detected'.format(str(data[2]))
print(markup, flush=True)
GLib.idle_add(self.set_markup, data[2])
prev_val = data[2]
...
label = Gtk.Label()
label.set_label('Work in progress')
label.set_alignment(0.5, 0.05)
win = Application()
win.fullscreen()
win.connect("destroy", Gtk.main_quit)
win.show_all()
def server():
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
while True:
if data[0] > 0:
print("Sending data")
socket.send(bytes(str(data[0]), encoding='utf-8'))
data[0] = 0
try:
detected = socket.recv()
data[1] = int(detected)
print(data[1], " Data received")
except:
pass
server_task = Process(target=server)
server_task.start()
while True:
Gtk.main()
From what I've read it might have been an issue related to memory and I've tried using GLib.idle_add and GLib.threads_init but no success on that.
How can I make markup changes work?