AutoHotkey Community

It is currently May 27th, 2012, 4:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: March 1st, 2010, 1:05 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
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

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 8:20 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
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.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 8:40 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
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 :)

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 8:45 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
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
:arrow: ; ****** 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 8:51 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 9:13 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
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

Image

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

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 9:34 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2010, 10:15 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
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

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2010, 11:00 am 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
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?

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2010, 2:46 pm 
SKANs thread might interest you.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2010, 4:14 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
answer4u wrote:
SKANs thread might interest you.


thank you!

its not perfect but yeah the gui is much more responsive now
so its definately better than urldownloadtofile

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2010, 5:10 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
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.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2010, 5:21 pm 
Offline
User avatar

Joined: July 17th, 2008, 12:58 am
Posts: 270
MasterFocus wrote:
httpQuery may be of your interest as well.
(see example 3)


i already tried it..i think i like SKANS method better

_________________
QuickSubs | Popcorn Movie Db
All my scripts are just in AutoHotkey v1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 2nd, 2010, 5:25 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
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.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Mickers, rbrtryn and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group