Are there plans to adjust the GUI in such a way that a treeview can easily be bound to GUI controls?
By that I mean that selecting a treeview on the left of a GUI will hide all controls not bound by that item, and show all controls that are bound by that item.
If there already is a good way to do this, please let me know.
GUI; treeview and controls
GUI; treeview and controls
- Attachments
-
- Image2.jpg (21.13 KiB) Viewed 2932 times
-
- Image1.jpg (28.73 KiB) Viewed 2932 times
Re: GUI; treeview and controls
An invisible Tab control would do the trick.
I haven't used AHK V2, the following is v1 code.
I haven't used AHK V2, the following is v1 code.
Code: Select all
global g_tabIndex := {}
Gui, Add, TreeView, w200 gMyTree vMyTree
P1 := TVAdd("First parent")
P1C1 := TVAdd("Parent 1's first child", P1)
Gui, Add, Tab, x+0 w0 h0 vHiddenTab, a|b
Gui, Tab, 1
Gui, Add, Text, xp+20 yp+30, Page 1
Gui, Tab, 2
Gui, Add, Text, xp+20 yp+30, Page 2
Gui, Show
return
MyTree:
idx := g_tabIndex[ TV_GetSelection() ]
GuiControl, Choose, HiddenTab, |%idx%
GuiControl, Focus, MyTree
Return
TVAdd(p*) {
id := TV_Add(p*)
g_tabIndex[id] := g_tabIndex.Count() + 1
return id
}
GuiClose:
ExitApp
Re: GUI; treeview and controls
Thanks, good idea!tmplinshi wrote: ↑25 Aug 2019, 14:05An invisible Tab control would do the trick.
I haven't used AHK V2, the following is v1 code.Code: Select all
global g_tabIndex := {} Gui, Add, TreeView, w200 gMyTree vMyTree P1 := TVAdd("First parent") P1C1 := TVAdd("Parent 1's first child", P1) Gui, Add, Tab, x+0 w0 h0 vHiddenTab, a|b Gui, Tab, 1 Gui, Add, Text, xp+20 yp+30, Page 1 Gui, Tab, 2 Gui, Add, Text, xp+20 yp+30, Page 2 Gui, Show return MyTree: idx := g_tabIndex[ TV_GetSelection() ] GuiControl, Choose, HiddenTab, |%idx% GuiControl, Focus, MyTree Return TVAdd(p*) { id := TV_Add(p*) g_tabIndex[id] := g_tabIndex.Count() + 1 return id } GuiClose: ExitApp
Code: Select all
#persistent
gui()
return
gui() {
g_tabIndex := Map()
GUI_Settings := GuiCreate("+LastFound",A_ScriptName " : Settings")
TV := GUI_Settings.Add("TreeView","y5 r25 w150 section")
P1 := TVAdd(TV,"General",, "expand select")
P1C1 := TVAdd(TV,"View", P1)
P2 := TVAdd(TV,"Settings")
Tab := GUI_Settings.Add("Tab", "x+0 w0 h0 vHiddenTab", "General|View|Settings")
Tab.UseTab(1)
GUI_Settings.Add("Text", "x170 yp+30 w200", "Page 1")
Tab.UseTab(2)
GUI_Settings.Add("Text", "xp+20 yp+30 w200", "Page 2")
Tab.UseTab(3)
GUI_Settings.Add("Text", "xp+20 yp+30 w200", "Page 3")
GUI_Settings.Show()
TV.OnEvent('ItemSelect', Func('TV_click').Bind(GUI_Settings,TV))
TV_click(gui, this, *) {
idx := g_tabIndex[ this.GetSelection() ]
gui["HiddenTab"].Choose(idx)
this.Focus()
return
}
TVAdd(TV,p*) {
id := TV.Add(p*)
g_tabIndex[id] := g_tabIndex.Count + 1
return id
}
}
GuiClose() {
ExitApp()
}
Re: GUI; treeview and controls
oh, and here's a version (Tab2 works as well) that will work with a103 as well as a104:
Code: Select all
#persistent
gui()
return
gui() {
if ( A_AHKVersion >= "2.0-a104-3e7a969d" )
g_tabIndex := Map()
else
g_tabIndex := {}
GUI_Settings := GuiCreate("+LastFound",A_ScriptName " : Settings")
TV := GUI_Settings.Add("TreeView","y5 r25 w150 section")
P1 := TVAdd(TV,"General",, "expand select")
P1C1 := TVAdd(TV,"View", P1)
P2 := TVAdd(TV,"Settings")
Tab := GUI_Settings.Add("Tab2", "x+0 w0 h0 vHiddenTab", "General|View|Settings")
Tab.UseTab(1)
GUI_Settings.Add("Text", "x170 yp+30 w200", "Page 1")
Tab.UseTab(2)
GUI_Settings.Add("Text", "xp+20 yp+30 w200", "Page 2")
Tab.UseTab(3)
GUI_Settings.Add("Text", "xp+20 yp+30 w200", "Page 3")
GUI_Settings.Show()
TV.OnEvent('ItemSelect', Func('TV_click').Bind(GUI_Settings,TV))
return
TV_click(gui, this, *) {
idx := g_tabIndex[ this.GetSelection() ]
gui["HiddenTab"].Choose(idx)
this.Focus()
return
}
TVAdd(TV,p*) {
id := TV.Add(p*)
if ( A_AHKVersion >= "2.0-a104-3e7a969d" )
g_tabIndex[id] := g_tabIndex.Count + 1
else
g_tabIndex[id] := g_tabIndex.Count() + 1
return id
}
}
GuiClose() {
ExitApp()
}
Re: GUI; treeview and controls
This is outside the purview of the TreeView control (and it's already easy to do).
Note: A script which contains Map() won't load on a103 if that function is not defined. However, Map.new() is permitted. You could check for the presence or type of Map instead of checking the version number.
Note: A script which contains Map() won't load on a103 if that function is not defined. However, Map.new() is permitted. You could check for the presence or type of Map instead of checking the version number.
Re: GUI; treeview and controls
Thank you for your reply, as always it's very useful to me.lexikos wrote: ↑29 Aug 2019, 04:10This is outside the purview of the TreeView control (and it's already easy to do).
Note: A script which contains Map() won't load on a103 if that function is not defined. However, Map.new() is permitted. You could check for the presence or type of Map instead of checking the version number.
Easy to do if you know how, yes An example on how to do it might be a useful addition to the help files.
As for your note... could you give an example?
Something else: instead of setting an onevent for each guictrl object, is there a way to set a default onevent?
Re: GUI; treeview and controls
Code: Select all
mymap := Map ? Map.new() : {}
Code: Select all
static mapf := IsFunc("Map") ? Func("Map") : Func("Object")
mymap := %mapf%()
Even if you don't know that you can utilize the Tab control in that way, it is simple to hide and show controls.
Default OnEvent: No, that doesn't even make sense. Some controls have multiple event types. All controls allow multiple handlers for one event. An event handler which is installed by default would still be called after registering other event handlers. You can already achieve that same behaviour by enumerating the controls with for and calling OnEvent.
Re: GUI; treeview and controls
Again, much appreciated!
As for the default onevent, I meant for each type, not for all, I guess I should have specified.
I'd used the enumeration method already, thanks for that, guess that's what I'll keep using:
Thank you for everything you're doing for this community, Lexikos!
As for the default onevent, I meant for each type, not for all, I guess I should have specified.
I'd used the enumeration method already, thanks for that, guess that's what I'll keep using:
Code: Select all
GuiSetOnEvent(GuiObj,*) { ; this function sets the onevent for each of the GUI items
clickcontrols := "Text, Pic, CheckBox, Radio, ListView, TreeView, Link, StatusBar" ; Button can also do an onEvent, but set that one separately
changecontrols := "Edit"
For Hwnd, GuiCtrlObj in GuiObj
{
if InStr(clickcontrols, GuiCtrlObj.Type) ; because OnEvent click only works on certain controls, this prevents an error. The controls that allow for OnEvent are Text, Pic, Button, CheckBox, Radio, ListView, TreeView, Link, StatusBar.
GuiCtrlObj.OnEvent("Click","GUI_Event")
else if InStr(changecontrols, GuiCtrlObj.Type) ; because OnEvent click only works on certain controls, this prevents an error. The controls that allow for OnEvent are Text, Pic, Button, CheckBox, Radio, ListView, TreeView, Link, StatusBar.
GuiCtrlObj.OnEvent("Change","GUI_Event")
}
}
Return to “AutoHotkey Development”
Who is online
Users browsing this forum: No registered users and 47 guests