29 Graphical Tools: TkTools

29.1 Error

The TkTools.error class extends TkTools.dialog.

tkInit

  
tkInit(title:  
+TitleTcl  <= 'Error' 
       master: 
+MasterTcl <= NoArg
       aspect: 
+AspectI   <= 250
       text:   
+TextTcl)
          

Initialise the widget object and create a new error dialog.

+AspectI specifies a non-negative integer value indicating desired aspect ratio for the text. The aspect ratio is specified as 100*width/height. 100 means the text should be as wide as it is tall, 200 means the text should be twice as wide as it is tall, 50 means the text should be twice as tall as it is wide, and so on.

29.2 Dialog

The TkTools.dialog class extends Tk.frame.

tkInit

tkInit(title:   +TitleTcl 
       master:  
+WidgetO      <= NoArg
       root:    
+Root         <= master
       buttons: 
+ButtonsL 
       pack:    
+PackB        <= true 
       focus:   
+FocusI       <= 0
       bg:      
+BackgroundA  <= NoArg
       default: 
+DefaultI     <= 0
       delete:  
+DeleteAction <= NoArg)

Initialise the widget object and create a new dialog. This widget needs at least two informations: the title and a list of buttons. Each element of the button list is of the form: LabelTcl # nullary procedure. Two examples are:

  • 'close' # tkClose

  • 'nothing'# proc {$skip end

A master widget is specified by +WidgetO. Depending on +Root the widget will be placed in relation to the master like following:

master

The dialog will be placed in the upper left corner within the master widget.

master#XOff#YOff

The dialog will be placed in the upper left corner of the master widget plus the xoffset and yoffset.

pointer

The dialog will be placed on the current pointer position.

X#Y

User defined position.

If you want to use a focus then you describe by +FocusI the button that gets the focus. By +DefaultI you set the default button.

tkPack

 tkPack

Pack the dialog.

tkClose

 tkClose

Close the dialog.

29.3 Menubar

{TkTools.menubar +PWidgetO +KBWidgetO  +L +R ?Widget0}

The TkTools.menubar function creates a menubar widget. The parent is described by +PWidgetO, while the KeyBinder is specified by +KBWidgetO. Usually both the parent and the key binder are the toplevel window. If you press a key combination, that is an abbreviation for a menu entry, within the key binder area the associated action will be done.

Menu entries are specified by the lists +L and +R, one for the left and one for the right menu part. Each element of both lists is a record with the label menubutton. The record has four features: text, underline, menu and feature.

menubutton(text:      +TextTcl 
           underline: 
+ULI 
           menu:      
+MenuL 
           feature:   
+Atom)

The field under the feature menu describes the view of the menu. It is a list of menu entries. Each entry may be: command, separator, ckeckbutton, radiobutton or cascade.

The separator is just an Atom. While checkbutton and radiobutton are usual Tk widgets, the command button is a new element and has the following form:

  
command(label:   
+TextTcl  
        action:  
+Action  
        key:     
+KeyTcl 
        feature: 
+Atom

The value for the key describes the keyboard accelerator and event binding to be created. They can be used as follows:

key option value

accelerator

event binding

a

a

a

ctrl(a)

C-a

<Control-a>

alt(a)

A-a

<Alt-a>

alt(ctrl(a))

A-C-a

<Alt-Control-a>

ctrl(alt(a))

C-A-a

<Control-Alt-a>

If you like to place a submenu you have to describe a cascade element, which consists only of the two features label and menu.

cascade(label: +TextTcl  
        menu:  
+MenuL)

29.4 Popup Menu

The TkTools.popupmenu class extends Tk.menubutton.

tkInit

           
meth tkInit(parent:   
+WidgetO 
            entries:  
+EL      <= [empty]
            selected: 
+SelI    <= 1
            font:     
+FontO   <= unit 
            action:   
+ActionP <= proc {$ S} skip end ...)   

Initialise the widget object and create a new popup menu. You always need to declare the parent of the widget. The field under the feature entries is a list of popup menu entries. Each entry is of the form: LabelAtom#ColorAtom. Although it is possible to declare an entry as [push#black push#green], you should not do this.

By +SelI you declare the initial entry. If action should be performed you have to declare a unary procedure.

getCurrent

getCurrent(?Atom)

Return the current active entry label.

add

add(+E)

Add a new entry. The entry must have the form: ColorAtom#LabelAtom.

rem

rem(+LabelA)

Remove (all) entries with the label +LabelA.

29.5 Textframe

The TkTools.textframe class extends Tk.frame and has only one method.

tkInit

tkInit(parent:  +WidgetO 
       'class'
+ClassTcl <= unit 
       text:    
+TextTcl 
       font:    
+FontO    <= DefaultFont)

Initialise the widget object and create a new textframe.

29.6 Notebook

The TkTools.notebook class extends Tk.canvas.

tkInit

tkInit(parent:  +WidgetO 
       font:    
+FontO    <= DefaultFont)

Initialise the widget object and create a new notebook.

add

add(+NoteO)

Add a new note.

remove

remove(+NoteO)

Remove a note.

toTop

toTop(+NoteO)

Bring note +NoteO to the top.

getTop

getTop(?NoteO)

Return the top note.

29.7 Note

The TkTools.note class extends Tk.frame.

tkInit

tkInit(parent:  +WidgetO 
       text:    
+TextTcl)

Initialise the widget object and create a new note. The note packs itself, thus you should avoid sending packaging commands, otherwise the system hangs.

toTop

toTop()

This is an empty method. If yo want any action to be performed you have to derive the TkTools.note class and to overwrite the toTop method.

29.8 Scale

The TkTools.scale class extends Tk.frame.

init

init(parent:  +WidgetO 
     width:   
+WidthI 
     values:  
+ValuesL 
     initpos: 
+PosI)

Initialise the widget object and create a new scale.The field +ValuesL describes all possible values, whereby the initial value is described by position +PosI.

drawTicks

drawTicks()

Draw.

get

get(?ValueI)

Get the current value.

29.9 Number Entry

The TkTools.numberentry class extends Tk.frame.

tkInit

tkInit(parent:       +WidgetO 
       min:          
+MinI    <= unit 
       max:          
+MaxI    <= unit 
       val:          
+ValI    <= MinI
       font:         
+FontO   <= DefaultFont
       width:        
+WidthI  <= 6
       action:       
+ActionP <= DummyAction
       returnaction: 
+RetActP <= unit)

Initialise the widget object and create a new number entry. The number entry contains all values within +MinI and +MaxI, and shows initially the value +ValI. Allthough it is possible to set +ValI less than +MinI you should not do it.

By +ActionP you define an unary procedure that is each time invoked, when alter the value of the number entry. Furthermore you may set a return procedure, that is invoked when you press Return.

tkAction

tkAction(+ActionP <= unit)

Set a new action procedure.

tkSet

tkSet(+ValI)

Set a new value.

tkGet

tkGet(?ValI)

Get value.

enter

enter(+B)

Hm. I see no difference.

29.10 Images

The function

{TkTools.images +L ?+R}

takes a list of URLs as input and returns a record of images, where the fields are atoms derived naturally from the URLs.

First the basename of the URL is computed by taking the last fragment of the URL (that is, 'wp.gif' for example). The extension (the part following the period, 'gif' for example), determines the type and format of the image. The part of the basename that precedes the period yields the feature.

29.11 Resolve Images

TkTools.resolveImages is deprecated. Please use TkTools.images instead.


Denys Duchier, Leif Kornstaedt, Martin Homik, Tobias Müller, Christian Schulte and Peter Van Roy
Version 1.4.0 (20080702)