WCK for Windows

December 13, 2003 | Fredrik Lundh

The WinWCK library is an implementation of the WCK programming model for Windows 2000 and later. A WinWCK application uses the Win32 API directly; it does not rely on any external GUI toolkit such as Tk or wxWindows.

To create and configure widgets, WinWCK uses a subset of the Tkinter programming model.

from WinWCK.WCK import Toplevel, Widget

class MyWidget(Widget):
    def ui_handle_repair(self, draw, x0, y0, x1, y1):
        ...

root = Toplevel()

w = MyWidget(root)
w.pack()

root.mainloop()

Implementation Notes

No Default Toplevel

If you want a toplevel, you have to create it yourself.

root = Toplevel()
root.title("My Application")

WinWCK supports standard toplevels and layered toplevels.

Layered toplevels can have arbitrary shapes, and also supports alpha layers. A special drawing API is used to associate an RGBA image with the window, and to “draw” various hotspots (minimize, close, resize, etc).

Standard Widgets

WinWCK comes with a small set of standard widgets, including Buttons, Entry fields, and Listbox widgets.

Event Structures

WinWCK uses a simplified event structure. The following attributes are available:

type
A string giving the event type.
time
Event timestamp.
x, y
Mouse position. Only valid for mouse events.
num
Button number. Only valid for mouse events.
state
Shift key and button state (a bit mask).
keycode
Virtual key code. This is only set for KeyPress and KeyRelease events that don’t have an associated character string (see below).
keysym
Virtual key name. Only set if keycode is set.
char
Character code. This is only set for KeyPress events that have an associated character string. The string is an 8-bit string for ASCII characters, and a Unicode string for non-ASCII text. The string may contain one or more characters.
widget
The widget instance that this event was generated for.

More About The KeyPress Event

Windows distinguishes between actual key presses and characters generated by such key presses. The former generates a WM_KEYDOWN event, the latter a WM_CHAR event. A KEYDOWN event may result in any number of CHAR events (including no CHAR event at all).

To simplify the implementation, WinWCK generates KeyPress events for both WM_KEYDOWN and WM_CHAR events. A KeyPress event is generated when any key is pressed, but KeyPress events are also generated for each resulting character.

To distinguish between the presses, check the char attribute. If the attribute is None, it’s an ordinary key press. If the attribute is not None, it’s a character (or a character string). WinWCK uses 8-bit strings for ASCII characters, and Unicode strings for everything else.

 

A Django site. rendered by a django application. hosted by webfaction.