GLADE Signals IN and OUT - Buttons won't work.

More
27 Dec 2017 11:45 #103743 by newbynobi
if you want to use python, try this:
            image = gtk.Image()
            file = "TheNameOfYourGraficsFile.png"
            filepath = os.path.join(IMAGEDIR, file) 
            image.set_from_file(filepath)
            btn = gtk.Button()
            btn.__name__ = "The Name of your button"
            btn.connect("clicked", your_signal, btn.__name__)
            btn.add(image)
            btn.show_all()

IMAGEDIR = the dir where you have placed you images
If you want also text on your button, use btn = gtk.Button("The Text on the Button")
btn.__name__ = "The Name of your button" not needed, I use that very often to check witch button did send the signal.
btn.show_all() di not use btn.show(), because than the image will not been shown.

Norbert

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

More
27 Dec 2017 14:58 - 27 Dec 2017 15:02 #103751 by Askjerry
Norbert - This only gives me more questions right now... because I am not yet familiar with where the instructions go to place the code or how to set up the relative path for the imagedir.



As you can see... for each configuration file, I have two subdirectories, ./ROUTINES and ./IMAGES where the .ngc routines and images used in panels and splash screen live. In this case we would be working on GLADE Panel (1.1) in the CONFIG directory.

The code you described above... i presume it would be placed into the subdirectory with the machine.ini and refer to the subdirectory ./IMAGES yes?

Also... are the images placed, centered, or trimmed? In other words, if I made an image that looked like brushed aluminum that was larger than the current button... would it center and trim that image... or expand the button to fit? If the image were smaller... would it center it, zoom it to fit, or attempt to shrink the button? If the image had to be the exact size, i would need to screen capture the current button, then use GIMP or INKSCAPE to measure it and produce an image specific to that size button.... I just need to know how to handle it.

For now... I will presume that the image must be the same size as the button I want to change... and I will presume this image will live in the ./IMAGES folder.

I can take a screen shot and copy a button... in this case, the x-minus button from panel.glade.


I can bring it into GIMP, then decorate it like this... and save it as button1a.png to be imported...


So then I would take your code...
image = gtk.Image()
            file = "button1a.png"
            filepath = os.path.join("./IMAGES", file) 
            image.set_from_file(filepath)
            btn = gtk.Button()
            btn.x-minus= "x-minus"
            btn.connect("clicked", your_signal, btn.x-minus)
            btn.add(image)
            btn.show_all()

So then... WHERE does this modified code go?
...and how do I let machine.ini know to run it??

let's say I called it "panel_graphics.py" and put it in the same directory as the machine.ini then I presume I either need to add a line to panel.glade or machine.ini to find it... which one? How?

Thanks,
Jerry
Attachments:
Last edit: 27 Dec 2017 15:02 by Askjerry.

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

More
28 Dec 2017 23:24 - 28 Dec 2017 23:35 #103804 by newbynobi
Hallo Jerry,

your idea is right. How do you load your panel? With the code to load the panel in the ini file you can add a hal file and also a python handler file. You may take a look in gmoccapy/gmoccapy-plasma, as in this config a do use python handler files.

If you post your config, i may take a closer look and help with basic code.
According to my knowledge it is possible to shring and zoom images to fit certain space, but that is a little bit more code and you will need a pixbuffer for that.
Would be something like
import gtk
pixbuf = gtk.gdk.pixbuf_new_from_file('/path/to/the/image.png')
then scale it:

pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
Then, if you want use it in a gtk.Image, crate the widget and set the image from the pixbuf.

image = gkt.Image()
image.set_from_pixbuf(pixbuf)
Or maybe in a direct way:

image = gtk.image_new_from_pixbuf(pixbuf)
Norbert
Last edit: 28 Dec 2017 23:35 by newbynobi.

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

More
28 Dec 2017 23:57 #103806 by cmorley
you can do the same thing right from the glade editor -which is easier.
if you are going to use python though then you can have the image change if it's a toggle button.

Chris M

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

More
30 Dec 2017 20:23 #103868 by Askjerry
I will see if I can find a simple SIM in my samples... and if I can... I'll add a simple GLADE panel to it... and supply a couple of image files. Then if one of you experts can make the changes... I'll see how they work and should be able to tinker from there. It may take me a day or two to get this uploaded... but I'll get that attachment posted.

Thanks in advance.
Jerry

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

More
06 Jan 2018 09:08 #104072 by Askjerry
In order to not clutter this topic with button decoration, I started a topic and included a nice SIMULATED machine configuration that you can download to play with. ( LINK HERE )

Hopefully you can show me where/how to include the code so that I can get some of the colors and soforth as I have done with the pyVCP panels.

Thanks in advance.
Jerry

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

More
27 Jun 2019 16:23 #138004 by dangu85
This button thing makes me mad. I created a simple gui with one led, one button and a slider to test things out and it doesn't work.... linuxcnc exits with error thinking the signal of the jog-slider does not exist in the gui. Without the hal directive in postgui.hal file, program starts correctly. I really don't n know what i'm doing wrong...:(
Files are generated by stepconf wizard for me. Link here:

File Attachment:

File Name: vcptest.zip
File Size:7 KB
Attachments:

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

More
27 Jun 2019 16:29 #138005 by cmorley
what is the exact error message?

Chris M

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

More
27 Jun 2019 16:58 #138012 by dangu85
Pin gladevcp.jog-speed does not exist
Attachments:

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

More
27 Jun 2019 17:15 #138013 by cmorley
You have used a gtkHscale for your jog slider. That widget does not make HAL pins.
You need to use a HAL_hscale.

Chris M

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

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