Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #233: TCP/IP UDP alarm threshold is set too low.


comp / comp.lang.tcl / Re: A ttk:combox with colors?

SubjectAuthor
* A ttk:combox with colors?Helmut Giese
+- Re: A ttk:combox with colors?greg
`* Re: A ttk:combox with colors?greg
 `* Re: A ttk:combox with colors?Helmut Giese
  `* Re: A ttk:combox with colors?greg
   `- Re: A ttk:combox with colors?Helmut Giese

1
Subject: A ttk:combox with colors?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Sat, 2 Nov 2024 21:24 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: A ttk:combox with colors?
Date: Sat, 02 Nov 2024 22:24:28 +0100
Organization: ratiosoft
Lines: 7
Message-ID: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 02 Nov 2024 22:24:34 +0100 (CET)
Injection-Info: dont-email.me; posting-host="e6f457745b6e189271865226c6dc607e";
logging-data="4174402"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CDfSGrvoI7kj6uqEywjnB"
Cancel-Lock: sha1:Xa4ArlmFLDkwkUX7IgiEC99Lb7M=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Hello out there,
I would like to have a combobox display stripes of colors instead of
text and the selection coloring the background of the combo's text
field. How could I go about creating such a beast (or maybe it exists
already)?
Any link or idea will be highly appreciated
Helmut

Subject: Re: A ttk:combox with colors?
From: greg
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 3 Nov 2024 07:54 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.ebbing@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: A ttk:combox with colors?
Date: Sun, 3 Nov 2024 08:54:41 +0100
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <vg7a81$96lt$1@dont-email.me>
References: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 03 Nov 2024 08:54:42 +0100 (CET)
Injection-Info: dont-email.me; posting-host="be265aa596638e3d436c4b009952cf8d";
logging-data="301757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18jWREaof/f7pyvUrZ4AcCP0MRd+KdKJmE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tT/sGKA2SzDprRu5QVEfS+G/z+Y=
Content-Language: de-DE
In-Reply-To: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com>
View all headers

Am 02.11.24 um 22:24 schrieb Helmut Giese:
> Hello out there,
> I would like to have a combobox display stripes of colors instead of
> text and the selection coloring the background of the combo's text
> field. How could I go about creating such a beast (or maybe it exists
> already)?
> Any link or idea will be highly appreciated
> Helmut

Hello Helmut,

I use the internal listbox of combobox. When I select an element for the
first time, the text in the combobox is visible for a short time. I have
no idea.

Gregor

#! /usr/bin/env tclsh

package require Tk

# Procedure to style the listbox items
# interna popdown.f.l
# https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm
proc styleListbox {cb} {
set popdown [ttk::combobox::PopdownWindow $cb]
set lb "$popdown.f.l"
set colors [$cb cget -values]
set i 0
foreach color $colors {
$lb itemconfigure $i -background $color
$lb itemconfigure $i -foreground $color
$lb itemconfigure $i -selectbackground $color
$lb itemconfigure $i -selectforeground $color
incr i
}
}

# Create a combobox with the custom style
set selectedValue ""
ttk::combobox .cb -style CustomCombobox.TCombobox \
-values [list "green" "red" "white" "yellow" "black"] \
-textvariable selectedValue -state readonly

pack .cb -padx 20 -pady 20

# Event binding to style the internal listbox when the combobox is opened
bind .cb <ButtonPress-1> {
after 100 {styleListbox .cb}
}

# Event binding
# https://wiki.tcl-lang.org/page/ttk%3A%3Acombobox
# Disabled/Readonly color (and pointer to color change)
bind .cb <<ComboboxSelected>> {
ttk::style map CustomCombobox.TCombobox -fieldbackground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -foreground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -background "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -selectforeground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -selectbackground "readonly
$selectedValue"
} ..cb set "white"
event generate .cb <<ComboboxSelected>>

Subject: Re: A ttk:combox with colors?
From: greg
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 3 Nov 2024 07:55 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.ebbing@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: A ttk:combox with colors?
Date: Sun, 3 Nov 2024 08:55:51 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <vg7aa7$96lt$2@dont-email.me>
References: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 03 Nov 2024 08:55:51 +0100 (CET)
Injection-Info: dont-email.me; posting-host="be265aa596638e3d436c4b009952cf8d";
logging-data="301757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4dTYk2yOIX4/yEej7k7JSHaNSJSglvsc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:OS+BvLvD+OHkE+PUxPXc+wnmRkk=
Content-Language: de-DE
In-Reply-To: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com>
View all headers

Am 02.11.24 um 22:24 schrieb Helmut Giese:
> Hello out there,
> I would like to have a combobox display stripes of colors instead of
> text and the selection coloring the background of the combo's text
> field. How could I go about creating such a beast (or maybe it exists
> already)?
> Any link or idea will be highly appreciated
> Helmut

Hello Helmut,

I use the internal listbox of combobox. When I select an element for the
first time, the text in the combobox is visible for a short time. I have
no idea.

Gregor

#! /usr/bin/env tclsh

package require Tk

# Procedure to style the listbox items
# interna popdown.f.l
# https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm
proc styleListbox {cb} {
set popdown [ttk::combobox::PopdownWindow $cb]
set lb "$popdown.f.l"
set colors [$cb cget -values]
set i 0
foreach color $colors {
$lb itemconfigure $i -background $color
$lb itemconfigure $i -foreground $color
$lb itemconfigure $i -selectbackground $color
$lb itemconfigure $i -selectforeground $color
incr i
}
}

# Create a combobox with the custom style
set selectedValue ""
ttk::combobox .cb -style CustomCombobox.TCombobox \
-values [list "green" "red" "white" "yellow" "black"] \
-textvariable selectedValue -state readonly

pack .cb -padx 20 -pady 20

# Event binding to style the internal listbox when the combobox is opened
bind .cb <ButtonPress-1> {
after 100 {styleListbox .cb}
}

# Event binding
# https://wiki.tcl-lang.org/page/ttk%3A%3Acombobox
# Disabled/Readonly color (and pointer to color change)
bind .cb <<ComboboxSelected>> {
ttk::style map CustomCombobox.TCombobox -fieldbackground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -foreground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -background "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -selectforeground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -selectbackground "readonly
$selectedValue"
} ..cb set "white"
event generate .cb <<ComboboxSelected>>

Subject: Re: A ttk:combox with colors?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Sun, 3 Nov 2024 22:46 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: A ttk:combox with colors?
Date: Sun, 03 Nov 2024 23:46:45 +0100
Organization: ratiosoft
Lines: 15
Message-ID: <seufijtvecnore0l6f7hfgtioc8al7407s@4ax.com>
References: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com> <vg7aa7$96lt$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 03 Nov 2024 23:46:52 +0100 (CET)
Injection-Info: dont-email.me; posting-host="bd63a6a1549c71ea884cbd4066c8a263";
logging-data="613813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2Os+YHwHTLcp6iMJ3POis"
Cancel-Lock: sha1:YXw7lA0tgdYX2a0D4emQnGTAtQI=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Hello greg,
thanks a lot for the code. Impressive: knowing about the internal
'popdown.f.l' and handling ttk::style - something I have (as yet?) not
understood.
Alas, for me it works only half: The color gets selected as wanted,
but only covers a small part of the entry field, the rest being either
blue when the combo has the focus and white when not. I made screen
shots and uploaded them to 'file.io' under the URL
https://file.io/SWF4GKTWvUva
in case you want to have a look.
Interesting: The width of the colored part seems to vary for all
colors - most notably for 'red' and 'yellow'.
Nevertheless thank you for the code
Helmut
PS: I am on Windows 10 and run Tcl8.6.14 or ...12

Subject: Re: A ttk:combox with colors?
From: greg
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Sun, 3 Nov 2024 23:58 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: gregor.ebbing@gmx.de (greg)
Newsgroups: comp.lang.tcl
Subject: Re: A ttk:combox with colors?
Date: Mon, 4 Nov 2024 00:58:04 +0100
Organization: A noiseless patient Spider
Lines: 91
Message-ID: <vg92mc$jcas$1@dont-email.me>
References: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com>
<vg7aa7$96lt$2@dont-email.me> <seufijtvecnore0l6f7hfgtioc8al7407s@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 04 Nov 2024 00:58:05 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d1622d9f29ffae309d86a18f7773b4f6";
logging-data="635228"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/scrEvvEtGZ1QOWFxOjMT0448MxQMxqXk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FmPDDCIzFfxQgK6gZiNiTQrSSDc=
In-Reply-To: <seufijtvecnore0l6f7hfgtioc8al7407s@4ax.com>
Content-Language: de-DE
View all headers

Am 03.11.24 um 23:46 schrieb Helmut Giese:
> Hello greg,
> thanks a lot for the code. Impressive: knowing about the internal
> 'popdown.f.l' and handling ttk::style - something I have (as yet?) not
> understood.
> Alas, for me it works only half: The color gets selected as wanted,
> but only covers a small part of the entry field, the rest being either
> blue when the combo has the focus and white when not. I made screen
> shots and uploaded them to 'file.io' under the URL
> https://file.io/SWF4GKTWvUva
> in case you want to have a look.
> Interesting: The width of the colored part seems to vary for all
> colors - most notably for 'red' and 'yellow'.
> Nevertheless thank you for the code
> Helmut
> PS: I am on Windows 10 and run Tcl8.6.14 or ...12

Hello Helmut

The solution has the following limitation: it does not work with a naive
theme.
(Can only be changed when using non-native and non-graphical theme) from
Manual

The ttk::combobox consists of a ttk::entry and a tk::listbox

It's in the manual
https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm

Gregor

#! /usr/bin/env tclsh

package require Tk

# Procedure to style the listbox items
# interna popdown.f.l
# https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm
proc styleListbox {cb} {
set popdown [ttk::combobox::PopdownWindow $cb]
set lb "$popdown.f.l"
set colors [$cb cget -values]
set i 0
foreach color $colors {
$lb itemconfigure $i -background $color
$lb itemconfigure $i -foreground $color
$lb itemconfigure $i -selectbackground $color
#text color in listbox
#$lb itemconfigure $i -selectforeground $color
incr i
}
}

# https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm
# Can only be changed when using non-native and non-graphical themes
ttk::style theme use clam

set selectedValue ""
# Create a combobox with the custom style

ttk::combobox .cb -style CustomCombobox.TCombobox \
-values [list "green" "red" "white" "yellow" "black"] \
-textvariable selectedValue -state readonly

pack .cb -padx 20 -pady 20

# Event binding to style the internal listbox when the combobox is opened
bind .cb <ButtonPress-1> {
after 5 [list styleListbox %W]
}

# Event binding
# https://wiki.tcl-lang.org/page/ttk%3A%3Acombobox
# SHOW Disabled/Readonly color (and pointer to color change)
# https://wiki.tcl-lang.org/page/Changing+Widget+Colors
bind .cb <<ComboboxSelected>> {
ttk::style map CustomCombobox.TCombobox -fieldbackground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -foreground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -background "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -selectforeground "readonly
$selectedValue"
ttk::style map CustomCombobox.TCombobox -selectbackground "readonly
$selectedValue"
}

#.cb set "white"
#event generate .cb <<ComboboxSelected>>

Subject: Re: A ttk:combox with colors?
From: Helmut Giese
Newsgroups: comp.lang.tcl
Organization: ratiosoft
Date: Mon, 4 Nov 2024 19:32 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgiese@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: A ttk:combox with colors?
Date: Mon, 04 Nov 2024 20:32:12 +0100
Organization: ratiosoft
Lines: 10
Message-ID: <ep7iij5o8a1t65f3ncarc9glj0nnck1vrc@4ax.com>
References: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com> <vg7aa7$96lt$2@dont-email.me> <seufijtvecnore0l6f7hfgtioc8al7407s@4ax.com> <vg92mc$jcas$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 04 Nov 2024 20:32:20 +0100 (CET)
Injection-Info: dont-email.me; posting-host="eb39d2e396ac3d3cb2af008fd30b19ca";
logging-data="1159938"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dAo9O6x5aFOcO96mC7pLu"
Cancel-Lock: sha1:P51Nq3SsZRvUQgSbHuQI0tvWGLY=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
View all headers

Hello Greg,
>The solution has the following limitation: it does not work with a naive
>theme.
>(Can only be changed when using non-native and non-graphical theme)
Ah, I see. Well, that's too bad. You see, I have never used any
'theme' whatsoever - Windows' 'out of the box' look and feel was good
enough.
Well, I have to think of something. Thanks for the clarification and
best regards
Helmut

1

rocksolid light 0.9.8
clearnet tor