Themes

[Explain what themes are.]

[People often think of them in terms of Qt and/or Gtk+` implementations.]

[Explain how BLT supports themes now]

Tk_Theme provides background themes. There is a version that only works with X and a version that is script based (new). The new scripted version works with standard geometry managers and uses the canvas. Here is a screenshot of a Tk demo that was modified to use it:


FB -- Quick glossary (in no special order):

Skin
custom image covering whole or part of a graphical interface (ie a whole widget hierarchy below the same toplevel window).
Tile
image pattern usually repeated horizontaly and verticaly over the background of a widget.
Element
part of a widget (eg a checkbox mark or a scrollbar arrow), usually active.
Icon
small picture associated with a given action or widget.
Style
the visual appearance of a widget. May include colors, skins, tiles, border drawing style (Windows, Motif...), element pictures.
Theme
a collection of graphical elements giving a consistent appearance to a whole widget hierarchy, application, or desktop. A theme is usually made of icons, colors, fonts (sizes, styles, emphasis), widget style, or even desktop background and sounds.

There are at least 6 types of windows that one may have in an application:

border
a window that should not show any decorations
dialog window
window interacting with user
menu
pinnable/tearable menu window
modal_dialog window
window that requires intervention by user before parent window can be accessed
normal
top level window for displaying information
utility window
persistant window such as palette or toolbox

Each window type can have a variety of frame states, and each state tends to have a way of displaying the frame pieces and window buttons that make up the widget. This is known as a style. These states include:

  • keyboard focus
  • maximized/minimized (aka iconified)
  • resized

The frame pieces include:

  • entire background
  • title bar
  • middle title bar
  • top edge title bar
  • left edge title bar
  • middle edge title bar
  • right edge title bar
  • bottom edge title bar
  • title
  • left frame edge
  • right frame edge
  • bottom frame edge
  • overlay background

Some of the buttons that window managers frequently decorate include

  • close
  • maximize
  • minimize
  • menu

Whatever happened to the 'theme' TIP#48 [L1 ] ? Is that in limbo or actually going to happen?

PT writes: let's answer this on Tk Style Support, where the finalized TIP, as integrated into Tk 8.5, is discussed.


FB -- Qt [L2 ] and GTK+ [L3 ] both support styles in their current versions. Styles seem to be implemented in a similar fashion by both toolkits: they define a set of common elements (arrows, checkmarks...) and associate each with one or several API calls.

Qt defines a generic QStyle class [L4 ] which is the base class for all styles (Windows, Motif...). QStyle-derived classes implement a number of virtual member methods, each being used to draw or compute the geometry of the many elements. Thanks to polymorphism, widgets can then use any style derived from this base class.

GTK+ seems to work in a similar fashion, if I understand clearly their so-called online documentation ([L5 ] for GTK+ 1.2 and [L6 ] for GTK+ 2.0). IMHO it seems incredibly poor for such a widely used toolkit. A bare collection of uncommented forward declarations. If I were in a bad mood I'd say it sucks so much it could lift steel plates, but I digress ;-) (If I've missed the real doc, someone please point me to the right place)

Contrary to the C++ -based Qt that defines a class gathering all style-related methods, GTK+ is C-based and defines individual procedures (eg. gtk_draw_slider). But overall, both use the same model: a predefined (albeit potentially extensible) set of elements, and associated overloadable methods/procs.


FB -- My feeling is that themes support is implemented in a very monolithic way by both Qt and GTK+. Only predefined elements can be themed, and widgets can't define their own new elements. Furthermore, any change to the core (eg. adding a new element) implies:

  • For QT, adding new member method to the QStyle class and thus a complete recompilation of all applications.
  • For GTK+, adding new API procedures. Recompilation may be needed, but not in a pathological way, as procedures need not be defined and/or implemented in a single place (a C+++ class).

Anyway, both methods aren't easily extensible without a break in binary compatibility, let alone dynamic script-level extensibility.

So we have two options here for extending Tk. Either we follow the Qt and GTK+ path and implement a monolithic system with predefined elements, or we define a novel, modular system that allows for new elements to be implemented (and even dynamically by loadable extensions).

The first option would be quite fast (and even easy) to implement, and may be sufficient. After all new widgets aren't implemented every day. And it seems to work fine for Qt and GTK, but I'm not sure it would fit the Tcl/Tk model.

Second option would take more time & effort, but IMHO better follows The Tcl Way better. Plus, it could make writing new widgets easier, and we know Tk is often criticized for the amount of effort needed to implement new widgets, and the lack of many widgets thereof. Most Tclers are convinced that the right way to build complex GUIs and widgets is at the script level, but that's not an excuse for making it harder at the C level ;-) Besides, we still don't have a good built-in megawidget framework.


 What: grdb
 Where: http://missoula.bigsky.net/shunter/grdb.html 
 Description: Tries to apply your gtk theme colors to Xt/Motif/Tk applications
        by setting variables based on the current them and piping them along
        with some other default files into an xrdb -merge command.
        Currently at version 0.2.4.
 Updated: 02/2000
 Contact: mailto:[email protected] 
 What: Oroborus Theme Changer
 Where: http://www.edazzle.net/#oroborus 
 Description: Tcl/Tk app for changing themes in the Oroborus window manager.
        Currently at version 1.2.
 Updated: 05/2002
 Contact: mailto:[email protected] 
 What: themeleme
 Where: http://mitglied.tripod.de/loppo/ 
 Description: Shell script for WindowMaker theme makers that eases the
        packaging of themes.  Now comes with a Tcl/Tk GUI.
 Updated: 09/1999
 Contact: mailto:[email protected] 

Recently on comp.lang.tcl someone referenced the KDE theme engine called mosfet [L7 ].


See also