Jump to content

Need help with my first GUI script


Recommended Posts

Hi,

First of all I must say that I love AuoIt. Even a programming idiot like me finds it quite easy to use. Right now I'm writing my first GUI script and I'm kind of stuck. The script's job is to read information from a file (Song info from iTunes) every 5 seconds. But that's not all. I want to display a window which the user can always have open so you can see what's playing on iTunes. Another function I've added is a button that opens Internet Explorer and submits the song info to Amazon. The problem is, I can either get the this button to work or the automatic update of the song info. Hope you understand my problem and can help me fixing my messy and confusing code. Thanks in advance!

$prev_duration = "empty"
DIM $file, $title, $artist, $album, $duration, $genre, $ref, $InternetExplorerSearch


AdlibEnable("updateinfo")


GuiCreate("Now playing on iTunes v1.0", 270, 150)

GUIDefaultFont(10)


$ref = GUISetControl("label", "Title: " & $title & @CR & "Artist: " & $artist & @CR & "Album: " & $album & @CR & "Duration: " & $duration & @CR & "Genre: " & $genre, 2, 2, 260, 100)
$amazon = GUISetControl( "button", "Track info", 2, 105, 80, 40)
GuiSetControlNotify()

GuiShow()


While GuiMsg() >0

Run ($InternetExplorerSearch)

Wend

;---------------------------------------------------

Func updateinfo()

    $file = FileOpen ( "\\butch\now playing\nowplaying.txt", 0 )
    
    $title      = FileReadLine ( $file, 1)
    $artist        = FileReadLine ( $file, 2)
    $album      = FileReadLine ( $file, 3)
    $duration   = FileReadLine ( $file, 4)
    $genre      = FileReadLine ( $file, 5)
    
    FileClose($file)
    
    If $duration <> $prev_duration Then
    
    
        GUIWrite($ref, 0, "Title: " & $title & @CR & "Artist: " & $artist & @CR & "Album: " & $album & @CR & "Duration: " & $duration & @CR & "Genre: " & $genre )
    
        $InternetExplorerSearch = @ProgramFilesDir & "\Internet Explorer\iexplore.exe http://www.amazon.com/exec/obidos/search-handle-url/index%3Dmusic%26field-keywords%3D" & $artist & " " & $album & "%26store-name%3Dmusic/104-9163304-3888742"  
    
    
        $prev_duration = $duration
    
    EndIf

EndFunc
Link to post
Share on other sites

I think the problem lies in how you handle when an item is selected here is your code with some changed items

This is not tested so I think I adapted it correctly

If you have any questions feel free to post

red

$prev_duration = "empty"
DIM $file, $title, $artist, $album, $duration, $genre, $ref, $InternetExplorerSearch

$InternetExplorerSearch = @ProgramFilesDir & "\Internet Explorer\iexplore.exe http://www.amazon.com/exec/obidos/search-handle-url/index%3Dmusic%26field-keywords%3D" & $artist & " " & $album & "%26store-name%3Dmusic/104-9163304-3888742"  

updateinfo()


GuiCreate("Now playing on iTunes v1.0", 270, 150)

GUIDefaultFont(10)


$ref = GUISetControl("label", "Title: " & $title & @CR & "Artist: " & $artist & @CR & "Album: " & $album & @CR & "Duration: " & $duration & @CR & "Genre: " & $genre, 2, 2, 260, 100)
$amazon = GUISetControl( "button", "Track info", 2, 105, 80, 40)
GuiSetControlNotify()


;Show window and check for changes
GuiShow()
AdlibEnable("_CheckChange")
WinWaitClose($Title)
AdlibDisable()
Exit

;Checks for changes
Func _CheckChange()
   UpdateInfo() 
   $n = GuiMsg (0)
   Select
     case $n>0
        ;If we got here someone selected something
         Select
            Case GuiRead() = $amazon
               run($InternetExplorerSearch)
          
          EndSelect
            
     Case $n=-1
      exit  ; or GuiDelete to stop the waiting WinWaitClose
     case $n=-2
      exit
     case $n=-3
      exit  ; or GuiDelete to stop the waiting WinWaitClose
     case $n=0
    ; no change
     case else
         
   EndSelect
EndFunc

Func updateinfo()

    $file = FileOpen ( "\\butch\now playing\nowplaying.txt", 0 )
    
    $title       = FileReadLine ( $file, 1)
    $artist     = FileReadLine ( $file, 2)
    $album       = FileReadLine ( $file, 3)
    $duration    = FileReadLine ( $file, 4)
    $genre       = FileReadLine ( $file, 5)
    
    FileClose($file)
    
    If $duration <> $prev_duration Then
    
    
        GUIWrite($ref, 0, "Title: " & $title & @CR & "Artist: " & $artist & @CR & "Album: " & $album & @CR & "Duration: " & $duration & @CR & "Genre: " & $genre )
    
    
        $prev_duration = $duration
    
    EndIf

EndFunc
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...