Jump to content

Second GUI doesnt work


russell
 Share

Recommended Posts

I was making a GUI to transfer files from my USB stick in my Raspberry Pi to a HDD hooked up to the Pi. I have that much of the code working  but im tring to make a progress bar for the file transfer using the file size and the destionations orginal size comparison. My problem lyes in the progress bar, the example from help wont work inside my script nor do i know how to use my vaules (file sizes) to make the bar move.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Downloads\Pi.ico
#AutoIt3Wrapper_Outfile=Dads File Transfer\Pi Fast File.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
Local $lixsource
Global $destination
Opt("GUIOnEventMode", 1); Change to OnEvent mode

GUICreate("Pi Fast File v1.20", 440, 160)
;GUICtrlCreateLabel("This will Run your code", 40, 10)
;GUICtrlCreateLabel("Select the drive", 140, 42)

GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$Sourcetxt = GUICtrlCreateLabel("Thumb Drive", 16, 24, 65, 17)
$SourceCombo = GUICtrlCreateCombo("(Source Drive)", 205, 20, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "DAD'S 4GB|DAD'S 29GB|Russells 29GB")

$sourcedirtxt = GUICtrlCreateLabel("Thumb Drive Directory", 16, 52, 120, 17)
$sourcedirinput = GUICtrlCreateInput("(Source directory)", 130, 48, 220, 20)

$browsebutton = GUICtrlCreateButton("Browse", 360, 48, 70, 20)
GUICtrlSetOnEvent($browsebutton, "BROWSEButton")

$DirorFilestxt = GUICtrlCreateLabel("Copy folder or just it's content?", 16, 80, 150, 17)
$DirorFilesCombo = GUICtrlCreateCombo("Content", 215, 76, 135, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Folder+Content")

$Destinationdirtxt = GUICtrlCreateLabel("WD MyBook Directory", 16, 107, 120, 17)
$Destinationdirinput = GUICtrlCreateInput("(Destination Directory)", 130, 103, 220, 20)

$browsebutton2 = GUICtrlCreateButton("Browse", 360, 103, 70, 20)
GUICtrlSetOnEvent($browsebutton2, "BROWSEButton2")


$okbutton = GUICtrlCreateButton("OK", 140, 130, 70, 20)
GUICtrlSetOnEvent($okbutton, "OKButton")

$exitbutton = GUICtrlCreateButton("EXIT", 240, 130, 70, 20)
GUICtrlSetOnEvent($exitbutton, "EXITButton")


While 1
    Sleep(1000)
WEnd

Func BROWSEButton()
    $searchsource = GUICtrlRead($SourceCombo)
            If $searchsource = "DAD'S 4GB" Then
            $winsource = "DADS 4GB"
            $lixsource = "DADS\ 4GB/"
            EndIf
            If $searchsource = "DAD'S 29GB" Then
            $winsource = "DADS29GB"
            $lixsource = "DADS29GB/"
            EndIf
            If $searchsource = "Russells 29GB" Then
            $winsource = "CC45-BCB4"
            $lixsource = "CC45-BCB4/"
            EndIf
    global $sourceselFile1
    global $sourceselFile1 = FileSelectFolder("","\\RASPBMC\devices\" & $winsource)
    If Not @error Then
        GUICtrlSetData($sourcedirinput, $sourceselFile1)
    EndIf


EndFunc  ;==>BROWSEButton

Func BROWSEButton2()

    global $desselFiled1
    ;$selFile = FileOpenDialog("Browse the exe", "C:\", "(*.exe)")
    ;\\RASPBMC\devices\CC45-BCB4
    global $desselFiled1 = FileSelectFolder("","\\RASPBMC\devices\WD MyBook")
    If Not @error Then
        GUICtrlSetData($Destinationdirinput, $desselFiled1)
    EndIf


EndFunc  ;==>BROWSEButton

Func OKButton()
    ;If $desselFiled = "\\RASPBMC\devices\WD MyBook\Kids Programs-Movies" Then $destination = "/Kids\ Programs-Movies"
    ;If $desselFiled = "\\RASPBMC\devices\WD MyBook\Movies" Then $destination = "/Movies"
    ;If $desselFiled = "\\RASPBMC\devices\WD MyBook\Music" Then $destination = "/Music"
    ;If $desselFiled = "\\RASPBMC\devices\WD MyBook\TV Shows - Series - Specials" Then $destination = "/TV\ Shows\ -\ Series\ -\ Specials"
    ;If $desselFiled = "\\RASPBMC\devices\WD MyBook\Offload" Then $destination = "/Offload"
    $sourceselFile = StringTrimLeft($sourceselFile1,18) ;cuts the //RBPMC/blabla bla out leaving only the select dir
    $sourceselFile = StringReplace($sourceselFile, "\", "/") ;turns backslashes slashes (windows) into forwardslashes (linux)
    $sourceselFile = StringReplace($sourceselFile, " ","\ ") ;replaces spaces with \(space)

    $desselFiled = StringTrimLeft($desselFiled1,18) ;cuts the //RBPMC/blabla bla out leaving only the select dir
    $desselFiled = StringReplace($desselFiled, "\", "/") ;turns backslashes slashes (windows) into forwardslashes (linux)
    global $desselFiled = StringReplace($desselFiled, " ","\ ") ;replaces spaces with \(space)
    global $Action = "cp -R "
    global $CPFilesorDir = GUICtrlRead ($DirorFilesCombo)
    ;BlockInput (1) ;disables user input
    Sleep (1000)
    ConsoleWrite(_getDOSOutput(Doit()) & @CRLF)


EndFunc  ;==>OKButton

Func EXITButton()
    Exit
EndFunc  ;==>EXITButton

Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked

Func _getDOSOutput($command)
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
            $text &= StdoutRead($Pid, False, False)
            If @error Then ExitLoop
            Sleep(10)
    WEnd
    Return StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutpu
;Opt("WinTitleMatchMode", 4)

Func Doit()
    #cs
    ToolTip ("Establishing Connection")
    Run("C:\WINDOWS\system32\cmd.exe")
    Sleep (3000)
    $handle = WinGetHandle("")
    $array = WinGetPos ( $handle , "" )
    WinMove($handle, "",(@DesktopWidth/2)-($array[2]/2),(@DesktopHeight/2)-($array[3]/2))
    Send("cd /putty")
    Send ("{Enter}")
    Send ("plink -v -ssh pi@192.168.1.165")
    Send ("{Enter}")
    Sleep (1000)
    Send ("raspberry")
    Send ("{Enter}")
    ToolTip ("Allowing Connection to catchup")
    Sleep(6000)
    ToolTip ("Issuing Transfer Command")
    Sleep (2000)
    Opt("SendKeyDelay", 80)
    Send ("cd /media/")
    Send ("{Enter}")
    Sleep(2000)
    If $CPFilesorDir = "Folder+Content" Then
        Send ($Action & $sourceselFile  & " "& $desselFiled)
    ElseIf $CPFilesorDir = "Content" Then
        Send ("cd " & $sourceselFile)
        Send ("{Enter}")
        Sleep (1000)
        Send ($Action & "*" & "  /media/" & $desselFiled)
        ;Send ($Action & "/media/" & $sourceselFile & "/" & " "& "/media/WD\ MyBook" & $desselFiled)
    EndIf
    Send ("{Enter}")
    BlockInput (0) ;enables user input
    MsgBox (48,"You have control","Your keyboard and mouse are now enabled. Please wait for the DOS window to complete befor closing the DOS window",5)
    #ce
    GUIDelete("Pi Fast File v1.20")
    Progress()
EndFunc

Func Progress2()
    Local $SourceSize = DirGetSize($sourceselFile1) ; this will denote size not size on disk
    Local $DestSize1st = DirGetSize($desselFiled1)

    $Progress = GUICreate("Progress", 211, 78, -1, -1)
    $Progressbar = GUICtrlCreateProgress(24, 32, 150, 16, $PBS_SMOOTH)
    $TransferStatustxt = GUICtrlCreateLabel("Transfer Status", 64, 8, 76, 17)
    GUISetState(@SW_SHOW)

    Local $statusofprogress
    $DestSize = DirGetSize($desselFiled1)
    $FullCopy = ($DestSize1st+$SourceSize)
    If ($DestSize) = $FullCopy Then $statusofprogress = 100
EndFunc

Func Progress()
    GUIDelete("Pi Fast File v1.20")
    Local $progressbar1, $progressbar2, $button, $wait, $s, $msg, $m

    GUICreate("Progress", 220, 100, -1, -1)
    $progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
    GUICtrlSetColor(-1, 32250); not working with Windows XP Style
    $progressbar2 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
    $button = GUICtrlCreateButton("Start", 75, 70, 70, 20)
    GUISetState()

    $wait = 20; wait 20ms for next progressstep
    $s = 0; progressbar-saveposition
    Do
        $msg = GUIGetMsg()
        If $msg = $button Then
            GUICtrlSetData($button, "Stop")
            For $i = $s To 100
                If GUICtrlRead($progressbar1) = 50 Then MsgBox(0, "Info", "The half is done...", 1)
                $m = GUIGetMsg()

                If $m = -3 Then ExitLoop

                If $m = $button Then
                    GUICtrlSetData($button, "Next")
                    $s = $i;save the current bar-position to $s
                    ExitLoop
                Else
                    $s = 0
                    GUICtrlSetData($progressbar1, $i)
                    GUICtrlSetData($progressbar2, (100 - $i))
                    Sleep($wait)
                EndIf
            Next
            If $i > 100 Then
                ;       $s=0
                GUICtrlSetData($button, "Start")
            EndIf
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

muppet hands are so soft :)

Link to comment
Share on other sites

Your problem is you cannot use Event Mode and GUIGetMsg at the same time.

If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.

Your progress function looks like it will work right if you make those changes.

BuckMaster

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...