Jump to content

Recommended Posts

  • Moderators
Posted

Jos,

Did you have to tell everyone! :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Sure you do... I pay you 5% each month of what I get. :)

And worth EVERY penny! Thanks for the lessons! And great work on this language. When is the OOP version coming out? ;)

Posted

Mat,

To carry on with the advanced tutorial now that we have started ;) - do you use the /SO option with Obfuscator? That strips all the unused constants and functions from any includes and seriously reduces the size of your final exe/au3. Jos has done a wonderful job with it and I find it can save as much as half the size of a script.

M23

No... I just write that way! I read binary and hex fluently :), My method saves more than his, and kind of obfuscates it at the same time (although I have tried un-obfuscating a file before to see just how good it was. I got pretty far, but it was very hard, and took a ridiculous amount of time).

I recommend everyone to do something along those lines, as it does make a difference

Mat

Posted

AndrewG,

I have simplified your code quite a bit and added a fair few comments to explain why. I hope you can follow:

#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $frmMain, $g_btnPlay, $g_btnStop, $sMessage, $i_CtrlID = 0
Global $i_isPlay = False ; Makes it easier to toggle between True/False
Global $i_Count = 1

$frmMain = GUICreate("Learning Looping", 800, 400, (@DesktopWidth - 800) / 2, (@DesktopHeight - 400) / 2) ; Not needed if only Default ,-1,-1)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp")
;Master Play Controls
$g_btnPlay = GUICtrlCreateButton("Play", 10, 360, 40, 30) ; Not needed if only Default , -1, -1)
GUICtrlSetOnEvent($g_btnPlay, "btnPlay")
$g_btnStop = GUICtrlCreateButton("Stop", 50, 360, 40, 30) ; Not needed if only Default , -1, -1)
GUICtrlSetOnEvent($g_btnStop, "btnStop")

;Messages
GUICtrlCreateGroup("Messages", 450, 180, 220, 140) ; Not needed if only Default , -1, -1)
$sMessage = GUICtrlCreateLabel("", 460, 200, 200, 100) ; Not needed if only Default , -1, -1)
GUICtrlCreateGroup("", -99, -99, 1, 1);Close group

GUISetState(@SW_SHOW)

While 1
    Playloop() ; See if we need to play
WEnd

Func ExitApp()
    Exit
EndFunc   ;==>ExitApp

;Play Function
Func btnPlay()

    $i_CtrlID = @GUI_CtrlId ; Save the ID of the button as a flag for Playloop()
    If $i_isPlay = False Then  ; == 0 Then  == is only for comparing case sensitive strings
        $i_isPlay = Not $i_isPlay ; Told you it is was easier!
        GUICtrlSetData($sMessage, $i_isPlay)
    ;ElseIf $i_isPlay == 1 Then   Not needed as $i_IsPlay can only be True/False
    ;        Return
    Else
        Return
    EndIf

EndFunc   ;==>btnPlay

;Stop Function  - see above for explanation of changes
Func btnStop()

    $i_CtrlID = @GUI_CtrlId
    If $i_isPlay = True Then
        $i_isPlay = Not $i_isPlay
    Else
        Return
    EndIf

EndFunc   ;==>btnStop

;Loop function
Func PlayLoop()

    While $i_isPlay = 1  ; Again no need for ==
        ; We only get here is the play button was pressed
        $i_Count = $i_Count + 1
        GUICtrlSetData($sMessage, $i_isPlay & @CRLF & " Looping" & @CRLF & $i_Count)
        Sleep(500) ; Just so you can see what is going on in the label - my old eyes cannot cope with anything less
    WEnd
    ; We can get here if the stop button was pressed or if the ButtonID has been reset to 0
    ; So if we do not check we get flickering in the label - try removing the If...Then part and see!
    If $i_CtrlId = $g_btnStop Then GUICtrlSetData($sMessage, $i_isPlay & @CRLF & "Stopping")
    ; Reset the buttonID so we do not fire anything when we loop next time
    $i_CtrlID = 0
EndFunc   ;==>PlayLoop

Although I can see what you were trying to do, I am a great believer in the KISS* principle and you, in my opinion, were getting a bit over-complicated. Not that you were wrong to try and do it another way - when I code I always think of Kipling: "There are nine and sixty ways of constructing tribal lays, and every single one of them is right!" :)

Please ask if anything is unclear.

M23

* Keep It Simple Stupid

Melba23,

I understand that, and thank you.

What I noticed though is the OnEventMode solution uses 100% of my cpu, and the Message-loop mode solution hardly uses any. So then the reason why would be that the in the OnEventMode the PlayLoop function is contantly being called where as in the Message-loop mode after the PlayLoop function has been called the gui is only being polled when the while loop is executing. So the message loop mode seem to be the mode to use in this case. right?

Posted (edited)

What I noticed though is the OnEventMode solution uses 100% of my cpu, and the Message-loop mode solution hardly uses any. So then the reason why would be that the in the OnEventMode the PlayLoop function is contantly being called where as in the Message-loop mode after the PlayLoop function has been called the gui is only being polled when the while loop is executing. So the message loop mode seem to be the mode to use in this case. right?

You may be right at it being the write mode to use in this case, but you should not be seeing any CPU usage at all when idle. Sorry Melba but that example definitely has something wrong!

Click "play" and it drops to < 2% becouse of the sleep (500), you just need one of those in the normal loop.

This would be better

#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $frmMain, $g_btnPlay, $g_btnStop, $sMessage, $i_CtrlID = 0
Global $i_isPlay = False ; Makes it easier to toggle between True/False
Global $i_Count = 1

$frmMain = GUICreate("Learning Looping", 800, 400, (@DesktopWidth - 800) / 2, (@DesktopHeight - 400) / 2) ; Not needed if only Default ,-1,-1)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp")
;Master Play Controls
$g_btnPlay = GUICtrlCreateButton("Play", 10, 360, 40, 30) ; Not needed if only Default , -1, -1)
GUICtrlSetOnEvent($g_btnPlay, "btnPlay")
$g_btnStop = GUICtrlCreateButton("Stop", 50, 360, 40, 30) ; Not needed if only Default , -1, -1)
GUICtrlSetOnEvent($g_btnStop, "btnStop")

;Messages
GUICtrlCreateGroup("Messages", 450, 180, 220, 140) ; Not needed if only Default , -1, -1)
$sMessage = GUICtrlCreateLabel("", 460, 200, 200, 100) ; Not needed if only Default , -1, -1)
GUICtrlCreateGroup("", -99, -99, 1, 1);Close group

GUISetState(@SW_SHOW)

While 1
    Playloop() ; See if we need to play
WEnd

Func ExitApp()
    Exit
EndFunc   ;==>ExitApp

;Play Function
Func btnPlay()

    $i_CtrlID = @GUI_CtrlId ; Save the ID of the button as a flag for Playloop()
    If $i_isPlay = False Then  ; == 0 Then  == is only for comparing case sensitive strings
        $i_isPlay = Not $i_isPlay ; Told you it is was easier!
        GUICtrlSetData($sMessage, $i_isPlay)
    ;ElseIf $i_isPlay == 1 Then   Not needed as $i_IsPlay can only be True/False
    ;        Return
    Else
        Return
    EndIf

EndFunc   ;==>btnPlay

;Stop Function  - see above for explanation of changes
Func btnStop()

    $i_CtrlID = @GUI_CtrlId
    If $i_isPlay = True Then
        $i_isPlay = Not $i_isPlay
    Else
        Return
    EndIf

EndFunc   ;==>btnStop

;Loop function
Func PlayLoop()

    While $i_isPlay = 1  ; Again no need for ==
        ; We only get here is the play button was pressed
        $i_Count = $i_Count + 1
        GUICtrlSetData($sMessage, $i_isPlay & @CRLF & " Looping" & @CRLF & $i_Count)
        Sleep(500) ; Just so you can see what is going on in the label - my old eyes cannot cope with anything less
    WEnd
    ; We can get here if the stop button was pressed or if the ButtonID has been reset to 0
    ; So if we do not check we get flickering in the label - try removing the If...Then part and see!
    If $i_CtrlId = $g_btnStop Then GUICtrlSetData($sMessage, $i_isPlay & @CRLF & "Stopping")
    ; Reset the buttonID so we do not fire anything when we loop next time
    $i_CtrlID = 0

    Sleep (100) ; Sleep Added to save CPU
EndFunc   ;==>PlayLoop
(One line added :) )

Mat

Edited by Mat
  • Moderators
Posted

AndrewG & Mat,

Mea culpa, mea culpa, mea maxima culpa! :)

I hate OnEvent mode!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

B) a man after my own heart B)

And i got called stupid earlier in this thread for expressing that opinion.

Hey I only said your argument was stupid, I didn't mean any offence to you as a person! :)

Now lets all be friends and code some events! ;)B)

Posted (edited)

you have my apology's sir !

Yea your right you did not say i was personally stupid , just that my argument was, which i cant even remember what it was right atm, but I'll certainly give way to you on that one.

No worries, its all good :)

;) AutoIt all the way, I will not be a lemming and follow the crowd over the cliff and into the C. B)

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Posted

You may be right at it being the write mode to use in this case, but you should not be seeing any CPU usage at all when idle. Sorry Melba but that example definitely has something wrong!

Click "play" and it drops to < 2% becouse of the sleep (500), you just need one of those in the normal loop.

This would be better

#include <GUIConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $frmMain, $g_btnPlay, $g_btnStop, $sMessage, $i_CtrlID = 0
Global $i_isPlay = False ; Makes it easier to toggle between True/False
Global $i_Count = 1

$frmMain = GUICreate("Learning Looping", 800, 400, (@DesktopWidth - 800) / 2, (@DesktopHeight - 400) / 2) ; Not needed if only Default ,-1,-1)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp")
;Master Play Controls
$g_btnPlay = GUICtrlCreateButton("Play", 10, 360, 40, 30) ; Not needed if only Default , -1, -1)
GUICtrlSetOnEvent($g_btnPlay, "btnPlay")
$g_btnStop = GUICtrlCreateButton("Stop", 50, 360, 40, 30) ; Not needed if only Default , -1, -1)
GUICtrlSetOnEvent($g_btnStop, "btnStop")

;Messages
GUICtrlCreateGroup("Messages", 450, 180, 220, 140) ; Not needed if only Default , -1, -1)
$sMessage = GUICtrlCreateLabel("", 460, 200, 200, 100) ; Not needed if only Default , -1, -1)
GUICtrlCreateGroup("", -99, -99, 1, 1);Close group

GUISetState(@SW_SHOW)

While 1
    Playloop() ; See if we need to play
WEnd

Func ExitApp()
    Exit
EndFunc   ;==>ExitApp

;Play Function
Func btnPlay()

    $i_CtrlID = @GUI_CtrlId ; Save the ID of the button as a flag for Playloop()
    If $i_isPlay = False Then  ; == 0 Then  == is only for comparing case sensitive strings
        $i_isPlay = Not $i_isPlay ; Told you it is was easier!
        GUICtrlSetData($sMessage, $i_isPlay)
    ;ElseIf $i_isPlay == 1 Then   Not needed as $i_IsPlay can only be True/False
    ;        Return
    Else
        Return
    EndIf

EndFunc   ;==>btnPlay

;Stop Function  - see above for explanation of changes
Func btnStop()

    $i_CtrlID = @GUI_CtrlId
    If $i_isPlay = True Then
        $i_isPlay = Not $i_isPlay
    Else
        Return
    EndIf

EndFunc   ;==>btnStop

;Loop function
Func PlayLoop()

    While $i_isPlay = 1  ; Again no need for ==
        ; We only get here is the play button was pressed
        $i_Count = $i_Count + 1
        GUICtrlSetData($sMessage, $i_isPlay & @CRLF & " Looping" & @CRLF & $i_Count)
        Sleep(500) ; Just so you can see what is going on in the label - my old eyes cannot cope with anything less
    WEnd
    ; We can get here if the stop button was pressed or if the ButtonID has been reset to 0
    ; So if we do not check we get flickering in the label - try removing the If...Then part and see!
    If $i_CtrlId = $g_btnStop Then GUICtrlSetData($sMessage, $i_isPlay & @CRLF & "Stopping")
    ; Reset the buttonID so we do not fire anything when we loop next time
    $i_CtrlID = 0

    Sleep (100) ; Sleep Added to save CPU
EndFunc   ;==>PlayLoop
(One line added :) )

Mat

Thanks Mat

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...