Gianni Posted April 19, 2014 Share Posted April 19, 2014 (edited) just for fun a simple interface to http://mp3skull.com expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiEdit.au3> #include <GuiTab.au3> #include <IE.au3> Opt("GUIOnEventMode", 1) ; some global variables Global $TabBrowser = False ; browser in a TabItem If $TabBrowser Then Global $oIE = _IECreateEmbedded() Else Global $oIE = _IECreate("http://mp3skull.com", 0, 0, 0, 0) ; run browser hidden EndIf Global $aLV_Click_Info Global $oForm Global $oInputFile Global $oQuery Global $oLinks = "" Local $Form1 = GUICreate("(web) Juke Box - (experimental)", 665, 545) GUISetOnEvent($GUI_EVENT_CLOSE, "Bye") Local $Label1 = GUICtrlCreateLabel("Type song title or artist to search and hit Enter", 8, 5, 650, 17) Global $Input1 = GUICtrlCreateInput("", 8, 24, 650, 21) GUICtrlSetTip(-1, "Insert a title here and hit 'Enter'") Global $StopButton = GUICtrlCreateButton("Stop playing music", 8, 522, 650, 21) GUICtrlSetOnEvent($StopButton, "StopButton") GUICtrlSetTip(-1, "Stop playing music") Global $compilation = GUICtrlCreateListView("Songs found", 8, 54, 650, 260) GUICtrlSetTip(-1, "DoubleClick on a link to play") _GUICtrlListView_SetColumnWidth($compilation, 0, 645) _GUICtrlListView_SetExtendedListViewStyle($compilation, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ; show grid; select whole row ; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Local $PageControl1 = GUICtrlCreateTab(8, 320, 650, 200);Creates a "Tab control" for the GUI. ; Global $TabSheet1 = GUICtrlCreateTabItem("Info") ; First tab Local $Info = "hello" & @CRLF & "Type song title or artist name" & @CRLF & "in the InputBox at top and hit 'Enter'" & _ @CRLF & "then DoubleClick on list to play music" & @CRLF & @CRLF & "have fun." Local $InfoBox = GUICtrlCreateEdit($Info, 13, 345, 638, 168, $ES_READONLY) GUICtrlSetFont(-1, 18, 0, 0, "Lucida Console") GUICtrlSetBkColor(-1, 0xEEEEEE) ; Color of background GUICtrlSetColor(-1, 0xFF0000) ; color of font ; Global $TabSheet3 = GUICtrlCreateTabItem("Activity log") ; second tab Global $crtLog1 = GUICtrlCreateEdit("awaiting commands" & @CRLF, 13, 345, 638, 168);,$ES_READONLY) ;Sets the font for a control. GUICtrlSetFont(-1, 9, 0, 0, "Lucida Console") GUICtrlSetBkColor(-1, 0x000000) ; Color of background (black) GUICtrlSetColor(-1, 0x00FF00) ; color of font (green) ; If $TabBrowser Then Global $TabSheet2 = GUICtrlCreateTabItem("Browser") ; third tab GUICtrlCreateObj($oIE, 13, 345, 638, 168) _IENavigate($oIE, "http://mp3skull.com/") _IE_ref_refresh() EndIf ; GUICtrlCreateTabItem("") ; end of tabitem definitions GUISetState(@SW_SHOW) ; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ; ; Setup the "Enter" key management Global $getEnter = GUICtrlCreateDummy() GUICtrlSetOnEvent(-1, "gotEnter") ; to call the function gotEnter() when Dummy control receives an "Enter" --+ Global $a_AccelKeys[1][2] = [["{ENTER}", $getEnter]] ; send the "Enter" keypresses to the Dummy control | GUISetAccelerators($a_AccelKeys) ; | ; | Func gotEnter() ; Here we manage the enter key <--------------------------------+ LogPrint("-> enter pressed somewhere" & @CRLF) If _GuiCtrlGetFocus($Form1) = $Input1 Then ; was cursor in control $Input1? _MyEnterFunc() ; if yes then call my enter function Else ; prosecute ahead the "Enter" key to the proper control GUISetAccelerators("") ControlSend($Form1, "", _GuiCtrlGetFocus($Form1), "{ENTER}") GUISetAccelerators($a_AccelKeys) EndIf EndFunc ;==>gotEnter Func _GuiCtrlGetFocus($hGui = "") ; Retrieves the internal handle of the control with the focus Local $InputID = ControlGetHandle($hGui, "", ControlGetFocus($hGui)) Return _ControlGetGuiID($InputID) ; --------------------------+ EndFunc ;==>_GuiCtrlGetFocus ; | Func _ControlGetGuiID($hCtrl) ; Transforms from Handle to ID <----+ Local $Result = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hCtrl) If @error = 0 Then Return $Result[0] Return SetError(1, 0, '') EndFunc ;==>_ControlGetGuiID ; GUIRegisterMsg($WM_NOTIFY, "_Check_Click") ; Register a user defined function for a known Windows Message ID (WM_MSG). ---------+ ; | ; WM_NOTIFY event handler for click example: http://www.autoitscript.com/forum/topic/143900-listview-onclick/#entry1013670 <---+ Func _Check_Click($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Local $hList = GUICtrlGetHandle($compilation) ; $fDblClk = False If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then ; event is from $hList and it is a $NM_CLICK ; is a Click $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList) If $aLV_Click_Info[0] <> -1 Then LogPrint("Click on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF) Else LogPrint("Click on empty" & @CRLF) EndIf EndIf ; what follows will check if it is a doubleClick and if is comming from the listview If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then ; event is from $hList and it is a $NM_DBLCLK ; is a DoubleClick $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList) If $aLV_Click_Info[0] <> -1 Then LogPrint("DoubleClick on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF) Else LogPrint("DoubleClick on empty" & @CRLF) EndIf SoundPlay("") SoundPlay(_GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0])) ControlFocus("", "", $Input1) ; set focus on Input1 EndIf Return ; $GUI_RUNDEFMSG EndFunc ;==>_Check_Click ControlFocus("", "", $Input1) ; set focus on Input1 ; ---- MAIN LOOP ---- While 1 Sleep(1000) WEnd ; ---- END MAIN LOOP ---- Func _MyEnterFunc() ; This function is called everytime the "Enter" key is pressed in the $Input1 control Local $qry = _GUICtrlEdit_GetText($Input1) LogPrint('received "' & $qry & '" passing request to browser.....' & @CRLF) _IE_ref_refresh() _IEFormElementSetValue($oInputFile, $qry) _IEAction($oQuery, "click") Do Until Not _IEPropertyGet($oIE, "busy") LogPrint("Query sent using http://mp3skull.com" & @CRLF) _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($compilation)) $oLinks = "" LogPrint("wait response for 3 seconds" & @CRLF) Sleep(3000) $oLinks = _IELinkGetCollection($oIE) Local $iNumLinks = @extended LogPrint("Links loaded " & @CRLF) _IEAction($oIE, "stop") Local $row = 0 If $iNumLinks Then For $oLink In $oLinks If StringRight($oLink.href, 4) = ".mp3" Then _GUICtrlListView_AddItem($compilation, $oLink.href, $row) $row += 1 EndIf Next EndIf LogPrint("ListView populated with " & $row & " songs" & @CRLF) ControlFocus("", "", $Input1) ; set focus on Input1 EndFunc ;==>_MyEnterFunc Func StopButton() SoundPlay("") ; Stop playing music EndFunc ;==>StopButton Func LogPrint($line) ; _GUICtrlTab_ActivateTab($PageControl1,1) _GUICtrlTab_SetCurFocus($PageControl1, 1) If StringLen(GUICtrlRead($crtLog1)) > 25000 Then ; Max Len of a CtrlBox is 30000 char _GUICtrlEdit_SetText($crtLog1, StringRight(GUICtrlRead($crtLog1), 20000)) ; short the content of CtrlBox to 20000 char EndIf _GUICtrlEdit_AppendText($crtLog1, @HOUR & ":" & @MIN & ":" & @SEC & " " & $line) EndFunc ;==>LogPrint Func _IE_ref_refresh() ; http://mp3skull.com ; <form id="f1" method="GET" action="/search.php" $oForm = _IEFormGetObjByName($oIE, "f1") ; <input id="sfrm" type="text" style="font-size:18px; vertical-align:middle; width:470px;" value="" autocomplete="off" name="q"></input> $oInputFile = _IEFormElementGetObjByName($oForm, "sfrm") ; <input id="search_button" type="submit" style="font-size:18px; vertical-align:middle;" value="Search"></input> $oQuery = _IEFormElementGetObjByName($oForm, "search_button") EndFunc ;==>_IE_ref_refresh Func Bye() _IEQuit($oIE) Exit EndFunc ;==>Bye EDIT: bug removed from listing (thanks to >UEZ) Edited April 19, 2014 by PincoPanco xan and Exit 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
lorenkinzel Posted April 19, 2014 Share Posted April 19, 2014 Today was not a good day for me; yet you managed to fix it! So, how did you know? (I.E. I really like your script) Gotta go, songs to hear....... Link to comment Share on other sites More sharing options...
UEZ Posted April 19, 2014 Share Posted April 19, 2014 (edited) I got a crash (LogPrint("ListView populated with " & $row & " songs" & @CRLF) because declaration of $row is in the If/then loop which wasn't executed. Suggestion: move line 146 (Local $row = 0) before the If line just above. Br, UEZ Edited April 19, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Gianni Posted April 19, 2014 Author Share Posted April 19, 2014 (edited) @ lorenkinzelthanks for the appreciation I got a crash (LogPrint("ListView populated with " & $row & " songs" & @CRLF) because declaration of $row is in the If/then loop which wasn't executed. Suggestion: move line 146 (Local $row = 0) before the If line just above. Br, UEZ Opss.... you are right. (now corrected in first post) Thanks! Edited April 19, 2014 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
xan Posted April 21, 2014 Share Posted April 21, 2014 Very good! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now