Automatic gadget numbering via names

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Fred, I was wondering if perhaps a future release of PureBasic could automatically
allocate gadget numbers, so that we can use constants to refer to them? What I was
thinking of, was that if the compiler saw a constant with a name starting with,
for example, #gad, then it could increment an internal counter and allocate that
number to that gadget/menu item/etc. See the following example routines to see
what I mean. Is this sort of idea feasible? It would save us having to renumber
our gadget constants if we add/remove gadgets during editing...

Code: Select all

[b]; Current method of allocating gadget numbers (user must do it).[/b]
If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  #Button1=1 ; Proposed method means this line won't be needed.
  #Button2=2 ; Proposed method means this line won't be needed.
  ButtonGadget(#Button1,20,20,50,25,"button1")
  ButtonGadget(#Button2,20,50,50,25,"button2")
  Repeat
    ev=WaitWindowEvent()
  Until ev=#PB_EventCloseWindow
EndIf

Code: Select all

[b]; Proposed method of allocating gadget numbers (compiler does it).[/b]
If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  ; Compiler sees [b]#gad[/b] prefix in constants, and allocates an internal number.
  ButtonGadget([b]#gad[/b]Button1,20,20,50,25,"button1")
  ButtonGadget([b]#gad[/b]Button2,20,50,50,25,"button2")
  Repeat
    ev=WaitWindowEvent()
  Until ev=#PB_EventCloseWindow
EndIf

PB - Registered PureBasic Coder

Edited by - PB on 02 July 2002 11:13:02
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

Nice Idea PB. Another idea could be to make the gadgetnumber optional and only use the returned handle for all other options. that would made life much easier.

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Nice Idea PB. Another idea could be to make the gadgetnumber optional and
> only use the returned handle for all other options. that would made life
> much easier.

Yes, that's what I was hoping for, but I thought I read that Fred didn't want to
lose the gadget numbers? I may be wrong. But note that if you're willing to use
the Windows API commands for all gadget commands, then you can already do it
your way:

Code: Select all

If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  but1=ButtonGadget(0,20,20,50,25,"button1") ; Gadget number 0!
  but2=ButtonGadget(0,20,50,50,25,"button2") ; Gadget number 0 again!
  EnableWindow_(but1,#FALSE) ; Disable but1 (instead of PureBasic's command).
  Repeat
    ev=WaitWindowEvent()
  Until ev=#PB_EventCloseWindow
EndIf

PB - Registered PureBasic Coder

Edited by - PB on 02 July 2002 13:40:59
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

The internal PureBasic Toolkit works with numbers not with handles and I suppose that Fred has a good reason for it, like managing the GUI on different OS.

The Handle of a window object (childwindow, gadget, whatever...) is only needed if you use WinAPI, and if you need it with a PureBasic Function there is always a PureBasic command to get it, like UseImage(Image#).

So if you need the handle of an object just do:

GadgetID(Gadget#)
or
WindowID(Window#)

Anyway.
The Problem with your suggestion is that you must do more:
if you have a Panel, ComboBox or such a thing and you work with AddGadgetItem, you need to know which Gadget number was the last one.
So you need not only a function that generates new Object numbers, you need also a second function to use the actual number for AddGadgetItem or such a command.

And I tell you what:
It seems that Fred did a very good job, and PureBasic has finally a good status (if I look at the bug reports from the users, there are only little things to worry about...).
I hope that PureBasic 3.3 will bring only new stuff and not change working functions again, and with that, bring new bugs to old commands.

I like to see that Fred works in his spare time on porting PureBasic to other OS or has time to get a nice documentation out the door, instead to always change the core of something that already works again and again...


And finally:
If you get bored with manually GUI Object numbering, there is a nice tool out there with a strange name...
If I recall it right it was PureGUI or something like that.


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Edited by - franco on 02 July 2002 16:30:54
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> The Problem with your suggestion is [...]

...nothing, really. Whether the user, or the compiler, assigns the constant
its value, is of no importance, which is why my request is a good one. You
talk about using AddGadgetItem -- so what? You still use AddGadgetItem with
the constant name, and the program won't know any different. Perhaps you don't
understand my request? Let me explain further:

Currently, when the compiler reads a line like #constant=1, it will then replace
any subsequent occurrence of #constant with 1, during compilation. This is fine,
except that the user did the work and told the compiler that #constant must be
1 whenever found.

With my way, when the compiler finds a new gadget, it increments an internal
gadget number count and uses that number whenever it finds that constant again,
just as it already does (except that the programmer has specified the number).

Both methods achieve exactly the same result, and both use an internal list by
the compiler during compilation, so no extra effort is really needed to add such
functionality to the compiler. It's a good idea.


PB - Registered PureBasic Coder

Edited by - PB on 02 July 2002 19:10:15
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
...nothing, really. Whether the user, or the compiler, assigns the constant
its value, is of no importance, which is why my request is a good one. You
talk about using AddGadgetItem -- so what? You still use AddGadgetItem with
the constant name, and the program won't know any different. Perhaps you don't
understand my request? Let me explain further:

Currently, when the compiler reads a line like #constant=1, it will then replace
any subsequent occurrence of #constant with 1, during compilation. This is fine,
except that the user did the work and told the compiler that #constant must be
1 whenever found.

With my way, when the compiler finds a new gadget, it increments an internal
gadget number count and uses that number whenever it finds that constant again,
just as it already does (except that the programmer has specified the number).

Both methods achieve exactly the same result, and both use an internal list by
the compiler during compilation, so no extra effort is really needed to add such
functionality to the compiler. It's a good idea.

PB - Registered PureBasic Coder
Now I understood what you meant.

YES, PB don't get me wrong, your idea is a good idea - no offense.

You want a dynamically increase of a 'Constant Group'.
Well if Fred could make such a function without changing already working commands would be great.

One suggestion:
Instead of having this constant only for Gadgets, use it for all your needs like Memory, Diretory, Files, Images...
The user must be able to use different 'Constant Groups' with '#User' like:
#UserGadget1, #UserGadget2 ...
#UserMemory1 ...
#UserDirectory1 ...
#UserFile1 ....
etc.

This would be great, and Fred doesn't have to change already working commands...


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> YES, PB don't get me wrong, your idea is a good idea - no offense.

No offense was taken.

> Instead of having this constant only for Gadgets, use it for all your
> needs like Memory, Diretory, Files, Images...

Yes, that is what I meant, but only spoke of gadgets in my example.

> #UserGadget1, #UserGadget2 ...

Yes, but let the user specify a unique name, except for a specifix prefix.
That way, the user is never locked into using sequential numbers for items.


PB - Registered PureBasic Coder

Edited by - PB on 02 July 2002 21:08:48
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Fred, I was wondering if perhaps a future release of PureBasic could automatically allocate gadget numbers, so that we can use constants to refer to them?
Wouldn't it be easier to use enumerated constants like in C? OK, you don't have the constant defined in the call to a gadget function, but I don't think that is a big problem.

It would also be easier for Fred to implement I think and of course would be a general purpose thing so you could use it wherever you want. And you would not be limited to a specific prefix on your constants.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.20)
Post Reply