[Tkinter-discuss] Re: Yet Another Table widget...
Martin Franklin
mfranklin1 at myrealbox.com
Fri Jan 21 11:40:54 CET 2005
Stewart Midwinter wrote:
> Cool! that would be a very useful little widget.
>
> Maybe you'd also like to share with the list generally what's involved
> in writing python bindings for a tcl widget; there are a number of
> others out there that don't have such bindings yet, and maybe some of
> us on the list could take on the task of making them available.
>
>
Be glad to.... read on for a few preliminary gotcha's
First thing to note is that tablelist is pure Tcl package and can be
either installed in the standard tcl package location or you can tell
Tcl where it is (I choose the later since I don't always have permission
to install)
So I unwrapped the tarball into my home directory:-
/home/martin/tablelist4.7
To use the package from this location Tcl I need to execute this:-
root.tk.call("lappend", "auto_path", "/home/martin/tablelist3.7")
where root is my main Tk() instance. I guess this is like appending a
path to python's sys.path
Next you have to register the package so that Tkinter can use/find it
root.tk.call("package", "require", "tablelist")
Next came the TableList class:
from Tkinter import *
class TableList(Widget):
def __init__(self, master=None, cnf={}, **kw):
Widget.__init__(self, master, 'tablelist::tablelist', cnf, kw)
Worth a mention is the tablelist::tablelist - it took me 20 minutes to
work this out... tablelist the Tcl widget is in a Tcl namespace called
tablelist hence the :: notation I guess
After that it is a case of adding all the Tcl tablelist widget commands
(AKA methods) to my class - a slow and boring cut'n'paste from the web
based command reference... I'm still working on that bit but it boils
down to this:
From the tablelist reference:
pathName activatecell cellIndex
Sets the active element to the one indicated by cellIndex if the
tablelist's state is not disabled. If cellIndex is outside the range of
elements in the tablelist or it refers to a hidden element, then the
closest non-hidden element is activated. The active element is drawn as
specified by the -activestyle configuration option when the widget has
the input focus and the selection type is cell. Its index may be
retrieved with the cell index active. Returns an empty string.
To this method:
def activatecell(self, cellIndex):
"""Sets the active element to the one indicated by cellIndex
if the tablelist"s state is not disabled.
If cellIndex is outside the range of elements in the tablelist
or it refers to a hidden element, then the closest non-hidden
element is activated. The active element is drawn as specified
by the -activestyle configuration option when the widget has the
input focus and the selection type is cell. Its index may be
retrieved with the cell index active. Returns an empty string.
"""
return self.tk.call((self._w, "activatecell", index))
As I said I'm still doing this last bit - I need to wrap all tablelist
commands and make sure I return the correct type of object. I also need
to edit all the doc strings to look more Tkinter'ish and resist changing
the names of the commands;-)
Cheers,
Martin.
More information about the Tkinter-discuss
mailing list