Call o-sub with toggle button

More
01 Nov 2018 23:20 - 02 Nov 2018 00:21 #119796 by FedX
Call o-sub with toggle button was created by FedX
Hi,

i think the answer is very simple, but i dont get it.. i want to call a mdi o-sub routine when activating a toggle button, and call another one when deactivating.
Ive implementet a button via GladeVCP into my gmoccapy. But i dont find out how to set the button up to do anything

best regards

ok.. well it seems it was to easy to find out :unsure: i used the vcp action mdi to call my ngc file and it worked so far. But the problem is that the button stays pressed and i can only set an action when the button is activated, but i want to set also an action when it gets deactivated..
Last edit: 02 Nov 2018 00:21 by FedX.

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

More
02 Nov 2018 06:06 #119805 by cmorley
Replied by cmorley on topic Call o-sub with toggle button
It seems MDI actions were not made with sending different commands on different states of the button.

What you could do is add a regular toggle button and select a 'toggled' signal to call a function in the handler file. In this function you could call one of two actions based on the state of the toggle button.

Chris M

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

More
02 Nov 2018 11:17 #119809 by FedX
Replied by FedX on topic Call o-sub with toggle button
Hi,

i thougt i could call one function when button is. I can add signals to toggle Button "pressed" and "released" in the GUI of gladeVCP but how do i call a function from there?

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

More
02 Nov 2018 16:41 #119835 by cmorley
Replied by cmorley on topic Call o-sub with toggle button
It's not clear to me if you want a momentary switch:
press and it automatically releases.
or a toggle switch:
changes state each time you press and release.

The first one uses 'pressed' and 'released' signals, the second uses 'toggled'.
The toggled signal will send you the state of the button.

I'm going with toggle button, but the process is the same.
Here is a picture of setting the signal

You can change the name of the signal - usually it uses the name of the button (like it automatically suggests.)
You would also add two mdi actions for the calls to your OWord routines. ( we will call them mdi_action1 and 2

Then in your gmoccapy handler file you would add a function such as this:
def on_toggle_button_toggled(self,w,data):
    if data:
        self.w.mdi_action1.emit('activate')
    else:
        self.w.mdi_action2.emit('activate')

Now the button will call the functions
(as long as I haven't made any mistakes)

Chris M
Attachments:

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

More
02 Nov 2018 17:14 #119836 by cmorley
Replied by cmorley on topic Call o-sub with toggle button
Ok It seems I led you astray a bit...Gmoccapy doesnt seem to use handler files, so you must use a gladevcp panel.
Maybe that is what you were doing anyways.
The process is the same other then you need to make your own complete handler file.
Do you need help with that process ( I admit the gladevcp eamples are probably a bit cryptic...

Chris M

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

More
02 Nov 2018 17:47 #119838 by islander261
Replied by islander261 on topic Call o-sub with toggle button
Look at the Gmoccapy examples file for plasma. It uses Python files to handle button presses from the replacement Glade tabs. It also has associated .hal files to go with the Glade files. I have done a similar thing to link tabs in my plasma GUI. Sorry I can't be of more help but I am a non programmer that just mostly copied what I found there and changed names and added bits until it worked.

John

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

More
02 Nov 2018 17:59 #119840 by cmorley
Replied by cmorley on topic Call o-sub with toggle button
Yes you are correct, but those file are actually used by gladevcp.
Gmoccapy was originally a Gscreen skin and Gscreen allows 'handler' files to modify the screen code. It works just like gladevcp's handler files. I guess I just assumed Gmoccapy still used them.

Anyways gladevcp panels will work fine.

Chris M

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

More
02 Nov 2018 20:51 #119848 by FedX
Replied by FedX on topic Call o-sub with toggle button
Thank you, yes youre right i want a toggle button or a checkbox, a on/off switch would also be nice. When checked first time it should call a .ngc via mdi. When unchecked it should call another .ngc file. I want to use these ngc files to set an offset for a camera with tool h99 like bonny did here: wiki.linuxcnc.org/cgi-bin/wiki.pl?Axis_Embed_Video
I used tried this as macro buttons and it worked but thats not a nice way..

Ok i build a button with pins. so now i have to write a python handler file to connect these pins to actions right?
Ive found some examples but i still dont know how the python file has to look like which files funcion etc i have to include..
do i get it right that i can call mdi function directly out of the python file? Or do i have to call a mdi command in the machine.ini file? like in axis where these calls have to be [HALUI] section?

and yes i think i do need some help with this python handler file :D :D

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

More
02 Nov 2018 22:19 #119853 by cmorley
Replied by cmorley on topic Call o-sub with toggle button
Try this for a handler file.
You need to edit the button names and the function name to match what you made in the GLADE file.
In this case I assumed you made two mdi actions in the GLADE file too.
class HandlerClass:
    def __init__(self, halcomp, builder, useropts):
        self.mdi_1 = self.builder.get_object('mdi_action_1')
        self.mdi_2 = self.builder.get_object('mdi_action_2')

    def on_toggle_button1_toggled(self, widget, state):
        print 'Button 1 toggled. state: ', state
        if state:
            self.mdi_1.emit('activate')
        else:
            self.mdi_2.emit('activate')

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

You also need to edit the gladevcp loading command in the INI file to include running the handler file.

Chris M

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

More
02 Nov 2018 23:09 - 02 Nov 2018 23:31 #119857 by FedX
Replied by FedX on topic Call o-sub with toggle button
ok i now have a mygui.ui and a myui.py file.

mygui.ui for the button and mdi calls:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <requires lib="gtk+" version="2.24"/>
  <!-- interface-requires gladevcp 0.0 -->
  <!-- interface-naming-policy project-wide -->
  <object class="EMC_Action_MDI" id="mdi_camoff">
    <property name="command">o&lt;_camoff&gt;call</property>
    <signal name="activate" handler="on_mdi_camoff_activate" swapped="no"/>
  </object>
  <object class="EMC_Action_MDI" id="mdi_camon">
    <property name="command">o&lt;_camon&gt;call</property>
    <signal name="activate" handler="on_mdi_camon_activate" swapped="no"/>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <child>
      <object class="GtkToggleButton" id="Cam_active">
        <property name="label" translatable="yes">togglebutton</property>
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <property name="use_action_appearance">False</property>
        <signal name="toggled" handler="on_Cam_active_toggled" swapped="no"/>
      </object>
    </child>
  </object>
</interface>

and myui.py:
class HandlerClass:
    def __init__(self, halcomp, builder, useropts):
        self.mdi_1 = self.builder.get_object('on_mdi_camon_activate')
        self.mdi_2 = self.builder.get_object('on_mdi_camoff_activate')

    def on_Cam_active_toggled(self, widget, state):
        print 'Button 1 toggled. state: ', state
        if state:
            self.mdi_1.emit('activate')
        else:
            self.mdi_2.emit('activate')

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

my machine ini file has the following call for the button:
EMBED_TAB_NAME = myui
EMBED_TAB_LOCATION = box_cooling
EMBED_TAB_COMMAND = gladevcp -x {XID} myui.ui

its not working yet im pretty sure i have to involve myui.py somewhere?
ive tried EMBED_TAB_COMMAND = gladevcp -x {XID} myui.ui -u myui.py but that seems to be wrong
Last edit: 02 Nov 2018 23:31 by FedX.

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

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