Sign in to follow this  
Followers 0
wisem2540

ControlsetText and GUICtrlSetData not working if window is not active

31 posts in this topic

I have a GUI with a progess bar.  I would like to be able to download while hidden.  I have -h parameter defined, and that works fine.  But the downloads do not continue because the script is waiting on CONTROLSETTEXT to change the status to IDLE before it starts the next download.  How can I make this work properly if the window is hidden?

Share this post


Link to post
Share on other sites



Is this GUI one in your script or is it an external application's? If it's a GUI in your script, use GUICtrlSetData instead of ControlSetText. The best thing to do would be to tell us what you're automating and post a reproducer script that demonstrates the problem.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

wisem2540,

I asked this very question to a Dev while ago and apparently the following is written in the core code:

 

"// If the GUI is hidden then we don't want to trigger any messages because we may be modifiying things

// via the script when hidden"

That referred to hiding the GUI using GUISetState. You might like to try using WinSetState - although I must warn you that I was specifically warned that this was not a good idea. So on your head be it! ;)

M23


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

Melba,

So you are saying I should put logic it to not trigger these commands if the window is hidden?  My ultimate goal would be to have the progress bar and text update in the background, so that if someone did restore the window, the most current data would be there.

I will test Brewmans idea in the mean time.  Im not sure I can update a label without using Settext.

Share this post


Link to post
Share on other sites

If it's your label, you don't need settext at all, use SetData.

BTW, you don't have to hide the window you can put it somewhere off screen that it can't be seen but not "hidden". 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Brewman,

Your suggestion of using SetData works beautifully!  thank you so much.  Seems like I learn something new about autoit every day that shows me there are more effective ways of doing things. 

I do have another quick question I hope I can ask in this thread.  While a download is happening, I am unable to exit the GUI, almost like it doesnt accept any commands.  Basically, I am using a FOR loop and looping through an array of Download Links.  Once I am in this loop, if I decide I want to cancel, I have to forcefully quit.

Share this post


Link to post
Share on other sites

Without seeing what you're doing I'd be guessing, and I'm not in a guessing mood today. ;)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

$selected ;Set URL
$folder = $Save ;Set folder
$hInet = InetGet($url, $save & "\" & $Filename, 1, 1) ;Forces a reload from the remote site and return immediately and download in the background
$FileSize = InetGetSize($url) ;Get file size
While Not InetGetInfo($hInet, 2) ;Loop until download is finished
Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    GUICtrlSetData ($Status, "Downloading"); sets text while downloading
   GUICtrlSetData ($Movieindicator, $Filename); sets text while downloading
    Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
    $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
    GUICtrlSetData($progress, $pct)
WEnd
GUICtrlSetData($progress, 0); Download complete, set progress to zero
GUICtrlSetData ($MovieIndicator, " "); Sets text to blank after finished
GUICtrlSetData ($Status, "Idle"); Sets text back to "idle" after finished

I looked the code over again, and I believe its because I am in this while loop....

So im using the loop to calculate the percentage and update the progress bar, but when im sort of dead in the water while the download runs.

Edited by wisem2540

Share this post


Link to post
Share on other sites

Look in the help file for AdLibRegister, use a function to periodically update the progress bar, which won't involve the While loop to do it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

In the function I would only need...

 $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
    GUICtrlSetData($progress, $pct)

correct?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I made my function like this....seems to work

Func Prog()

if Not InetGetInfo($hInet, 2) Then ;if download is running
Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    GUICtrlSetData ($Status, "Downloading"); sets text while downloading
   GUICtrlSetData ($Movieindicator, $Filename); sets text while downloading
    Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
    $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
    GUICtrlSetData($progress, $pct)
Else; download stopped
GUICtrlSetData($progress, 0); Download complete, set progress to zero
GUICtrlSetData ($MovieIndicator, " "); Sets text to blank after finished
GUICtrlSetData ($Status, "Idle"); Sets text back to "idle" after finished
EndIf
EndFunc
Edited by wisem2540

Share this post


Link to post
Share on other sites

Sounds like I spoke too soon.  Now i am in a situation where if I just download one file, things work fine.  But I need the program to wait until the download is finished before moving on to the next one in the array.  So, The adlib function does work, but I need something in the for loop to cause a wait before it starts the next one.  I tried Do Sleep Until $Progress = 0 but that does not seem to work.

Share this post


Link to post
Share on other sites

Use AdLibUnRegister to temporarily disable the function, then reregister the AdLib once you start downloading again.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Im sorry, I dont see how that would solve the problem.

Example....

For $x=1 to 10

Download File

Adlibregister "Prog" ; Check progress





Func Prog()

if Not InetGetInfo($hInet, 2) Then ;if download is running
Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    GUICtrlSetData ($Status, "Downloading"); sets text while downloading
   GUICtrlSetData ($Movieindicator, $Filename); sets text while downloading
    Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
    $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
    $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
    GUICtrlSetData($progress, $pct)
Else; download has stopped
GUICtrlSetData($progress, 0); Download complete, set progress to zero
GUICtrlSetData ($MovieIndicator, " "); Sets text to blank after finished
GUICtrlSetData ($Status, "Idle"); Sets text back to "idle" after finished
EndIf
EndFunc

I have even tried to sleep 15sec in the prog function if the download is still going, just to see if it works.  Can you please elaborate?  Im not understanding.  Once it does the Adlibregister, it moves on through the loop.  It needs to wait until the download is done,  Adding a sleep 5000 after the adlibregister does seem to produce some result,  While it allows for the downloads to loop properly, it still does not allow the GUI to accept commands, so its really no better than the while loop

Edited by wisem2540

Share this post


Link to post
Share on other sites

Seeing tiny snippets of your script is making this far more difficult than it would be if you'd just post the whole thing. I'm trying to alter your script to work the way you would like it to, but without knowing what you're trying to do in the rest of the script makes it extremely tough.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I am hardly as skilled in autoit as some of the more seasoned members, so I would wonder if youd be able to understand the mess that is written here. :)

 

thanks for your help

Edited by wisem2540

Share this post


Link to post
Share on other sites

Brewman,

Did you have any opprotunity to dive into this?

Share this post


Link to post
Share on other sites

Give this a try, it's not the best way of doing it, but it gets rid of a lot of redundant code and some globals that aren't needed. I haven't done much with it other than the downloading of files part as well as the progress bar updating. At least it should give you some ideas for where to take this from here.
 

#Tidy_Parameters=/rel /sf
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=clipart_tractor_trailer.ico
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         Chip Means

 Script Function:
    Used to download trailers from web

#ce ----------------------------------------------------------------------------
; Will return every available movie to a list
#include <Inet.au3>
#include <String.au3>
#include <Array.au3>
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#include <File.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1) ;Set the AutoIt Mode to On Event
Opt("TrayAutoPause", 0) ;Turns off the auto pause when the tray icon is clicked
Opt("TrayMenuMode", 9) ;Remove the default exit, script paused controls from the tray menu
;Read some settings from INI
$Hidetotray = IniRead("Settings.ini", "Settings", "Hide_to_tray_on_start", "no")
$Save = IniRead("Settings.ini", "Settings", "Save", "Error"); download location
;end read ini
FileDelete("TL.txt")
;start create GUI
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Chippy's Trailer Downloader", 994, 442, 19, 147)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
$Beer = GUICtrlCreateButton("Like This App?", 5, 5, 81, 50)
GUICtrlSetOnEvent(-1, "BuyBeer")
$Beer2 = GUICtrlCreateButton("Buy Me a Beer", 550, 5, 81, 50)
GUICtrlSetOnEvent(-1, "BuyBeer")
$Refresh = GUICtrlCreateButton("Refresh", 816, 8, 81, 25)
GUICtrlSetOnEvent(-1, "Refresh")
$ListView1 = GUICtrlCreateListView("", 0, 64, 993, 377)
Local $contextmenu = GUICtrlCreateContextMenu($ListView1)
$idTrailer = GUICtrlCreateMenuItem("Get Trailer", $contextmenu)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $idTrailer = ' & $idTrailer & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
GUICtrlSetOnEvent(-1, "_DownloadFiles")
GUICtrlCreateMenuItem("Open Movie Page", $contextmenu)
GUICtrlSetOnEvent(-1, "GoToMovie")
$Get = GUICtrlCreateButton("Get", 903, 8, 81, 25)
GUICtrlSetOnEvent(-1, "_DownloadFiles")
$All = GUICtrlCreateButton("Download All", 847, 37, 129, 25)
GUICtrlSetOnEvent(-1, "_DownloadFiles")
Global $Progress = GUICtrlCreateProgress(650, 25, 122, 12)
Global $Status = GUICtrlCreateLabel("Idle", 700, 40, 100, 20)
Global $MovieIndicator = GUICtrlCreateLabel("", 635, 5, 180, 20)
$Label1 = GUICtrlCreateLabel("Chippy's Trailer Downloader v1.03  ", 125, 8, 400, 39)
GUICtrlSetFont(-1, 23, 400, 2, "MS Serif")
$TrayMenuRestore = TrayCreateItem("Restore", -1) ;Create a Tray Item option for restoring the GUI
TrayItemSetOnEvent($TrayMenuRestore, "Trayclick") ;Set the OnEvent for the above control
$gTrayMenuLine = TrayCreateItem("", -1) ;Create a Tray Item option for restoring the GUI
TraySetOnEvent(-13, "trayclick") ;Set the OnEvent for when the user double clicks the tray
$cmd = _ArraySearch($CmdLine, "-h")
If $cmd > 0 Or $Hidetotray = "yes" Then ; If Hidden switch or if specified in INI, hide to tray
    GUISetState(@SW_HIDE)
Else
    GUISetState(@SW_SHOW)
EndIf
#endregion ### END Koda GUI section ###
;The following is an autodelete routine
If IniRead("Settings.ini", "Settings", "Enable_Purge", "Error") = 1 Then
    $Days = IniRead("Settings.ini", "Settings", "Days_old", "365")
    $CurrentDirectory = FileChangeDir(IniRead("Settings.ini", "Settings", "Save", "Error")) ; Changes the current working directory to the trailer dir in INI
    If IniRead(@ScriptDir & "\Settings.ini", "Settings", "Show_Warning", "1") = 1 Then
        $msg = MsgBox(4, "Purging is enabled", "Please confirm ONLY trailers are located in " & @WorkingDir & @CRLF & "All files will be purged from here if they are over " & $Days & " Days old" & @CRLF & "Obviously, this could cause serious damage to your system if files other than trailers are removed")
        If $msg = 6 Then IniWrite(@ScriptDir & "\Settings.ini", "Settings", "Show_Warning", "0")
        If $msg = 7 Then Exit
    EndIf
    ;MsgBox(0, "", "Current Working Directory: " & @WORKINGDIR) ; Used for viewing the output of variable
    ; Shows the filenames of all files in the current directory.
    Local $search = FileFindFirstFile("*.*")
    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        If $file = "." Then ContinueLoop ; Blocks output of the root directory "."
        If $file = ".." Then ContinueLoop ; Blocks output of the current directory ".."
        $FileDate = FileGetTime($file, 0, 0)
        $FileDate = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]
        ;MsgBox(0, "Info", "File Name is: " & $file & @CRLF & "File Date is: " & $FileDate)
        $TodaysDateIs = (@YEAR & "/" & @MON & "/" & @MDAY) ; Sets up the date format for calculation, must use Year, month, day format
        $DateDiffTotal = _DateDiff('D', $FileDate, $TodaysDateIs)
        ;MsgBox(0, $file, "Difference in Days: " & $DateDiffTotal ) ; Used for viewing the output of variable
        If $DateDiffTotal > $Days Then
            ; MsgBox(0, "", $file & " is " & $DateDiffTotal & " days old and will be DELETED")
            FileDelete($file) ; Actual delete statement.
        EndIf
    WEnd
    ; Close the search handle
    FileClose($search)
    FileChangeDir(@ScriptDir)
EndIf
;end of autodelete routine
; Add columns to list view
_GUICtrlListView_InsertColumn($ListView1, 0, "Index", 100)
_GUICtrlListView_InsertColumn($ListView1, 1, "Movie", 200)
_GUICtrlListView_InsertColumn($ListView1, 2, "Trailer", 600)
GUICtrlSetData($Status, "Gathering List"); Sets text while building list
$pg = 1
$MainUrl = ("http://www.hd-trailers.net/") ;Home Page URL
$moviestoread = IniRead("Settings.ini", "Settings", "Movies_to_Read", "Error") ;number of movies to display
$allowclips = IniRead("Settings.ini", "Settings", "Allow_Clips", "0") ;clips ok??
For $p = 1 To 10 Step 1; for every page up to 10 pages
    $Source = _INetGetSource($MainUrl & "Page/" & $pg); Source Code to get new trailer list
    FileWrite("source.txt", $Source) ; write source code from each page to file
    $pg = $pg + 1; increase page number and continue loop
Next
$Source = FileRead("Source.txt"); use file as master source list
$string = StringRegExp($Source, 'movie/(.*?)/', 3); Returns a movie list from source code, assumes everything after "Movie/" is a movie title
;Debugging
;_ArrayDisplay($String)
$MovieList = _ArrayUnique($string) ;Returns only unique movie entries
;_Arraydisplay ($Movielist, "Movie List")
$col2 = 0; define column and column of listview outside of FOR loop
$col3 = 0
For $x = 1 To $moviestoread; build listview using index numbers, movie names and trailer links
    $Moviepage = ($MainUrl & "movie/" & $MovieList[$x])
    ;MsgBox(0, "Element " & $x, $movielist[$x])
    _GUICtrlListView_InsertItem($ListView1, $x); Insert index numbers as items into column 1
    _GUICtrlListView_SetItemText($ListView1, $col2, $MovieList[$x], 1); Insert movie names as text into colum 2
    $col2 = $col2 + 1
    ;MsgBox(0, $x, $moviepage); Will return link to each movies page
    $i = _INetGetSource($Moviepage); get source for every movie page
    ;
    ;debugging
    ;FileWrite ("source.txt", $i)
    ;MsgBox(0, $x, $i)
    $string = StringRegExp($i, '(http://trailers.apple.*?tlr\d_h720p\.mov|http://trailers.apple.*?tlr\d_h1080p\.mov)', 3); Returns only trailers from apple that are 720p and 1080p
    ;MsgBox (0, "test", $string)
    If $string = 1 Then; if no apple trailers
        ;MsgBox (0, "test", "no apple trailers")
        If $allowclips = 0 Then $string = StringRegExp($i, '(http://.*?\.mov)', 3); Returns all links with mov ext, no clips
        If $allowclips = 1 Then $string = StringRegExp($i, '(http://.*?\.mov|http://.*?\.mp4)', 3); Returns all links with mov or mp4 ext, clips
        ;$string = StringRegExp($i, '(http://.*?\.mov)', 3); Returns all links
        $string = _ArrayUnique($string); filter out duplicates
        ;_ArrayDisplay($string, "no apple or dupes")
    Else
        $string = _ArrayUnique($string); filter out duplicates
        ;Debugging
        ;_ArrayDisplay($string, "no dupes")
    EndIf
    If $string = 0 Then; If no trailers available, set CHOOSE value to -2 to be used below
        $Choose = -2
    Else
        $Choose = _ArraySearch($string, "1080", "", "", "", 1) ;If $String does return a value Then Choose a trailer containing "1080" for 1080p resolution
        If $Choose = -1 Then $Choose = _ArraySearch($string, "_8.mp4", "", "", "", 1) ;If $String does return a value Then Choose a clip containing "_8.mp4" for 1080p resolution
    EndIf
    If $Choose = -1 Then $Choose = _ArraySearch($string, "720", "", "", "", 1); if no 1080p trailers are available then try 720
    If $Choose = -1 Then $Choose = _ArraySearch($string, "_4.mp4", "", "", "", 1) ;If $String does return a value Then Choose a clip containing "_4.mp4" for 720p resolution
    If $Choose = -1 Or $Choose = -2 Then; If no 720 "-1" or if $Sring above returns null "-2" Then consider trailer unavailable
        $Trailer = "Unavailable"
    Else
        $Trailer = $string[$Choose]; If trailer is available, choose one
    EndIf
    _GUICtrlListView_SetItemText($ListView1, $col3, $Trailer, 2); one trailer is defined, add it to col3
    FileWriteLine("TL.txt", $Trailer)
    $col3 = $col3 + 1
Next
If Not FileExists($Save) Then DirCreate($Save); check if save dir exists, if not, create it
GUICtrlSetData($Status, "Idle"); Sets text back to idle after building list
FileDelete(@ScriptDir & "\source.txt"); delete temp source file
;Check for $cmdline option
$cmd = _ArraySearch($CmdLine, "-getall")
If $cmd > 0 Then Call("Allclick");If getall switch used then Download ALL
;end check
Global $AllDownloading = 0
Global $hInet
While 1
    Sleep(100); list is built, now wait for button click
    If $AllDownloading Then
        If InetGetInfo($hInet, 2) Then
            Allclick()
        EndIf
    EndIf
WEnd
Func _DownloadFiles()
    Local $Indices, $sSelected
    Switch @GUI_CtrlId
        Case $All
            $AllDownloading = 1
            Allclick()
        Case $Get, $idTrailer
            ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Trailer = ' & $Trailer & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
            $Indices = _GUICtrlListView_GetSelectedIndices($ListView1) + 1; returns line number that user has selected (add 1 because index starts at 0)
            $sSelected = _GUICtrlListView_GetItemText($ListView1, $Indices - 1, 2); item text of selected line
            Download($sSelected)
    EndSwitch
EndFunc   ;==>_DownloadFiles
Func Allclick()
    Local $Selected
    Local Static $z = 1
;~  $start = 0
    Local $Allmovies[1]
    _FileReadToArray("TL.txt", $Allmovies)
;~  For $z = 1 To $Allmovies[0]; For all movies
    $Selected = $Allmovies[$z]
    Download($Selected)
    $z += 1
    If $z > $Allmovies[0] Then Exit
;~  Next
;~  Exit
EndFunc   ;==>Allclick
Func BuyBeer()
    ShellExecute("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CBAT6LPVKN4RS")
EndFunc   ;==>BuyBeer
Func Download($Selected)
    ;Will download user selected trailer when pressing "GET" button
    Global $Filename = StringTrimLeft($Selected, StringInStr($Selected, "/", Default, -1)); finds last "\" and trims only the file name
    $ext = StringTrimLeft($Selected, StringInStr($Selected, ".", Default, -1)); finds last "." and returns only the ext
    $Append = IniRead("Settings.ini", "Settings", "Append_Text", "")
    If IniRead("Settings.ini", "Settings", "Append_FileName", "Error") = 1 Then; if append is enabled
        $Filename = StringTrimRight($Filename, 4); trim file ext
        $Filename = $Filename & $Append & "." & $ext; add append text and file ext for new filename
    EndIf
    If StringInStr($Selected, "Apple") = 0 Then; if download link is not from apple, do not change UserAgent
        HttpSetUserAgent("AutoIt")
    Else; if it is from apple, change user string to Quicktime.  As of creation of this script, apple only allows quicktime to download trailers.  This will spoof that
        HttpSetUserAgent("QuickTime")
    EndIf
    ;Start progress bar code
    If FileExists($Save & "\" & $Filename) Then
        MsgBox(4096, "Info", $Save & "\" & $Filename & " Already Downloaded"); If file exists, warn. ELSE download
    Else
        $url = $Selected ;Set URL
        $folder = $Save ;Set folder
        $hInet = InetGet($url, $Save & "\" & $Filename, 1, 1) ;Forces a reload from the remote site and return immediately and download in the background
        Global $FileSize = InetGetSize($url) ;Get file size
        AdlibRegister("Prog", 1000); updates progress bar every second
    EndIf
EndFunc   ;==>Download
Func Form1Minimize()
    GUISetState(@SW_HIDE, $Form1)
EndFunc   ;==>Form1Minimize
Func Form2Close()
    FileDelete(@ScriptDir & "\source.txt")
    FileDelete(@ScriptDir & "\TL.txt")
    Exit
EndFunc   ;==>Form2Close
Func GoToMovie()
    $Indices = _GUICtrlListView_GetSelectedIndices($ListView1) + 1; returns line number that user has selected (add 1 because index starts at 0)
    $Selected = _GUICtrlListView_GetItemText($ListView1, $Indices - 1, 1); item text of selected line
    ShellExecute($MainUrl & "movie/" & $Selected)
EndFunc   ;==>GoToMovie
Func Prog()
    If Not InetGetInfo($hInet, 2) Then ;if download is running
        Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
        GUICtrlSetData($Status, "Downloading"); sets text while downloading
        GUICtrlSetData($MovieIndicator, $Filename); sets text while downloading
        Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
        $BytesReceived = InetGetInfo($hInet, 0) ;Get bytes received
        $Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
        GUICtrlSetData($Progress, $Pct)
    Else; download has stopped
        GUICtrlSetData($Progress, 0); Download complete, set progress to zero
        GUICtrlSetData($MovieIndicator, " "); Sets text to blank after finished
        GUICtrlSetData($Status, "Idle"); Sets text back to "idle" after finished
        AdlibUnRegister("Prog")
    EndIf
EndFunc   ;==>Prog
Func Refresh()
    If @Compiled Then
        Run(FileGetShortName(@ScriptFullPath))
    Else
        Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc   ;==>Refresh
Func Trayclick()
    GUISetState(@SW_SHOWNORMAL, $Form1)
EndFunc   ;==>Trayclick

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I apreciate you taking the time to simplify my code.  I will compare when I get home tonight.  After some more testing, I have discovered the following...

1.  If Inetget to set to 1, meaning download in background, multiple downloads will be started, and progress bar with not reflect any activity

2.  If Inetget is set to 0, meaning wait for download to finish, the GUI becomes unresponsive.  

At this point I see no way around this but to disable the progress bar when downloading all,

Share this post


Link to post
Share on other sites

I apreciate you taking the time to simplify my code.  I will compare when I get home tonight.  After some more testing, I have discovered the following...

Testing with your code, or mine?

1.  If Inetget to set to 1, meaning download in background, multiple downloads will be started, and progress bar with not reflect any activity

From my testing my code a couple of times, this doesn't happen. Whether further testing will find flaws in my approach or not, only time will tell.

2.  If Inetget is set to 0, meaning wait for download to finish, the GUI becomes unresponsive.  

 

At this point I see no way around this but to disable the progress bar when downloading all,

Let me know if you encounter any issues with what I posted. Just remember, I only focused on the downloading parts.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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
Sign in to follow this  
Followers 0