Creating a group
Posted
#1
(In Topic #1273)
Regular

Posted
Guru

Code (gambas)
- hButton As ToggleButton
- BuildForm
- .Arrangement = Arrange.Vertical
- .W = 450
- .H = 50
- .Padding = 5
- .H = 28
- .W = 100
- .W = 50
- .H = 28
Is that what you want?
Posted
Regular

I just found your reply - very quick - thank you.
I need to sit and study it for a while, to see if I can make sense of it, because I'm not too good at this yet. Would you be kind enough to post a short description of what is happening in the code for this thicko?. Probably one of the reasons I am having difficulty is that I don't always understand what I'm reading, and trying to find explanations can be really difficult - if I can understand what is happening, then I can reproduce it.
Meantime I'll have a play with it.
An.
Posted
Regular

Your code does exactly what I want - many thanks. Would appreciate a short description so I can understand the operation.
If you could, would you also explain the use/function of the Group attribute which seems to appear in every control, yet appears to do nothing (for me!). At first glance, this would seem an obvious way to go (create a Group somehow), then use this attribute to add a control to the Group - its what I started trying to do, and made a real mess of it.
Almost everything I could find about grouping controls in Gambas seemed to mention creating a group, either in Code or by adding (for example) a ButtonBox (that was OpenAI!), then adding controls into it, either in code or by 'drag and drop', but as I now know, that is wrong - OpenAI spent about an hour trying this route, until I in my ignorance pointed out to it that adding Buttons to a ButtonBox didn't work to create a Group - it then gave up and suggested the procedure had a bug - so much for AI.
Regards, An
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

Was your reply aimed at me or Cogier - it makes no sense at all to me, I'm afraid. Can you make it a little clearer please?
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Administrator

It might help broaden your understanding of groups.
It is an example of how to use groups in IDE (not only from code), but for menus.
https://forum.gambas.o…iewtopic.php?p=8786#p8786
If you added several button controls on a form and add them to a group (see screen below where to do so).
Next if you right click one of the controls part of the group and in the menu go to event click it will create an click event for the group that you can code (see below).
I hope this simple example will get you started in IDE as well.
Use the Tag property to identify what control in the group was clicked.
Place the controls in a Collection if you want to use them as an array, combined with group and tags very powerful to abstract code.
Good luck..
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Guru

Code (gambas)
Note that in the IDE all the ToggleButtons are in the same Group. Clicking on any of the ToggleButtons will then call the same routine - Public Sub AllButtons_MouseDown()
<IMG src="https://www.cogier.com/gambas/ToggleButtons.png">
</IMG>Hope this helps.
Posted
Regular

I need to play with this for a while, but I'm getting there, and the latest inputs should help a lot.
FYI: while I have been working on this, I have sometimes posted questions to OpenAI - and am NOT impressed. For example, my early efforts at writing code for my 'grouped buttons' didn't use groups (I didn't understand), so I 'hard-coded' the whole thing. Problem was then with 9 buttons (they were for selection of an Eprom type in a programmer I am working on), I needed to select only one button (like a radio button), which meant effectively having to 'switch off' the unused buttons, resulting in a "button_click()" routine for every button, and each routine had to reset all the other switches - long repetitive code. It worked, though, so I posted it to OpenAi and asked if it could be shortened/simplified. Back came what looked like a short code snippet - but it had syntax errors, which I had trouble resolving using Gambas. A query to OpenAI resulted in modified code…and so on…etc, etc, until eventually it told me there may be a bug in the code - big help.
So you guys are doing better than OpenAI so far, for which I thank you.
An
Posted
Guru

Especially us humans , we're awesome
Posted
Regular

regards, AN
Posted
Guru

an_other said
I have to agree with you about AI re Gambas, Bruce, but remember even AI has to learn![]()
regards, AN
Exactly , it's like asking a child , who talks like they know what they are talking about , over-confident regardless of how wrong it turns out to be.
Mostly it gives bad advice and only confuses people with incorrect code.
Like you say it needs to learn . that makes it a rubbish teacher.
Posted
Regular

I can't disagree with you, but I have had some success with AI - I guess its like any other tool - if you use it properly, then you can get some use out of it. I suppose the trick is to know what you are looking for, or at least the intelligence to assess its answers correctly. For now, I just assume its in a learning stage, and will be for some time yet, and use it accordingly (which is why I turned to this forum
On a serious level, AI is one way of collating and correlating vast amounts of data, and getting that data presented to you in an understandable state - what you make of it is still your problem. Its also a pity that 'Big Tech' has shown itself willing to misuse or steal data derived by others, without crediting the authors. This also makes it very difficult to verify or challenge such data, which I think may be a big problem as time goes on.
As an aside, I would mention that I have used AI to 'clean up' and simplify C/C++ code (which I use quite a lot), and it has been very useful for that, by pointing out and reminding me of techniques and procedures which I had long forgotten. probably also the user base for C/C++ is much larger than for Gambas, and therefore more likely to be correct. Just think of AI output as an opinion, and take it or leave it as you wish.
Regards, An
Posted
Regular

I finally found time to try out the suggestions you made earlier - and now I have a better idea what I need.
All your suggestions have been fine, and I like being able to build up the control situation I need from the IDE, because I can label buttons individually. However, my problem is that I haven't yet understood how I can create the Group, and I'm not sure I have made that clear. As gbWilly suggests, I added my controls (ToggleButtons in a Panel - 9 of them). At this point, I still have no Group. As suggested, I right-clicked on one of the buttons, and selected Event/Click. This only gives me the click() event for that button - not for all of them. I tried selecting all the buttons, then doing Event/Click, but also nothing. The 'Group' dropdown box in the attributes remains stubbornly empty, so clearly I have missed something, and have not created a Group.
Cogiers code from early in the thread does create a Group, because the function works, but I haven't been able to do it from the IDE. Give my backside a kick and tell me what I'm missing…..Please?
Regards, An
PS: Incidentally, I played around with Collections after finding some info about them, and produced the following, which does work, but still seems a bit cumbersome:
Public Sub ToggleButtonClick(Sender As ToggleButton)
Dim buttons As New Collection
buttons.Add(ToggleButton1, "ToggleButton1")
buttons.Add(ToggleButton2, "ToggleButton2")
buttons.Add(ToggleButton3, "ToggleButton3")
buttons.Add(ToggleButton4, "ToggleButton4")
buttons.Add(ToggleButton5, "ToggleButton5")
buttons.Add(ToggleButton6, "ToggleButton6")
buttons.Add(ToggleButton7, "ToggleButton7")
buttons.Add(ToggleButton8, "ToggleButton8")
buttons.Add(ToggleButton9, "ToggleButton9")
For Each button As ToggleButton In buttons
If button <> Sender Then
button.Background = SoftYellow
Else
If button.Background = SoftYellow Then
button.Background = SoftOrange
Else
button.Background = SoftYellow
Endif
Endif
Next
End
Public Sub ToggleButton1_Click()
ToggleButtonClick(ToggleButton1) 'one subroutine for each button calls routine above.
End
Public Sub ToggleButton2_Click()
ToggleButtonClick(ToggleButton2)
End
etc, etc
Thanks for the help - have a good weekend all.
Posted
Administrator

an_other said
As gbWilly suggests, I added my controls (ToggleButtons in a Panel - 9 of them). At this point, I still have no Group. As suggested, I right-clicked on one of the buttons, and selected Event/Click. This only gives me the click() event for that button - not for all of them. I tried selecting all the buttons, then doing Event/Click, but also nothing. The 'Group' dropdown box in the attributes remains stubbornly empty, so clearly I have missed something, and have not created a Group.
When you have drawn a ToggleButton1 in IDE on a form, next you go to the left panel (properties).
The group property is a dropbox that is editable.
So you type the name of the Group in the field.
Note: You might have to type and next click another property field before seeing result in the group property. It somehow doesn't refresh properly on my system. Might be a bug.
Next you can select it as group for ToggleButton2 in its properties (or any other ToggleButton you want to add)
If you now left click a ToggleButton part of the group and select event -> MouseDown you will be able to start coding:
Hope that get's you started..
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Administrator

Taking previous example I added a third ToggleButton and put it in MyGroup.an_other said
PS: Incidentally, I played around with Collections after finding some info about them, and produced the following, which does work, but still seems a bit cumbersome:
Next I gave them all a Tag:
ToggleButton1 -> tag = 1
ToggleButton2 -> tag = 2
ToggleButton3 -> tag = 3
Next I added this code (using a collection, groups and tags all in one):
Code (gambas)
- '-- Make collection private so you can use it everywhere --
- '-- initialise the collection--
- AddToCollection
- Me.Center
- '' To fill the collection with ToggleButtons
- $colToggle["ToggleButton1"] = ToggleButton1
- $colToggle["ToggleButton2"] = ToggleButton2
- $colToggle["ToggleButton3"] = ToggleButton3
Added is the source archive below so you can play around (gambas 3.19.3 -> if you have a lower version just do a compile all).
Enjoy..
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Regular

I had tried typing into the dropbox for 'Group' in the attributes, because it seemed the obvious thing to do, but nothing happened. I assumed that I had to generate the Group in another manner (perhaps in code), then would be able to select it in the attribute Group dropbox - not realising it might be a bug preventing that. I guess that is why I didn't realise what you guys were telling me when I couldn't enter a Group in the attributes.
I haven't had chance to try your tip about refreshing things (later, time permitting), but I suspect you are right - perhaps something to be fixed in the next iteration of Gambas (hint!) - if that works, then I am home and dry (if not - I'll report back)
Thanks again for the patience and help from all concerned.
Best Regards, An
Posted
Regular

You mention using the Tag value as a means of identifying which button was clicked in the group. I had intended to use the 'Value' attribute - which is either True or False depending on whether the button was pressed. There can only be one button with the 'True' condition if they are in a group such as we have discussed (I think).
Is there any advantage in using either Tag or Value?
Another option (in my case) would be to use the background color of the button - I change it in the Click() subroutine so it indicates which button I have hit, and all the other buttons are set to the colour for an unused button.
I mention this in case the Tag attribute was needed to carry other information.
Regards, An
Posted
Guru

essentially the best thing to use is the .Name property.
.Value will not work as in the Click event the button has been pressed and released. .Value is more for a ToggleButton or a ToolButton set as a toggle. when togglebutton is depressed it's Value is True, when not down it's Value is False (it's just like a CheckBox). for a normal Button the press and release triggers the Click event so it's value is already False.
(EDIT: oops i just noticed you are talking about using ToggleButtons so that comment could be moot)
But,,, You can just use the "Last" keyword to find what was clicked
In any event handler the keyword "Last" points to the object that called the event.
Imagine you have some buttons all using the GroupClick event name, when one is clicked it will trigger the GroupClick_Click event…
If you have given them unique names you can identify them that way. or if you do not plan anything being multi-language then you could just use the .Text property
Posted
Regular

for gbWilly: I just followed your latest advice on entering a group, and you are right - nothing appears in the attribute 'Group' box in this version (3.19.3) of Gambas when you type something, but if you then change another attribute of the same control, it is also updated, so the 'Group' entry appears. I guess this has been the source of my problem all along, since its a fairly obvious thing to do to create a new Group in the new IDE - but not realising there is a bug, and seeing nothing, I assumed I was doing something wrong (I know - one should never assume….). Hope this bug gets sorted soon.
Thanks to all for your useful help - it was very much appreciated - now I have a nice, correctly operating set of buttons - on with the rest of it (so I might be back with more questions yet…..
Regards, An
Posted
Regular

As one of two maintenance techs, we were fed up with the operating restrictions of this thing, and sheer difficulty keeping it going (non-saturating discrete component logic - evil stuff) so in our spare time (ho-hum), we eventually managed to get first a Sinclair ZX81 to do the same job, and later my Oric (all totally unknown to our bosses). To do this I eventually blew new code we wrote into first a 27128 Eprom, and later a 27512, which was a plug-in replacement for the Orics ROM. We also replaced the processor with a 65C02, which has a better instruction set than the plain 6502.
I cam across my old 65C02 development board a while ago, and after playing with things like Arduinos and ESP32s for some time, thought it would be interesting to play with a CPU which could handle whole bytes again, instead of single bits. Since I have the Eproms, I needed a programmer (threw my old one away years ago - mistake) so decided to build one. Its based around an Arduino Nano to do all the bit twiddling and a couple of 74HC393s to generate the addressing, and connected by its USB Serial port to the PC. The PC will eventually have a Gambas-based controlling application to send/receive serial data to the Nano, along with a 'control byte' to set up the Nano for the correct Eprom type - hence the Grouped Buttons problem - to select which Eprom to use.
To the Question "why Gambas"? - my reply would be "Why not"? - but seriously, I just wanted to write something that used a graphical interface without getting into the chaos caused by multiple graphics libraries used by the likes of C, Python, Rust, Java, etc. (I know – Qt and GtK pops up everywhere, but at least you are fairly isolated from them, and their attendant horrors when using Gambas). - and if it all works eventually, I can easily produce a compiled executive from Gambas - already done it for an application producing Gcode from LibreOffice SVG drawings for my CNC setup.
None of this has any commercial use, or any use to anyone at all except me, but it keeps me happy, and reasonably sane.
So thanks again - AN
Posted
Administrator

an_other said
Sorry - just had a thought after my last post.
You mention using the Tag value as a means of identifying which button was clicked in the group.
Is there any advantage in using either Tag or Value?
I think Bruce explained the value part just fine.
The Tag property comes in very handy when using controls in a collection and combine it with group events.
As I did in my example
Togglebutton1 had tag=1 and collection index "ToggleButton1"
Togglebutton2 had tag=2 and collection index "ToggleButton2"
Togglebutton3 had tag=3 and collection index "ToggleButton3"
The are all in a group and in a collection in my example.
To identify the one in the collection I use tag combined with Subst() on the index name in the collection:
So, the tag identifies the control and as naming of indexes has been set u accordingly the tag of ToggleButton MouseUp will be shown as name. Last.Tag was used in a Subst() to determine the exact ToggleButton that triggered the event.
If you fill a form with many of the same controls doing likewise things, using both tags and collections, you can identify and code each and every group event of those controls to detail by using clever index naming for you collections. That is my point. There are so many use cases where putting a bunch of controls in a collection and use tags and groups to make stuff happen without having to repeat code over and over again for each individual control. And with tags you can even have them to different things in the same event.
Very powerful once you know how to use them.
Abstracting is where a lot of real power of Gambas is.
Just my 2 cents
Enjoy..
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Regular

Another Question (Sorry) - As described, I now have my Group, and it all works just as you described and I want…. but…. I tried to create a second group or buttons in another frame on the same form, still using ToggleButtons. When I came to allocate them to the (second) group, I found the dropdown Group attribute contained the first group created, as expected, and I blithely assumed I just had to type in the name of a second group for my second button Group - but no.
It doesn't show d Hey Presto). I tried typing something into the Group attribute, (nothing shows as I type), then refreshed another attribute, but the second group didn't appear - just had the first group in the drop down.quite the same symptoms as the first group (invisible entry, then refresh another attribute and Hey Presto). I tried typing something into the Group attribute, (nothing shows as I type), then refreshed another attribute, but the second group didn't appear - just had the first group in the drop down. I haven't had chance yet to try creating a second group in code, then seeing if it appears in the group attribute. Nothing I could try produced another group in the dropdown.
I assume the intention is that you could create multiple groups, then use the dropdown box to select whichever you need, so is this another bug? (or more likely part of the first bug).
I also wondered if I should raise this as a bug (somewhere?) or has it already been done?
Regards, An
Posted
Guru

There are ways to resolve
Sometimes the bug is bad because your desktop font size is too small.
On my Mint-MATE system i do not get the bug at all,
The Group property inputs visibly as expected
but i do see this on other systems.
Changing the desktop GTK widget theme and/or increasing font size can help with this
Or run the IDE using QT
$ env GB_GUI=gb.gui.qt gambas3
or right click the gambas3 icon in a panel to see the actions to run with QT
PS. this has been raised many times but the main developer does not get it, and if he cannot reproduce a bug he cannot fix it.
So ergo, he's doing something we are not, my money is on font size and some widget themes being better than others.
1 guest and 0 members have just viewed this.








