For Programmers: Free Programming Magazines  


Home > Archive > Tcl > January 2006 > Tile style questions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Tile style questions
Jeff Godfrey

2006-01-27, 7:03 pm

Using Tile on WinXP, I'm trying to create toolbar buttons with a
standard XP look (flat until mouse-over). I'm guessing that I'll need
to create my own button style and fiddle with some internal options
(-relief, etc...). The trouble is, I haven't figure out how to do
that yet...

According to the Tile docs, "style element names" returns the names of
all elements for the current style...

So, using that, the only "button" related element I see is
Button.button. Now, according to the docs, "style element options"
should return a list of the element's options...

So, I assume that "style element options Button.button" should show me
the available options (likely including "-relief"). Unfortunately, it
doesn't return anything.

Obviously, I'm misunderstanding something. Anyone care to shed some
light on both "how do I do this?" and "how do I *know how to* do
this?"

Thanks,

Jeff


Andrés García

2006-01-27, 7:03 pm

Jeff Godfrey wrote:

> Using Tile on WinXP, I'm trying to create toolbar buttons with a
> standard XP look (flat until mouse-over). I'm guessing that I'll need
> to create my own button style and fiddle with some internal options
> (-relief, etc...). The trouble is, I haven't figure out how to do
> that yet...
>

You don't need to do much, just add '-style Toolbutton' to the
ttk::button definition, like:

ttk::button .frameName.buttonName -style Toolbutton

Andres
Jeff Godfrey

2006-01-27, 7:03 pm


"Andrés García" <fandom@spamme.telefonica.net> wrote in message
news:drdt5n$qfs$1@nsnmpen2-gest.nuria.telefonica-data.net...
> Jeff Godfrey wrote:
>
> You don't need to do much, just add '-style Toolbutton' to the
> ttk::button definition, like:
>
> ttk::button .frameName.buttonName -style Toolbutton
>
> Andres


Andres,

Thanks for the info - it's exactly what I needed. For some reason, my
development system doesn't have the Tile "demos" directory in the
installation folder. Now that I've found the demos, I see an example
of the toolbar functionality I was trying to mimic.

Thanks again.

Jeff


Joe English

2006-01-27, 9:57 pm

Jeff Godfrey wrote:
>
>Using Tile on WinXP, I'm trying to create toolbar buttons with a
>standard XP look (flat until mouse-over). I'm guessing that I'll need
>to create my own button style and fiddle with some internal options
>(-relief, etc...).


This is one of the few cases where you *don't* have to do it
yourself -- every theme has a predefined "Toolbutton" custom
style, so you can use:

ttk::button -style Toolbutton -command ... -text ...

(The eventual goal is to have a number of predefined
"common custom styles" like this, that application
developers can count on being present in every theme.)

You'll probably also want to specify an -image and '-compound top',
depending on user preferences. The tile widgets support two
additional values for -compound, '-compound text' and '-compound image',
which makes it easier to support the conventional "Show icons/
Show text/Show both" user preference than the default '-compond none'
does.

>So, I assume that "style element options Button.button" should show me
>the available options (likely including "-relief"). Unfortunately, it
>doesn't return anything.


That's because in the XP theme, the Button.button element
doesn't have any options. This element just calls the UXTHEME
routine DrawThemeBackground(), with iPartID set to BP_PUSHBUTTON
and iStateId determined by the widget state.

>Obviously, I'm misunderstanding something. Anyone care to shed some
>light on both "how do I do this?" and "how do I *know how to* do
>this?"


demos/toolbutton.tcl contains an annotated listing demonstrating
how to define a toolbar-style button; see also how the built-in themes
do it. (Pushbuttons are actually a lot more complicated than they look --
there's a huge variation in design across different platforms
and toolkits.)


--Joe English
Jeff Godfrey

2006-01-27, 9:57 pm


"Joe English" <jenglish@flightlab.com> wrote in message
news:dre6320c2o@news3.newsguy.com...
> Jeff Godfrey wrote:
>
> This is one of the few cases where you *don't* have to do it
> yourself -- every theme has a predefined "Toolbutton" custom
> style, so you can use:
>
> ttk::button -style Toolbutton -command ... -text ...


Joe,

As always, thanks for a very informative reply.

To carry this a step further, what if I wanted to represent the
checked and unchecked states of the button with 2 different icons (in
this case, a "padlock" in an open and closed state). I've fumbled
through the online docs and have discovered various pieces of what I
(think) I need to know, but I haven't been able to put it all
together.

I kind of have a love/hate thing going with Tile right now - as I
*really* like what it does for me out of the box, but I'm struggling
to deal with my corner cases. In the end, it seems that I can usually
get what I need from Tile, but I'm frustrated by the fact that I
sometimes can't find my way out of the woods without the need of a
flare gun...

Maybe I'm unaware of some documentation that would clarify some of my
recent questions? I only have the online docs, but they seem a bit
sparse right now.

Thanks for any additional pointers.

Jeff


Jeff Godfrey

2006-01-27, 9:57 pm


"Jeff Godfrey" <jeff_godfrey@pobox.com> wrote in message
news:3VxCf.7896$Hd4.6107@newsread1.news.pas.earthlink.net...
>
> "Joe English" <jenglish@flightlab.com> wrote in message
> news:dre6320c2o@news3.newsguy.com...
>
> Joe,
>
> As always, thanks for a very informative reply.
>
> To carry this a step further, what if I wanted to represent the
> checked and unchecked states of the button with 2 different icons
> (in this case, a "padlock" in an open and closed state).


I just realized that I neglected to mention I'm using a
ttk::checkbutton widget in the above case...

Jeff


Joe English

2006-01-28, 3:57 am

Jeff Godfrey wrote:
>
>To carry this a step further, what if I wanted to represent the
>checked and unchecked states of the button with 2 different icons (in
>this case, a "padlock" in an open and closed state). I've fumbled
>through the online docs and have discovered various pieces of what I
>(think) I need to know, but I haven't been able to put it all
>together.


See <URL: http://tktable.sourceforge.net/tile...l#stdopt_-image >:

| -image
| Specifies an image to display. This is a list of 1 or more
| elements. The first element is the default image name. The rest
| of the list is a sequence of statespec / value pairs as per [style
| map], specifying different images to use when the widget is in
| a particular state or combination of states. [...]


So you could use:

image create open_padlock [ ... ]
image create closed_padlock [ ... ]
# ...
ttk::checkbutton $cb -image { open_padlock selected closed_padlock }

(assuming that "closed" represents the "on" or "selected" state;
otherwise do it the other way around).

And if the application ever disables the button, you can do
something like:

ttk::checkbutton $cb -image {
open_padlock
{!selected disabled} closed_padlock_cantchange
{selected disabled} open_padlock_cantchange
selected closed_padlock
}

statespec/value pairs are examined in order, and the first matching
one is used. If none match, then it uses the default value
(so in the above, the widget uses the "open_padlock" image
if it's neither selected nor disabled).

You can also test the 'active' state to use a brighter image
when the mouse cursor is over the widget, or use a greyscale
icon when it's not, as found in some older Windows applications.

Most manpages have a "WIDGET STATES" section describing which
state flags are used. (Hm. It looks like most of them are also
incomplete -- the checkbutton also uses 'active' and 'focus' states,
but these aren't listed ... must remember to fix this ...)


--Joe English
matben@users.sourceforge.net

2006-01-29, 7:57 am

> ttk::checkbutton $cb -image { open_padlock selected closed_padlock }

That wont work on the Mac at least. You need to make a new style:

foreach name [tile::availableThemes] {
style theme settings $name {
style layout Phone.Toolbutton {
Phone.label
}
}
}

for something minimalistic, and then:

ttk::radiobutton $bts.r1 -style Phone.Toolbutton \
-image [list $images(klickety) selected $images(babelfish)] \
-variable ::radio -value 1

Mats

Joe English

2006-01-29, 7:00 pm

Mats wrote:
>
>That wont work on the Mac at least. [...]


Hm. Worked for me, with both the default and Toolbutton styles.
What goes wrong?


--Joe English
matben@users.sourceforge.net

2006-01-30, 8:01 am

If I do
ttk::checkbutton .c -image {image31 selected image38}
I get: aquaCheckIndicator + image
while with
ttk::checkbutton .c2 -style Phone.Toolbutton -image {image31 selected
image38}
I only get the image. In both cases the images switch depending on
state.
I interpreted "...I wanted to represent the checked and unchecked
states of the button with 2 different icons ..." as the second case.

Mats

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com