 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Mon Mar 01, 2010 12:05 pm Post subject: Gui freezing while UrlDownloadToFile is active |
|
|
This problem is really annoying me and i cant figure out a way to solve it
A very important part of my script is using urldownloadtofile then loads the xml with xpath,retrieves the sections and updates the gui controls with the new info
while this is happening the rest of my gui becomes unresponsive and i cant do anything...i would really like to be able to do other things on my main gui while the second gui is doing its thing
i have searched the forum and seen some topics about createthread but its none was working and from what i have read its not reliable enough
so is there any way to do this?
i have also read about IPC but i really dont want to use 2 scripts
sorry about no code..but i think its too big to post _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Mon Mar 01, 2010 7:20 pm Post subject: |
|
|
I had to deal with the same problem once. My (absolutely not fashion) solution was this:
1) Main script contains a timer that checks (and deletes) a file called INFO_TO_SHOW (or anything like that). Whenever the file exists, the new info is retireved and shown.
2) Main script also creates a file called FILE_TO_DL when I click the download button.
3) Secondary script also contains a timer. This one is for FILE_TO_DL, so it can retireve the file and perform the download without messing with the main script.
4) Secondary script gathers desired info from downloaded file and creates a file called INFO_TO_SHOW.
I hope you understand the method and may be able to adapt it. _________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Mon Mar 01, 2010 7:40 pm Post subject: |
|
|
i have tried a similar method to what you said but i didnt really like it
as i said i dont want to use 2 scripts to do this
i would prefer everything in one script if possible
thanks for your reply anyway  _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Mon Mar 01, 2010 7:45 pm Post subject: |
|
|
A functioning rudimentary script on your part would be helpful.
What kind of things are you trying to do with the GUI during d/l ?
This is a contrived example of one script. Please notice the line
; ****** some improvment in response in the "PIC" routine if the following 3 lines are enabled
| Code: | ;Gui, -SysMenu ; no system menu, min/max buttons
;Gui -Caption ; no border
Gui, Margin ,0,0
;Gui, Margin ,20,20
gui, add, button, w200 gurl, press for url down
gui, add, button, w200 h200 vpic gpic, click for cursor location and file size
gui, show, x1300
return
pic:
mousegetpos,x,y
FileGetSize, size1, map1.jpg
size1+=0 ; ensure result is not blank
loop, 100000
z++
tooltip %A_GuiEvent% X%X% Y%Y%`n%size1%, x+100
return
url:
; ****** some improvment in response in the "PIC" routine if the following 3 lines are enabled
;settimer url_down, 100
;return
;url_down:
size1=0
msgbox url d/l press OK to start d/l
fred++
UrlDownloadToFile, http://collections.mun.ca/maps/G_3400_1690_M6_MAP.jpg , map1.jpg
return
f12::reload
esc::exitapp
|
|
|
| Back to top |
|
 |
answer4u Guest
|
Posted: Mon Mar 01, 2010 7:51 pm Post subject: |
|
|
Have you tried a Http Request rather than URLDownLoadtoFile? Here's an example using AHKL & COM_L: | Code: | url := "http://www.google.com"
pwhr := COM_CreateObject( "WinHttp.WinHttpRequest.5.1" ) ; Instantiate a WinHttpRequest object.
pwhr.Open( "GET", url ) ; Initialize an HTTP request.
pwhr.Send() ; Send the HTTP request.
text := pwhr.ResponseText ; get the response text.
FileAppend, %text%, URLDownLoad.htm |
|
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Mon Mar 01, 2010 8:13 pm Post subject: |
|
|
| Leef_me wrote: |
What kind of things are you trying to do with the GUI during d/l ?
|
well this is what my script looks like :
sorry cant post code now...the script is too big
everytime i click on a movie in my listview it automatically downloads info and updates the second gui (it downloads 2 xml files and the cover)
during this time i want to be able to do everything else on my main gui...like scrolling the listview..searching...modifying entries etc
| answer4u wrote: | | Here's an example using AHKL & COM_L: |
i think ahk l would break my script so i prefer staying on "normal" ahk _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
answer4u Guest
|
Posted: Mon Mar 01, 2010 8:34 pm Post subject: |
|
|
Ok, here'd be an example using normal AHK with the normal COM library: | Code: | url := "http://www.google.com"
COM_Init()
pwhr := COM_CreateObject( "WinHttp.WinHttpRequest.5.1" )
COM_Invoke( pwhr, "Open", "GET", url )
COM_Invoke( pwhr, "Send" )
text := COM_Invoke( pwhr, "ResponseText" )
COM_Release( pwhr ), COM_Term()
FileAppend, %text%, URLDownLoad.htm |
|
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Mon Mar 01, 2010 9:15 pm Post subject: |
|
|
| answer4u wrote: | Ok, here'd be an example using normal AHK with the normal COM library: | Code: | url := "http://www.google.com"
COM_Init()
pwhr := COM_CreateObject( "WinHttp.WinHttpRequest.5.1" )
COM_Invoke( pwhr, "Open", "GET", url )
COM_Invoke( pwhr, "Send" )
text := COM_Invoke( pwhr, "ResponseText" )
COM_Release( pwhr ), COM_Term()
FileAppend, %text%, URLDownLoad.htm |
|
this worked for the xml files but not for the cover
but will this make a big difference? because my gui was still unresponsive _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Tue Mar 02, 2010 10:00 am Post subject: |
|
|
| Code: |
GETMOVIEINFO:
;================= reset controls
GuiControl %$MovieInfoGui%: ,$ExpCover,
GuiControl %$MovieInfoGui%: Move, $ExpCover, w210 h230
GuiControl %$MovieInfoGui%: Text, $ExpTitle, Downloading Info...
GuiControl %$MovieInfoGui%: Text, $ExpRating,
GuiControl %$MovieInfoGui%: Text, $ExpRelease,
GuiControl %$MovieInfoGui%: Text, $ExpRuntime,
GuiControl %$MovieInfoGui%: Text, $ExpBudget,
GuiControl %$MovieInfoGui%: Text, $ExpPlot,
GuiControl %$MovieInfoGui%: Text, $ExpCast,
$TMDbHomepage := ""
$TMDbTrailer := ""
Sleep 200
;=================
LV_GetText($MovieToGetInfo,LV_GetNext("C"),1), LV_GetText($IMDbLink,LV_GetNext("C"),3) ;get movie title and imdblink
;================= delete the file if it exists already
IFExist % $TMDbXMLFile
FileDelete % $TMDbXMLFile
;================= check internet connection
IF NOT ConnectedToInternet() {
Notify("Internet Connection - ERROR", "You are not connected to the internet!", "5", "GC=White TC=Black MC=Black IN=13", $ResDLL)
GuiControl %$MovieInfoGui%: Text, $ExpTitle, No Info Found...
RETURN
}
;================= if imdblink does not exist do normal search
IF $IMDbLink =
{
UrlDownloadToFile, http://api.themoviedb.org/2.1/Movie.search/en/xml/%$TMDbAPIKey%/%$MovieToGetInfo%, %$TMDbXMLFile%
IF not XPath_Load(xml, $TMDbXMLFile)
Notify("Xpath - ERROR", "Xml File could Not be Loaded!", "5", "GC=White TC=Black MC=Black IN=13", $ResDLL)
FileDelete % $TMDbXMLFile
$TMDbTitle := XPath(xml, "/OpenSearchDescription/movies/movie[1]/name/text()")
$TMDbID := XPath(xml, "/OpenSearchDescription/movies/movie[1]/id/text()")
$TMDbCover := XPath(xml, "/OpenSearchDescription/movies/movie[1]/images/image[@size=""mid""]/@url/text()")
$TMDbRating := XPath(xml, "/OpenSearchDescription/movies/movie[1]/rating/text()")
$TMDbRelease := XPath(xml, "/OpenSearchDescription/movies/movie[1]/released/text()")
$TMDbPlot := XPath(xml, "/OpenSearchDescription/movies/movie[1]/overview/text()")
;================= movie.getinfo by id
UrlDownloadToFile, http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/%$TMDbAPIKey%/%$TMDbID%, %$TMDbXMLFile%
DownloadXML_MovieGetInfo = http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/%$TMDbAPIKey%/%$TMDbID%
DownloadFile(DownloadXML_MovieGetInfo)
IF not XPath_Load(xml, $TMDbXMLFile)
Notify("Xpath - ERROR", "Xml File could Not be Loaded!", "5", "GC=White TC=Black MC=Black IN=13", $ResDLL)
FileDelete % $TMDbXMLFile
$TMDbRuntime := XPath(xml, "/OpenSearchDescription/movies/movie[1]/runtime/text()")
$TMDbBudget := XPath(xml, "/OpenSearchDescription/movies/movie[1]/budget/text()")
$TMDbCast := XPath(xml, "/OpenSearchDescription/movies/movie[1]/cast/person[@job=""Actor""]/@name/text()")
$TMDbHomepage := XPath(xml, "/OpenSearchDescription/movies/movie[1]/homepage/text()")
$TMDbTrailer := XPath(xml, "/OpenSearchDescription/movies/movie[1]/trailer/text()")
} ELSE {
;================= else do search by imdb id
RegExMatch($IMDbLink, "/title/\K[^/]+", $IMDbID)
UrlDownloadToFile, http://api.themoviedb.org/2.1/Movie.imdbLookup/en/xml/%$TMDbAPIKey%/%$IMDbID%, %$TMDbXMLFile%
IF not XPath_Load(xml, $TMDbXMLFile)
Notify("Xpath - ERROR", "Xml File could Not be Loaded!", "5", "GC=White TC=Black MC=Black IN=13", $ResDLL)
FileDelete % $TMDbXMLFile
$TMDbTitle := XPath(xml, "/OpenSearchDescription/movies/movie/name/text()")
$TMDbID := XPath(xml, "/OpenSearchDescription/movies/movie/id/text()")
$TMDbCover := XPath(xml, "/OpenSearchDescription/movies/movie/images/image[1][@size=""mid""]/@url/text()")
$TMDbRating := XPath(xml, "/OpenSearchDescription/movies/movie/rating/text()")
$TMDbRelease := XPath(xml, "/OpenSearchDescription/movies/movie/released/text()")
$TMDbPlot := XPath(xml, "/OpenSearchDescription/movies/movie/overview/text()")
;================= movie.getinfo by id
UrlDownloadToFile, http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/%$TMDbAPIKey%/%$TMDbID%, %$TMDbXMLFile%
IF not XPath_Load(xml, $TMDbXMLFile)
Notify("Xpath - ERROR", "Xml File could Not be Loaded!", "5", "GC=White TC=Black MC=Black IN=13", $ResDLL)
FileDelete % $TMDbXMLFile
$TMDbRuntime := XPath(xml, "/OpenSearchDescription/movies/movie/runtime/text()")
$TMDbBudget := XPath(xml, "/OpenSearchDescription/movies/movie/budget/text()")
$TMDbCast := XPath(xml, "/OpenSearchDescription/movies/movie/cast/person[@job=""Actor""]/@name/text()")
$TMDbHomepage := XPath(xml, "/OpenSearchDescription/movies/movie/homepage/text()")
$TMDbTrailer := XPath(xml, "/OpenSearchDescription/movies/movie/trailer/text()")
}
;================= update controls with info
UrlDownloadToFile, %$TMDbCover%, %$TMDbTempCover%
GuiControl %$MovieInfoGui%: ,$ExpCover, % $TMDbTempCover
FileDelete % $TMDbTempCover
$TitleText := % (($TMDbTitle = "") ? ("No Info Found...") : ($TMDbTitle))
GuiControl %$MovieInfoGui%: Text, $ExpTitle, % $TitleText
GuiControl %$MovieInfoGui%: Text, $ExpRating, % $TMDbRating
GuiControl %$MovieInfoGui%: Text, $ExpRelease, % $TMDbRelease
$RuntimeText := (($TMDbTitle = "") ? ("") : ($TMDbRuntime " min"))
GuiControl %$MovieInfoGui%: Text, $ExpRuntime, % $RuntimeText
$TMDbBudgetNew := "$" ThousandsSep($TMDbBudget)
$BudgetText := (($TMDbTitle = "") ? ("") : ($TMDbBudgetNew))
GuiControl %$MovieInfoGui%: Text, $ExpBudget, % $BudgetText
GuiControl %$MovieInfoGui%: Text, $ExpPlot, % $TMDbPlot
GuiControl %$MovieInfoGui%: Text, $ExpCast, % $TMDbCast
RETURN
|
this is the part that downloads the info and updates the control
it would be nice if the whole thing could be launched in another thread
also is there an alternative to urldownloadtofile like the com example posted that downloads all kinds of files? _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
answer4u Guest
|
Posted: Tue Mar 02, 2010 1:46 pm Post subject: |
|
|
| SKANs thread might interest you. |
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Tue Mar 02, 2010 3:14 pm Post subject: |
|
|
thank you!
its not perfect but yeah the gui is much more responsive now
so its definately better than urldownloadtofile _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Tue Mar 02, 2010 4:10 pm Post subject: |
|
|
httpQuery may be of your interest as well.
(see example 3) _________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Tue Mar 02, 2010 4:21 pm Post subject: |
|
|
| MasterFocus wrote: | httpQuery may be of your interest as well.
(see example 3) |
i already tried it..i think i like SKANS method better _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Tue Mar 02, 2010 4:25 pm Post subject: |
|
|
| Delusion wrote: | | MasterFocus wrote: | httpQuery may be of your interest as well.
(see example 3) |
i already tried it..i think i like SKANS method better |
Just pointing it out since I was trying to use SKAN's method yesterday but somehow it failed inside a Loop so I had to try something else. _________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|