Bwidget Source Code
View Ticket
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.
Ticket UUID: 75101bf5cecad8ea9e42640d4ebab61ded3b604d
Title: Enhancements to the SelectColor dialog
Type: Patch Version: branch bwidget, tag 1.9.6
Submitter: anonymous Created on: 2013-06-14 14:08:05
Subsystem: bwidget Assigned To: oehhar
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2018-01-09 18:03:42
Resolution: Accepted Closed By: oehhar
    Closed on: 2018-01-09 18:03:42
Description:
bwidget-color.patch

This patch provides a number of enhancements to the SelectColor dialog.

Each change in the code is commented with "MODS"

File color.tcl -
* Add options -variable and -background; -variable is the name of a variable that the caller can trace, to follow the color that the user selects in the dialog (typically to modify a color in the calling GUI).
* Add an entry widget that displays the GUI selection as a (24-bit) hexadecimal number, and can also be used to type in a (12n-bit) hexadecimal number as a color.
* Use a TitleFrame "Color Selectors" for the canvas selectors
* Use a TitleFrame "Your Selection" for the entry widget and the frame display $fg.round
* Add DynamicHelp to explain the use of the dialog.
* Add a new command, SelectColor::setbasecolor, to allow the caller to set the base colors of the palette.
* Use highlight color instead of focus to show the selection of a palette color.  This fixes a bug in the tab traversal of focus.
* Configure buttons appropriately for Aqua (which uses native buttons).
* Add command SelectColor::ReColor to change the background color of the dialog.

File pkgIndex.tcl -
* Add reference to new command SelectColor::setbasecolor
User Comments: oehhar added on 2018-01-09 18:03:42:

Merged by commit [5f374d671e].

Thank you for the valueable contribution !

Harald


kjnash added on 2018-01-09 17:26:49:
Yes, it's ready to merge.

Traces added too much complexity so I removed the -variable option and replaced it with a -command option.  This also fixes the problems you mentioned below.

oehhar added on 2018-01-08 11:08:15:

Sorry, I have lost track of that ticket.

Is it in a final state and ready to review and merge ?

So, its back on my table, look into it soon.

Thank you, Harald


kjnash added on 2017-10-28 00:25:28:
Revision [9f462bd2fa] to branch "patch-75101".

These revisions to color.tcl and related files address the issues raised below.

REVISIONS TO color.tcl

1.  Remove option -variable
2.  Remove variable _varName which held the value of option -variable
3.  Use variable _unsavedSelection in place of $_varName when a value must be
    stored
4.  Add option -command
5.  Add variable _command which holds the value of option -command
6.  Set the default value for option -help to 1
7.  Add command _userCommand to evaluate $_command at stack level #0.
    _userCommand is called whenever the selected color changes, i.e. instead
    of setting $_varName.
8.  To avoid issues with trace, fully qualify
    ::SelectColor::_unsavedSelection
    when its value is set or it is used in a trace command.
9.  Use 8.4-compatible syntax for string indices in "string range" commands.
10. Amend SelectColor::_SetWithoutTrace so it sets the colors in the Color
    Selectors when the value in the entry widget changes.

PURPOSE
Tracing the variable set by the "-variable" option is too awkward in
practice, and so the "-variable" option has been replaced with "-command"
which allows the caller to specify a command to be executed whenever
the selected color changes.

The use of the -command option is now included in the demo.

The properties of DynamicHelp balloon help have been changed in the demo, to
make the text easier to read.

The manual page has been updated to reflect the changes in color.tcl.

oehhar added on 2013-06-25 12:29:37:

thank you for the patch [d439b24425]

A) Improve -variable option

A) I am wondering, if we could improve the "-variable" option.

Looking at:

    set _varName [Widget::cget $path:SelectColor -variable]
    if {[string range $_varName 0 1] ne {::}} {
        set _varName ::SelectColor::_unsavedSelection
    }
I have two comments:
  1. A1) if the value of -variable is ignored due to no leading "::", there should be an error message.
  2. why ignore not fully qualified variable names. Shouldn't they better be made fully qualified in the callers scope?

Do something like:

    if {0 == [string length $_varName]} {
        set _varName ::SelectColor::_unsavedSelection
    elseif {![string equal [string range $_varName 0 1] "::"} {
        set _varName [uplevel 1 [namespace current]]::$varname
    }

B) Baloon-Help for entry widgety

I could imagine, that the bollon-help for keyboard traversal may also be bound on the entry widget.

C) TCL8.4 compatibility

I have replaced all "eq" and "ne" operations be "string equal", as we should take care to be tcl8.4 compatible.

Thank you, Harald


anonymous added on 2013-06-24 15:52:03:
I have tested branch "patch-75101" and it works for me.

The patch revisions-to-75101.patch does the following:

1. Localizes all strings, including help text.
2. Implements a boolean option -help that is switched off by default, and controls the Dynamic Help.
3. Fixes a bug that the new -background color did not get applied to the buttons on X11 and Windows.

The reason I included the Dynamic Help is that, even before the patch, it was not obvious to me how to use the different parts of the Color Selector.

oehhar added on 2013-06-23 12:13:59:
Thank you !
You are correct with the localisation.

Happy to hear from you,
Harald

anonymous added on 2013-06-22 13:59:08:
The -variable option must be fully qualified - with this modification the script works:

set curColor 0
proc tc {name args} {
	upvar #0 $name var
	puts $var
}
trace add variable curColor write tc
SelectColor .s -background yellow -color blue -parent . -placement at\
	-title CS -type dialog -variable ::curColor

I agree with your changes and I will try to implement them.  If I understand BWidget localization correctly, it uses msgcat (if available) to discover the locale, but keeps the localized strings in an option database file.

I attach a demo script for -variable and setbasecolor.

oehhar added on 2013-06-21 16:14:08:

Committed to branch patch-75101.

Unfortunately, I would like to have the following changed until it goes to trunk:

  • Make the help part display optional
  • The widget shows now in a mixed language for me. The new textes should also be localized using msgcat.

I have personally never used this widget and did not get all of it.

Here is my test script for the trace:

set curColor 0
proc tc {name args} {
	upvar #0 $name var
	puts $var
}
trace add variable curColor write tc
SelectColor .s -background yellow -color blue -parent . -placement at\
	-title CS -type dialog -variable curColor
Unfortunately, for me the trace never fires (which might be my fault, seldomly uses traces).


Attachments: