 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Wed Sep 30, 2009 8:48 am Post subject: gui.ahkl - a gui object for AutoHotkey_L v.1a |
|
|
requires options.ahkl
- http://www.autohotkey.com/forum/viewtopic.php?p=299850#299850
requires control.ahkl
- http://www.autohotkey.com/forum/viewtopic.php?p=299851#299851
requires newest update of autohotkey_l
still probably has bugs
version .1 alpha
i know there is lots of room for improvement, and im working on it.
| Quote: | ;Exposed Functions
[ControlIndex :=]Gui.Add(Type[,Text="",Options=""])
Gui.Show([Options=""])
Gui.Submit([Options=""])
Gui.Hide()
Gui.Cancel()
Gui.Destroy()
Gui.Font([Options="",FontName=""])
Gui.Color(WindowColor=""[,ControlColor=""])
Gui.Margin([x="",y=""])
Gui.Move(x=""[,y="",h="",w=""])
;Exposed Properties
; IMPORTANT the Proprties are set to the STRING True or False, not 0 or 1
Gui.GuiProperty := "True" ; Same as specifying +GuiProperty in the Options
Gui.GuiProperty := "False" ; Same as specifying -GuiProperty in the Options
; Example
Gui.AlwaysOnTop := "True" ; Make Gui AlWaysOnTop
Gui.ToolWindow := "True" ; Make Gui ToolWindow
; The properties exposed in this manner are:
; AlwaysOnTop,Border,Caption,Delimiter,Disabled,Label,MaximizeBox,MaximizeBox
; MinimizeBox,MinSize,MaxSize,OwnDialogs,Resize,SysMenu,Theme,ToolWindow
;Other Information
;getters
; available any time
Gui.GuiNum ; returns the Gui Number for the Gui (used with Gui, %GuiNum%:Show)
Gui.hWnd ; the gui's hWnd
Gui.ControlCount ; the number of controls in the gui... useful for iterating all controls in a gui
;After Using Gui.Add() to add a control Gui.ControlIndex.* is always available to use
Gui.1.* ; operate on the first control
;If a Variable name was specified in options
Gui.VarName.* ; immediately available
;it is also immediately available once the variable is manually set, like the following line
Gui.1.v := "SomeVarName" ; set the var
;Once Gui.Show() has been called
Gui.ClassNN.* ; is available....think Gui.Static1.SetText("Some Text")
|
Test Script (It really does work!)
i still need to write documentation!
| Code: | GUI1 := GUI()
GUI1.Add("Text","Default Text","w2000 h200")
GUI1.Show()
o := GUI()
o.Add("Text","Name:")
o.Add("Text","Address1:")
o.Add("Text","Address2:")
o.Add("Edit","Name"," ","name")
o.Add("Edit","Address1"," ","address1")
o.Add("Edit","Address2"," ","address2")
o.Add("Button","Ok"," ","OK")
o.name.ym := "True"
o.name.w := 200
o.address1.w := 200
o.address2.w := 200
o.OK.g := "ButtonLabel"
o.Show("x600 y50","Enter Your Details")
o2 := GUI() ; Gui Object
o2.Add("Text") ; Add a Text Control
o2.Add("Edit") ; Add an Edit Control
o2.2.v := "MyEdit1" ; set VarName
o2.1.Text := "Gui 2" ; use control index instead of VarName
o2.MyEdit1.Text := "Put Some Text In The Control Now"
; Make All the controls the same size
Loop % o2.ControlCount
o2[A_Index].h := 50, o2[A_Index].w := 400
o2.Resize := "True"
o2.ToolWindow := "True"
o2.Show("x100 y100","Object Test Gui # 2")
o3 := GUI()
o3.Color("Lime")
o3.Add("Text","Default Text","","MyText1")
o3.MyText1.Text := "New Text"
o3.MyText1.h := 100
o3.MyText1.w := 200
o3.Border := "True"
o3.Caption := "False"
o3.Resize := "True"
o3.Show("x50 y500","Object Test Gui # 1")
;=====================
o4 := GUI()
o4.Color("Blue","Yellow")
o4.Add("Text","Some Text 2")
o4.Add("Edit","Type Some **** Shit Here 2")
o4.Add("Button","Wooo 2")
;o4.ToolWindow := "True" ; String true
o4.AlwaysOnTop := "True" ; String true
o4.Show("x200 y200")
Loop, 25 {
o4.Move(A_Index * 20, A_Index * 20)
Sleep, 50
}
o4.2.SetText("Change The Text Now")
Sleep, 2000
o4.2.SetText("Some More New Text")
return
ButtonLabel:
o.Submit()
MsgBox % "name: " . o.name.Text . "`n"
. "address1: " . o.address1.Text . "`n"
. "address2: " . o.address2.Text . "`n"
MsgBox % "name: " . name . "`n"
. "address1: " . address1 . "`n"
. "address2: " . address2 . "`n"
Return
Esc::ExitApp |
| Code: | ; gui.ahkl
; requires AutoHotkey_L
;requires control.ahkl
; by ahklerner
;version .1 alpha
; This object handles a gui!!!
; intended use is by YOU
GUI_GetVal(obj, name){
;MsgBox % Name
return obj[name]
}
GUI_SetVal(obj, name, val){
list1 = AlwaysOnTop,Border,Caption,Delimiter,Disabled,Label,LastFound,LastFoundExist,MaximizeBox,MaximizeBox,
,MinimizeBox,MinSize,MaxSize,OwnDialogs,Resize,SysMenu,Theme,ToolWindow
list2=Owner
GuiNum := obj.GuiNum
if name in %list1%
{
if val = False
Gui, %GuiNum%:-%name%
else if val = True
Gui, %GuiNum%:+%name%
}
}
GUI_Delete(obj){
}
GUI_Submit(obj,opts,title){
}
GUI_Call(obj, func, prm0=" ",prm1=" ",prm2=" ",prm3=" ",prm4=" ",prm5=" "){
list1 = Show,Hide,Cancel,Destroy,Font,Color,Margin
loop 6
num := A_Index - 1, VarSetCapacity(prm%num%, -1)
SetWinDelay, -1
GuiNum := obj.GuiNum
if (func = "Add") {
Type := prm0, Text := prm1, Options := prm2, VarName := prm3
c := Control(obj,Type)
VarName = %VarName%
Options = %Options%
Text = %Text%
if VarName {
obj[VarName] := c
c.Options.v := VarName
}
if Options
c.Options.Import(Options)
c.Text := Text ? Text : " "
Return ControlIndex := c.Index
}else if (func = "Show"){
num := obj.ControlCount
;MsgBox % num
Loop % num
{
;MsgBox Create Being Called
num := A_Index
if (obj[num].HasBeenCreated = false)
obj[num].Create()
}
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
}else if (func = "Submit"){
;MsgBox % GuiNum
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
num := obj.ControlCount
;MsgBox % num
Loop % num
{
varname := obj[A_Index].Options.v
VarSetCapacity(varname, -1)
varname = %varname%
;varname
if varname
obj[A_Index].Text := GUI_GetGlobal(varname)
else {
hWnd := obj[A_Index].hWnd
ControlGetText, OutputVar, % "ahk_id " . hWnd
obj[A_Index].Text := OutputVar ? OutputVar : " "
}
}
} else if (func = "Move"){
prm0 = %prm0%
prm1 = %prm1%
prm2 = %prm2%
prm3 = %prm3%
hWnd := obj.hWnd
hWnd = %hWnd%
;WinGetTitle, Title, ahk_id %hWnd%
WinGetClass, Class, ahk_id %hWnd%
;MsgBox % Class
;obj.Show("x" . prm0 . " y" . prm1)
WinMove, ahk_id %hWnd%,,%prm0%,%prm1%,%prm2%,%prm3%
}else if func in %list1%
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
}
GUI_GetGlobal(varname){
global
VarSetCapacity(varname, -1)
varname = %varname%
Transform, val, Deref,% %varname%
;MsgBox % "VarName: " . varname . "`nVal: " . val
return val
}
GUI(param="¬"){
static COBase
if ((param = "¬")||(!param)){
; get first unused gui number
loop, 99 {
num := A_Index
Gui, %A_Index%:+LastFoundExist
If !WinExist()
break ;
}
param := num
}
If !COBase
COBase := Object("__Get", "GUI_GetVal", "__Set", "GUI_SetVal", "__Delete", "GUI_Delete", "__Call", "GUI_Call")
Gui, %param%:+LastFound
hWnd := WinExist()
return Object("GuiNum", param, "ControlCount", 0, "hWnd", hWnd, "base", COBase)
}
/*
Gui := Gui()
;Exposed Functions
[ControlIndex :=]Gui.Add(Type[,Text="",Options=""])
Gui.Show([Options=""])
Gui.Submit([Options=""])
Gui.Hide()
Gui.Cancel()
Gui.Destroy()
Gui.Font([Options="",FontName=""])
Gui.Color(WindowColor=""[,ControlColor=""])
Gui.Margin([x="",y=""])
Gui.Move(x=""[,y="",h="",w=""])
;Exposed Properties
; IMPORTANT the Proprties are set to the STRING True or False, not 0 or 1
Gui.GuiProperty := "True" ; Same as specifying +GuiProperty in the Options
Gui.GuiProperty := "False" ; Same as specifying -GuiProperty in the Options
; Example
Gui.AlwaysOnTop := "True" ; Make Gui AlWaysOnTop
Gui.ToolWindow := "True" ; Make Gui ToolWindow
; The properties exposed in this manner are:
; AlwaysOnTop,Border,Caption,Delimiter,Disabled,Label,MaximizeBox,MaximizeBox
; MinimizeBox,MinSize,MaxSize,OwnDialogs,Resize,SysMenu,Theme,ToolWindow
;Other Information
;getters
; available any time
Gui.GuiNum ; returns the Gui Number for the Gui (used with Gui, %GuiNum%:Show)
Gui.hWnd ; the gui's hWnd
Gui.ControlCount ; the number of controls in the gui... useful for iterating all controls in a gui
;After Using Gui.Add() to add a control Gui.ControlIndex.* is always available to use
Gui.1.* ; operate on the first control
;If a Variable name was specified in options
Gui.VarName.* ; immediately available
;it is also immediately available once the variable is manually set, like the following line
Gui.1.v := "SomeVarName" ; set the var
;Once Gui.Show() has been called
Gui.ClassNN.* ; is available....think Gui.Static1.SetText("Some Text")
*/
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ
Last edited by ahklerner on Thu Mar 17, 2011 7:29 pm; edited 9 times in total |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Wed Sep 30, 2009 8:56 am Post subject: |
|
|
here it is all in one script for easy testing
| Code: | GUI1 := GUI()
GUI1.Add("Text","Default Text","w500 h200")
GUI1.Show()
o := GUI()
o.Add("Text","Name:")
o.Add("Text","Address1:")
o.Add("Text","Address2:")
o.Add("Edit","Name","","name")
o.Add("Edit","Address1","","address1")
o.Add("Edit","Address2","","address2")
o.Add("Button","Ok","","OK")
o.name.ym := "True"
o.name.w := 200
o.address1.w := 200
o.address2.w := 200
o.OK.g := "ButtonLabel"
o.Show("x600 y50","Enter Your Details")
o2 := GUI() ; Gui Object
o2.Add("Text") ; Add a Text Control
o2.Add("Edit") ; Add an Edit Control
o2.2.v := "MyEdit1" ; set VarName
o2.1.Text := "Gui 2" ; use control index instead of VarName
o2.MyEdit1.Text := "Put Some Text In The Control Now"
; Make All the controls the same size
Loop % o2.ControlCount
o2[A_Index].h := 50, o2[A_Index].w := 400
o2.Resize := "True"
o2.ToolWindow := "True"
o2.Show("x100 y100","Object Test Gui # 2")
o3 := GUI()
o3.Color("Lime")
o3.Add("Text","Default Text","","MyText1")
o3.MyText1.Text := "New Text"
o3.MyText1.h := 100
o3.MyText1.w := 200
o3.Border := "True"
o3.Caption := "False"
o3.Resize := "True"
o3.Show("x50 y500","Object Test Gui # 1")
;=====================
o4 := GUI()
o4.Color("Blue","Yellow")
o4.Add("Text","Some Text 2")
o4.Add("Edit","Type Some **** Shit Here 2")
o4.Add("Button","Wooo 2")
;o4.ToolWindow := "True" ; String true
o4.AlwaysOnTop := "True" ; String true
o4.Show("x200 y200")
Loop, 27 {
o4.Move(A_Index * 20, A_Index * 20)
Sleep, 50
}
o4.2.SetText("Change The Text Now")
Sleep, 2000
o4.2.SetText("Some More New Text")
;o4.Show("x200 y200")
return
ButtonLabel:
o.Submit()
MsgBox % "name: " . o.name.Text . "`n"
. "address1: " . o.address1.Text . "`n"
. "address2: " . o.address2.Text . "`n"
MsgBox % "name: " . name . "`n"
. "address1: " . address1 . "`n"
. "address2: " . address2 . "`n"
Return
Esc::ExitApp
/*
Gui := GUI()
Gui := GUI()
Gui.Color("White")
Gui.Add("Picture", A_WinDir "\system32\ntimage.gif", "x0 y0 h350 w450")
Gui.Add("Button", "Start the Bar Moving", "+Default xp+20 yp+250")
Gui.Add("Progress", "", "vMyProgress w416")
Gui.Add("Text","", "vMyText wp")
Gui.Show()
Esc::ExitApp
ButtonStartTheBarMoving:
Loop, %A_WinDir%\*.*
{
if A_Index > 100
break
;GuiControl,, MyProgress, %A_Index%
Gui.MyProgress.Text := A_Index
GuiControl,, MyText, %A_LoopFileName%
Sleep 50
}
GuiControl,, MyText, Bar finished.
return
GuiClose:
ExitApp
*/
; gui.ahkl
; requires AutoHotkey_L
;requires control.ahkl
; by ahklerner
;version .1 alpha
; This object handles a gui!!!
; intended use is by YOU
/*
Gui := Gui()
;Exposed Functions
Gui.Add(Type[,Text="",Options=""])
Gui.Show([Options=""])
Gui.Submit([Options=""])
Gui.Hide()
Gui.Cancel()
Gui.Destroy()
Gui.Font([Options="",FontName=""])
Gui.Color(WindowColor=""[,ControlColor=""])
Gui.Margin([x="",y=""])
;Exposed Properties
; IMPORTANT the Proprties are set to the STRING True or False, not 0 or 1
Gui.GuiProperty := "True" ; Same as specifying +GuiProperty in the Options
Gui.GuiProperty := "False" ; Same as specifying -GuiProperty in the Options
; Example
Gui.AlwaysOnTop := "True" ; Make Gui AlWaysOnTop
Gui.ToolWindow := "True" ; Make Gui ToolWindow
; The properties exposed in this manner are:
; AlwaysOnTop,Border,Caption,Delimiter,Disabled,Label,MaximizeBox,MaximizeBox
; MinimizeBox,MinSize,MaxSize,OwnDialogs,Resize,SysMenu,Theme,ToolWindow
*/
GUI_GetVal(obj, name){
;MsgBox % Name
return obj[name]
}
GUI_SetVal(obj, name, val){
list1 = AlwaysOnTop,Border,Caption,Delimiter,Disabled,Label,LastFound,LastFoundExist,MaximizeBox,MaximizeBox,
,MinimizeBox,MinSize,MaxSize,OwnDialogs,Resize,SysMenu,Theme,ToolWindow
list2=Owner
GuiNum := obj.GuiNum
if name in %list1%
{
if val = False
Gui, %GuiNum%:-%name%
else if val = True
Gui, %GuiNum%:+%name%
}
}
GUI_Delete(obj){
}
GUI_Submit(obj,opts,title){
}
GUI_Call(obj, func, prm0=" ",prm1=" ",prm2=" ",prm3=" ",prm4=" ",prm5=" "){
list1 = Show,Hide,Cancel,Destroy,Font,Color,Margin
loop 6
num := A_Index - 1, VarSetCapacity(prm%num%, -1)
SetWinDelay, -1
GuiNum := obj.GuiNum
if (func = "Add") {
Type := prm0, Text := prm1, Options := prm2, VarName := prm3
c := Control(obj,Type)
VarName = %VarName%
Options = %Options%
Text = %Text%
if VarName {
obj[VarName] := c
c.Options.v := VarName
}
if Options
c.Options.Import(Options)
c.Text := Text ? Text : " "
Return ControlIndex := c.Index
}else if (func = "Show"){
num := obj.ControlCount
;MsgBox % num
Loop % num
{
;MsgBox Create Being Called
num := A_Index
if (obj[num].HasBeenCreated = false)
obj[num].Create()
}
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
}else if (func = "Submit"){
;MsgBox % GuiNum
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
num := obj.ControlCount
;MsgBox % num
Loop % num
{
varname := obj[A_Index].Options.v
VarSetCapacity(varname, -1)
varname = %varname%
;varname
if varname
obj[A_Index].Text := GUI_GetGlobal(varname)
else {
hWnd := obj[A_Index].hWnd
ControlGetText, OutputVar, % "ahk_id " . hWnd
obj[A_Index].Text := OutputVar ? OutputVar : " "
}
}
} else if (func = "Move"){
prm0 = %prm0%
prm1 = %prm1%
prm2 = %prm2%
prm3 = %prm3%
hWnd := obj.hWnd
hWnd = %hWnd%
;WinGetTitle, Title, ahk_id %hWnd%
WinGetClass, Class, ahk_id %hWnd%
;MsgBox % Class
;obj.Show("x" . prm0 . " y" . prm1)
WinMove, ahk_id %hWnd%,,%prm0%,%prm1%,%prm2%,%prm3%
}else if func in %list1%
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
}
GUI_GetGlobal(varname){
global
VarSetCapacity(varname, -1)
varname = %varname%
Transform, val, Deref,% %varname%
;MsgBox % "VarName: " . varname . "`nVal: " . val
return val
}
GUI(param="¬"){
static COBase
if ((param = "¬")||(!param)){
; get first unused gui number
loop, 99 {
num := A_Index
Gui, %A_Index%:+LastFoundExist
If !WinExist()
break ;
}
param := num
}
If !COBase
COBase := Object("__Get", "GUI_GetVal", "__Set", "GUI_SetVal", "__Delete", "GUI_Delete", "__Call", "GUI_Call")
Gui, %param%:+LastFound
hWnd := WinExist()
return Object("GuiNum", param, "ControlCount", 0, "hWnd", hWnd, "base", COBase)
}
; control.ahkl
; requires AutoHotkey_L
; by ahklerner
;version .1 alpha
; This object handles a gui's controls
; intended use is by gui object... but can be modified to suit other purposes
;
Control_GetVal(obj, name){
if name = hWnd
{
text := obj[name]
;MsgBox % text
VarSetCapacity(text, -1)
return text ? text : " "
}
if name = HasBeenCreated
return obj.HasBeenCreated
;MsgBox % "GetVal: " . name
return obj.Options[name]
}
Control_SetVal(obj, name, val){
if name = hWnd
obj.hWnd := val
else if name = HasBeenCreated
obj.HasBeenCreated := val
else if name = Text
obj.Text := val
else
obj.Options[name]:= val
if name = v
obj.Parent[val] := obj
}
Control_Delete(obj){
MsgBox "Delete"
}
Control_GetClassNN(hWndWindow,hWndControl){
DetectHiddenWindows, On
WinGet, ClassNNList, ControlList, ahk_id %hWndWindow%
Loop, PARSE, ClassNNList, `n
{
ControlGet, hwnd, hwnd,,%A_LoopField%,ahk_id %hWndWindow%
if (hWnd = hWndControl)
return A_LoopField
}
}
Control_SetText(obj,NewText){
if (obj.HasBeenCreated = True) {
hWnd := obj.hWnd
GuiNum := obj.Parent.GuiNum
controlvarname := obj.v
controlvarname = %controlvarname%
if controlvarname
GuiControl, %GuiNum%:, %controlvarname%, %NewText%
else
ControlSetText,, %NewText%,ahk_id %hWnd%
}
obj.Text := NewText
}
Control_GetText(obj,NewText){
if (obj.HasBeenCreated = True) {
hWnd := obj.hWnd
ControlGetText, out,,ahk_id %hWnd%
obj.Text := out
}
return obj.Text
}
Control_Call(obj, func, prm0="¬",prm1="",prm2="",prm3="",prm4="",prm5=""){
loop 6
num := A_Index - 1, VarSetCapacity(prm%num%, -1)
if (func = "Create"){
;MsgBox % obj.Text
Control_Create(obj,obj.Type,obj.Options.ToParam(),obj.Text)
obj.HasBeenCreated := True
}else if (func = "Text"){
prm0 = %prm0%
;GuiNum := obj.Parent.GuiNum
if (prm0 != "¬"){
hWnd := obj.hWnd
ControlSetText,, %prm0%,ahk_id %hWnd%
obj.Text := prm0
}else{
hWnd := obj.hWnd
ControlGetText, out,,ahk_id %hWnd%
obj.Text := out
return out
}
}
}
Control_Create(obj,Type,Opts="",Text=""){
Global
Local GuiNum, hWnd
;MsgBox Create Called
Type = %Type%
Opts = %Opts%
Text = %Text%
GuiNum := obj.Parent.GuiNum
Gui, %GuiNum%:Add, %Type%, %Opts% hWndhWndControl, %Text%
obj.hWnd := hWndControl
;MsgBox % "hWndControl: " . hWndControl
hWndWindow := obj.Parent.hWnd
;MsgBox % "hWndWindow: " . hWndWindow
ClassNN := Control_GetClassNN(hWndWindow,hWndControl)
ClassNN = %ClassNN%
; MsgBox % "New Control ClassNN: " . ClassNN
obj.Parent[ClassNN] := obj
}
Control(Parent,Type){
static COBase
;Local AddCount
If !COBase
COBase := Object( "__Get" , "Control_GetVal" ; default getter
, "__Set" , "Control_SetVal" ; default setter
, "GetText" , "Control_GetText" ; .GetText()
, "SetText" , "Control_SetText" ; .SetText(NewText)
; , "Text" , "Control_Text" ; .Text([NewText])
; , "__Delete" , "Control_Delete"
, "__Call" , "Control_Call")
;MsgBox % "Control():Type " . Type
AddCount := Parent.ControlCount
VarSetCapacity(AddCount, -1)
if !AddCount
AddCount = 0
AddCount++
Control := Object("Type", Type, "Parent", parent,"HasBeenCreated", false, "Index", AddCount, "hWnd", " ", "Text", " ", "Options", opt := options(), "base", COBase)
opt.Parent := Control
Control.Parent.ControlCount := AddCount
Control.Parent[AddCount] := Control
Control.Parent[AddCount] := Control
return Control
}
; options.ahkl
; requires AutoHotkey_L
; by ahklerner
;version .1 alpha
; This object handles a gui's or control's "Options"
; intended use is by control and gui object... but can be modified to suit other purposes
;
Options_Opt(ByRef sOpts,sName,sVal="¬"){
if (sVal = "¬"){ ; get the option
if RegExMatch(sOpts, sName . "=(\+?-?[a-zA-Z0-9\s]*)¬",Match)
return Match1
else
return ""
}
if RegExMatch(sOpts, sName . "=(\+?-?[a-zA-Z0-9\s]*)¬",Match)
sOpts := RegExReplace(sOpts,sName . "=(\+?-?[a-zA-Z0-9\s]*)¬",sName . "=" . sVal . "¬")
else if (sOpts = "¬")
sOpts := sName . "=" . sVal . "¬"
else
sOpts .= sName . "=" . sVal . "¬"
return sOpts
}
Options_GetVal(obj, name){
if name = Parent
return obj.Parent
sOpts := obj.ToStr
return Options_Opt(sOpts,name)
}
Options_SetVal(obj, name, val){
;MsgBox % "options:SetVal`nname:" . name . "`nval:" . val
if name = Parent
return obj.Parent := val
if name = ToStr
return obj.ToStr := val
sOpts := obj.ToStr
ret := Options_Opt(sOpts,name,val)
obj.ToStr := sOpts
return ret
}
Options_Import(obj,prm0){
options := obj
Loop, Parse, prm0, %A_Space%
{
if RegExMatch(A_LoopField,"wp(-[a-zA-Z0-9\s]*)",Match)
out .= "wp=" . Match1 . "¬"
, options.wp := Match1
else if RegExMatch(A_LoopField,"hp(-[a-zA-Z0-9\s]*)",Match)
out .= "hp=" . Match1 . "¬"
, options.hp := Match1
else if RegExMatch(A_LoopField,"wp(\+[a-zA-Z0-9\s]*)",Match)
out .= "wp=" . Match1 . "¬"
, options.wp := Match1
else if RegExMatch(A_LoopField,"hp(\+[a-zA-Z0-9\s]*)",Match)
out .= "hp=" . Match1 . "¬"
, options.hp := Match1
else if RegExMatch(A_LoopField,"xp(-[a-zA-Z0-9\s]*)",Match)
out .= "xp=" . Match1 . "¬"
, options.xp := Match1
else if RegExMatch(A_LoopField,"yp(-[a-zA-Z0-9\s]*)",Match)
out .= "yp=" . Match1 . "¬"
, options.yp := Match1
else if RegExMatch(A_LoopField,"xp(\+[a-zA-Z0-9\s]*)",Match)
out .= "xp=" . Match1 . "¬"
, options.xp := Match1
else if RegExMatch(A_LoopField,"yp(\+[a-zA-Z0-9\s]*)",Match)
out .= "yp=" . Match1 . "¬"
, options.yp := Match1
else if RegExMatch(A_LoopField,"xm(-[a-zA-Z0-9\s]*)",Match)
out .= "xm=" . Match1 . "¬"
, options.xm := Match1
else if RegExMatch(A_LoopField,"xm(\+[a-zA-Z0-9\s]*)",Match)
out .= "xm=" . Match1 . "¬"
, options.xm := Match1
else if RegExMatch(A_LoopField,"ym(-[a-zA-Z0-9\s]*)",Match)
out .= "ym=" . Match1 . "¬"
, options.ym := Match1
else if RegExMatch(A_LoopField,"ym(\+[a-zA-Z0-9\s]*)",Match)
out .= "ym=" . Match1 . "¬"
, options.ym := Match1
else if RegExMatch(A_LoopField,"xs(-[a-zA-Z0-9\s]*)",Match)
out .= "xs=" . Match1 . "¬"
, options.xs := Match1
else if RegExMatch(A_LoopField,"xs(\+[a-zA-Z0-9\s]*)",Match)
out .= "xs=" . Match1 . "¬"
, options.xs := Match1
else if RegExMatch(A_LoopField,"ys(-[a-zA-Z0-9\s]*)",Match)
out .= "ys=" . Match1 . "¬"
, options.ys := Match1
else if RegExMatch(A_LoopField,"ys(\+[a-zA-Z0-9\s]*)",Match)
out .= "ys=" . Match1 . "¬"
, options.ys := Match1
else if RegExMatch(A_LoopField,"ym",Match)
out .= "ym=True¬"
, options.ym := "True"
else if RegExMatch(A_LoopField,"xm",Match)
out .= "xm=True¬"
, options.xm := "True"
else if RegExMatch(A_LoopField,"xs",Match)
out .= "xs=True¬"
, options.xs := "True"
else if RegExMatch(A_LoopField,"ys",Match)
out .= "ys=True¬"
, options.ys := "True"
else if RegExMatch(A_LoopField,"v([a-zA-Z0-9\s]*)",Match){
Match1 = %Match1%
;MsgBox Var Imported
out .= "v" . "=" . Match1 . "¬"
options.Parent.v := Match1
obj.Parent[Match1] := options.Parent
}
else if RegExMatch(A_LoopField,"g([a-zA-Z0-9\s]*)",Match)
out .= "g" . "=" . Match1 . "¬"
, options.g := Match1
else if RegExMatch(A_LoopField,"w([a-zA-Z0-9\s]*)",Match)
out .= "w" . "=" . Match1 . "¬"
, options.w := Match1
else if RegExMatch(A_LoopField,"h([a-zA-Z0-9\s]*)",Match)
out .= "h" . "=" . Match1 . "¬"
, options.h := Match1
else if RegExMatch(A_LoopField,"x([a-zA-Z0-9\s]*)",Match)
out .= "x" . "=" . Match1 . "¬"
, options.x := Match1
else if RegExMatch(A_LoopField,"y([a-zA-Z0-9\s]*)",Match)
out .= "y" . "=" . Match1 . "¬"
, options.y := Match1
else if RegExMatch(A_LoopField,"\+([a-zA-Z0-9\s]*)",Match)
out .= Match1 . "=True¬"
, options[Match1] := "True"
else if RegExMatch(A_LoopField,"\-([a-zA-Z0-9\s]*)",Match)
out .= Match1 . "=False¬"
, options[Match1] := "False"
}
}
Options_ToParam(obj){
StringOpt := obj.ToStr
Loop, Parse, StringOpt, ¬
{
RegExMatch(A_LoopField,"([a-zA-Z0-9\s]*)=",name)
OptName = %name1%
RegExMatch(A_LoopField,"=(\+?-?[a-zA-Z0-9\s]*)",val)
OptVal = %val1%
if OptVal = False
RetVal .= "-" . OptName . " "
else if OptVal = True
RetVal .= "+" . OptName . " "
else
RetVal .= OptName . OptVal . " "
}
return RetVal
}
Options_SetParent(obj,parentObj){
}
Options(parent="",param="¬"){
static COBase
If !COBase
COBase := Object( "__Get" , "Options_GetVal" ; default getter
, "__Set" , "Options_SetVal" ; default setter
, "ToParam" , "Options_ToParam" ; .ToParam()
, "Import" , "Options_Import") ; .Import(sOptions)
; , "SetParent" , "Options_SetParent") ; .SetParent(parentObj)
obj := Object("ToStr", " ", "Parent"," ","base", COBase)
if (param != "¬"){
obj.Import(param)
}
return obj
}
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ
Last edited by ahklerner on Thu Oct 01, 2009 2:55 am; edited 5 times in total |
|
| Back to top |
|
 |
temp01
Joined: 09 Jul 2009 Posts: 120
|
Posted: Wed Sep 30, 2009 9:21 am Post subject: |
|
|
Nice!
Link to Autohotkey_L |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Wed Sep 30, 2009 10:12 am Post subject: |
|
|
updated _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Wed Sep 30, 2009 8:08 pm Post subject: |
|
|
updated.
Fully Working Example Gui From Help File:
| Code: |
; Example: A moving progress bar overlayed on a background image.
Gui := GUI()
;Gui, Color, White
Gui.Color("White")
;Gui, Add, Picture, x0 y0 h350 w450, %A_WinDir%\system32\ntimage.gif
Gui.Add("Picture", A_WinDir "\system32\ntimage.gif", "x0 y0 h350 w450")
;Gui, Add, Button, Default xp+20 yp+250, Start the Bar Moving
Gui.Add("Button", "Start the Bar Moving", "+Default xp+20 yp+250")
;Gui, Add, Progress, vMyProgress w416
Gui.Add("Progress", "", "vMyProgress w416")
;Gui, Add, Text, vMyText wp ; wp means "use width of previous".
Gui.Add("Text","", "vMyText wp")
;Gui, Show
Gui.Show()
return
Esc::ExitApp
ButtonStartTheBarMoving:
Loop, %A_WinDir%\*.*
{
if A_Index > 100
break
;GuiControl,, MyProgress, %A_Index%
Gui.MyProgress.SetText(A_Index)
;GuiControl,, MyText, %A_LoopFileName%
Gui.MyText.SetText(A_LoopFileName)
Sleep 50
}
;GuiControl,, MyText, Bar finished.
Gui.MyText.SetText("Bar finished.")
return
GuiClose:
ExitApp
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Thu Oct 01, 2009 2:47 am Post subject: |
|
|
Updated code in first 2 posts. second post is ready to run example.
Compare The 2 Gui's...
Unintended by good side effect of the lib
Since the control is sized automatically by ahk at Gui.Show() time instead of at Gui.Add() time, the Edit control is large enough where we can actually see all the info...
| Code: | var=
(
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
I live in a van down by the river. I live in a van down by the river.
)
o := GUI()
o.Add("Edit","Default Text")
o.1.SetText(var)
o.Show("x20 y20")
Gui, 2:Add, Edit,,Default Text
GuiControl, 2:,Edit1,%var%
Gui 2:Show
Sleep, 2000
return |
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
tidbit
Joined: 09 Mar 2008 Posts: 1807 Location: Minnesota, USA
|
Posted: Thu Oct 01, 2009 3:05 am Post subject: |
|
|
Very nice.
OOP looks better. but the current way AHK is, is more noob-friendly  _________________ rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
Even monkeys fall from trees. - Japanese proverb |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Thu Oct 01, 2009 3:12 am Post subject: |
|
|
for the people whe are line concious
a 1 liner Gui (I manually added a line break so word wrap didnt kick in)
(It Works)
| Code: | o:=GUI(),o.Color("Lime"),o.Add("Text","Default Text","","MyText1"),o.MyText1.Text:="New Text",o.MyText1.h:=100
,o.MyText1.w:=200,o.Border:="True",o.Caption:="False",o.Resize:="True",o.Show("x50 y500","Object Test Gui # 1")
|
and the word-wrap monster struck anyway _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
infogulch
Joined: 27 Mar 2008 Posts: 649
|
Posted: Thu Oct 01, 2009 6:19 pm Post subject: |
|
|
Very nice ahklerner! Thanks! _________________ Scripts - License |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Thu Mar 17, 2011 7:02 pm Post subject: |
|
|
WOW they are here LOL _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Fri Mar 18, 2011 10:40 am Post subject: |
|
|
It would be nice if you could modify control objects which would work like this:
| Code: | Edit := Control("Text")
Edit.Text := "Some text"
GUI := GUI()
GUI.Add(Edit)
GUI.Show() |
The GUI would then take all the properties from the control object and use it to add a control. Ideally, the control objects listed in the GUI (Gui.1 etc) would be compatible with this format. If you can overwrite the assignment operator you could even modify a GUI by replacing a control object.
In the style of C# or similar languages, the GUI variable of the control might be accessible under the "Name" property. By the way, is this variable made global or how is it referenced internally? I haven't read the implementation yet.
I'm also wondering if there is a "Type" property for the control objects, but I suppose there is.
I really like the approach here and I hope that you might consider adding some of my ideas. |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Sat Mar 19, 2011 2:42 pm Post subject: |
|
|
i am working on rewriting the gui object first, it was really convoluted, also some new stuff in ahk will make coding easier.
the problem with adding the control before the gui is there is no way to get hwnd until gui is added to gui and shown, i use hwnd alot,
Ideas/suggestions are always welcome. working example of how to implement idea is even better  _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1381 Location: USA
|
Posted: Sat Mar 19, 2011 2:49 pm Post subject: |
|
|
also in the mix is modding this to allow easy custom controls, like the rotary knob for example. i have proof of concept, but its messy _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
fragman
Joined: 13 Oct 2009 Posts: 1193
|
Posted: Sat Mar 19, 2011 8:17 pm Post subject: |
|
|
| ahklerner wrote: | i am working on rewriting the gui object first, it was really convoluted, also some new stuff in ahk will make coding easier.
the problem with adding the control before the gui is there is no way to get hwnd until gui is added to gui and shown, i use hwnd alot,
Ideas/suggestions are always welcome. working example of how to implement idea is even better  |
I was imaging this to be just a collection of styles and properties until it gets added to the gui. I will see if I can take a look into it later, but I need to get the next version of 7plus released first. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|