Der_Andi Posted January 6, 2010 Share Posted January 6, 2010 (edited) Hi,there's a button on my GUI I can't disable.As this is the last used button, I moved the focus to another control. Still I can't disable it.Let's call this button the problem-button.About the button:The problem-button calls a function, which creates a child GUI, displays it and disables the main GUI.This child GUI has a button, too. It calls the work-function, which does some work and when finished calls the close-function and then the update-function.The close-function deletes the child GUI, re-enables the main GUI and moves the focus from the problem-button to another button.The update function then will refresh some data on the main GUI and depending on that data finally disables the problem-button.And THAT does not work and makes me really mad! In a manner of speaking, the update-function is triggered by the problem-button. I came to the conclusion, the program has to exit the whole chain of functions to "free" the button. Only after that it could be disabled. So I hotkey-ed a test function, that just disables the button, when I press F10.I pressed the problem-button and it did the usual work. When everything was finished and the main GUI seemed to be in normal state again, I pressed F10, but the button still can't be disabled! GUICtrlSetState($btn, $gui_disable) returns always 0 in this case. Why? Is there anything else, that keeps blocking the button?I tried to make an example script with exactly the same 'architecture', but for some reasons this just works fine. Regards,AndreasEdit: I'll cut this short. Here's the whole thing. Just find the line with GUICtrlSetOnEvent($btnErase, "showEraseWarning") and follow the white rabbit.expandcollapse popup#NoTrayIcon #include <GuiConstants.au3> #include <StaticConstants.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <ComboConstants.au3> #include <ProgressConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> #include <File.au3> #include <Misc.au3> _Singleton(@ScriptName & "@" & @ComputerName) Opt("GuiOnEventMode", 1) ;Captions $cp_cardConnected = "Speicherkarte eingelegt" $cp_cardNotConnected = "Keine Speicherkarte vorhanden" $cp_picturePlural = "Fotos" $cp_pictureSingular = "Foto" ;Global vars $g_dcimFolder = "DCIM\" $g_cameraDrive = "" $g_picturePath = "" $g_iniFile = "foto-transfer.ini" $g_iniSection = "places" HotKeySet("{F10}", "_test") ;=========================================== ;TESTING AREA ;=========================================== ;~ $x = StringFormat("%04i.jpg", 1) ;~ print($x) ;~ Exit ;=========================================== ;END TESTING AREA ;=========================================== ;Internal vars $guiTitle = "Foto Transfer" $guiWidth = 480 $guiHeight = 620 $guiFontsize = 11 $guiFontname = "Tahoma" $guiWarning = 0 $guiWarningTitle = "Warnung" $guiWarningWidth = 400 $guiWarningHeight = 190 $btnCancel = 0 $btnErase = 0 $iconFile = "warning.ico" $icoWarningLeft = 0 $icoWarningRight = 0 $lblWarning = 0 $guiMain = GUICreate($guiTitle, $guiWidth, $guiHeight) GUISetOnEvent($gui_event_close, "quit") GUISetFont($guiFontsize, 400, 0, $guiFontname) ;Memory card section $topCard = 10 GUICtrlCreateGroup("Speicherkarte", 10, $topCard, 460, 120) GUICtrlSetFont(-1, $guiFontsize, 600) GUICtrlCreateLabel("Status:", 30, $topCard+30, 100, 20, $ss_centerimage) GUICtrlCreateLabel("Bezeichnung:", 30, $topCard+50, 100, 20, $ss_centerimage) GUICtrlCreateLabel("Größe:", 30, $topCard+70, 100, 20, $ss_centerimage) GUICtrlCreateLabel("Inhalt:", 30, $topCard+90, 100, 20, $ss_centerimage) $lblStatus = GUICtrlCreateLabel("", 140, 40, 250, 20, $ss_centerimage) $lblName = GUICtrlCreateLabel("", 140, 60, 250, 20, $ss_centerimage) $lblSize = GUICtrlCreateLabel("", 140, 80, 250, 20, $ss_centerimage) $lblContent = GUICtrlCreateLabel("", 140, 100, 250, 20, $ss_centerimage) ;Content section $topContent = 150 GUICtrlCreateGroup("Inhalt und Auswahl", 10, $topContent, 460, 240) GUICtrlSetFont(-1, $guiFontsize, 600) GUICtrlCreateLabel("Bilder:", 30, $topContent+30, 100, 20, $ss_centerimage) GUICtrlCreateLabel("Vorschau:", 220, $topContent+30, 100, 20, $ss_centerimage) $lstPictures = GUICtrlCreateListView(" ", 30, $topContent+50, 180, 150, $lvs_nocolumnheader, _ BitOR($lvs_ex_checkboxes, $lvs_ex_fullrowselect, $ws_ex_clientedge)) _GUICtrlListView_SetColumnWidth(-1, 0, 156) $hLstPictures = GUICtrlGetHandle($lstPictures) $picPreview = GUICtrlCreatePic("", 220, $topContent+50, 240, 180) ;, $ss_sunken) $btnCheckAll = GUICtrlCreateButton("Alle", 30, $topContent+200+5, 90, 25) $btnCheckNone = GUICtrlCreateButton("Keine", 30+90, $topContent+200+5, 90,25) GUICtrlSetOnEvent($btnCheckAll, "checkAllPictures") GUICtrlSetOnEvent($btnCheckNone, "uncheckAllPictures") ;Save location section $topSave = 410 GUICtrlCreateGroup("Wohin speichern?", 10, $topSave, 460, 100) GUICtrlSetFont(-1, $guiFontsize, 600) GUICtrlCreateLabel("Speicherort:", 30, $topSave + 30, 100, 20, $ss_centerimage) GUICtrlCreateLabel("Ordnername:", 30, $topSave + 60, 100, 20, $ss_centerimage) $cboPlaces = GUICtrlCreateCombo("", 140, $topSave + 30, 320, 20, $cbs_dropdownlist) $cboFolder = GUICtrlCreateCombo("", 140, $topSave + 60, 320, 20) GUICtrlSetOnEvent($cboPlaces, "loadFolders") ;Action section $topAction = 530 GUICtrlCreateGroup("Aktionen", 10, $topAction, 460, 70) GUICtrlSetFont(-1, $guiFontsize, 600) $lblProgress = GUICtrlCreateLabel("Fortschritt:", 30, $topAction+30, 80, 25, $ss_centerimage) $progress = GUICtrlCreateProgress(110, $topAction+30, 350, 25, $pbs_smooth) GUICtrlSetState($lblProgress, $gui_hide) GUICtrlSetState($progress, $gui_hide) $btnCopy = GUICtrlCreateButton("Auswahl auf PC speichern", 30, $topAction+30, 210, 25) $btnErase = GUICtrlCreateButton("Speicherkarte löschen", 250, $topAction+30, 210, 25) GUICtrlSetOnEvent($btnCopy, "copyPictures") GUICtrlSetOnEvent($btnErase, "showEraseWarning") ;Display GUI GUISetState() ;Set erase warning status $warningDisplayed = False ;Get information about card $cardConnected = False updateCardInformation($cardConnected) ;Load places from INI file loadPlaces() While True Sleep(1000) $cardStatus = cardIsConnected() If Not $cardStatus = $cardConnected Then updateCardInformation($cardStatus) $cardConnected = $cardStatus EndIf If $warningDisplayed Then If BitAND(GUICtrlGetState($icoWarningLeft), $gui_hide) = $gui_hide Then GUICtrlSetState($icoWarningLeft, $gui_show) GUICtrlSetState($icoWarningRight, $gui_show) Else GUICtrlSetState($icoWarningRight, $gui_hide) GUICtrlSetState($icoWarningLeft, $gui_hide) EndIf EndIf WEnd Func cardIsConnected() ;Returns True, if memory card is inserted, otherwise False. If getMemoryCardDrive() = "" Then Return False Else Return True EndIf EndFunc Func _test() print("F10/disable: " & GUICtrlSetState($btnErase, $gui_disable)) EndFunc Func updateCardInformation($connected = True) ;Get information from memory card and display results in GUI ;$connected: True, if card is connected (default) ; False, if not. ;Information to update Local $status, $label = "", $size = "", $content = "" If $connected Then ;Get drive information $drive = getMemoryCardDrive() $path = getPicturePath($drive) ;Set some status information to display $status = $cp_cardConnected $statusColor = 0x00AA00 ;some green $label = DriveGetLabel($drive) $size = getMemoryCardSizeGB($drive) & " GB" ;Get list of picture files (jpg) Local $aFiles, $pictureCount = 0 If $path <> "" Then $aFiles = _FileListToArray($path, "*.jpg", 1) If IsArray($aFiles) Then $pictureCount = $aFiles[0] EndIf EndIf ;Manage text according to number of pictures Switch $pictureCount Case 0 $content = $pictureCount & " " & $cp_picturePlural Case 1 $content = $pictureCount & " " & $cp_pictureSingular Case Else $content = $pictureCount & " " & $cp_picturePlural EndSwitch ;Refresh picture list, if possible _GUICtrlListView_DeleteAllItems($hLstPictures) If $pictureCount > 0 Then _ArraySort($aFiles, 0, 1) For $i = 1 To $aFiles[0] GUICtrlCreateListViewItem($aFiles[$i], $lstPictures) GUICtrlSetOnEvent(-1, "previewPicture") Next ;Update global variables $g_cameraDrive = $drive $g_picturePath = $path ;Activate buttons GUICtrlSetState($btnCopy, $gui_enable) GUICtrlSetState($btnErase, $gui_enable) Else ;Deactivate buttons, because no pictures are there GUICtrlSetState($btnCopy, $gui_disable) GUICtrlSetState($btnErase, $gui_disable) EndIf Else $status = $cp_cardNotConnected $statusColor = 0xBB0000 ;some red _GUICtrlListView_DeleteAllItems($hLstPictures) ;Deactivate buttons GUICtrlSetState($btnCopy, $gui_disable) GUICtrlSetState($btnErase, $gui_disable) EndIf ;Display memory card information GUICtrlSetData($lblStatus, $status) GUICtrlSetData($lblName, $label) GUICtrlSetData($lblSize, $size) GUICtrlSetData($lblContent, $content) GUICtrlSetColor($lblStatus, $statusColor) EndFunc Func previewPicture() ;Display the selected picture ;Get ID of listview item $fileName = _GUICtrlListView_GetItemTextString($hLstPictures, -1) ; -1 = current selection GUICtrlSetImage($picPreview, $g_picturePath & $fileName) EndFunc Func checkAllPictures() ;Checks all pictures _GUICtrlListView_SetItemChecked($hLstPictures, -1) EndFunc Func uncheckAllPictures() ;Unchecks all pictures _GUICtrlListView_SetItemChecked($hLstPictures, -1, False) EndFunc Func getPicturePath($cameraDrive) ;Returns the complete path of the folder, that contains the pictures. ;Returns "", if no pictures available ;Get folders in DCIM folder $aFolders = _FileListToArray($cameraDrive & $g_dcimFolder, "*", 2) ; 2 = folders only ;Search for the folder with the pictures in it For $i = 1 To $aFolders[0] $path = $cameraDrive & $g_dcimFolder & $aFolders[$i] & "\" If FileExists($path & "*.jpg") Then Return $path EndIf Next Return "" EndFunc Func loadPlaces() ;Loads the places from the INI file and it's categories $aPlaces = IniReadSection($g_iniFile, $g_iniSection) If Not IsArray($aPlaces) Then Return For $i = 1 To $aPlaces[0][0] If $i = 1 Then GUICtrlSetData($cboPlaces, $aPlaces[$i][0], $aPlaces[$i][0]) Else GUICtrlSetData($cboPlaces, $aPlaces[$i][0]) EndIf Next loadFolders() EndFunc Func loadFolders() ;Loads the folders of the currently selected place $currentSelection = GUICtrlRead($cboFolder) ;Delete folder list GUICtrlSetData($cboFolder, "") ;Get place and corresponding path $place = GUICtrlRead($cboPlaces) $path = IniRead($g_iniFile, $g_iniSection, $place, "") If $path = "" Then Return ;Get folders $aFolders = _FileListToArray($path, "*", 2) If Not IsArray($aFolders) Then Return For $i = 1 To $aFolders[0] GUICtrlSetData($cboFolder, $aFolders[$i]) Next ;Set previously selected folder, if available If $currentSelection <> "" Then GUICtrlSetData($cboFolder, $currentSelection) EndIf EndFunc Func copyPictures() ;Copies the picture in the selected folder ;Get list with the checked pictures $aNames = getCheckedPictures() If $aNames[0] = 0 Then MsgBox(0, "", "Keine Bilder ausgewählt.", 1) EndIf ;Get target path for pictures $path = IniRead($g_iniFile, $g_iniSection, GUICtrlRead($cboPlaces), "") $folder = GUICtrlRead($cboFolder) If $path = "" Then Return If $folder = "" Then Return If StringRight($folder, 1) <> "\" Then $folder &= "\" EndIf ;Switch to progress bar showProgress() ;Copy For $i = 1 To $aNames[0] $fileName = validateFilename($path, $folder, $aNames[$i]) FileCopy($g_picturePath & $aNames[$i], $path & $folder & $fileName, 8) ;Calculate percentage of transfered pictures $p = Round($i * 100 / $aNames[0], 0) GUICtrlSetData($progress, $p) Next ;Return to buttons Sleep(1000) hideProgress() loadFolders() EndFunc Func validateFilename($path, $folder, $name) ;Checks, if the current filename of the current picture ;already exists in the target folder. ;If so, a new filename will be generated and returned. If Not FileExists($path & $folder & $name) Then Return $name EndIf $count = 0 Do $fileName = StringFormat("%04i.jpg", $count) $count += 1 Until Not FileExists($path & $folder & $fileName) Return $fileName EndFunc Func showProgress() ;Hides buttons and shows the progress bar GUICtrlSetState($btnCopy, $gui_hide) GUICtrlSetState($btnErase, $gui_hide) GUICtrlSetState($lblProgress, $gui_show) GUICtrlSetState($progress, $gui_show) EndFunc Func hideProgress() ;Hides progressbar again and shows buttons GUICtrlSetState($btnCopy, $gui_show) GUICtrlSetState($btnErase, $gui_show) GUICtrlSetState($lblProgress, $gui_hide) GUICtrlSetState($progress, $gui_hide) EndFunc Func getCheckedPictures() ;Returns an array with the filenames of pictures which are checked ;array[0] will contain the number of filenames in any case - even 0. Dim $aNames[1] = [0] $count = _GUICtrlListView_GetItemCount($hLstPictures) For $i = 0 To $count - 1 If _GUICtrlListView_GetItemChecked($hLstPictures, $i) Then _ArrayAdd($aNames, _GUICtrlListView_GetItemTextString($hLstPictures, $i)) $aNames[0] += 1 EndIf Next Return $aNames EndFunc Func showEraseWarning() $guiWarning = GUICreate($guiWarningTitle, $guiWarningWidth, $guiWarningHeight, -1, -1, _ $ds_modalframe, _ -1, _ $guiMain) GUISetFont($guiFontsize, 400, 0, $guiFontname) $icoWarningLeft = GUICtrlCreateIcon($iconFile, -1, 10, 30) $icoWarningRight = GUICtrlCreateIcon($iconFile, -1, 350, 30) GUICtrlSetState($icoWarningLeft, $gui_hide) GUICtrlSetState($icoWarningRight, $gui_hide) $warningText = "ACHTUNG !" & @CRLF & _ "Das Löschen der Bilder kann nicht" & @CRLF & _ "rückgängig gemacht werden." & @CRLF & @CRLF & _ "Fortfahren?" $lblWarning = GUICtrlCreateLabel($warningText, 70, 10, 280, 90) GUICtrlSetFont(-1, $guiFontsize, 600) $btnCancel = GUICtrlCreateButton("Nein, abbrechen", 10, 120, 150, 25, $bs_defpushbutton) $btnErase = GUICtrlCreateButton("Ja, alles löschen", 240, 120, 150, 25) GUICtrlSetOnEvent($btnCancel, "closeEraseWarning") GUICtrlSetOnEvent($btnErase, "eraseMemoryCard") GUISetState(@SW_SHOW, $guiWarning) GUISetState(@SW_DISABLE, $guiMain) $warningDisplayed = True EndFunc Func closeEraseWarning() $warningDisplayed = False GUISetState(@SW_ENABLE, $guiMain) GUISetState(@SW_RESTORE, $guiMain) GUIDelete($guiWarning) GUISwitch($guiMain) GUICtrlSetState($btnCheckAll, $gui_focus) ;just remove the focus from $btnErase EndFunc Func eraseMemoryCard() ;Erases all picutures in the camera's picture path ;Prepare GUI for deleting $warningDisplayed = False GUICtrlSetState($icoWarningLeft, $gui_hide) GUICtrlSetState($icoWarningRight, $gui_hide) GUICtrlSetState($btnCancel, $gui_hide) GUICtrlSetState($btnErase, $gui_hide) $deleteText = @CRLF & "Bilder werden gelöscht." & @CRLF & "Bitte warten... " GUICtrlSetData($lblWarning, $deleteText) ;Delete FileDelete($g_picturePath & "*.jpg") ;Update gui $deleteText &= "fertig!" GUICtrlSetData($lblWarning, $deleteText) Sleep(1000) closeEraseWarning() updateCardInformation() ;<-- will try to disable $btnErase. Does not work. EndFunc Func getMemoryCardDrive() ;Return the drive letter with trailing \ that contains the DCIM folder. ;Otherwise return an empty string. $aDrives = DriveGetDrive("REMOVABLE") If Not IsArray($aDrives) Then Return "" For $i = 1 To $aDrives[0] If $aDrives[$i] = "A:" Then ContinueLoop If DriveStatus($aDrives[$i]) <> "READY" Then ContinueLoop If FileExists($aDrives[$i] & "\DCIM") Then Return $aDrives[$i] & "\" Next Return "" EndFunc Func getMemoryCardSizeGB($cameraDrive) ;Returns the size of the specified drive in GB $size = Round(DriveSpaceTotal($cameraDrive) / 1000, 0) Return $size EndFunc Func quit() Exit EndFunc Func print($s) ConsoleWrite($s & @LF) EndFunc Edited January 6, 2010 by Der_Andi Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2010 Moderators Share Posted January 6, 2010 Der_Andi,You have this line in your main script:$btnErase = GUICtrlCreateButton("Speicherkarte löschen", 250, $topAction+30, 210, 25)and this line in your showEraseWarning function:$btnErase = GUICtrlCreateButton("Ja, alles löschen", 240, 120, 150, 25)Does that give you a clue? M23You are overwriting the ControlID so that the first button no longer exists as far as AutoIt is concerned! Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Der_Andi Posted January 6, 2010 Author Share Posted January 6, 2010 (edited) Does that give you a clue? YES!!! I need a break. Good god! And I just wondered why $btnErase first has the value 29 and later 33! And now I also know, why the example script worked. I used completely different variable names!Thanks very much!! Edited January 6, 2010 by Der_Andi Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now