Foreground Fileview [SOLVED]

Post

Posted
Rating:
#1 (In Topic #1035)
Trainee
Hello,

I am using a fileview and I would need to have a different foreground color, for example, if the file name contains "Picture056".
Is this possible?  :?:

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi toto96 and welcome to the forum.

Can you tell us exactly what you are trying to achieve. I can't find a setting to change a background of a single FileView icon, but there may well be another way.
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
Hi :)

I would like to change the font color of one or several items in the fileview.

For my example:

In my application, I save a "note" on an image and I would like the text color of the element to change. I can do it with the foreground parameter, but it modifies everything (here in red).
Sorry for my English - I am French.


Code (gambas)

  1.     .MaxPreviewSize = -1
  2.     .ShowPreview = True
  3.     .IconSize = 192
  4.     .filter = extension_fichier_image
  5.     .Drop = True

Code (gambas)

  1.  FILEVIEW.Foreground = Color.Red

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
You can do it with IconView

IconView has Keys and the items have a .RichText property so you can set <font color=red>.

FileView uses an IconView to show it's contents so you can access it like this…

Code (gambas)

  1. Public Sub Make_b_Red()
  2.  
  3.  
  4.   ' get the IconView  control inside the FileView
  5.   Dim p As Panel = FileView1.Children[0]
  6.   Dim IView As IconView = p.Children[0]
  7.  
  8. ' if file name has a b in it then set its text red
  9.   For Each s In IView.Keys
  10.     If  IView[s].Text Like "*b*" Then
  11.       IView[s].RichText = "<font color=red>" & IView[s].Text & "</font>"
  12.     Endif
  13.   Next
  14.  
  15.  

That will show every file with a b in it as red text.
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
vuott is in the usergroup ‘Regular’

BruceSteers said

FileView uses an IconView to show it's contents so you can access it like this…

Code (gambas)

  1. ' get the IconView  control inside the FileView
  2.   Dim p As Panel = FileView1.Children[0]
  3.   Dim IView As IconView = p.Children[0]
  4.  

Bravo ! <EMOJI seq="1f44d" tseq="1f44d">👍</EMOJI>

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’

vuott said

BruceSteers said

FileView uses an IconView to show it's contents so you can access it like this…

Code (gambas)

  1. ' get the IconView  control inside the FileView
  2.   Dim p As Panel = FileView1.Children[0]
  3.   Dim IView As IconView = p.Children[0]
  4.  

Bravo ! <EMOJI seq="1f44d" tseq="1f44d">👍</EMOJI>

Why thank you kind sir :)

So let's take it a step further…
The above code only works if the FileView is not in "Detailed" view mode as detailed mode uses a ColumnView not an IconView.

So below is the test code I just made
The Form has a FileView a TextBox and a ComboBox
The combobox changes the View mode
With the TextBox you can provide a pcre text pattern and names matching the pattern will show red.  Ie. IMG_*
it will work in all FileView View modes

Code (gambas)

  1.  
  2. Public Sub Form_Open()
  3.  
  4.   FileView1.Dir = User.Home ' load Home dir in FileView
  5.   ComboBox1.List = ["Normal", "Compact", "Detailed", "Preview"]
  6.   ComboBox1.Index = FileView1.View
  7.  
  8.  
  9. Public Sub ComboBox1_Click()
  10.  
  11.   If FileView1.View = Last.Index Then Return
  12.  
  13.   FileView1.View = Last.Index
  14.   MakeFileViewTextRed(TextBox1.Text)
  15.  
  16.  
  17. Public Sub TextBox1_Activate()
  18.  
  19.   MakeFileViewTextRed(TextBox1.Text)
  20.  
  21.  
  22.  
  23. ' Make FileView1 text red or not depending on the pcre Pattern
  24. Public Sub MakeFileViewTextRed(Pattern As String)
  25.  
  26.  
  27.   Dim p As Panel = FileView1.Children[0]
  28.   Dim IView As IconView = p.Children[0]
  29.   Dim CView As ColumnView = p.Children[1]
  30.  
  31.   If FileView1.View <> FileView.Detailed Then
  32.  
  33.     For Each s In IView.Keys
  34.       If IView[s].Text Like Pattern Then
  35.         IView[s].RichText = "<font color=red>" & IView[s].Text & "</font>"
  36.       Else
  37.         IView[s].RichText = IView[s].Text
  38.       Endif
  39.     Next
  40.     IView.Refresh
  41.  
  42.   Else
  43.  
  44.     For Each s In CView.Keys
  45.       If CView[s].Text Like Pattern Then
  46.         CView[s].Foreground = Color.Red
  47.       Else
  48.         CView[s].Foreground = Color.Default
  49.       Endif
  50.     Next
  51.     CView.Refresh
  52.  
  53.  
  54.  
  55.  
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

cogier said

Hi toto96 and welcome to the forum.

Can you tell us exactly what you are trying to achieve. I can't find a setting to change a background of a single FileView icon, but there may well be another way.

With Gambas there is very often another way :)

Let me explain how i figured out the above posted method…

1. I added this simple test code to my Form_Open

Code (gambas)

  1.  
  2.   Print FileView1.Children[0]  ' this was Panel 0x56283a42d348)
  3.   Print FileView1.Children[1]  ' this was TextLabel 0x55a579d76898)
  4.   Print FileView1.Children[2]  ' this gave a Null object error
  5.  
So then from that i knew i wanted the Panel at FileView1.Children[0]

2. So I then tried this code..

Code (gambas)

  1.   Dim p As Panel = FileView1.Children[0]
  2.   Print p.Children[0]  '  bingo, that was (IconView 0x562b09c0a9f8)
  3.   Print p.Children[1]  '  that was (ColumnView 0x55f1134bcb38)
  4.  
That was all I needed to know.
I have access to the IconView and the ColumnView of the FileView control and can use their properties for customization.

I use this method a lot to find the way to private controls within controls for tweaks.

Happy coding :)
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’

toto96 said

Hi :)

I would like to change the font color of one or several items in the fileview.

For my example:

In my application, I save a "note" on an image and I would like the text color of the element to change. I can do it with the foreground parameter, but it modifies everything (here in red).
Sorry for my English - I am French.


Code (gambas)

  1.     .MaxPreviewSize = -1
  2.     .ShowPreview = True
  3.     .IconSize = 192
  4.     .filter = extension_fichier_image
  5.     .Drop = True

Code (gambas)

  1.  FILEVIEW.Foreground = Color.Red

You should be able to use the above method to access the IconView inside the FileView and set individual items of choice.

But watch out for the Key names with the IconView not quite matching the text.  (mine were prefixed with 1)
Ie.
If the file name is IMG_4591.jpg
The ColumView Key name was CView["IMG_4591.jpg"]
The IconView Key name was IView["1IMG_4591.jpg"]

Best of luck :)
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’
So finally..

Here is code that sets individual items.
it uses a String[] array called $aMarkedFiles
Any items added to this list show red while others show default colour

I've attached the project so you can test it out.
it has 2 buttons "Mark file" and "Unmark file" that toggle items having red text for you.

Hopefully you can use it for your needs :)

Attachment


Code (gambas)

  1. ' Gambas class file
  2.  
  3. Private $aMarkedFiles As New String[]
  4.  
  5. Public Sub Form_Open()
  6.  
  7.   FileView1.Dir = User.Home
  8.   ComboBox1.List = ["Normal", "Compact", "Detailed", "Preview"]
  9.   ComboBox1.Index = FileView1.View
  10.  
  11.  
  12. Public Sub ComboBox1_Click()
  13.  
  14.   If FileView1.View = Last.Index Then Return
  15.   FileView1.View = Last.Index
  16.   Wait 0.1  ' give the FileView a moment to refresh it's contents
  17.   MakeFileViewTextRed
  18.  
  19.  
  20. ' go through the FileView contents setting any items that are in the $aMarkedFiles array to red
  21. Public Sub MakeFileViewTextRed()
  22.  
  23.  
  24.   Dim p As Panel = FileView1.Children[0]
  25.   Dim IView As IconView = p.Children[0]
  26.   Dim CView As ColumnView = p.Children[1]
  27.  
  28.   If FileView1.View <> FileView.Detailed Then
  29.  
  30.     For Each s In IView.Keys
  31.       If $aMarkedFiles.Exist(IView[s].Text) Then
  32.         IView[s].RichText = "<font color=red>" & IView[s].Text & "</font>"
  33.       Else
  34.         IView[s].RichText = IView[s].Text
  35.       Endif
  36.     Next
  37.     IView.Refresh
  38.  
  39.   Else
  40.  
  41.     For Each s In CView.Keys
  42.       If $aMarkedFiles.Exist(CView[s].Text) Then
  43.         CView[s].Foreground = Color.Red
  44.       Else
  45.         CView[s].Foreground = Color.Default
  46.       Endif
  47.     Next
  48.     CView.Refresh
  49.   FileView1_Click
  50.  
  51.  
  52. Public Sub btnMark_Click()
  53.  
  54.   If Not FileView1.Current Then Return
  55.   $aMarkedFiles.Add(FileView1.Current)
  56.   MakeFileViewTextRed
  57.  
  58.  
  59. Public Sub btnUnmark_Click()
  60.  
  61.   If Not FileView1.Current Then Return
  62.   $aMarkedFiles.Remove($aMarkedFiles.Find(FileView1.Current))
  63.   MakeFileViewTextRed
  64.  
  65.  
  66. Public Sub FileView1_Click() ' enable/disable the Mark/Unmark buttons depending if item is marked
  67.  
  68.   If Not FileView1.Current Then Return
  69.   Dim bMarked As Boolean = $aMarkedFiles.Exist(FileView1.Current)
  70.   btnMark.Enabled = Not bMarked
  71.   btnUnmark.Enabled = bMarked
  72.  
  73.  
  74.  
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
vuott is in the usergroup ‘Regular’
 No files appear in the FileView Control.
Why ?

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’

vuott said

No files appear in the FileView Control.
Why ?

I have no idea.

You can see in form open…
 FileView1.Dir = User.Home

It populates just fine here with files in $HOME !
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
vuott is in the usergroup ‘Regular’
 Ah, right !
ok.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#13
Trainee
 A big thank you to BruceSteers, it works perfectly.
Thanks to everyone for your help
Online now: No Back to the top

Post

Posted
Rating:
#14
Guru
BruceSteers is in the usergroup ‘Guru’

toto96 said

A big thank you to BruceSteers, it works perfectly.
Thanks to everyone for your help

No worries, happy to help.

My advice to help you experiment with making controls do things beyond the normal would be this..

* See if the control exists in the components gb.form or gb.gui.base and examine it's source code.
If you do not have the source downloaded it can be viewed here..
comp/src/gb.form · master · Gambas / gambas · GitLab
comp/src/gb.gui.base · master · Gambas / gambas · GitLab

Examining the source of the custom gambas controls can really help see what can and cannot be done.

* use the "Print object.Children[x]" trick i mentioned in the previous post to find the Children/types and the path to the internal control you want to tweak.

* use the wiki to see what properties/methods the controls have to get what you want (Ie. like using .RichText in place of .Foreground for text colour)


Also be aware things like this can possibly break at some point if the main component changes.  (i think it is rare)
For example if something changes in the FileView control that adds an Object/Panel before the others, then the Panel we want may not be Children[0] anymore.
Online now: No Back to the top
1 guest and 0 members have just viewed this.