Sign in to follow this  
Followers 0
tylo

Au3gui Wrapper Library Almost Done

21 posts in this topic

#1 ·  Posted (edited)

You're all gonna love the wrapper lib I've made for Au3GUI. B)

@Larry: However, Au3GUI 1.0.10 and 1.0.11 doesn't seem to work at all.

V10 is writing bad stuff to ini, and V11 shows no controls. I am using 1.0.90 at the moment.

I can't get runtime parameters to work (enable/disable show/hide controls by toggling another). However, Close/Submit/Cancel and Cmd actions works fine.

Combo boxes: You have default sort on - is this desirable? I prefer not. Also you have no WS_VSCROLL, which is needed, but CBS_AUTOHSCROLL is probably not.

Input box:

if ( Style & ES_MULTILINE )
      Style = Style & !ES_MULTILINE;

You mean to bitmask multiline away. must be:

Style = Style & ~ES_MULTILINE, or Style &= ~ES_MULTILINE, which I prefer.

Thanks for a great utility, Larry. Hope you can sort these things out when you find time, so I can release the wrapper include library. :whistle:

Edited by tylo

blub

Share this post


Link to post
Share on other sites



Here's a teaser:

#include "Au3GUI_lib.au3"

GUI()

Func GUI()
   $title = "My Au3GUI test"
   Au3GUIForm(1, 100, 200, 400, 300, $title, -1, $WS_EX_TOOLWINDOW)
   
   $cbstyle = BitOr($CBS_DROPDOWN,$WS_VSCROLL)
   $lang = Au3GUIControl("combo", "", 50, 50, 100, 100, "", $cbstyle, 0)
  ; Data accepts either "|" separated string or array
   Au3GUIData("Python|C++|Delphi|AutoIt|Java", "AutoIt")
   Au3GUITooltip("A programming language")
   
   $member = Au3GUIControl("combo", "+", 0, 30, -1, -1, "", $cbstyle, 0)
   Au3GUIData("CyberSlug|Larry|Jon|Trids|Tylo", "Jon"); default Jon
   Au3GUITooltip("An AutoIt member")
   
  ; Last argument: selected
   $chk1 = Au3GUIControl("checkbox", "+", 0, 30, -1, 20, "Hello", -1, 1)
  ; "+" means relative positioning
   $chk2 = Au3GUIControl("checkbox", "+", 0, 30, -1, 20, "Goodbye", -1, 0)
   Au3GUIDisable(1, 0); Disable, but not hide (second param)

  ; Doesn't work :(
   Au3GUIAction($chk1, "unchecked.disable1", $chk2); 
   
   Au3GUIControl("button", "+",  0, 30, -1, 20, "OK", -1, 0)
   Au3GUIButtonAction("submit")
   Au3GUIButtonAction("close")
   
   Run("Au3GUI")
   WinWait($title)
   
   While (WinExists($title))
      Do
         Sleep(300)
      Until Au3GUIFormChange() 

      If (@error = 0) Then
         Local $res
         $res = $res & Au3GUIRead($lang, "") & @LF
         $res = $res & Au3GUIRead($member, "") & @LF
         $res = $res & Au3GUIReadState($chk1) & @LF
         $res = $res & Au3GUIReadState($chk2) & @LF
         MsgBox(0, "Result", $res)
      EndIf
   Wend
   
   Au3GUIClear()
EndFunc

blub

Share this post


Link to post
Share on other sites

And this is the complete API (for now).

$Au3GUIObj = 0
Dim $Au3GUIPos[4]
Dim $Au3GUIFont[3]

; --------------------------------------------------
Func Au3GUIForm($useIni, $x, $y, $w, $h, $title, $style, $exStyle)
Func Au3GUIFormColor($background)
Func Au3GUIFormIcon($iconFile)
Func Au3GUIFormHelpCmd($helpCmd)
Func Au3GUIFormExitCmd($exitCmd)

; Checks if form has changed (submitted or canceled)
Func Au3GUIFormChange()

; --------------------------------------------------
; $type   : label,picture,button,input,combo,date,edit,radio,checkbox,group,list,icon
; $attrib : '+' = relative pos
Func Au3GUIControl($type, $attribs, $x, $y, $w, $h, $text, $style, $selected)
Func Au3GUISetCurrentPos($relative, $x, $y, $w, $h)
Func Au3GUISetCurrentFont($name, $size, $weight)

Func Au3GUITooltip($tip)
Func Au3GUIExStyle($exStyle)
Func Au3GUIDisable($disabled, $hidden)
Func Au3GUIFocus()

; $data can be either an array or a "|" separated string
Func Au3GUIData($data, $default)

; $action must be "submit", "cancel", or "close"
Func Au3GUIButtonAction($action)
Func Au3GUICommand($cmd)

; Any control: setext#, disable#, enable#, hide#, show#
; Checkboxes : <checked|unchecked|indeterminate>.<enable|disable|show|hide>#
Func Au3GUIAction($obj, $param, $refObj)

Func Au3GUIRead($obj, $default)
Func Au3GUIReadState($obj)

Func Au3GUIClear()

; --------------------------------------------------
; Utility func
Func Au3GUIBitOr($numbers); e.g. $WS_GROUP &"|"& $WS_VISIBLE &"|"& $WS_MINIMIZE

blub

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yep, both the ini file and the controls are fine now. But the other issues remain...

/No, wait, the runtime parameters now work! :whistle:

Edited by tylo

blub

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Nope, but that's not a bad idea. I did it more brute force. $Au3GUIObjs is the number of controls created. Haven't tested it with big GUIs, but it seems to work fast enough. (It is only linear time complexity in practice, although it looks worse).

$a = StringSplit("title|icon|background|x|y|w|h|style|exstyle|focus|parent|action|file|help|run", "|")
   For $i = 1 To $a[0]
      EnvSet("GUI." & $a[$i], "")
   Next
   
   $a = StringSplit("type|text|x|y|w|h|hidden|disabled|style|exstyle|selected|tooltip|font|fontsize|fontweight|submit

|cancel|close|run", "|")
   $b = StringSplit("data|setext|disable|enable|hide|show|checked.enable|checked.disable|checked.show|checked.hide|un

checked.enable|unchecked.disable|unchecked.show|unchecked.hide|indeterminate.enable|indeterminate.di

sable|indeterminate.show|indeterminate.hide", "|")
   For $i = 1 To $Au3GUIObjs
      $tmp = "OBJ" & $i & "."
      For $j = 1 To $a[0]
         EnvSet($tmp & $a[$j], "")
      Next
      For $j = 1 To $b[0]
         For $k = 1 To 1000
            $var = $tmp & $b[$j] & $k
            If (EnvGet($var) = "") Then ExitLoop; normally at $k=1
            EnvSet($var, "")
         Next
      Next
   Next

/Later: It takes about 200ms to clear a gui with 50 objects, and 0.5 sec. for 100 objects on my PC. I'll do some testing with your method. That may have some time issues when creating the gui objects though.

Edited by tylo

blub

Share this post


Link to post
Share on other sites

I lost v1.0.13.0, but it seems that v1.0.14.0 intoduced the following: "submit" only works once (globally). So if you have a button (or two) with submit, but no close, it will only update the INI file on first press only.


blub

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

v1.0.15.0 - fixed submit once...

http://www.hiddensoft.com/fileman/users/Larry/au3gui.zip

thanks for your patience...

Lar.

Much better Still a Unchecked file generated by StudyMe.au3 no more .ini ???

only the part with AutoItSetTitle working

Edited by jpm

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Thanks, Lar. Works great here too. Still, I'd really like to see the default style values change for COMBO and LIST, as mentioned in the first post:

"list": remove LBS_SORT

"combo": remove CBS_SORT, add WS_VSCROLL

WS_VSCROLL is really required for combos (when elements does not fit in dropdown).

TL.

Edited by tylo

blub

Share this post


Link to post
Share on other sites

I'm getting 404's on your link now Larry.

404: The page/file you requested could not be found."


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Ok it worked that time. Thanks


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

OK, here's the library:

http://home.tiscali.no/tylohome/autoit3/Au3GUI_lib.zip

I've made a clever Clear routine, so check it out. No documentation yet, but the test will show the basic usage. Will add a simple doc later. I'm getting married in an hour, so I gotta go! :lmao:

Congratulations for the engagement :whistle::angry:B):evil:

Share this post


Link to post
Share on other sites

B) Congratulations. I can just see you explaining to your wife that you were late because you were coding. Ha ha ha

Remember the second year sucks... Just get through it. =) I would like to say that we have lot s of $ex but my wifes pregnant and that's been out the window :angry:

Congrats again. :whistle:

red

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Thanks, folks. It all went real well :angry:

Got a problem: There is some kind of efficiency problem with autoit. Take a look at the following code:

Global $n = 10000

T1()
T2()
T1()
T3()
T2()
T1()

Func T1()
  Local $begin, $end, $i, $var
  $begin = TimerStart()
  For $i = 1 To $n
     $var = "OBJ." & $i
     EnvSet("OBJ.1", "")
  Next
  $end = TimerStop($begin)
  msgbox(0,"T1", $end)
EndFunc


Func T2()
  Local $begin, $end, $i, $var
  $begin = TimerStart()
  For $i = 1 To $n
     $var = "OBJ."
     EnvSet($var, "")
  Next
  $end = TimerStop($begin)
  msgbox(0,"T2", $end)
EndFunc

Func T3()
  Local $begin, $end, $i, $var
  $begin = TimerStart()
  For $i = 1 To $n
     $var = "OBJ." & $i
     EnvSet($var, "")
  Next
  $end = TimerStop($begin)
  msgbox(0,"T3", $end)
EndFunc

The printout:

T1: 326

T2: 286

T1: 346

T3: 4371

T2: 3555

T1: 3680

Suddenly, the same routines takes more than 10 times longer! Some resources is not freed somewhere, it seems. :whistle:

T3 is basically a combo of T1 and T2, but that is the one that is causing all the problems. Even if run alone it will take 10 times more than it should, and it will slow down following code too B) .

Note: If $n is reduced to 1000 the differences are only a factor of about 2, (compared to 10). However, when increasing the complexity of the string expressions, the problem appears again.

Edited by tylo

blub

Share this post


Link to post
Share on other sites

There are 2 problems, one is your script, the other is with EnvSet (Or more specifically the API function it calls).

You have a couple problems with your script which are giving misleading results. I don't know if those were intentional or not, but they are misleading you, I think.

In T1() you have:

$var = "OBJ." & $i

EnvSet("OBJ.1", "") "OBJ.1" should be $var

In T2() you have:

$var = "OBJ." Forgot & $i? It needs this or you just set "OBJ." every time

EnvSet($var, "")

T3() is correct.

When I run it with those changes made, T1() first run takes half as much time. The rest of the calls are about the same, which is about double or slightly more than the first run of T1().

The explanation:

For whatever reason, it appears the more environment variables that are set, the longer the API function takes to work. Lets look at why you original script took so little time the first time T1() and T2() run, but so long the next time.

With the way the functions were written, T1() would run through and only set 1 environment variable "OBJ.1". T2() would also set only 1 "OBJ.". T3() would set $n environment variables. The next time T1() was called, it was slow because it had $n or more variables set. This seems to happen only when a lot of environment variables are set, and T3() properly set a whole bunch of them.

In short, its not AutoIt's fault. EnvSet passes the information right along to a Windows API function. Comment out or replace EnvSet with anything else and AutoIt will run each function as expected.

Share this post


Link to post
Share on other sites

I see. Thanks. Yes, the funcs were intentionally written like that to explore all the smilar combination which worked fast, compared to the one that worked slow.

I would never guessed that the difference in speed of such an apparently low level API function (EnvSet) would impact the speed of AutoIt in that way!

It means though, that creating huge GUI's with Au3GUI is not very suitable, because of the high number of environment variables that must be set and cleared for each control. However, normal sized GUIs are no problem.

PS: the old AutGUI was maybe more optimal in that respect, because it used only one or two environment variables for each control.


blub

Share this post


Link to post
Share on other sites

Here's an idea. Use an Environment variable ONLY for the type. Just enough information to get the control to exist, then use the Control family of functions to load them with data and position them. This should significantly reduce the amount of environment variables in existence.

Share this post


Link to post
Share on other sites

Here's an idea. Use an Environment variable ONLY for the type.  Just enough information to get the control to exist, then use the Control family of functions to load them with data and position them.  This should significantly reduce the amount of environment variables in existence.

I should of explained that a little better, I was in a hurry at the time. You'll have to store the pertinent information in arrays or write it out to a temporary text file Ini might be easier). You'll also library functions that emulate Run and RunWait on the GUI. These functions should both read the INI and use the Control functions to move the control into the proper position. It will work flawlessly and faster than using environment variables if the user uses the library to do everything with Au3GUI.

Larry, idea request here. Can you allow us to pass other SW states when we launch the window? SW_HIDE would be nice (Run("au3gui", "", @SW_HIDE) doesn't hide it for me).

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Larry, I've done some coding. I'm not trying in any way to take over your project here, so take this only as a suggestion which I hope you like.

Only ONE environment variable per control, e.g (the attrib sequence is irrelevant):

EnvSet("GUI.in", "title=Au3GUI Test|w=400|h=300")  ; etc..
EnvSet("OBJ1.in", "type=combo|x=20|y=30|w=100|h=80|data=Choice 1;Choice 2;*Choice 3|data=Even one more choice"); "Choice 3" is default
EnvSet("OBJ2.in", "type=checkbox|x=20|y=60|w=100|h=20|text=Check me|selected=1")

It took a little more work than I thought, so there may be bugs, but it seems to work great on the few controls I've made so far. The code is still easy to read (maybe easier?), so it should not be any problems for you to continue working on it. Also the .exe is about the same size as it was.

There is a small .bat file which demonstrate a GUI with runtime actions. Actions are stored in an dynamic array, so the environment variables are cleared after they are read and filled into a data struct (struct OBJ).

A few other improvements:

- Increased MAX_OBJS to 5000

- Takes 1st item as default if no specified in COMBO and LIST.

- You don't need to count item number in action and data lists: either do (e.g.) "enable=5;8;12" or alternatively "enable=5|enable=8|enable=12". This also works for data lists.

- Removed NoSpace() - I can't see the need for it (?).

(/add: for most usage, I think actually it is better to add an attribute "default=Choice 3" explicitly, instead of the "*" prefix - or maybe both).

Download: http://home.tiscali.no/tylohome/autoit3/au...0.20.1.tylo.zip

What do you all think.

Edited by tylo

blub

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0