Jump to content
itsid

GUI message gets lost (ignored?)

Recommended Posts

itsid

Hi,

I hope I'm not exactly familiar with AutoIt tbh.. I only use it occasionally for some "sketching" let's say...

 

Anywhoo, I ran into an issue with the GUIMessage...

here.. have my loop for a quick view:

;//runtime variables init
    local $runmx = -1
    local $runit = 1
    local $dofetch = False
    $runmx = grabAllLinks()
    
    ;//loop di loop
    While 1
        Local $aMsg = GUIGetMsg(1)
        Switch $aMsg[1]
            Case $MainGui
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        ExitScript()
                    Case $men_addsite
                        GuiAddSite()
                    Case $men_addreg
                        GuiAddReg()
                    Case $men_exit
                        ExitScript()
                    Case $btn_startop
                        if $dofetch = true Then
                            $dofetch = false
                            GUICtrlSetData($btn_startop, "Start")
                        Else
                            $dofetch = True
                            GUICtrlSetData($btn_startop, "Pause")
                        EndIf
                    Case Else
                        For $i = 1 To UBound($sites)-1 ;// on the fly created submenu that's why it's an array it loops...
                            If $aMsg[0] = $runsit[$i] Then
                                $runmx = grabLinks($sites[$i][0]) ;rowid
                                $runpname = $sites[$i][1]
                                $dofetch = True
                                GUICtrlSetData($btn_startop, "Pause")
                            elseif $aMsg[0] = $runrefsit[$i] Then
                                local $html = loadPage($sites[$i][2]) ;url
                                $runmx = grabinsertLinks($html, $sites[$i][0]) ;rowid
                                $runpname = $sites[$i][1]
                                $dofetch = True
                                GUICtrlSetData($btn_startop, "Pause")
                            elseif $aMsg[0] = $expsit[$i] Then
                                exportSQL($sites[$i][1])
                            EndIf
                        Next
                EndSwitch
            Case $frmSiteAdd
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($frmSiteAdd)
                    Case $btn_add
                        ;//blablabla waaaaay too long
                        GUIDelete($frmSiteAdd)
                EndSwitch
            Case $frmRegAdd
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($frmRegAdd)
                    Case $btn_add
                        ;//blablabla waaaaay too long
                        GUIDelete($frmRegAdd)
                EndSwitch
        EndSwitch
        ;//the running code is what kinda looses the GUI-message
        ;//ConsoleWrite($aMsg[0]&", ")  simply does NOT write to console once the code below gets triggered
        if $runit <= $runmx Then
            if $dofetch = true Then
                _GUICtrlStatusBar_SetText($StatusBar1, @TAB&@TAB&"page: "&$runit&" of "&$runmx, 2)
                GUICtrlSetData($total_progress,100*$runit/$runmx)
                ;// GUI Updates working nicely!
                ;// so does all other code (reading files, writing to database...everything)
                ;// except setting $dofetch to false with the GUI button
                $runit = $runit +1
            EndIf
        EndIf
    WEnd

I'm kinda lost ATM..

occasionally the ConsoleWrite($aMsg[0]) flickers but always a mouse release, never a mouse down (negative values if any)

removing the "work" from the While Loop and calling an external function doesn't make it any different,
Soooo how can I cache GUIGetMsg(1) in order to trigger or rather UN-trigger the dofetch so the actual workload gets indeed paused?

 

it digs through some thousand files with some hundred loop runs per file, so most of the time it's simply not in said while loop actually,
and I just wouldn't want to go through the hassle and requery GUIGetMsg every other line of code just to be sure it triggers my switch...

There must be a simpler way of achieving this, no?
Do I need a Windows message handle or is there even a simpler way than that...

Frankly, personally it's almost quicker for me to get this done in c++... but I kinda like the AutoIt idea 
and I'd like to use it for sketches like these before I care about error handling or system architecture and all the boring stuff :D

 

thank you for your help

'sid
 

Share this post


Link to post
Share on other sites
itsid

alright alright.. windows message handle it is....:yawn:

 

Share this post


Link to post
Share on other sites
Melba23

itsid,

Welcome to the AutoIt forums.

In future, you might like to consider posting runnable code - lots of people will not take the trouble to add the necessary additional code to get snippets running.

Anyway, I did - and your loop seems to work just fine for me (with a small change to the ConsoleWrite line to prevent it going mad and printing for every pass):

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>


;//runtime variables init
Local $runmx = -1
Local $runit = 1
Local $dofetch = False
$runmx = 2000

Global $sites[2]


$MainGui = GUICreate("main", 200, 200, 100, 100)

$btn_startop = GUICtrlCreateButton("Test", 10, 10, 80, 30)

$total_progress = GUICtrlCreateProgress(10, 90, 180, 20)

$men_exit = GUICtrlCreateButton("Exit", 110, 160, 80, 30)

$cTest_1 = GUICtrlCreateDummy()
$cTest_2 = GUICtrlCreateDummy()
$cTest_3 = GUICtrlCreateDummy()

GUISetState()

$frmSiteAdd = GUICreate("SiteAdd", 200, 200, 400, 100)

$btn_add_Site = GUICtrlCreateButton("Add", 10, 10, 80, 30)

GUISetState()

$frmRegAdd = GUICreate("RegAdd", 200, 200, 700, 100)

$btn_add_Reg = GUICtrlCreateButton("Add", 10, 10, 80, 30)

GUISetState()

;//loop di loop
While 1
    Local $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $MainGui
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE, $men_exit
                    Exit ; ExitScript()
                ;Case $men_addsite
                    ;GuiAddSite()
                ;Case $men_addreg
                    ;GuiAddReg()
                ;Case $men_exit
                ;   ExitScript()
                Case $btn_startop
                    If $dofetch = True Then
                        $dofetch = False
                        GUICtrlSetData($btn_startop, "Start")
                    Else
                        $dofetch = True
                        GUICtrlSetData($btn_startop, "Pause")
                    EndIf
                Case Else
                    For $i = 1 To UBound($sites) - 1 ;// on the fly created submenu that's why it's an array it loops...
                        If $aMsg[0] = $cTest_1 Then ;$runsit[$i] Then
                            $runmx = 2000
                            ;$runpname = $sites[$i][1]
                            $dofetch = True
                            GUICtrlSetData($btn_startop, "Pause")
                        ElseIf $aMsg[0] = $cTest_2 Then ; $runrefsit[$i] Then
                            ;Local $html = loadPage($sites[$i][2]) ;url
                            $runmx = 2000
                            ;$runpname = $sites[$i][1]
                            $dofetch = True
                            GUICtrlSetData($btn_startop, "Pause")
                        ElseIf $aMsg[0] = $cTest_3 Then ; $expsit[$i] Then
                            ;exportSQL($sites[$i][1])
                        EndIf
                    Next
            EndSwitch
        Case $frmSiteAdd
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($frmSiteAdd)
                Case $btn_add_Site
                    ;//blablabla waaaaay too long
                    GUIDelete($frmSiteAdd)
            EndSwitch
        Case $frmRegAdd
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($frmRegAdd)
                Case $btn_add_Reg
                    ;//blablabla waaaaay too long
                    GUIDelete($frmRegAdd)
            EndSwitch
    EndSwitch
    ;//the running code is what kinda looses the GUI-message
    If $aMsg[0] <> 0 Then
        ConsoleWrite($aMsg[0] & @CRLF) ; simply does NOT write to console once the code below gets triggered
    EndIf
    If $runit <= $runmx Then
        If $dofetch = True Then
            ;_GUICtrlStatusBar_SetText($StatusBar1, @TAB & @TAB & "page: " & $runit & " of " & $runmx, 2)
            GUICtrlSetData($total_progress, 100 * $runit / $runmx)
            ;// GUI Updates working nicely!
            ;// so does all other code (reading files, writing to database...everything)
            ;// except setting $dofetch to false with the GUI button
            $runit = $runit + 1
        EndIf
    EndIf
WEnd

So I would suggest that the problem lies elsewhere in your script - of which there is obviously a lot more.

M23

  • Thanks 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
itsid

Hi thank you..

 

also for trying!

 that's the issue.. the code itself as I mentioned is quite long and depending on various conditions is getting rather complex quickly..

a single loop (that's called one after another after the switch-cases) can take several seconds

loading a file if possible from the HDD, if not from the internet,
checking it against a regular expression, and comparing the results against a database,
updating the database and/or the GUI according to that, marking the read file as read in the database... aaaand so on and so forth.

and worse the code spreads over several files
since I like to keep mainloops away from Database or GUI stuff local file access away from remote file access and so forth
so that I can replace either more conveniently by just including some other script
swapping back if needed ;)

As I said it's a sketch, (no error handling, GUI is subpar, cluttered with data in memory, full with dummy functions and unnecessary includes at times etc..) 
I wouldn't want to bother someone with digging through such mess
that's why I didn't post any of my running code
(but you are right.. I should have at least fabricobbled some testscript like yours... my apologies)

Anyways, a short test like yours works fine for me as well.. that's why I was baffled seeing it fail with longer running tasks;
and if I'd put a sleep(2000) in (the dofetch condition) to emulate that longer running task your testscript fails on me as well  :(
Just didn't thought of that before I'm afraid

Nevermind, I added a windows message handle to resolve that... 
just removed the case for the start/stop button from the  switch and it works fine now... (or say good enough for what I was after here)

'sid

 

Share this post


Link to post
Share on other sites
Zedna

It's quite important to test result of GUIGetMessage() to nonzero when you use Case Else + For/Next in your GUI loop like this:

Note: I shortened your code only to related parts

;//loop di loop
    While 1
        Local $aMsg = GUIGetMsg(1)
        Switch $aMsg[1]
            Case $MainGui
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        ExitScript()
                    Case $men_addsite
                        GuiAddSite()
                    Case Else
                        If $aMsg[0] <> 0 Then ; ===> this line added by Zedna to avoid unwanted looping <===
                            For $i = 1 To UBound($sites)-1 ;// on the fly created submenu that's why it's an array it loops...
                                If $aMsg[0] = $runsit[$i] Then
                                    $runmx = grabLinks($sites[$i][0]) ;rowid
                                    $runpname = $sites[$i][1]
                                    $dofetch = True
                                    GUICtrlSetData($btn_startop, "Pause")
                                elseif $aMsg[0] = $runrefsit[$i] Then
                                    local $html = loadPage($sites[$i][2]) ;url
                                    $runmx = grabinsertLinks($html, $sites[$i][0]) ;rowid
                                    $runpname = $sites[$i][1]
                                    $dofetch = True
                                    GUICtrlSetData($btn_startop, "Pause")
                                elseif $aMsg[0] = $expsit[$i] Then
                                    exportSQL($sites[$i][1])
                                EndIf
                            Next
                        EndIf
                EndSwitch
            Case $frmSiteAdd
                Switch $aMsg[0]
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($frmSiteAdd)
                    Case $btn_add
                        ;//blablabla waaaaay too long
                        GUIDelete($frmSiteAdd)
                EndSwitch
        EndSwitch
    WEnd

 

Edited by Zedna

Share this post


Link to post
Share on other sites
itsid

Jeez, not only are you late to the party (problem solved) 
but why on earth would do you think it'd be important to check non zero first... that loop's too short to cause any significant increase in runtime..
and if it would be relevant, then it'd be better to only check values greater than zero (you know to also ignore button release and such) ... so that's quite a half455 line of code there...
luckily it's not important at all (not until you add a couple of hundred menu items which quite frankly is an insane idea anyways)
since it's solely the work that caused the issue not the switch case
and worst if you'd paid attention, you'd noticed that I solved my problem with the windows message handle .... (a method mentioned in the linked wiki)

Also double posting, really? I'm new around here and even I know where that edit button is!

'sid
 

Share this post


Link to post
Share on other sites
Earthshine

you're not a happy child--are you sid? That member is a really cool member who likes to help others and is generous in giving code. shm

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Zedna

@itsid

Such an aggresive reaction is absoltelly inadequate! :puke:

I have added you to my ignore list and I'm done with you.

 

I'm happy that the most of people on this forum don't behave the way like you ...

Edited by Zedna
  • Thanks 1

Share this post


Link to post
Share on other sites
Jos
7 hours ago, itsid said:

Also double posting, really? I'm new around here and even I know where that edit button is!

'sid

@itsid,

Wonder whether you could tell me what justified your patronizing smart ass response to a member only trying to assist?
Try you ignore when you feel it doesn't help you instead off taking the bullying approach, as that will go much further.

Jos  

EDIT: I found a great quote used/made by ... yourself,  that could very well apply here:

Quote

If you don't know why you're here... you might as well leave.

 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Melba23

itsid,

I agree wholeheartedly with the above comments. Please change your attitude for future posts or you may well find that you will no longer be able to post at all.

M23

Edit: Managing to get 2 members of the Moderation team reacting at the same time is usually a sign that you are doing something we regard as pretty OTT - please take note.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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

×