Jump to content

Added copy and exit to _ArrayDisplay


wolflake
 Share

Recommended Posts

I liked the clean interface of the "new" _ArrayDisplay and being able to sort but I missed being able to pick rows and copy them and being able to exit to the script.  The _DebugArrayDisplay adds those but doesn't have the sorting.

So I wrote an overlaying interface that would add copy, and exit to the existing _ArrayDisplay without actually changing it.  It also lets you chose whether you return the row(s) index or the it's value.  It's defaults to returning a value but if you'd rather it defaulted to returning an index feel free to change $a = 0  to $a = 1.

In the example press "Enter" when you have highlighted your choices, or press esc to return without a choice or press x to exit the script.

In the Example swap the commenting on the "$aItemx  =" lines to return index(es) instead of values.

Note you can still pass all the parameters you would use on the normal _ArrayDisplay.
 

Example:

#include "ad_ex.au3"

Global $aItem2[4] = ["one", "two", "three", "four"]
$aItemx = _ad($aItem2, "Press Enter")
;~ $aItemx = _ad($aItem2, "Press Enter",1)
If $aItemx = -1 Then ConsoleWrite("No Pick" & @CRLF)
If IsArray($aItemx) Then
    For $i = 1 To $aItemx[0]
        ConsoleWrite($aItemx[$i] & @CRLF)
    Next
EndIf
ConsoleWrite("Done" & @CRLF)
Exit

UDF:

;_ArrayDisplay with extras copy and exit keys return index or value
;$array,Title,0 or 1 Return-> 0=value 1=index
#include-once
#include <array.au3>
#include <misc.au3>
#include <GuiListView.au3>


; #FUNCTION# ====================================================================================================================
; Name ..........: _ad
; Description ...: Added the ability to return selected rows by index number or value. Exit the script immediately. To the _ArrayDisplay()
; Syntax ........: _ad(Byref $aI[, $t = ""[, $a = 0[, $sArrayRange = ""[, $iFlags = 0[, $vUser_Separator = Default[,
;                  $sHeader = Default[, $iMax_Colwidth = Default]]]]]]])
; Parameters ....: $aI                  - [in/out] array to display
;                  $t                   - [optional] Title Default is "".
;                  $a                   - [optional] Return Value(0) or Index(1) Default is 0.
;
;                   Variables below are a pass through of the normal _ArrayDisplay parameters
;
;                  $sArrayRange         - [optional] a string value. Default is "".
;                  $iFlags              - [optional] an integer value. Default is 0.
;                  $vUser_Separator     - [optional] a variant value. Default is Default.
;                  $sHeader             - [optional] a string value. Default is Default.
;                  $iMax_Colwidth       - [optional] an integer value. Default is Default.
; Return values .: Array of either value(s) or index(es) or -1 if there was no pick
; Author ........: Wolflake
; Modified ......:
; Remarks .......:Select your rows press Enter to return you choices. Press x to exit script. Press escape to return without a choice.
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _ad(Const ByRef $aI, $t = "", $a = 0, $sArrayRange = "", $iFlags = 0, $vUser_Separator = Default, $sHeader = Default, $iMax_Colwidth = Default) ;start keychk and arraydisplay
    ToolTip("Press Enter to copy", 650, 300)
    Sleep(750)
    ToolTip("", 500, 300)
    Global $s
    AdlibRegister("_ChkKey", 100)    ;turn on key checking

    _ArrayDisplay($aI, $t, $sArrayRange, $iFlags, $vUser_Separator, $sHeader, $iMax_Colwidth)

    $aItem = _ChkKey($a) ;get the data from picks
    If Not IsArray($aItem) Then Return -1
    If $a = 0 Then ;pull data instead of index
        For $i = 1 To $aItem[0]
            $aItem[$i] = $aI[$aItem[$i]]
        Next
    EndIf
    Return $aItem
EndFunc   ;==>_ad

Func _ChkKey($a=0)
    Static Local $hForm1, $aItem, $dll = DllOpen("user32.dll")
    If $hForm1 = "" Then
        $hForm1 = WinGetHandle("[Active]")
    EndIf
    If Not WinActive($hForm1) And WinExists($hForm1) Then ; don't run while not active but run to get data
        Return ;don't check for keys
    EndIf
    If _IsPressed("58") Then Exit ; x

    If _IsPressed("1B", $dll) Then ; esc
        AdlibUnRegister("_ChkKey")
        Send("{esc}")
        Return -1
    EndIf

    If _IsPressed("0D", $dll) Then ; Enter
        ;get picks, note the control id for the list is 3
        AdlibUnRegister("_ChkKey")
        While _IsPressed("0D", $dll)
            Sleep(20)
        WEnd
        $hlist = ControlGetHandle("[active]", "", "[CLASS:SysListView32; INSTANCE:1]")
        $aItem = _GUICtrlListView_GetSelectedIndices($hlist, True)
;~      ConsoleWrite("Count " & $aItem[0] & @CRLF)
        For $i = 1 To $aItem[0]
;~          ConsoleWrite("row " & _GUICtrlListView_GetItemText(3, $aItem[$i]) & @CRLF)
;~          ConsoleWrite("Value " & _GUICtrlListView_GetItemText(3, $aItem[$i],1) & @CRLF)
;~          ConsoleWrite("Index " & $aItem[$i] & "  ")
            $aItem[$i] = StringMid(_GUICtrlListView_GetItemText($hlist, $aItem[$i]), 5)
        Next
;~      ConsoleWrite(@CRLF)
        Sleep(100)
        Send("{esc}")
    EndIf
    AdlibRegister("_ChkKey", 100)
    Return $aItem
EndFunc   ;==>_ChkKey

 

Edited by wolflake
Correction
Link to comment
Share on other sites

On 2/26/2021 at 7:09 PM, wolflake said:

_DebugArrayDisplay adds those but doesn't have the sorting.

In what AutoIt version?

I have it in 3.3.14.5 (final release).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

I was wrong about _DebugArraySort() not sorting although in my test the first click on the header didn't sort the second one did.  I have a lot of things running which look for keys so it's possible that they are not returning in time to get the first mouse click.

Thanks for picking up my mistake.

It is in version 3.3.14.5
To see the _ArrayDisplay of the "past" you need to #include <debug.au3> and use _DebugArrayDisplay(,"") .

Here is the header for the debug.au3 include file:

; #INDEX# =======================================================================================================================
; Title .........: Debug
; AutoIt Version : 3.3.14.5
; Language ......: English
; Description ...: Functions to help script debugging.
; Author(s) .....: Nutster, Jpm, Valik, guinness, water
; ===============================================================================================================================

 

; #FUNCTION# ====================================================================================================================
; Author ........: Melba23
; Modified.......: jpm

; ===============================================================================================================================
Func _DebugArrayDisplay(Const ByRef $aArray, $sTitle = Default, $sArrayRange = Default, $iFlags = Default, $vUser_Separator = Default, $sHeader = Default, $iMax_ColWidth = Default, $hUser_Function = Default)
    Local $iRet = __ArrayDisplay_Share($aArray, $sTitle, $sArrayRange, $iFlags, $vUser_Separator, $sHeader, $iMax_ColWidth, $hUser_Function, True)
    Return SetError(@error, @extended, $iRet)
EndFunc   ;==>_DebugArrayDisplay

 

 

Edited by wolflake
Correction
Link to comment
Share on other sites

Could someone confirm this:

If I have a three column arraydisplay counting the row header and I click once on each one once ie Row Col0 Col1 nothing sorts and I can repeat that and still nothing sorts. If I double click (quickly) it also doesn't sort but if I single click twice on the same column it does sort and will continue to sort with each single click on the same header.

I think when I first tried sorting I just click once on each column header and said well that's not working. 😚

Link to comment
Share on other sites

5 hours ago, wolflake said:

I click once on each one once ie Row Col0 Col1 nothing sorts...

Hi wolflake :)
This can happen if the columns are already sorted (ascending) when you call ArrayDisplay, I just tested it again now.

I also tested what happens if a column isn't sorted (ascending) when ArrayDisplay initially shows it, then a 1st click on its header immediately sorts it (ascending)

Actually, in ArrayDisplay, there isn't a sort arrow (up or down) to make it easier for the user.
This lack of sort arrow in the listview header has been discussed in this thread and the solution is found in the middle of the thread.

If you want a sort arrow to appear, here is what you'll have to do in the file ArrayDisplayInternals.au3 (version 3.3.14.5)

Just move line 560 to the empty line 564, as shown in the 2 following pictures :

Before :
1_ArrayDisplayInternals_before.png.d29c3106c77fe1b69871972d876ee8da.png

After :
2_ArrayDisplayInternals_after.png.dac0b4760d89239aef2665549ee3c896.png

Now you will have a sort arrow appearing in ArrayDisplay, making it easier for you.
Good luck

Link to comment
Share on other sites

3 hours ago, pixelsearch said:

Now you will have a sort arrow appearing in ArrayDisplay

And if we add

__ArrayDisplay_SortItems($idListView, 0)

after

__ArrayDisplay_RegisterSortCallBack($idListView, 2, True, "__ArrayDisplay_SortCallBack")

we get this arrow displayed at the beginning (right after the array is displayed).

Btw, is this arrow should be in opposite direction or i am wrong?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

37 minutes ago, MrCreatoR said:

And if we add [...] after [...] we get this arrow displayed at the beginning (right after the array is displayed)

Hi MrCreatoR :)
I wouldn't do that for 2 reasons :

1) 1st column (named "Row") is already sorted ascending when ArrayDisplay appears.
2) most important: if the user used the flag "$ARRAYDISPLAY_NOROW (64) = No 'Row' column displayed", then you force his 1st data column to be sorted ascending, maybe he wanted it to appear 1st as it was created, unsorted.

Concerning the sort arrow direction, I like to follow this rule (as found in AutoIt, Windows Explorer etc...)
* arrow pointing to the sky (up) => ascending sort
* arrow pointing to the ground (down) => descending sort

But as you wrote, it maybe indicated differently in some other software.

Link to comment
Share on other sites

Thanks guys now it all makes sense!  

@pixelsearch I just made the change you suggested (after changing the ReadOnly property of the file) and it works beautifully. 

I really appreciate your detailed explanation and the links.  I think your suggestion should be implemented in the next version of Autoit.

... got to go set that read only flag back :)

Edited by wolflake
Link to comment
Share on other sites

15 hours ago, pixelsearch said:

1) 1st column (named "Row") is already sorted ascending when ArrayDisplay appears.
2) most important: if the user used the flag "$ARRAYDISPLAY_NOROW (64) = No 'Row' column displayed", then you force his 1st data column to be sorted ascending, maybe he wanted it to appear 1st as it was created, unsorted.

Then we do it like this:

If Not $iNoRow Then
        __ArrayDisplay_SortItems($idListView, 0)
    EndIf

 

15 hours ago, pixelsearch said:

Concerning the sort arrow direction, I like to follow this rule

Well, the logics says that ascending should be from up to down, so i think that the arrow as well should indicate the same.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Instead of looking at it as an arrow pointing in a direction I look at it as a symbol with a small top and a big bottom (small to large) or a big top and a small bottom (large to small) just a different perspective.

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...