[Class] LV_Colors - 1.1.05.00 (2024-03-16)

Post your working scripts, libraries and tools for AHK v1.1 and older
just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by just me » 19 Mar 2016, 02:23

Hi ecksphore,

seemingly it is working here. Would you provide a sample showing the issue, please?

ecksphore
Posts: 33
Joined: 03 Feb 2015, 22:36

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by ecksphore » 19 Mar 2016, 13:33

After re-reading the comments in the script, maybe I misunderstood something.
Static color assignment, i.e. the colors will be assigned permanently to the row contents rather than to the row number.
I was under the impression this would mean I could move a row up/down and the custom background color would stick? or am I wrong?

Also, I can't seem to find any real examples on how to properly use this script. All the comments in this thread have different code (some labeled as "no longer needed"). Where can I find the 'up-to-date' usage information?

just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by just me » 20 Mar 2016, 02:23

My description may be confusing, but I don't know any better. The colors are 'tied' to the item at the moment it is added to the LV.

I don't know a way to 'move' items within a LV except the built-in sort. In all other cases you most probably delete the original item and add/insert a new item. So the connection between the item and the colors get's lost if you don't renew it.

ecksphore
Posts: 33
Joined: 03 Feb 2015, 22:36

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by ecksphore » 20 Mar 2016, 20:33

Ah .. after looking at my custom function again, that's exactly what's happening.

When rows are moved up/down, they are getting deleted and re-created. I'm going to solve the issue by looping through the first column contents and re-applying the color.

Thank you very much for all your hard work!

User avatar
JoeWinograd
Posts: 2241
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by JoeWinograd » 21 Mar 2016, 10:17

Hi just me,
I'm using a single-column LV_Colors to implement what I call the Processing Console, which gives the user feedback as the program is processing (mentioned in this previous post). One of the menu items in the program allows the user to copy the contents of the Processing Console to the clipboard. Here's the code snippet for it:

Code: Select all

AllRecords:=""
NumberConsoleRecords:=LV_GetCount()
Loop,%NumberConsoleRecords%
{
  LV_GetText(CurrentRecord,A_Index)
  AllRecords:=AllRecords . CurrentRecord . "`n"
}
StringTrimRight,AllRecords,AllRecords,1
Clipboard:=AllRecords
It works well, but does not get the colors. The AHK doc says that ClipboardAll (rather than Clipboard) "contains everything on the clipboard, such as pictures and formatting", which would presumably include colors, but ClipboardAll cannot be on the left side of an assignment statement. How can I can get the rows, including the colors from LV_Colors, to be on the clipboard so that a user can Paste them into a program that handles color? Thanks very much, Joe

just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by just me » 21 Mar 2016, 12:00

No chance to do it automatically! As the name implies LV_GetText() gets only the column text. Also, the colors are only used internally for drawing, not as text attributes which could be interpreted by other programs.

User avatar
JoeWinograd
Posts: 2241
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by JoeWinograd » 21 Mar 2016, 12:16

OK, thanks for the explanation. Btw, LV_Colors is terrific — really appreciate your efforts on it!

Treashunter

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by Treashunter » 23 Mar 2016, 16:08

Hi again!

Ive got an issue where when running my compiled program(in x86) on 32 bit machines, the color in the listview rows does not maintain its proper width when being resized(single column listviews - colors span the listview width). It does work fine though when im running the program on an x64 PC.....any ideas why that would happen?

Everything works great except for on these 32bit PC's. All running Win7.

Thank you much for any Insight!

~Treashunter

User avatar
JoeWinograd
Posts: 2241
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by JoeWinograd » 23 Mar 2016, 17:36

Hi just me,
Something strange is happening with LV_Colors that I'm hoping you can explain. As mentioned earlier, I'm using a single-column LV_Colors to implement what I call the Processing Console, which gives the user feedback as the program is processing. One of the menu items in the program allows the user to clear the contents of the Processing Console. The code for that is simply LV_Delete().

In case the user accidentally clicked Clear Processing Console, there's a menu item Restore Processing Console. What that does is read a plain text logfile that has the text-only contents of the Processing Console. The code for that is:

Code: Select all

Loop,Read,%Logfile%
{
  If (ErrorLevel<>0)
  {
    Gui,+OwnDialogs
    MsgBox,4112,Fatal Error 001041,Error Level=%ErrorLevel% trying to read logfile`n%Logfile%
    ExitApp
  }
  RowNumber:=LV_Add("",A_LoopReadLine)
}
Now here's what's strange. Since the logfile is plain text, I would expect there to be no colors in the restored Processing Console (i.e., just the default text and background colors). But there are colors! The colors are on the "wrong" rows, that is, not where they were before the Clear Processing Console was issued, but why are there any (non-default) colors at all? I'd rather have there be no colors on rows (just the default text and background colors) rather than the wrong colors. How would I do that? Thanks, Joe

Update: It's even stranger than I thought. Turns out that the reason for the colors being on the "wrong" rows is that I put out new messages in the LV that say, "Processing Console cleared on..." and "Processing Console restored on...". So the row numbers in the cleared LV don't match the row numbers in the restored LV. When I stop writing out the "Processing Console cleared on..." and "Processing Console restored on..." messages, the row numbers match — and, guess what? — the colors (text and background) are right! This means that LV_Colors is somehow retaining the text and background colors of previously added row numbers. I'm actually thrilled about this, but I don't understand what's happening under the covers. I'm sure you do, and if you could take a moment to explain, I'd appreciate it. Regards, Joe

just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by just me » 24 Mar 2016, 01:59

Hi JoeWinograd,

nothing strange at all! ;)

LV_Colors() keeps its own color array. In the default 'non-static' mode the array is indexed by the row numbers. In 'static' mode an internal ID is used instead which (according to the MSDN) is unique for each row for the lifetime of the control.

LV_Delete() does not touch this array. So subsequently added rows will use the stored colors if their row numbers are contained in the array. To clear the whole array you have to call LV_Colors.Clear().

User avatar
JoeWinograd
Posts: 2241
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by JoeWinograd » 24 Mar 2016, 08:21

LV_Colors() keeps its own color array.
Ah, that explains it! Very nice!
To clear the whole array you have to call LV_Colors.Clear().
Was unaware of that — great to know!

Thanks again for your help. Regards, Joe

User avatar
JoeWinograd
Posts: 2241
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by JoeWinograd » 04 Apr 2016, 14:47

AHK 1.1.22.09 32-bit Unicode (reluctant to go to 1.1.23.05 because of this issue)
W7 Pro 64-bit
LV_Colors 1.1.03.00/2015-04-11

Hi just me,
As you know from my previous posts, I'm using a single-column LV_Colors to implement what I call the Processing Console, which gives the user feedback as the program is processing. I've been troubleshooting a problem where the program hangs, and I've been able to isolate the problem as being related to LV_Modify when using LV_Colors. The whole script is fairly large (more than 1,500 lines) but I created a small script that reproduces the problem:

Code: Select all

; start of lines to change
#Include c:\library location\Class_LV_Colors.ahk
LogfilePath:="c:\temp"
Iterations:=10000
; end of lines to change

#Warn,UseUnsetLocal
#NoEnv
SetBatchLines,-1
FormatTime,DateTime,A_Now,yyyy-MM-dd_HH.mm.ss
Logfile:=LogfilePath . "\DebugColorsLogfile_" . DateTime . ".txt"
ColorBackground:="0xFFFFFF"
ColorText:="0xFF0000"

Gui,Color,%ColorBackground%
Gui,Font,bold s10 c0000FF,Arial
Gui,+Resize
Gui,Add,ListView,vConsoleListView hwndConsoleHandle r20 w700,Processing Console
ColorConsole:=New LV_Colors(ConsoleHandle)
GuiControl,Font,ConsoleListView
Menu,FileMenu,Add,&Run,FileMenuRun
Menu,FileMenu,Add,E&xit,FileMenuExit
Menu,MenuBar,Add,&File,:FileMenu
Gui,Menu,MenuBar
Gui,Show,w800 h500,Debug LV_Colors
Return

FileMenuRun:
Loop,%Iterations%
{
  ConsoleRow:="Loop index=" . A_Index " at " . A_Now
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError
  RowNumber:=LV_Add("",ConsoleRow)
  ConsoleRow:="Return from LV_Add at " . A_Now . " with row number " . RowNumber
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError

  LV_Modify(RowNumber,"Vis") ; scroll LV so newly added last row is visible - seems to be the culprit!

  ConsoleRow:="Return from LV_Modify at " . A_Now . " with row number " . RowNumber
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError
  ColorConsole.Row(RowNumber,ColorBackground,ColorText)
  ConsoleRow:="Return from ColorConsole at " . A_Now . " with row number " . RowNumber . " CB=" . ColorBackground . " CT=" . ColorText
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError
  GuiControl,+Redraw,%ConsoleHandle%
  ConsoleRow:="Return from GuiControl Redraw at " . A_Now . " with Console Handle " . ConsoleHandle
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError
}
Return

FileAppendError:
MsgBox,4112,Fatal Error,Error Level %ErrorLevel% from FileAppend
ExitApp

FileMenuExit:
GuiClose:
GuiEscape:
ExitApp
When you do a File>Run on the above, it will eventually hang. The logfile shows that it returns from the LV_Add and then dies, meaning that it never comes back from the following LV_Modify (unless it's hanging in FileAppend to write the logfile, which I think is highly unlikely). It dies at different places — I ran it ten times and it hung at these rows (random, as far as I can tell):

652
53
56
202
93
2287
483
128
183
1111

I then commented out the LV_Colors code:

Code: Select all

; start of lines to change
#Include c:\library location\Class_LV_Colors.ahk
LogfilePath:="c:\temp"
Iterations:=10000
; end of lines to change

#Warn,UseUnsetLocal
#NoEnv
SetBatchLines,-1
FormatTime,DateTime,A_Now,yyyy-MM-dd_HH.mm.ss
Logfile:=LogfilePath . "\DebugColorsLogfile_" . DateTime . ".txt"
ColorBackground:="0xFFFFFF"
ColorText:="0xFF0000"

Gui,Color,%ColorBackground%
Gui,Font,bold s10 c0000FF,Arial
Gui,+Resize
Gui,Add,ListView,vConsoleListView hwndConsoleHandle r20 w700,Processing Console
;ColorConsole:=New LV_Colors(ConsoleHandle)
GuiControl,Font,ConsoleListView
Menu,FileMenu,Add,&Run,FileMenuRun
Menu,FileMenu,Add,E&xit,FileMenuExit
Menu,MenuBar,Add,&File,:FileMenu
Gui,Menu,MenuBar
Gui,Show,w800 h500,Debug LV_Colors
Return

FileMenuRun:
Loop,%Iterations%
{
  ConsoleRow:="Loop index=" . A_Index " at " . A_Now
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError
  RowNumber:=LV_Add("",ConsoleRow)
  ConsoleRow:="Return from LV_Add at " . A_Now . " with row number " . RowNumber
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError

  LV_Modify(RowNumber,"Vis") ; scroll LV so newly added last row is visible - seems to be the culprit!

  ConsoleRow:="Return from LV_Modify at " . A_Now . " with row number " . RowNumber
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError
;  ColorConsole.Row(RowNumber,ColorBackground,ColorText)
;  ConsoleRow:="Return from ColorConsole at " . A_Now . " with row number " . RowNumber . " CB=" . ColorBackground . " CT=" . ColorText
;  FileAppend,%ConsoleRow%`n,%Logfile%
;  If (ErrorLevel<>0)
;    Goto,FileAppendError
  GuiControl,+Redraw,%ConsoleHandle%
  ConsoleRow:="Return from GuiControl Redraw at " . A_Now . " with Console Handle " . ConsoleHandle
  FileAppend,%ConsoleRow%`n,%Logfile%
  If (ErrorLevel<>0)
    Goto,FileAppendError
}
Return

FileAppendError:
MsgBox,4112,Fatal Error,Error Level %ErrorLevel% from FileAppend
ExitApp

FileMenuExit:
GuiClose:
GuiEscape:
ExitApp
The two scripts are identical except for the six commented out lines relating to the use of LV_Colors. It processed all 10,000 iterations without hanging — four times!

Maybe I'm calling LV_Colors incorrectly, but I'm hoping you can help me figure this out as my users find the colors in the Processing Console to be extremely helpful. But for now I've stopped using colors, as the program's hanging is a show-stopper. Thanks very much, Joe

just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by just me » 05 Apr 2016, 04:35

Hi JoeWinograd!

LV_Colors() has to process WM_NOTIFY notifications sent by the ListView to do its job. It's a known issue that this might cause problems if the contents of the ListView is changing fast. One possible workaround ist to set the LV_Colors object's Critical property to On or another sufficient value (e.g.ColorConsole.Critical := "On"), but Critical might cause its own special issues.

Usually it's best to disable redrawing while adding a large amount of items. But if you have to add single items in rapid sequence this will be no option.

After testing your example I think that the use of GuiControl,+Redraw,%ConsoleHandle% is causing the issue. It will redraw the whole control so notifications for all visible items have to be processed by the LV_Colors object after each added item. I think that you're doing it to update the added item's colors. For me, LV_Modify(RowNumber, "Vis") seems to redraw the item on its own, so it seems to be sufficient to set the colors before it is called:

Code: Select all

FileMenuRun:
Loop,%Iterations%
{
  ConsoleRow := "Loop index=" . A_Index " at " . A_Now
  FileAppend,%ConsoleRow%`n, %Logfile%
  If (ErrorLevel <> 0)
    Goto, FileAppendError ; are you sure you want to 'Goto'?
  RowNumber := LV_Add("", ConsoleRow)
  ColorConsole.Row(RowNumber, ColorBackground, ColorText) ; set the colors before you call LV_Modify()
  LV_Modify(RowNumber, "Vis") ; scroll LV so newly added last row is visible
}
Return
It's working here. If it doesn't work for you, we can try other options.

Regards,
just me

User avatar
JoeWinograd
Posts: 2241
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by JoeWinograd » 05 Apr 2016, 09:30

Hi just me,
Removing GuiControl,+Redraw,%ConsoleHandle% did the trick! I just ran 10,000 iterations (twice) — no problem! Thanks for the quick response — I really appreciate it. Regards, Joe

P.S. Yes, I'm sure I want the Goto there. It executes only when FileAppend fails — should never happen, but if it does, I'm fine with a "Fatal Error" MsgBox and ExitApp at that point.

User avatar
oldbrother
Posts: 279
Joined: 23 Oct 2013, 05:08

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by oldbrother » 15 Apr 2016, 07:56

Is it a Bug?

Hi Just me,

This class disables sorting! Please try on your example. When "Colors on" checked, the script will stop responding to the clicks on the headers.

One of the greatest classes though.

Best regards,

just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by just me » 15 Apr 2016, 08:46

Hi oldbrother,

sorting might cause the well-known issues.That's why it is disabled by default. You can change the default by setting NoSort to False when creating the LVObject or you can call LVObject.NoSort(True/False) whenever you need it.

User avatar
oldbrother
Posts: 279
Joined: 23 Oct 2013, 05:08

Re: [Class] LV_Colors - 1.1.03.00 (2015-04-12)

Post by oldbrother » 15 Apr 2016, 10:05

Hi Just me,

Thank you very much for your quick responding.

The order versions seem do not have this issue. One of my script is using "0.5.00.00/2014-08-13/just me". There is no sorting problem at all, the color is always on.

Best regards,

just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.00 (2016-05-03)

Post by just me » 03 May 2016, 07:01

*Update 1.1.04.00 on 2016-05-03*
Added SelectionColor() method.

User avatar
JoeWinograd
Posts: 2241
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: [Class] LV_Colors - 1.1.04.00 (2016-05-03)

Post by JoeWinograd » 03 May 2016, 09:48

Hi just me,

First, thanks for the enhancement — really appreciate that you keep the code up-to-date. Second, a question about the new feature: when would I use

CLV.SelectionColors(ColorBackground,ColorText)

instead of

CLV.Row(RowNumber,ColorBackground,ColorText)

Thanks, Joe

just me
Posts: 9763
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

Post by just me » 03 May 2016, 10:04

*Another small update 1.1.04.01*
Added change to remove the focus border for custom drawn rows (SelectionColor).

Hi Joe,

CLV.Row() sets the colors for a specific row whereas CLV.SelectionColor() sets the colors used for the currently selected row(s). Without it the row colors set by CLV.Row() before the row gets selected are ignored.

Post Reply

Return to “Scripts and Functions (v1)”