dRsrb Posted February 14, 2009 Posted February 14, 2009 Hi everybody! I'm new to autoit and again I have a problem, that I don't understand. I extract the following code segment out of my application: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <EditConstants.au3> AutoItSetOption('GUIOnEventMode', 1) AutoItSetOption('MustDeclareVars', 1) Global Const $ApplicationTitle = 'Test' Global $Main Global $ListView _Main() Func _Main() $Main = GUICreate($ApplicationTitle, 118, 62, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, '_ExitApplication') $ListView = GUICtrlCreateListView('Image|Text', 0, 0, 118, 62, $ES_READONLY) _GUICtrlListView_SetExtendedListViewStyle($ListView, $LVS_EX_INFOTIP) _GUICtrlListView_SetColumnWidth($ListView, 0, 46) _GUICtrlListView_SetColumnWidth($ListView, 1, 67) _GUICtrlListView_SetSelectedColumn($ListView, 2) GUICtrlSetResizing($ListView, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKRIGHT, $GUI_DOCKBOTTOM)) GUISetState(@SW_SHOW) _TestFunc_SetItem() _TestFunc() While True Sleep(1000) WEnd EndFunc Func _ExitApplication() If @GUI_WINHANDLE = $Main Then Exit 0 EndIf EndFunc Func _TestFunc_SetItem() GUICtrlCreateListViewItem('|Test1', $ListView) GUICtrlSetImage(-1, '.\red.ico') GUICtrlCreateListViewItem('|Test2', $ListView) GUICtrlSetImage(-1, '.\red.ico') MsgBox(0, '', 'Items created') EndFunc Func _TestFunc() Local $j, $ListViewItemCount, $ListViewItemText, $ListViewItemAttributes, $Test, $AnyFile $ListViewItemCount = _GUICtrlListView_GetItemCount($ListView) For $j = 0 To $ListViewItemCount - 1 $ListViewItemText = _GUICtrlListView_GetItemTextArray($ListView, $j) $ListViewItemAttributes = _GUICtrlListView_GetItem($ListView, $j) If $ListViewItemText[2] = 'Test1' Then _GUICtrlListView_SetItem($ListView, 'Tested', $j, 1) $Test = GUICtrlSetImage($ListViewItemAttributes[5], '.\green.ico') MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Test' & @lf & @lf & 'Return:' & @lf & $Test);### Debug MSGBOX ExitLoop EndIf Next $AnyFile = FileOpenDialog('Select any file', 'C:\', 'All (*.*)', 1) MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$AnyFile' & @lf & @lf & 'Return:' & @lf & $AnyFile);### Debug MSGBOX For $j = 0 To $ListViewItemCount - 1 $ListViewItemText = _GUICtrlListView_GetItemTextArray($ListView, $j) $ListViewItemAttributes = _GUICtrlListView_GetItem($ListView, $j) If $ListViewItemText[2] = 'Test2' Then _GUICtrlListView_SetItem($ListView, 'Tested', $j, 1) $Test = GUICtrlSetImage($ListViewItemAttributes[5], '.\green.ico') If $Test = 0 Then _GUICtrlListView_SetItem($ListView, 'Not tested!', $j, 1) EndIf MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Test' & @lf & @lf & 'Return:' & @lf & $Test);### Debug MSGBOX ExitLoop EndIf Next EndFunc The problem: "GUICtrlSetImage()" doesn't work, if "FileOpenDialog()" is true. This behaviour makes no sense for me. If you cancel the "FileOpenDialog()" "$AnyFile" is false and "GUICtrlSetImage()" works. You can remove the variable "$AnyFile". It makes no difference. The two icons for testing are attached.green.icored.ico
Moderators Melba23 Posted February 14, 2009 Moderators Posted February 14, 2009 dRsrb,The icon changes for me whether I select a file or press cancel within the FileOpenDialog. So GUICtrlSetImage is working in both cases.Or have I completely misunderstood the problem?M23 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
dRsrb Posted February 14, 2009 Author Posted February 14, 2009 (edited) Oh, really? This is my result (I can always reproduce it):1.: Start2.: Press OK~Open a file in "FileOpenDialog()"3.1.: Select and open a file (in my case it's "Öffnen")4.1.: See the selection5.1.: "GUICtrlSetImage()" has an error~Cancel the "FileOpenDialog()"3.2.: Cancel (in my case it's "Abbrechen")4.2.: No selection5.2.: "GUICtrlSetImage()" works fineAlways the same. In the test application as in my "real" application! EDIT:SciTEVersion 1.77 Oct 23 2008 19:06:08 Edited February 14, 2009 by dRsrb
Moderators Melba23 Posted February 14, 2009 Moderators Posted February 14, 2009 dRsrb, I used my own icons because I could not be bothered to download yours, but that should not affect the price of fish. M23 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
ResNullius Posted February 14, 2009 Posted February 14, 2009 (edited) The problem: "GUICtrlSetImage()" doesn't work, if "FileOpenDialog()" is true. This behaviour makes no sense for me. If you cancel the "FileOpenDialog()" "$AnyFile" is false and "GUICtrlSetImage()" works.This is a known behaviour of FileOpenDialog() & FileSaveDialog(). From the help file remarks @WorkingDir is changed on successful return.Because you are using a relative path for your icons '.\green.ico' on a return of TRUE your script is now looking for the icon to use in the folder your FileOpen() command was used in. Change you icon paths to@ScriptDir & '\green.ico' and all should work as planned. Edit: I'm gussing that Melba23 must have used FileOpenDialog to select a file from the folder the script was in. Edited February 14, 2009 by ResNullius
Moderators Melba23 Posted February 14, 2009 Moderators Posted February 14, 2009 ResNullius, Close, but no cigar! By chance I used the full path for the icons when I ran the script, so that is why it worked for me. Thanks for the explanation. M23 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
ResNullius Posted February 14, 2009 Posted February 14, 2009 ResNullius,Close, but no cigar! By chance I used the full path for the icons when I ran the script, so that is why it worked for me. Thanks for the explanation.M23Well then, that makes it difficult to troubleshoot the OP's code if you change it, doesn't it?
Moderators Melba23 Posted February 14, 2009 Moderators Posted February 14, 2009 (edited) Touché! Edited February 14, 2009 by Melba23 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
dRsrb Posted February 14, 2009 Author Posted February 14, 2009 (edited) Great! Thank you very much! I spent over 3 hs trying to find the problem, but without success. I read the remarks, but it was not clear enough for me (@WorkingDir rather @ScriptDir). Now it is. Edited February 15, 2009 by dRsrb
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