
littlebigman
Active Members-
Posts
193 -
Joined
-
Last visited
Everything posted by littlebigman
-
[run] Append StdOut to console?
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
I'll append to this thread, although it's now a GUI issue. While converting the code to a GUI, for some reason, the Edit box displays nothing. Does it need to be refreshed or something? Case $OK _GUICtrlButton_Enable($OK, False) ; to prevent user from clicking while CLI app running Local $iReturn = Run($LINE, $OUTPUTDIR, @SW_HIDE,$STDOUT_CHILD + $STDERR_CHILD) If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Run failed.") Local $sOutput = Null ;nothing in Edit box ;Doesn't catch any error from CLI While True $sOutput &= StdoutRead($iReturn) & @CRLF If @error Then ExitLoop GUICtrlSetData($Edit1, $sOutput) ;TODO Append + scroll WEnd $sOutput &= "Done." & @CRLF GUICtrlSetData($Edit1, $sOutput) ConsoleWrite($sOutput) --- Edit: Still flickers Case $OK _GUICtrlButton_Enable($OK, False) Local $iReturn = Run($LINE, $OUTPUTDIR, @SW_HIDE,$STDOUT_CHILD + $STDERR_CHILD) If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Run failed.") Local $sOutput = Null While True $sOutput = StdoutRead($iReturn) & @CRLF If @error Then ExitLoop ConsoleWrite($sOutput) ;_GUICtrlEdit_AppendText($Edit1, @CRLF & $sOutput) ;_GUICtrlEdit_AppendText($Edit1, $sOutput) _GUICtrlEdit_BeginUpdate($Edit1) _GUICtrlEdit_AppendText($Edit1, $sOutput) _GUICtrlEdit_EndUpdate($Edit1) WEnd _GUICtrlEdit_AppendText($Edit1, @CRLF & "Done." & @CRLF) ConsoleWrite("Done." & @CRLF) --- Edit: Better, but still flickers GUICtrlSetData($Edit1, $sOutput,1) ; 1 = the string is inserted at the current insertion point (caret). -
[run] Append StdOut to console?
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
Thanks much -
Hello, What is the right to loop through StdOut and append it to the console? The following replaces it, so I can't see what's going on: $StartTimer = TimerInit() Local $sOutput Local $iReturn = Run($LINE, $OUTPUTDIR, @SW_HIDE,$STDOUT_CHILD + $STDERR_CHILD) If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Run failed.") Do $sOutput = StdoutRead($iReturn) If @error Then ExitLoop ;TODO how to check reached EOF or error? ;TODO how to append to console instead of replacing? ConsoleWrite($sOutput & @CRLF) Until Not ProcessExists($iReturn) $StopTimer = TimerDiff($StartTimer) Thank you. --- Edit: This doesn't work: The console flickers Do $sOutput = ConsoleRead() & @CRLF $sOutput &= StdoutRead($iReturn) & @CRLF ConsoleWrite($sOutput) Until Not ProcessExists($iReturn)
-
[_ArraySearch] Fails finding text
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
Bingo! Thank you. -
Hello, This is my first time using _ArraySearch(), and I can't figure out why it fails finding the line that includes "RESOLUTION": Local $iReturn = Run($LINE, $OUTPUTDIR, @SW_SHOW,$STDOUT_CHILD + $STDERR_CHILD) If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Command failed.") ProcessWaitClose($iReturn) Local $sOutput = StdoutRead($iReturn) ;BAD Local $aArray = $sOutput Local $aArray = StringSplit(StringTrimRight(StringStripCR($sOutput), StringLen(@LF)), @LF) If @error then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error filling array") _ArrayDisplay($aArray, "From stdout") ;OK Local $aiResult = _ArraySearch($aArray, "RESOLUTION") ;BAD ;~ 1 - $aArray is not an array ;~ 2 - $aArray is not a 1D or 2D array ;~ 3 - $aArray is empty ;~ 4 - $iStart is greater than $iEnd ;~ 5 - Array not 2D and $bRow set True ;~ 6 - $vValue was not found in array HERE If @error Then Exit MsgBox($MB_ICONERROR, "Error",@error & @CRLF & @extended) _ArrayDisplay($aiResult, "Found") Any idea? Thank you.
-
Ternary line for GUI loop?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
Makes sense. So it's not a good idea -
Ternary line for GUI loop?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
Just because I was curious to see if it could be further shortened. -
Hello, Just to keep the GUI open after doing stuff, I need to rerun a basic GUI loop. As an alternative to a Do/Until, I tried a ternary one-liner, but AutoIt doesn't like the syntax: ;So the app doesn't close after the for loop ;~ Do ;~ Sleep(10) ;~ Until GUIGetMsg() = $GUI_EVENT_CLOSE ;BAD (GUIGetMsg() = $GUI_EVENT_CLOSE) ? (Exit) : (Sleep(10)) ;BAD GUIGetMsg() = $GUI_EVENT_CLOSE ? Exit : Sleep(10) Is that syntax just impossible? Thank you.
-
Double click on an item in a list
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
(New reply since I can't figure out how to edit below the quote above). Fixed using this: ConsoleWrite(GUICtrlRead($hListBox) & @CRLF) -
Double click on an item in a list
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
Thanks. For some reason, I can't get the text of the selected item that I double-clicked in the listbox. Could it be because it's read in a WM_COMMAND section? #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <array.au3> #Region GUICreate("Form1", 200, 350) $hListBox = GUICtrlCreateList("", 5, 5, 190, 340) GUICtrlSetData($hListBox,"item1|item2") #EndRegion GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW) ;in GUI loop, don't refer to listbox, or double-clicks won't be properly handled While True Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox) $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word $iCode = BitShift($iwParam, 16) ; Hi Word Switch $hWndFrom Case $hListBox, $hWndListBox Switch $iCode Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box ;BAD: Returns an array ConsoleWrite("Item "& _GUICtrlListBox_GetCurSel($hListBox)&@CRLF) ;NO CHANGE Local $selItems = _GUICtrlListBox_GetSelItemsText($hWndListBox) Local $selItems = _GUICtrlListBox_GetSelItemsText($hListBox) ConsoleWrite("Array size: " & UBound($selItems) & @CRLF) ConsoleWrite("Number of items: " & $selItems[0] & @CRLF) ConsoleWrite("Array: " & $selItems & @CRLF) ;BLOCKS _ArrayDisplay($selItems) ;BAD ConsoleWrite("Selected item: " & $selItems[1] & @CRLF) ; Array variable has incorrect number of subscripts or subscript dimension range exceeded.: EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Here's the output: -
Double click on an item in a list
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
Thanks. Too bad catching double-clicks on a list requires handling messages outside the GUi loop. -- Edit: Out of curiosity, what's the difference between $WM_COMMAND and $WM_NOTIFY, and which function is recommended to handle double-clicks on a list? GUIRegisterMsg($WM_COMMAND, "WM_COMMAND"); Needed to handle double-click on list widget GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;this allows you to capture all window messages. Global $DoubleClicked = False Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ;there are a lot of window messages and they fire all the time. ;We'll need to filter the ones we want. Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) ;this should give us the handle of the control that triggered the event. $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $List1 ;Only react to messages from the $List1 Switch $iCode ;check the type of message Case $LBN_DBLCLK ;double click message ConsoleWrite("In WM_NOTIFY, double-click" & @CRLF) EndSwitch EndSwitch ; if you don't return $GUI_RUNDEFMSG, or 0 the rest of the messages won't be handles as they should. Return $GUI_RUNDEFMSG EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($List1) Then $hWndListBox = GUICtrlGetHandle($List1); BUG? $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) $iCode = BitShift($iwParam, 16) Switch $hWndFrom Case $hWndListBox Switch $iCode Case $LBN_DBLCLK If Not $DoubleClicked Then $DoubleClicked = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc -
How to read Data from my GPS module?
littlebigman replied to AlainB's topic in AutoIt General Help and Support
I don't understand why it's such a problem adding to a thread that dealt with the same problem, or close enough to not justify creating a new one, but I can live with that. -
Double click on an item in a list
littlebigman replied to tommeke228's topic in AutoIt General Help and Support
I generally don't like creating a new thread when a similar problem has been asked before — and when I do create a new thread, some people complain just as well. -
Double click on an item in a list
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
From what I can tell, it misinterprets the very first double-click a single click, and when, later, single-clicking, it reports the first one as a double-click: Edit: Could it be the GUI loop is called before the WM_COMMAND function, making the "If $DoubleClicked" test unreliable? Edit: Apparently, it's not a good idead to mix code in the GUI loop and the WM_COMMAND function. taiete's code above works OK. #include <WindowsConstants.au3> #include <GUIListBox.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 449, 279, 114) $List1 = GUICtrlCreateList("", 0, 52, 622, 396) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND"); Needed to handle double-click on list widget Global $DoubleClicked = False ;Used to know if user double-clicked #EndRegion ### END Koda GUI section ### Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($List1) Then $hWndListBox = GUICtrlGetHandle($List1); BUG? What if $List1 IS a handle? $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) $iCode = BitShift($iwParam, 16) Switch $hWndFrom Case $hWndListBox Switch $iCode Case $LBN_DBLCLK If Not $DoubleClicked Then $DoubleClicked = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG ;Makes no difference EndFunc GUICtrlSetData($List1, "item1") GUICtrlSetData($List1, "item2") While True $nMsg = GUIGetMsg() Switch $nMsg Case $List1 If $DoubleClicked Then ConsoleWrite("Double Clicked ") $DoubleClicked = False Else ConsoleWrite("Single click ") EndIf ConsoleWrite(GUICtrlRead($List1) & @CRLF) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd -
How to read Data from my GPS module?
littlebigman replied to AlainB's topic in AutoIt General Help and Support
For those who just need to compute the distance between two locations in lat+lon, and in meters instead of km: #include <Math.au3> Func _atan2($y, $x) Return (2 * ATan($y / ($x + Sqrt($x * $x + $y * $y)))) EndFunc Func _DistanceInMeters($Lat1,$Lon1,$Lat2,$Lon2) Local $Distance ;Calculating the distance Local $R = 6378.1 ;Earth radius in Km (Possibly the value used by Google to calculate distances) Local $dLat = _Radian($lat2-$lat1) Local $dLon = _Radian($lon2-$lon1) Local $lat11 = _Radian($lat1) Local $lat22 = _Radian($lat2) Local $a = sin($dLat/2) * sin($dLat/2) + sin($dLon/2) * sin($dLon/2) * cos($lat11) * cos($lat22) Local $c = 2 * _atan2(sqrt($a), sqrt(1-$a)); $Distance = $R * $c $Distance = Round($Distance,2) * 1000 ;Round to two decimal places, and convert to meters Return $Distance EndFunc $distance =_DistanceInMeters($REF_LAT, $REF_LON, $GpsLatitude_Decimal, $GpsLongitude_Decimal) ConsoleWrite(StringFormat("CurrLat %s CurrLon %s Distance %s" & @CRLF,$GpsLatitude_Decimal, $GpsLongitude_Decimal,$distance)) -
To catch a double-click on a plain list (not a listview), is a GUIRegisterMsg() + WM_COMMAND() required, or can it be done more simply within the while loop? While True $nMsg = GUIGetMsg() Switch $nMsg ;how to catch double-clicks? Case $List1 ConsoleWrite("Clicked on listbox: " & GUICtrlRead($List1)& @CRLF) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd --- Edit: It misses some double-clicks. Am I doing it wrong? #include <GDIPlus.au3> #include <File.au3> #include <GDIPlus.au3> #include <Math.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 449, 279, 114) $List1 = GUICtrlCreateList("", 0, 52, 622, 396) $Label1 = GUICtrlCreateLabel("Label1", 8, 8, 428, 31) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Global $DoubleClicked = Null GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($List1) Then $hWndListBox = GUICtrlGetHandle($List1) $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) $iCode = BitShift($iwParam, 16) Switch $hWndFrom Case $hWndListBox Switch $iCode Case $LBN_DBLCLK If Not $DoubleClicked Then $DoubleClicked = 1 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc While True $nMsg = GUIGetMsg() Switch $nMsg Case $List1 ;ConsoleWrite("Clicked on listbox: " & GUICtrlRead($List1)& @CRLF) If $DoubleClicked Then $filename = GUICtrlRead($List1) ConsoleWrite("Double Clicked! " & $filename & @CRLF) ;Fails if filename contains spaces RunWait(@comspec & ' /c start ' & $filename, '', @SW_HIDE) $DoubleClicked = 0 EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
-
Running lengthy task in GUI?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
Thank you! #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 449, 279, 114) $List1 = GUICtrlCreateList("", 0, 52, 622, 396) $Label1 = GUICtrlCreateLabel("Label1", 8, 8, 428, 31) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func ProcessGUI() Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch EndFunc For blah ProcessGUI() ;to keep the GUI responsive ;do stuff Next WinSetTitle($Form1, "", "Done!") ;So the app doesn't close after the for loop While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd -
Running lengthy task in GUI?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
The for/next loop is a task that can take minutes, and will just add some items to the listbox. That's why I need a way to keep the GUI responsive, and keep it open once I'm out of the loop. -
What UDF to work with XML/HTML files?
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
Thanks for the update. -
Running lengthy task in GUI?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
Not sure how I can get control back to the GUI once the code was launched with ShellExecute(). I'll read the examples to fork. -
Running lengthy task in GUI?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
Thanks. What files do I need, and would you have a "Hello, World!" I could try fast and see if it solves the problem? Example_Fork_Broadcast.au3 Example_Fork_BroadcastWithFMIPC.au3 Example_Fork_Events.au3 Example_Fork_FileMonitor.au3 Example_Fork_FileMonitor_NoGui.au3 Example_Fork_Reciever.au3 Example_Fork_TCP.au3 FMIPC.au3 Fork.au3 ForkDbgAid.au3 ForkDbgWr.au3 MailSlot.au3 -
Running lengthy task in GUI?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
The GUI still closes: For blah $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit ExitLoop EndSwitch ;do stuf Next ;gone! Alternatively, is there some Refresh() command that I could call within the GUI loop to keep the application responsive? -
Running lengthy task in GUI?
littlebigman replied to littlebigman's topic in AutoIt GUI Help and Support
Thanks. But then the GUI closes when the code exits the for/next loop, while I need to keep it open to display data I found within the loop. How would I prevent this? For blah $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch ;do stuf Next ;gone! -
What UDF to work with XML/HTML files?
littlebigman replied to littlebigman's topic in AutoIt General Help and Support
Indeed, while learning about mLipok's XML UDF, I wondered what its benefit is compared to working with the MSXML COM object directly because the calls looked so similar. As for converting XML to JSON with jq.exe: Besides adding a second binary to the mix, I have a preliminary question: When reading data, is there a way to know whether the value came from the node's text or one of its attributes? If I need to then write data to a new file, I must know. For example: <trkpt lat="48.81782" lon="2.24906"> <ele>123</ele> <time>Dummy time</time> </trkpt> If "48.81782", "2.24906", "123", and "Dummy time" all end up in the array, the only way to tell them apart is by keeping this info in the source (eg. lat = attribute, time = value).