[HLA] Using Python threads

Hi,
I’m trying to use the threading module in an HLA. I want to display a custom GUI using Tk in a separate thread, but the thread doesn’t start.

class Gui(threading.Thread):
    def __init__(self):
        super().__init__()
        self.root = Tk()
        self.frm = ttk.Frame(self.root, padding=10)
        self.frm.grid()
        ttk.Label(self.frm, text="Hello World!").grid(column=0, row=0)
        ttk.Button(self.frm, text="Quit", command=self.root.destroy).grid(column=1, row=0)

    def run(self):
        print("run thread")
        self.root.mainloop()

class Hla(HighLevelAnalyzer):
    def __init__(self):
        self.gui = Gui()
        self.gui.start()

        print("Hello world")

Calling self.gui.start() has no effect at all. Neither the GUI shows up nor “run thread” gets printed. Any advice?

Best regards

@gietljohannes Sorry for the late reply! Our offices were closed for the holidays by the time your message came in.

I’ll need the expertise of our software team for this one. Let me send this over to them and we’ll share our updates with you.

Sorry for the trouble with this! I’d like to test this on our end, but I’m not 100% sure how it would work, since we generally call into python and then return from python, at which point we’re no longer running python code. I’ll check with the developer who owns the HLA system once he’s back from vacation.

I’ve been thinking about trying to do the same thing - I would suggest two other approaches:

  1. Use IPC and another python process to run the GUI, and push events from the HLA to the other process for display.
  2. Use an HTML front-end, and a web socket to push events from the HLA into the HTML UI. You should be able to launch the browser window from the HLA source code. I’m not sure exactly how well running a web socket server in the LLA will work, but it might make for a pretty flexible solution.

I love the idea of running a live dashboard entirely within an HLA while running a live recording!

Hi Mark,

thanks for your reply! Yes, I’ve also been thinking about using one of your proposed solutions.
But it still would be nice to know why the original solution isn’t working.

Best regards

FYI –

I came across this older post when trying my own attempt at creating Tk GUI within an HLA. In my case, I didn’t even try threading, but got an error when I tried to add my extension to a capture:
image

… digging into the Python installation within Logic (on Windows 10), in the directory:

C:\Program Files\Logic\resources\windows-x64

I didn’t find any init.tcl file within that subdirectory/subtree. So, maybe the built-in python doesn’t have a full/correct installation of Tcl/Tk and you just don’t see the same error information when running from a thread?

Meanwhile, I was hoping that at least Tkinter might be supported, but just assumed once I got the error message above that the HLA environment was just a stripped down/more basic environment and not designed to allow spawning any GUI widgets out of it.

For what it’s worth - I did see some files in:

C:\Program Files\Logic\resources\windows-x64\pythonlibs\DLLs

Specifically:

  • tcl86t.dll
  • tk86t.dll
  • _tkinter.pyd

… so maybe there’s partial support, but the TclError() above seems to indicate that not everything is included that might be needed for full support?

Note: All I tried was a basic Tk() UI setup:

from tkinter import *
      :

    def __init__(self):
           :
        root = Tk()
        root.title('Logic2: Test Tk')
        root.mainloop()

And I got the TclError() above.

@BitBob, have you seen this post already?

I didn’t realize we included and tkinter files, I’ll look into what’s pulling that in later.

I recommend trying to pull these packages with your local python install. (we use 3.8, you may want to use that temporarily to maximize the chances of this working).

Hi @markgarrison
No, I didn’t see that, so thanks for the extra reference. Based on the fact that tkinter doesn’t appear to be supported in the official HLA python environment, I think I’ll avoid messing around with it for now.