Gmoccapy - A new screen for linuxcnc

More
11 Dec 2013 22:25 #41516 by mariusl
Thanks Norbert, I will fix the files and send them to you when I am done.

Regards
Marius


www.bluearccnc.com

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

More
12 Dec 2013 03:39 #41525 by mariusl
@ Andy
Must I incorporate the persistent variable stuff in the plasma handler file or can I use a separate file? Any suggestions welcome here :S

Regards
Marius


www.bluearccnc.com

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

More
12 Dec 2013 04:12 #41526 by newbynobi
Please include it in plasma.py

Norbert

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

More
13 Dec 2013 01:25 - 13 Dec 2013 01:27 #41552 by mariusl
Hi Norbert,
I need some help here please. Remember I dont know python at all so I am in deep water here. I started to change the plasma panel to include some buttons so please have a look at the unfinished code to tell me why I dont see the button pressed event in the python file. The button I am pressing is G0 Gap +


File Attachment:

File Name: plasma.glade
File Size:33 KB

Regards
Marius


www.bluearccnc.com

Attachments:
Last edit: 13 Dec 2013 01:27 by mariusl.

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

More
13 Dec 2013 01:29 #41553 by mariusl
The forum will not let my upload a python file why?

# This is only to show, that you can implement also your
# own python callbacks.

import linuxcnc
import os

class PlasmaClass:

    def __init__(self,halcomp,builder,useropts):
        inifile = linuxcnc.ini(os.getenv("INI_FILE_NAME"))
        self.builder = builder

        self.THC_StepSize = self.builder.get_object("THC_StepSize")
        value = inifile.find("PLASMA","THC_StepSize")
        self.THC_StepSize.set_value(float(value))

        self.TravelHeight = self.builder.get_object("TravelHeight")
        value = inifile.find("PLASMA","TravelHeight")
        self.TravelHeight.set_value(float(value))

        self.SwitchTravel = self.builder.get_object("SwitchTravel")
        value = inifile.find("PLASMA","SwitchTravel")
        self.SwitchTravel.set_value(float(value))

        self.PierceDelay = self.builder.get_object("PierceDelay")
        value = inifile.find("PLASMA","PierceDelay")
        self.PierceDelay.set_value(float(value))

        self.PierceGap = self.builder.get_object("PierceGap")
        value = inifile.find("PLASMA","PierceGap")
        self.PierceGap.set_value(float(value))

        self.Piercing_autostart = self.builder.get_object("Piercing_autostart")
        value = inifile.find("PLASMA","Piercing_autostart")
        self.Piercing_autostart.set_active(int(value))

        self.enable_HeightLock = self.builder.get_object("enable_HeightLock")
        value = inifile.find("PLASMA","enable_HeightLock")
        self.enable_HeightLock.set_active(int(value))

        self.CHL_Threshold = self.builder.get_object("CHL_Threshold")
        value = inifile.find("PLASMA","CHL_Threshold")
        self.CHL_Threshold.set_value(float(value))

        self.THC_TargetVoltage = self.builder.get_object("THC_TargetVoltage")
        value = inifile.find("PLASMA","THC_TargetVoltage")
        self.THC_TargetVoltage.set_value(float(value))

        self.btn_torch = self.builder.get_object("btn_torch")
        self.btn_torch.connect("toggled",self.on_btn_torch_toggled,self.btn_torch)

        self.Piercing_autostart = self.builder.get_object("Piercing_autostart")
        self.Piercing_autostart.connect("toggled",self.on_Piercing_autostart_toggled,self.Piercing_autostart)

        self.connect_signals()

    def on_btn_torch_toggled(self, widget, data=None):
        if widget.get_active():
            print("active")
        else:
            print("not active")

    def on_Piercing_autostart_toggled(self, widget, data=None):
        print("Checkbox Piercing has been toggled to state %s"%widget.get_active())
    
    def on_btn_g0_plus_pressed(self, widget, date=None):
        print("G0 Plus pressed %s")

def get_handlers(halcomp,builder,useropts):
    return(PlasmaClass(halcomp,builder,useropts))

Regards
Marius


www.bluearccnc.com

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

More
13 Dec 2013 02:59 #41560 by newbynobi
Hallo Marius,

first question, what should the button do?
If they should switch a hal signal, then do not use normal button, use hal_button instead.

A button do not need to have a button press event in the python file, it is an option.
If you want to use a button signal in python, than you have to:

first get the object from builder with something like:
self.btn_g0_plus = self.builder.get_object("btn_g0_plus")

and second you have to connect the pressed event to a handler like so:
self.btn_g0_plus.connect("pressed",self.on_btn_g0_plus_pressed,self.btn_g0_plus)

and third you need a def to tell what should happen
def on_btn_g0_plus_pressed(self, widget, date=None):
        print("G0 Plus pressed")

But as I see, you are really on the very beginning of python, I will help you as much as possible!

Have you taken a look here?
http://linuxcnc.org/docs/html/gui/gladevcp.html


And if you add more buttons, what about the size? Does it still fit in the cooling/spindle frame?

Norbert

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

More
13 Dec 2013 03:00 #41561 by newbynobi
Marius,

to upload a python file, just rename it from py to txt, it is not allowed to upload for security reasons.

Norbert

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

More
13 Dec 2013 03:14 #41562 by newbynobi
Hallo Marius,

I just saw, you did the signal connections in the glade file. That is normally no problem, and would work in most circumstances, but this is a very special case, as the GUI will be re parented as embedded window, so the connections will not go through. OK, that is not the exact trues, they do not come through, because the are in the plasma class, and we do need that class, to get the widgets to python code. And that is needed to save later on the states on exit.

Like Michael told me long time ago, you get this way a longer rope to hang up yourself ;-)

And please, take names for the widgets that do tell the meaning of the widget, button2 will not be as easy as btn_THC_speed_minus.

Norbert

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

More
13 Dec 2013 03:19 - 13 Dec 2013 03:20 #41563 by newbynobi
Hallo Marius,

here is the modified plasma glade file.
I did not change the button to hal button and I do not know why you are using hal boxes.

Norbert

Please rename the file to plasma.glade
Attachments:
Last edit: 13 Dec 2013 03:20 by newbynobi.

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

More
13 Dec 2013 03:35 #41564 by mariusl
Hi Norbert

I have not named anything correctly just yet. I am just trying to get the hang of things. I will name the stuff according to your standard.

The buttons must just increase and decrease the value of the hal label

It still fits as I will remove the first frame once I have renamed the objects correctly.

This looks like a lot of trouble for someone like me who know zip about python. But I will try.

Thanks for helping, I do appreciate it very much.

Regards
Marius


www.bluearccnc.com

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

Moderators: newbynobiHansU
Time to create page: 0.377 seconds
Powered by Kunena Forum