Updated: 2nd March 1998
The library (documented here) is now released. It can be downloaded from
neosoft
Or...
You can download it from
this web page.
[Click right over this web page link and choose "Save Link As".]
Contents
Writing KDE Applications using Tcl/Tk
To date (February 1998) applications for KDE have been written in C++
using the Qt toolkit. Currently there is no scripting language for Qt.
This web page gives details of my Tcl/Tk library (called K.tk)
which allows wish programs to come as close to the native KDE look
and feel as is going to be possible in the short-term.
K.tk
is designed to be used with the
Tix extension
for wish. There are
several reasons why Tix has been chosen--support for xpm and several
new ``mega widgets'' being the most significant.
It should be fairly easy
to retro-fit K.tk to an existing wish application in order to
``K-ise'' it, though modifications may still be necessary in order to
conform to the
KDE style guide.
KDE Applications: differences with Tcl/Tk
There are several areas where standard Tcl/Tk (actually the Tk toolkit) is
different from KDE applications (actually the Qt toolkit).
Drag and Drop
Tk does not support the Qt drag-and-drop mechanism. This is a crucial area
that requires more investigation and work.
Colours and Fonts
KDE applications can be re-coloured and the default font changed via
the control panel. KDE applications which are open are updated
dynamically. Tk applications can read the current colour scheme and
default font (stored in $HOME/.kderc) and would be capable of
dynamically updating if the ``update'' event can be bound.
Version 0.1 of K.tk provides a procedure which initialises the
Tk option database to use the currently selected colour scheme and
font. If the user changes these settings in mid-session, Tk
applications will not use the new values until re-started.
Dialogues
Qt uses different images for the dialogues.
Version 0.1 of K.tk provides a new procedure which mimics the
KDE/Qt dialogue.
Menubars and Toolbars
Qt has a small button at the left-end of all menu and tool bars. This allows
the bar to dragged out of the application's window. This is a bit like the
tear-off feature of Tk's menus. Tk could provide a movable bar by making
it switch to a toplevel when it is dragged, but version 0.1 of K.tk
is designed only make wish applications look like KDE/Qt
applications. See the
example screen-shots below.
Buttons displaying images (KDE Tool bars)
Buttons which display images in Qt normally display pixmaps. This
is possible with the Tix extension.
Standard Tk cannot handle pixmaps; only bitmaps (xbm) or
full-colour ``photo'' images.
The Qt image button is flat until the mouse enters the widget, when it
becomes raised. A tool-tip is posted if the mouse remains over the
widget for longer than about 1 second.
Version 0.1 of K.tk provides an new widget which mimics the Qt
image button.
Advanced widgets
Tk lacks some of the more advanced widgets such as the tabbed dialog box, the
combobox and the labelled-frame. All of these (and many more) are available
in the Tix extension.
Tear-off Menus
Tk supports tear-off menus but KDE/Qt does not. Tear-offs menus are
disabled by K.tk. Because of this change the index position of
menu items (they are reduced by 1) some scripts may break.
Some examples
Here are some screen shots of wish application which demonstrate the
capabilities of version 0.1 K.tk.
I wrote TeXtool some time ago.
It simplifies the separate stages of creating documents using TeX or LaTeX.
Here are two shots before and after K-ising it.
Before

(obtained from a fvwm2-based system)
After

(obtained from Beta2 KDE under Linux)
The next example is a mock-up of a typical KDE application with menu, toolbar
and entry fields. The screen shot shows how similar it looks to a
KDE/Qt application, but using it shows even more similarities;
the toolbar buttons have identical behaviour including tool tips, and
the pop-up dialogues look just like KDE/Qt.
The source for this application is included in the distribution.
Installing K.tk
You will require the Tix extension for Tcl/Tk. Version 0.1 of
K.tk has been tested with Tix 4.1.0.
Having downloaded the library, installation is very simple:
- place K.tk in a convenient directory, such as
/usr/local/lib. To make life easy, install it in the same
directory as other Tk libraries
- (re-)create the tclIndex file by doing the following
(you'll need write permission on the directory where you've just
installed K.tk in)
- start tclsh
- at the tclsh prompt, type auto_mkindex . *.tk
- in your wish application which wants to use K.tk, add the
pathname of the install-directory to the special Tcl list
auto_path using
lappend auto_path install-pathname
Using Ktk
A Tcl/Tk application that is to use K.tk must call the
procedure Kinit before creating any widgets. In my programs
I normally call Kinit after setting-up variables, but before
creating any widgets.
K.tk contains the additional following routines which you'll
find useful:
Kbutton
Usage: Kbutton widget [options]
Kbutton creates a button which mimics the KDE/Qt image buttons
which appear in the toolbar. widget specified the pathname
for the new widget. The following options are accepted by kbutton;
- -image name
- specifies name as the image to appear on the button.
Kbutton searches the directories in the environment variable
ICONPATH in order to find name. In version 0.1
of K.tk, name name can be a bitmap, a pixmap, a GIF
file or a ppm image.
- -tip text
- specifies the text for a tooltip.
- -command Tcl-script
- specifies the command(s) to be executed when the button is clicked.
Kbutton actually has a lot more options, but in order to conform to
the style guide, these are not required.
Kbutton_control
Kbutton_control is used to control Kbuttons. It functions like a
widget-command allowing already existing Kbuttons to be re-configured.
Usage: Kbutton_control widget [options]
widget is the pathname of an existing kbutton widget.
- -image name
- changes the displayed image to name. As for Kbutton,
name is searched-for in the directories mentioned in the
ICONPATH environment variable.
- -state normal|disable
- changes the state of the button. Disabled buttons are grayed-out and
do not respond to mouse events. The code correctly re-colours xpm
pixmaps when disabling buttons so that they look exactly like the KDE/Qt
versions.
Kbarbutton
Kbarbutton is used to modify an existing menubar or toolbar by adding
the small button on the extreme left-hand end.
Usage: Kbarbutton bar_widget left_widget [height]
bar_widget is the pathname of the frame and
left_widget is the pathname of the first (i.e. leftmost) widget
which is packed into the bar.
Kbarbutton creates a pixmap button and arranges to pack this at
the extreme left-hand end of the named bar frame widget.
The optional height parameter defines how high the frame is.
If omitted the height of the bar is measured automatically.
Kdialog
Kdialog provides a dialogue window with an identical
API to the standard tk_dialog.
Kfileselect
Kfileselect provides a file select dialog which is (almost) identical
to the of KDE/Qt.
Usage: Kfileselect widget [filter pattern]
widget is the pathname of the dialogue frame and filter
pattern defines the initial file-filtering pattern, which defaults to
*.
Andrew F. Lack
Last Updated: 2nd March 1998
You were reader
747.