Receiving GStat messages in GladeVCPs

More
19 Sep 2024 07:49 - 19 Sep 2024 07:51 #310427 by HansU
I want to use some GStat messages in a Glade VCP (in gmoccapy), but it seems that not all messages seem to work there.

If I take the example from linuxcnc.org/docs/2.9/html/gui/gstat.htm...tension_code_pattern everything works as expected.
Then I added
    GSTAT.connect("file-loaded", self.file_loaded)

    def file_loaded(self, obj, data):
        print("FILE LOADED:", data)

The result is that I only get the message resp. signal when a new file is loaded, not on a reload.
But if I add this signal in the gmoccapy code directly, I get an event on every reload.

Furthermore the signal "graphics-gcode-properties" works fine inside gmoccapy, but in a VCP I don't get the message at all?

Any ideas about this behaviour?
Last edit: 19 Sep 2024 07:51 by HansU.

Please Log in or Create an account to join the conversation.

More
28 Sep 2024 09:07 #310950 by andypugh
This sounds like a question for Chris, and might do better on the dev mailing list.

Please Log in or Create an account to join the conversation.

More
28 Sep 2024 12:58 #310975 by cmorley
From hal_glib.py:
        # file changed
        file_old = old.get('file', None)
        file_new = self.old['file']
        if file_new != file_old:
            # if interpreter is reading or waiting, the new file
            # is a remap procedure, with the following test we
            # partly avoid emitting a signal in that case, which would cause
            # a reload of the preview and sourceview widgets.  A signal could
            # still be emitted if aborting a program shortly after it ran an
            # external file subroutine, but that is fixed by not updating the
            # file name if call level != 0 in the merge() function above.
            # do avoid that a signal is emitted in that case, causing
            # a reload of the preview and sourceview widgets
            if self.stat.interp_state == linuxcnc.INTERP_IDLE:
                self.emit('file-loaded', file_new)

Specifically ignores loading with the same filename (reloading)
I'll have to dig a bit to comment about gcode-properties - just off to work :)

Chris

Please Log in or Create an account to join the conversation.

More
28 Sep 2024 14:20 #310979 by cmorley
Thinking more about it...
If your gladevcp panel does not have gremlin object in it, you will not get gcode properties generated in that pythons context.

Please Log in or Create an account to join the conversation.

More
30 Sep 2024 02:33 #311051 by cmorley
This stems from the short coming of linuxcnc's status process or maybe better a lack of development of GUI communication process.

Gstat is an intermediate communication process between linuxcnc status and the GUi, that is easily modified/extended for the GUI needs.

If a single Gstat instance could be used/communicated to by all GUIs - that would be much better. You can kind of do this by using ZMQ etc to broadcast some data. I don't know if using ZMQ for all linuxcnc status would be fast enough. I was toying with adding it to HALUI as a test but again only some messages.

Or if linuxcnc's status was more easily extended and allowed GUIs to send messages that would be better too.

Chris
This is mostly beyond my programming skills.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
13 Nov 2024 19:20 #314396 by HansU

This sounds like a question for Chris, and might do better on the dev mailing list.

Yes and I was pretty sure he will read this ;-)

Sorry for my late reply but I was expecting to get an email notification...

From hal_glib.py:
Thinking more about it...
If your gladevcp panel does not have gremlin object in it, you will not get gcode properties generated in that pythons context.

Why do you think so? It's just a textual message giving some information about the G-code.

From hal_glib.py:
Specifically ignores loading with the same filename (reloading)

Okay but why do I get a signal though when I run it as a user command file?


In detail, I have this VCP:
#!/usr/bin/env python3

from hal_glib import GStat
GSTAT = GStat()

class HandlerClass:

    def __init__(self, halcomp, builder, useropts):
        self.builder = builder
        GSTAT.connect("graphics-gcode-properties", self.gcode_properties)
        GSTAT.connect("file-loaded", self.file_loaded)
        GSTAT.connect("line-changed", self.line_changed)

    def gcode_properties(self, obj, data):
        print("[VCP] G-code properties:", data["name"], data["size"].replace("\n",", "))
        
    def file_loaded(self, obj, data):
        print("[VCP] File loaded:", data)
        
    def line_changed(self, obj, data):
        print("[VCP] Line changed:", data)

def get_handlers(halcomp,builder,useropts):
    return [HandlerClass(halcomp,builder,useropts)]

and I have a user command file in gmoccapy running with
USER_COMMAND_FILE = custom_init.py

def gcode_properties(obj, data, widgets):
    print("[rc] G-code properties:", data["name"], data["size"].replace("\n",", "))

def file_loaded(obj, data):
    print("[rc] File loaded:", data)
    
def line_changed(obj, data, widgets):
    print("[rc] Line changed:", data)

hal_glib.GStat().connect("graphics-gcode-properties", gcode_properties, self.widgets)
hal_glib.GStat().connect("line-changed", line_changed, self.widgets)
hal_glib.GStat().connect("file-loaded", file_loaded)


When first open a file, I get this output:
[VCP] File loaded: /home/cnc/linuxcnc/nc_files/3D_Chips.ngc
[rc] G-code properties: 3D_Chips.ngc 200509 bytes, 4714 gcode lines
[rc] File loaded: /home/cnc/linuxcnc/nc_files/3D_Chips.ngc

On reload I get only the messages from the user command file:
[rc] G-code properties: 3D_Chips.ngc 200509 bytes, 4714 gcode lines
[rc] File loaded: /home/cnc/linuxcnc/nc_files/3D_Chips.ngc

When staring the program, I get the line-changes from both:
[VCP] Line changed: 24
[rc] Line changed: 24
[VCP] Line changed: 25
[rc] Line changed: 25
[rc] Line changed: 26
[VCP] Line changed: 26
...

 

Please Log in or Create an account to join the conversation.

More
14 Nov 2024 02:37 #314414 by cmorley
Gcode properties are generated in Gremlin and then sent out using Gstat messages to whomever is connected in that GSTAT python instance context.

line change messages come from linuxcnc status, which is available in every GSTAT python instance.

So if your vcp has no gremlin then it gets no gcode properties message.


'hal_glib.GStat()' is an unusual way to create a callback. usually GStat is instantiated once with a self.variable_name = GStat().
I have a hunch that is why you get a 'file-changed' message on reload, but would have to test to confirm.

Chris

Please Log in or Create an account to join the conversation.

More
16 Nov 2024 00:14 #314580 by HansU

Gcode properties are generated in Gremlin and then sent out using Gstat messages to whomever is connected in that GSTAT python instance context.

line change messages come from linuxcnc status, which is available in every GSTAT python instance.

So if your vcp has no gremlin then it gets no gcode properties message.


If I add a Gremlin object to the Glade file, then I get the G-code properties, nice. Thanks for that hint :)

I have a hunch that is why you get a 'file-changed' message on reload, but would have to test to confirm.

Chris



I am looking forward to your idea.. :)

Please Log in or Create an account to join the conversation.

Moderators: HansU
Time to create page: 0.197 seconds
Powered by Kunena Forum