List Info

Thread: A small fix for NoteBook in Tix




A small fix for NoteBook in Tix
user name
2006-11-28 20:03:39
Problem:

<code>;
>>&gt; from Tix import *
>>> root=Tk()
>>>; nb=NoteBook(root)
>;>> nb.add('pg_1', label='pg 1')
>&gt;> nb.pages()
Traceback (most recent call last):
&nbsp; File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.4/lib-tk/Tix.py", line 1160, in pages
&nbsp; &nbsp; ret.append(self.subwidget(x))
&nbsp; File "/usr/local/lib/python2.4/lib-tk/Tix.py", line 337, in subwidget
  ;  raise TclError, "Subwidget " + name + " not child of " + self._name
_tkinter.TclError: Subwidget p not child of -1211878740
</code>

Visiting Tix.py I found at line 1155 the following function:

<code&gt;
 &nbsp;  def pages(self):
 &nbsp; &nbsp;   ; # Can't call subwidgets_all directly because we don't want .nbframe
&nbsp;   ; &nbsp;  names = self.tk.split(self.tk.call(self._w, 'pages'))
  ; &nbsp; &nbsp;  ret = []
 &nbsp;   ; &nbsp; for x in names:
&nbsp; &nbsp; &nbsp;   ; &nbsp;  ret.append(self.subwidget(x))
&nbsp; &nbsp;   ;  return ret
</code>

The issue is that, for only one tab "names" is a string (the name of the tab), while for 2 or
more it is a tuple of names of tabs. For an empty NoteBook, "names" is an empty string. The
for loop in the case of one tab will go through the letters of the tab's name, and that is where
subwidget fails.

Resolution:
&lt;code>
 &nbsp;  def pages(self):
 &nbsp; &nbsp;   ; # Can't call subwidgets_all directly because we don't want .nbframe
&nbsp;   ; &nbsp;  names = self.tk.split(self.tk.call(self._w, 'pages'))
  ; &nbsp; &nbsp;  ret = []
 &nbsp;   ; &nbsp; if names and type(names) == type('a'): # sxn # 1 tab gives a string
&nbsp; &nbsp; &nbsp;   ; &nbsp;  ret.append(self.subwidget(names)) # sxn #
 &nbsp; &nbsp;   ; else: # sxn # 2+ tabs give a tuple
&nbsp; &nbsp; &nbsp; &nbsp;   ;  for x in names:
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  ret.append(self.subwidget(x))
&nbsp; &nbsp;   ;  return ret
</code>

I am on Linux, Python 2.4.2, Tcl/Tk 8.4, Tix 8.2

Sorin


Everyone is raving about the all-new Yahoo! Mail beta.
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )