Yet Another Table widget...
All, I stumbled across a pure tcl table widget here:- http://www.nemethi.de/ and thought it may be of interest. I have started writing the python bindings for it (I couldn't find any with google) and will add a link to the wiki when i'm done... I have played with it on Windows (Python 2.4, Win2K) and Linux (Python 2.3.4, Fedora Core 3 and Python 2.2.?, RedHat 9) Cheers, Martin.
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. On Thu, 20 Jan 2005 16:20:44 -0000, Martin Franklin <mfranklin1@gatwick.westerngeco.slb.com> wrote:
I stumbled across a pure tcl table widget here:- http://www.nemethi.de/
cheers, -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com
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.
I thought maybe the list would benefit from hearing about how I chose to wrap the bwidget family of widgets for my pybwidget package. On Fri, Jan 21, 2005 at 10:40:54AM +0000, Martin Franklin wrote:
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) [...] To use the package from this location Tcl I need to execute this:-
root.tk.call("lappend", "auto_path", "/home/martin/tablelist3.7") [...] Next you have to register the package so that Tkinter can use/find it
root.tk.call("package", "require", "tablelist")
in pybwidget, setup.py installs the .tcl files (and a few other files) in a known location relative to the Python installation. (The downside of this is that the package is not available in "wish", the tk interactive shell) That path is defined as _datadir = os.path.join(sys.prefix, "share", "pybwidget") The files are installed by the 'data_files=' parameter to setup() When a bwidget is created, the _datadir is added to auto_path if it wasn't already present, and then the package is require'd: def _require(self, master): auto_path = master.tk.call("set", "auto_path") if not _datadir in auto_path: master.tk.call("lappend", "auto_path", _datadir) master.tk.call("package", "require", "BWidget")
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
In bwidget, the class names and the tcl commands to create the widgets were generally identical, so I put a __init__ in a base class: def __init__(self, master, cnf={}, **kw): self._require(master) Tkinter.Widget.__init__(self, master, self.__class__.__name__, cnf, kw) Jeff
Thanks Jeff, Martin. That information is quite helpful! cheers S -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com
Martin: How's it going with the Python wrapper for that interesting tablelist widget you found? Are you making any headway? cheers S -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com
Stewart Midwinter wrote:
Martin:
How's it going with the Python wrapper for that interesting tablelist widget you found? Are you making any headway?
cheers S
Stewart, I updated the Wiki with a link to my code.. http://tkinter.unpythonic.net/wiki/Widgets http://mfranklin.is-a-geek.org/docs/TableList/index.html The wrapper is complete (all methods are wrapped) but relatively untested.. I have started using it in a new project at work but I am only using it as a multi column list box - no cell editing... my TO DO list for TableList would look something like ;-) 1) edit all doc-strings (to make them more pythonic) 2) TEST I have added a few extra convenience methods (getcurselection, clear, setlist) that make it feel a bit like a Pmw widget - I also added a ScrolledTableList widget ala ScrolledText in the standard library It's far from complete but seems very usable. Cheers Martin
Nice work, Martin! I especially liked the way you provided a web page with detailed instructions on how you did the conversion so that others can use it as a guide for their own requirements if they discover other Tcl widgets that would be useful to use under Python. In addition, you provided a simple test for the widget so someone can get an immediate example of the widget in use. Fredrik Lundh could take a page from your book! I see you did your work under Linux. Have you tested it at all under Windows? For me under Win2k, when I try to run the example, I get the following error complaining about the tablelist::tablelist that you spent so much time on. Same error with both standard and scroll-bar version of the tablelist: Traceback (most recent call last): File "TableList.py", line 1049, in ? selectmode="extended") File "TableList.py", line 999, in __init__ self.tablelist = TableList(self, **kw) File "TableList.py", line 55, in __init__ Widget.__init__(self, master, 'tablelist::tablelist', cnf, kw) File "c:\python24\lib\lib-tk\Tkinter.py", line 1861, in __init__ self.tk.call( _tkinter.TclError: invalid command name "tablelist::tablelist" -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com
Stewart Midwinter wrote:
Nice work, Martin! I especially liked the way you provided a web page with detailed instructions on how you did the conversion so that others can use it as a guide for their own requirements if they discover other Tcl widgets that would be useful to use under Python.
In addition, you provided a simple test for the widget so someone can get an immediate example of the widget in use. Fredrik Lundh could take a page from your book!
I see you did your work under Linux. Have you tested it at all under Windows? For me under Win2k, when I try to run the example, I get the following error complaining about the tablelist::tablelist that you spent so much time on. Same error with both standard and scroll-bar version of the tablelist:
Traceback (most recent call last): File "TableList.py", line 1049, in ? selectmode="extended") File "TableList.py", line 999, in __init__ self.tablelist = TableList(self, **kw) File "TableList.py", line 55, in __init__ Widget.__init__(self, master, 'tablelist::tablelist', cnf, kw) File "c:\python24\lib\lib-tk\Tkinter.py", line 1861, in __init__ self.tk.call( _tkinter.TclError: invalid command name "tablelist::tablelist"
Stewart, Sorry for the quick reply but I am just leaving work.... I just downloaded my tar ball and unwrapped it on my Win2K laptop, I edited the TableList.py file and pressed F5 (SciTE run buffer) and sorry to say it just worked! can you give me some more info (python version, command used to test etc) I'll take a look when I get home (2+ hours from now!) Cheers Martin
hi Martin: I'm using SciTE as well - great editor! anyway, I installed it under Python 2.4, then opened tablelist.py under SciTE and ran it from there. I can't remember if I ran the file from the folder where I downloaded it, or from its installed folder. I'm now at work (GMT-7), so I'll try installing it here and see what happens... let's see, open the .tar.gz file, copy the contents to ..python24\lib\site-packages, browse to that folder, open tablelist.py with SciTE, press F5 for Run - bingo! I notice that the button on the side of the list seems to be fixed in that location. Is there a way to have it display underneath the table list? (no biggie if not). Very easy to get back the selection: just click on a row and then click on the button (to which I added text="select"). The show method could be modified as needed by the user. Just yesterday, I used a multiListBox to display some information (see attached graphic); but it looks like TableList could be more powerful in the future if it supports cell by cell editing. It could then support data entry as well as its current display capabilities. Thanks for you work so far on this! cheers, S -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com
Stewart Midwinter wrote:
hi Martin:
I'm using SciTE as well - great editor!
anyway, I installed it under Python 2.4, then opened tablelist.py under SciTE and ran it from there. I can't remember if I ran the file from the folder where I downloaded it, or from its installed folder.
I'm now at work (GMT-7), so I'll try installing it here and see what happens... let's see, open the .tar.gz file, copy the contents to ..python24\lib\site-packages, browse to that folder, open tablelist.py with SciTE, press F5 for Run - bingo!
Great, it would be nice to find out what happened on your other machine...
I notice that the button on the side of the list seems to be fixed in that location. Is there a way to have it display underneath the table list? (no biggie if not). Very easy to get back the selection: just click on a row and then click on the button (to which I added text="select"). The show method could be modified as needed by the user.
Yes that demo/test code at the end of the module could be cleaned up a bit!
Just yesterday, I used a multiListBox to display some information (see attached graphic); but it looks like TableList could be more powerful in the future if it supports cell by cell editing. It could then support data entry as well as its current display capabilities.
I was using a multi-column list box (part of the Pmw Contrib I think) but a new project at work required a column with images in. This is why I started this whole thing. I would like to get the cell editing tested - I have not even switched it on yet! Only trouble is I don't have a good enough reason (not project that requires it!)
Thanks for you work so far on this!
No problem Cheers, Martin.
cheers, S
Martin Franklin wrote:
All,
I stumbled across a pure tcl table widget here:-
and thought it may be of interest.
I have started writing the python bindings for it (I couldn't find any with google) and will add a link to the wiki when i'm done...
I have played with it on Windows (Python 2.4, Win2K) and Linux (Python 2.3.4, Fedora Core 3 and Python 2.2.?, RedHat 9)
Cheers, Martin.
Just FYI. I've added a few examples to my website including two editable examples (entry and checkbutton) I will try to add an interesting 'other' widget soon (after I've finished basking in the glory of my new found fame ;-) http://mfranklin.is-a-geek.org/docs/TableList/index.html Cheers, Martin.
participants (4)
-
Jeff Epler -
Martin Franklin -
Martin Franklin -
Stewart Midwinter