GUI suggestions

Discuss the future of the AutoHotkey language
User avatar
tank
Posts: 3130
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: GUI suggestions

22 Jul 2014, 10:40

its an almost valid arguement guest3456
except for the fact that you can click other things like lists, images etc
guest3456 wrote: I guess you're proposing doing away with A_GuiEvent
I dont think anyone is saying that. just a more noob friendly way of triggering a label from a specific event.

everything works as is there isnt a mechanical reason to change anything. but mylbl_Click and mylbl_dblClick kind of feel more natural to tutorial readers that also see ahk_id and ahk_pid and ahk_class etc. but its all just oppinion

i am more comfy using A_GuiEvent
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: GUI suggestions

22 Jul 2014, 10:45

fincs mentioned in the other GUI thread that event handling might be implemented as similar to ComObjConnect which I believe is the most intuitive way since user will be dealing with window and control objects. There will be no need for vControlVar, you have the object reference to work with.
e.g.:

Code: Select all

GuiEventConnect(gui_obj, "MyGuiEvent_")

MyGuiEvent_Close(this) {
	
}

MyGuiEvent_Size(this, w, h) {
	
}
OR

Code: Select all

GuiEventConnect(gui_obj, MyGuiEvent) ;// MyGuiEvent is an object/class

class MyGuiEvent
{
	Close() {

	}

	Size(w, h) {

	}
}
Last edited by Coco on 22 Jul 2014, 11:11, edited 1 time in total.
User avatar
fischgeek
Posts: 435
Joined: 29 Jan 2014, 21:39

Re: GUI suggestions

22 Jul 2014, 10:57

So, you'd have to connect each event to a control and then it's respective code block? That seems like a lot of work to just get something to happen on any click event. it just feels like overkill to me. What if I have 8 buttons?

Code: Select all

Gui, Add, Button, vbtn1
Gui, Add, Button, vbtn2
Gui, Add, Button, vbtn3
Gui, Add, Button, vbtn4
Gui, Add, Button, vbtn5
Gui, Add, Button, vbtn6
Gui, Add, Button, vbtn7
Gui, Add, Button, vbtn8

GuiEventConnect(btn1, "MyGuiEventForBtn1_")
GuiEventConnect(btn2, "MyGuiEventForBtn2_")
GuiEventConnect(btn3, "MyGuiEventForBtn3_")
GuiEventConnect(btn4, "MyGuiEventForBtn4_")
GuiEventConnect(btn5, "MyGuiEventForBtn5_")
GuiEventConnect(btn6, "MyGuiEventForBtn6_")
GuiEventConnect(btn7, "MyGuiEventForBtn7_")
GuiEventConnect(btn8, "MyGuiEventForBtn8_")

MyGuiEvent1_Close(this) {
   
}

MyGuiEvent1_Size(this, w, h) {
   
}

MyGuiEvent2_Close(this) {
   
}

MyGuiEvent2_Size(this, w, h) {
   
}

MyGuiEvent3_Close(this) {
   
}

MyGuiEvent3_Size(this, w, h) {
   
}

MyGuiEvent4_Close(this) {
   
}

MyGuiEvent4_Size(this, w, h) {
   
}

MyGuiEvent5_Close(this) {
   
}

MyGuiEvent5_Size(this, w, h) {
   
}

MyGuiEvent6_Close(this) {
   
}

MyGuiEvent6_Size(this, w, h) {
   
}

MyGuiEvent7_Close(this) {
   
}

MyGuiEvent7_Size(this, w, h) {
   
}

MyGuiEvent8_Close(this) {
   
}

MyGuiEvent8_Size(this, w, h) {
   
}
User avatar
joedf
Posts: 9000
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: GUI suggestions

22 Jul 2014, 10:58

@fischgeek
Woah woah! I'm not against it at all! I love the idea!
I'm just saying, ( excuse me if I didn't get it)... That it should the default behavior if no gLabel is defined.
If the gLabel is specified, this behavior should be ignored. If it's like that, then I think the idea is "sublime" ;)
@coco fischgeek is right.. But the class does seem interesting... But I don't know.. We'll have to see if it gets "its way" First ..
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: GUI suggestions

22 Jul 2014, 11:10

Perhaps vControlVar can be retained as an internal ID.
Another option:

Code: Select all

btn3 := gui_obj.AddButton("x10 y10 w80 h30 vbtn3")
GuiEventConnect(btn1, btn2, btn3, ButtonEvent) ;// connect buttons w/ similar routines

class ButtonEvent
{
	;// Dynamic event handler
	__Call(event, args*) {
		if (event = "Click") {
			;// code here to handle click event(s)
			if (this.name = "btn1") {
				MsgBox You clicked button 1
			}
		}
	}
}
OR the non-class way:

Code: Select all

btn3 := gui_obj.AddButton("x10 y10 w80 h30 vbtn3")
GuiEventConnect(btn1, btn2, btn3, "ButtonEvent_") ;// connect buttons w/ similar routines

;// Not suffixed with event type/name ; works like __Call
ButtonEvent_(this, event, args*) {
	if (event = "Click") {
		if (this.name = "btn1")
			;// code here
	}
}
Last edited by Coco on 22 Jul 2014, 11:16, edited 1 time in total.
User avatar
joedf
Posts: 9000
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: GUI suggestions

22 Jul 2014, 11:12

Thats pretty cool :D
But as Said, ill wait till obj-style GUI Is "accepted", its still too blurry for me to say... Since Arent necessarily newbie friendly... :(
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
fischgeek
Posts: 435
Joined: 29 Jan 2014, 21:39

Re: GUI suggestions

22 Jul 2014, 11:15

@joedf
no worries. Sorry if I came off a little strong.

@Coco
I really don't like handling multiple button events in the same event and checking names/senders. I have a co-worker who prefers that methodology and it just bugs me. I would prefer to have an event for each control. But, that's just my personal preference.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: GUI suggestions

22 Jul 2014, 11:25

@fischgeek: It depends on the user(s) on whether they would like to have one event handler or multiple ones, it's up to their preferences. GuiEventConnect or whatever the name is can be implemented to accept a variable number of parameters. Perhaps similar to DllCall. e.g. GuiEventConnect( ctrl_obj1, handler1 [, ctrl_obj2, handler2 ..... ] ).
User avatar
fischgeek
Posts: 435
Joined: 29 Jan 2014, 21:39

Re: GUI suggestions

22 Jul 2014, 11:31

I see your point. I just strongly disagree with having to connect objects to events on a separate line. That's going even further than having to specify a g-Label. I can see cause for that kind of event connection on events that aren't regularly used, but on the high profile events (like clicks) I believe they should be built in.
guest3456
Posts: 3469
Joined: 09 Oct 2013, 10:31

Re: GUI suggestions

22 Jul 2014, 11:33

yea i'm not a fan of any of this

User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: GUI suggestions

22 Jul 2014, 11:34

I think my proposed OOP Gui API has been misunderstood. There won't be any such thing as GuiEventConnect() (and for good measure; the code above posted using it is extremely horrid), instead information would be specified during the creation of the Gui or the control like this:

Code: Select all

gui := GuiCreate("Title", "Options", "MyGui_") ; the last parameter is the object or function name prefix to bind Gui events to
; and then for each button
gui.AddButton("Button 1",, "btnClick") ; the last parameter is the partial function/event name -- if it is omitted it is automatically generated
gui.AddButton("Button 2",, "btnClick")
gui.AddButton("Button 3",, "btnClick")
gui.AddButton("Button 4",, "btnClick")
gui.AddButton("Button 5",, "btnClick")
gui.Show()
; And now the event handlers
MyGui_Close(g) ; first parameter is a reference to the Gui that triggered the event
{
    ; etc
}
MyGui_btnClick(g, ctrl) ; as above; and the second param is likewise a ref to the control
{
    MsgBox You clicked on %ctrl.Text%
}
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: GUI suggestions

22 Jul 2014, 11:36

Or gLabel can be renamed as eHandler wherein Handler is A string to prefix to the event name to determine which function to call when an event occurs OR Handler is the name of a global(super) variable that contains a reference to an object. When an event is raised, the corresponding method is called.

EDIT: Didn't see finc's reply, yep, something like that. @fincs: Will there be a support for object(s) as well, similar to ComObjConnect?
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: GUI suggestions

22 Jul 2014, 11:43

Of course; the above example could also have been written this way:

Code: Select all

gui := GuiCreate("Title", "Options", MyGui)
; and then for each button
gui.AddButton("Button 1",, "btnClick")
gui.AddButton("Button 2",, "btnClick")
gui.AddButton("Button 3",, "btnClick")
gui.AddButton("Button 4",, "btnClick")
gui.AddButton("Button 5",, "btnClick")
gui.Show()

class MyGui
{
    ; In the case of object event handlers, the object itself is prepended to the argument list
    ; in order to fit the hidden 'this' parameter.
    Close(g)
    {
        ; etc
    }
    btnClick(g, ctrl)
    {
        MsgBox You clicked on %ctrl.Text%
    }
}
EDIT: or even this:

Code: Select all

gui := GuiCreate("Title", "Options")
; and then for each button
fn1 := Func("myGuiClose"), fn2 := Func("btnClick")
gui.AddButton("Button 1",, fn1)
gui.AddButton("Button 2",, fn2)
gui.AddButton("Button 3",, fn2)
gui.AddButton("Button 4",, fn2)
gui.AddButton("Button 5",, fn2)
gui.Show()

myGuiClose(g)
{
    ; etc
}
btnClick(g, ctrl)
{
    MsgBox You clicked on %ctrl.Text%
}
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: GUI suggestions

22 Jul 2014, 11:46

@fincs: How would one handle different types of events? Let's say for List/TreeView contorls? Consult A_GuiEvent / A_EventInfo or supply a third parameter in the function for the event type?
User avatar
joedf
Posts: 9000
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: GUI suggestions

22 Jul 2014, 11:47

Interesting...
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: GUI suggestions

22 Jul 2014, 11:50

A_GuiEvent, A_EventInfo and all other Gui-related BIVs would become parameters to these event handler functions/methods; therefore removing the need to support and document several BIVs. Please take a look at the full design document as there's a list of all possible events.
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
User avatar
fischgeek
Posts: 435
Joined: 29 Jan 2014, 21:39

Re: GUI suggestions

22 Jul 2014, 11:53

fincs wrote:

Code: Select all

gui.AddButton("Button 1",, "btnClick") ; the last parameter is the partial function/event name -- if it is omitted it is automatically generated
I'd be curious to know what "automatically generated looks like". Short of this being like a gLabel, I think it is more clear for "noobs".
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: GUI suggestions

22 Jul 2014, 11:55

The same rules that currently apply for automatic Button g-label generation would apply here (except that some additional characters are illegal in function/method names and therefore have to be removed too). So e.g.

Code: Select all

gui := GuiCreate("Title",, "myGui_")
gui.AddButton("Click Me")
gui.Show()
myGui_ButtonClickMe()
{
    MsgBox You clicked me!
}
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]
User avatar
fischgeek
Posts: 435
Joined: 29 Jan 2014, 21:39

Re: GUI suggestions

22 Jul 2014, 12:10

I see. How would I handle a RightClick on a ListView?
User avatar
fincs
Posts: 527
Joined: 30 Sep 2013, 14:17
Location: Seville, Spain
Contact:

Re: GUI suggestions

22 Jul 2014, 12:20

Same way as it is now:

Code: Select all

gui := GuiCreate("Title",, "MyGui_")
lv := gui.AddListView("Col1|Col2|Col3", "AltSubmit", "LVEvent") ; AltSubmit is very likely to be renamed to something more intuitive
lv.Add("", "val1", "val2", "val3")
lv.Add("", "val4", "val5", "val6")
gui.Show()

MyGui_LVEvent(ctrl, rowId, guiEvent) ; rowId is former A_EventInfo
{
    if guiEvent = "RightClick", MsgBox You right-clicked on %ctrl.GetText(rowId, 1)% ; note how I did away with the OutputVar of LV_GetText, it is more tentatively going to throw an exception instead on failure
}
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 - [My project list]

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: Marium0505 and 28 guests