Programatically Assign Picture to PictureBox

Ask about the individual Gambas components here.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Programatically Assign Picture to PictureBox

Post by BruceSteers »

Askjerry wrote: Thursday 25th February 2021 6:18am I was using pseudo code to describe the button as I was typing from my laptop in a different area.

The color change code was not added until today... so that's not the reason... I only really noticed the button was not green today and started thinking, "maybe I should specify it in code."

As for your comment, "if your app is qt you should run gambas in qt mode too just so it looks more like your design"

I'm not really sure what you mean... I'm typing "sudo gambas3" in a terminal to get the program started... after that I jumped in hard and fast to get the pigpio operational and start testing functions. Honestly... I'm amazed at how fast I got as far as I did with this. I've been programming with Gambas about 3 days.
Yes the Gambas IDE and the help popups practically guide you through it.
It's an awesome development environment for coders of all levels.

do you have to run gambas as root?

check out these alternative commands...

env GB_GUI="gb.qt5" gambas3
or
env GB_GUI="gb.qt5" sudo gambas3
or
env GB_GUI="gb.gtk3" sudo gambas3

running gambas that way you can control what gui interface gambas itself uses.

also if you drag-n-drop the gambas menu icon to your desktop panel you can right click the icon and select the gui simply :)

If at first you don't succeed , try doing something differently.
BruceS
User avatar
Askjerry
Posts: 64
Joined: Saturday 18th August 2018 9:06pm
Location: Kyle, Texas, USA
Contact:

Re: Programatically Assign Picture to PictureBox

Post by Askjerry »

It really doesn't care... I can use a decimal number, Hex with or without the ending "&", or a variable... no change at all.

In the design window I can select a color, even type in a value... it's happy as a clam. Run the program.. grey.

I can have any color I want as long as it is grey apparently.

Ironically, if I use...

BTN_LED_16.Foreground = &H00ff0000
or...
BTN_LED_16.Foreground = &H0000ff00

The foreground text and border are quite happy to change as expected. :roll:

There is another method... thinking outside the box a bit... I could just make a PictureBox and assign it an image of a button... then swap the image as needed. An image will support a routine... so I can do a _MouseDown to make the change.

I just tried it... made a PictureBox, assigned the background color as blue...
Created a routine Picturebox_OnMouseClick() and told it to be either Red or Green depending on a Public variable I created... and had it toggle the variable from 1 to 0.

When I click on it, it toggles between Green and Red perfectly. I'm pretty sure that if I made a transparent image with text... it would work.
It's an odd way to do it... but functional. For now the great button is fine... but I've made plenty of button images for my CNC projects so that's an option if I want 3D shaded buttons that appear to stand our or be recessed into the menu. Hummm... now I want that. :geek:
User avatar
Askjerry
Posts: 64
Joined: Saturday 18th August 2018 9:06pm
Location: Kyle, Texas, USA
Contact:

Re: Programatically Assign Picture to PictureBox

Post by Askjerry »

I was doing the last response at the same time you were making your video...

Yes, on the Raspberry Pi using the piGPIO library... to allow the use of the GPIO, you MUST run in ROOT or it will give you a failure.

I'll attempt the suggestions you face me and see if they address any of the issues. Likely I'll have to put "sudo" in front to get the result.

I'll let you know. (Thanks!)

UPDATE: I tried all three... they all looked exactly the same.

It's ok... I'll update my code. For me the score is like this...

10,000 Points = Get GPIO to work. (Accomplished)
5,000 Points = Get Servo and Graphics to work. (Accomplished)
9,000 Points = Get Serial and/or I2C working (Next)
500 Points = Get the button to change color instead of a work-a-round.

So I'm ahead of the game still.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Programatically Assign Picture to PictureBox

Post by BruceSteers »

Askjerry wrote: Friday 26th February 2021 12:53am
Ironically, if I use...

BTN_LED_16.Foreground = &H00ff0000
or...
BTN_LED_16.Foreground = &H0000ff00

The foreground text and border are quite happy to change as expected. :roll:
That's more than ironic that's crazy talk :lol:

the change you "expect" there is quite incorrect.

hexidecimal values begin with &H and end with &
Your code is wrong as is your statement.
Not usng a & at the end of a hex value really does not get "expected" results unless the expected result is an incorrect value.

i'm not sure what your problem is.

maybe that button just does not want to change for you ;)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Programatically Assign Picture to PictureBox

Post by stevedee »

BruceSteers wrote: Thursday 25th February 2021 3:39pm
Askjerry wrote: Thursday 25th February 2021 6:18am ... I'm typing "sudo gambas3" in a terminal to get the program started...
...do you have to run gambas as root?
Its true that accessing i/o in Linux requires special privileges, and using root in the short term to develop the system is fine. But in the longer term you should probably find an alternative workaround.

What I do is modify the sudoers file, as this is a fairly easy approach to implement and understand. At least doing this limits elevated privileges to one user on one program. So something like:-
askjerry ALL=NOPASSWD: /usr/local/bin/pigpio
...should work (assuming username and pigpio path were correct).
See my notes towards the end of my blog post: http://captainbodgit.blogspot.com/2014/ ... ccess.html

Or you may be able just to add yourself to a user group which already has access to Linux i/o (possibly the dialout group). For example, just open a terminal and type something like:-
sudo usermod -a -G dialout askjerry
Or there maybe some other fancy-pants way of avoiding using full-blown root!
User avatar
Askjerry
Posts: 64
Joined: Saturday 18th August 2018 9:06pm
Location: Kyle, Texas, USA
Contact:

Re: Programatically Assign Picture to PictureBox

Post by Askjerry »

Bruce... it turned out that I needed to create the project in QT mode... then the button colors were fine... and the sliders look a hell of a lot better.

It's all in this video if you are interested...
https://www.youtube.com/watch?v=L3XHeS-iGl4
Post Reply