Call o-sub with toggle button

More
07 Nov 2018 19:15 - 07 Nov 2018 19:17 #120194 by cmorley
You can use python to manipulate the mdi_action command.
Change the code in the sample I provided to this:
    def on_togglebutton1_toggled(self, widget):
        state = widget.get_active()
        if state:
            number = 100
            self.mdi.set_property('command', '(MSG, The number is: %s)' % number
            self.mdi_1.emit('activate')
        else:
            self.mdi_2.emit('activate')

Should give the idea of how to use your dialog spinbox to call an oword subroutine with a parameter from python.

Chris M
Last edit: 07 Nov 2018 19:17 by cmorley. Reason: wrong property name

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

More
08 Nov 2018 10:35 - 08 Nov 2018 10:48 #120245 by FedX
Replied by FedX on topic Call o-sub with toggle button
thank you i´ll try this and the M66 thing, but set_property wont give a parameter into the oword sub or does it?

this question may seem dumb, but how can i start the program in terminal without starting linuxcnc evereytime? i never used linux before..

Ok just found this www.linuxcnc.org/docs/2.5/html/gui/glade...#_emc_action_widgets under 7.5 there seem to be more examples ill check this when i have some time
Last edit: 08 Nov 2018 10:48 by FedX.

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

More
08 Nov 2018 19:29 - 08 Nov 2018 19:39 #120285 by cmorley
I your oword program requires arguments then you can provide them:
For instance Gmocapy has a macro for positioning the machine called go_to_position.ngc. It requires 3 arguments X position Y position and Z position.

something like this would work to move to x1 y1 z1 (not tried):
x = 1
y = 1
z = 1
command = str("O<go_to_positon> call [%s] [%s] [%s] " % ( x,y,z))
self.mdi.set_property('command', command)

If you mean can you run the gladevcp program separately yes you can, it just mon't be included in the screen.
You need to comment out the command for gladevcp in the INI and then use a similar command to load gladevcp stand alone in another terminal.

Chris M
Last edit: 08 Nov 2018 19:39 by cmorley. Reason: fix command

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

More
08 Nov 2018 19:34 #120287 by cmorley
To give more detail:

here is the original command from the INI:
gladevcp -x {XID} -u test.py test.glade

Here is what you would put in the terminal to load it stand alone:
If using a RIP linuxcnc the terminal environment must be set up as usual ( . scripts/rip-environment)

halcmd loadusr gladevcp -u test.py test.glade

Chris M

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

More
10 Nov 2018 11:31 - 10 Nov 2018 11:43 #120382 by FedX
Replied by FedX on topic Call o-sub with toggle button
I think i have a lag of understanding how the glade and px file interact..

how is it possible that a self created function like def on_togglebutton1_toggled(self, widget): interacts with the same named handler in glade file? def is a definition of a self created function isnt it?

I imported a popup and start it when button is toggled. Now i want to create a function which destroys the pop up when button1 gets clicked. But i dont know how i call the function right, im not even sure if the function on_button1_clicked can work this way..

Im sorry to ask all theese basic questions, but all code examples i found look different
class HandlerClass:
    def __init__(self, halcomp, builder, useropts):
        self.mdi_1 = builder.get_object('vcp_action_mdi1')
        self.mdi_2 = builder.get_object('vcp_action_mdi2')
	self.popup = builder.get_object('dialog1')

	def  on_button1_clicked(self, widget):
		state = widget.get_clicked()
		if state:
			self.popup.destroy()
	
	def on_togglebutton1_toggled(self, widget):
		state = widget.get_active()
		if state:
			self.popup.run()
			on_button1_clicked(self)
			
		self.mdi_1.emit('activate')
		else:
			self.mdi_2.emit('activate')



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

<?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="vcp_action_mdi2">
    <property name="command">o&lt;_camoff&gt;call</property>
  </object>
  <object class="GtkAdjustment" id="adjustment1">
    <property name="upper">150</property>
    <property name="step_increment">0.10000000000000001</property>
    <property name="page_increment">10</property>
  </object>
  <object class="EMC_Action_MDI" id="vcp_action_mdi1">
    <property name="command">o&lt;_camon&gt;call</property>
  </object>
  <object class="GtkDialog" id="dialog1">
    <property name="can_focus">False</property>
    <property name="border_width">5</property>
    <property name="type">popup</property>
    <property name="window_position">center</property>
    <property name="icon_name">applications-development</property>
    <property name="type_hint">dialog</property>
    <child internal-child="vbox">
      <object class="GtkVBox" id="dialog-vbox1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="spacing">2</property>
        <child internal-child="action_area">
          <object class="GtkHButtonBox" id="dialog-action_area1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="layout_style">end</property>
            <child>
              <object class="GtkButton" id="button1">
                <property name="label">gtk-cancel</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>
                <property name="use_stock">True</property>
                <signal name="clicked" handler="on_button1_clicked" swapped="no"/>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="button2">
                <property name="label">gtk-apply</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>
                <property name="use_stock">True</property>
                <signal name="clicked" handler="on_button2_clicked" swapped="no"/>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="pack_type">end</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="label1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">Werkstückhöhe</property>
            <attributes>
              <attribute name="weight" value="bold"/>
              <attribute name="size" value="15000"/>
            </attributes>
          </object>
          <packing>
            <property name="expand">True</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkSpinButton" id="spinbutton1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="invisible_char">●</property>
            <property name="width_chars">4</property>
            <property name="xalign">1</property>
            <property name="caps_lock_warning">False</property>
            <property name="primary_icon_activatable">False</property>
            <property name="secondary_icon_activatable">False</property>
            <property name="primary_icon_sensitive">True</property>
            <property name="secondary_icon_sensitive">True</property>
            <property name="adjustment">adjustment1</property>
            <property name="climb_rate">0.5</property>
            <property name="digits">2</property>
          </object>
          <packing>
            <property name="expand">True</property>
            <property name="fill">True</property>
            <property name="position">2</property>
          </packing>
        </child>
      </object>
    </child>
    <action-widgets>
      <action-widget response="0">button1</action-widget>
      <action-widget response="0">button2</action-widget>
    </action-widgets>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <child>
      <object class="GtkToggleButton" id="CamActive">
        <property name="label" translatable="yes">Camactive</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_togglebutton1_toggled" swapped="no"/>
      </object>
    </child>
  </object>
</interface>
Last edit: 10 Nov 2018 11:43 by FedX.

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

More
10 Nov 2018 20:13 #120416 by cmorley
The word 'self' is python's way of referencing the class instance.
So In your example self = HandlerClass (well the instance of it, but that's not really important now)
If you didn't use it the references in the _INIT_ function would be local to that function - they wouldn't work in the rest of the file.

The connection between GLADE signals and the function in the handler file is set up by GladeVCP.
It searches for the signals defined in the GLADE file, then searches all classes to see it it can find a match.
If it does it 'binds' them together, so the widget calls the function.

To get the dialog to disappear, you must command it to do so, either by hiding it or destroying it.
Looks like you do that but you call 'on_button1_clicked(self)' in the function 'on_togglebutton1_toggled'

First it should be closer to : self.on_button1_clicked(WIDGET_REFERENCE)
But the WIDGET_REFRENCE needs to be substituted for the actual button.
and you have not defined a reference to the button.

Second - I don't think you want to do this.
The logic you are setting up (as I see it) is:
If toggle button1 is toggled and is true:
pop up dialog and run it.
when the pop up is finished:
call a function that acts like the button1 was clicked
which all it does is close the dialog

If this is what you want the why have a button1? you call it if the toggle button is toggled so it doesn't have to be pushed.

I didn't try your example - I'm out of time today.
But maybe you want the dialog to close if either the togglebutton is toggled or the button is clicked.
In that case change the 'on_button1_clicked(self)
to:
'self.popup.destroy()'

Chris M

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

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