[Python-checkins] r63951 - in sandbox/trunk/ttk-gsoc: Doc/library/ttk.rst samples/treeview_multicolumn.py src/2.x/ttk.py src/3.x/ttk.py
guilherme.polo
python-checkins at python.org
Thu Jun 5 02:00:56 CEST 2008
Author: guilherme.polo
Date: Thu Jun 5 02:00:55 2008
New Revision: 63951
Log:
Methods heading and tag_bind of Treeview supports Python objects as callback
now, before the person would need to use Misc.register before passing it.
Modified:
sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
sandbox/trunk/ttk-gsoc/samples/treeview_multicolumn.py
sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
sandbox/trunk/ttk-gsoc/src/3.x/ttk.py
Modified: sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
==============================================================================
--- sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst (original)
+++ sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst Thu Jun 5 02:00:55 2008
@@ -904,9 +904,8 @@
* anchor: anchor
Specifies how the heading text should be aligned. One of the standard
Tk anchor values.
- * command: script
- A script to evaluate when the heading label is pressed.
- This could be passed using Misc.register(callback).
+ * command: callback
+ A callback to be invoked when the heading label is pressed.
To configure the tree column heading, call this with column = "#0"
@@ -1038,12 +1037,10 @@
*column* in *given* item to the specified *value*.
- .. method:: tag_bind(tagname[, sequence=None[, script=None]])
+ .. method:: tag_bind(tagname[, sequence=None[, callback=None]])
- Bind a script for the event *sequence* to the tag *tagname*. *script* is
- possibly passed using Misc.register(callback) combined with substitutions.
-
- When an X event is delivered to an item, the script for each of the
+ Bind a callback for the given event *sequence* to the tag *tagname*.
+ When an event is delivered to an item, the callbacks for each of the
item's tags option are called.
Modified: sandbox/trunk/ttk-gsoc/samples/treeview_multicolumn.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/treeview_multicolumn.py (original)
+++ sandbox/trunk/ttk-gsoc/samples/treeview_multicolumn.py Thu Jun 5 02:00:55 2008
@@ -38,8 +38,8 @@
tree.move(item[1], '', indx)
# switch the heading so that it will sort in the opposite direction
- tree.heading(col, command=tree.register(
- lambda col=col: sortby(tree, col, int(not descending))))
+ tree.heading(col,
+ command=lambda col=col: sortby(tree, col, int(not descending)))
class App(object):
def __init__(self):
@@ -81,8 +81,7 @@
def _build_tree(self):
for col in tree_columns:
self.tree.heading(col, text=col.title(),
- command=self.tree.register(
- lambda c=col: sortby(self.tree, c, 0)))
+ command=lambda c=col: sortby(self.tree, c, 0))
# XXX tkFont.Font().measure expected args are incorrect according
# to the Tk docs
self.tree.column(col, width=tkFont.Font().measure(col.title()))
Modified: sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/ttk.py (original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/ttk.py Thu Jun 5 02:00:55 2008
@@ -1170,11 +1170,16 @@
anchor: anchor
Specifies how the heading text should be aligned. One of
the standard Tk anchor values
- command: script
- A script to evaluate when the heading label is pressed.
- This could be passed using Misc.register(callback).
+ command: callback
+ A callback to be invoked when the heading label is
+ pressed.
To configure the tree column heading, call this with column = "#0" """
+ cmd = kw.get('command')
+ if cmd and not isinstance(cmd, basestring):
+ # callback not registered yet, do it now
+ kw['command'] = self.master.register(cmd, self._substitute)
+
return self.tk.call(self._w, "heading", column, *(_format_optdict(kw)))
@@ -1317,14 +1322,11 @@
return res
- def tag_bind(self, tagname, sequence=None, script=None):
- """Bind a script for the event sequence to the tag tagname.
- script is possibly passed using Misc.register(callback) combined
- with substitutions.
-
- When an X event is delivered to an item, the script for each
+ def tag_bind(self, tagname, sequence=None, callback=None):
+ """Bind a callback for the given event sequence to the tag tagname.
+ When an event is delivered to an item, the callbacks for each
of the item's tags option are called."""
- self.tk.call(self._w, "tag", "bind", tagname, sequence, script)
+ self._bind((self._w, "tag", "bind", tagname), sequence, callback, add=0)
def tag_configure(self, tagname, **kw):
Modified: sandbox/trunk/ttk-gsoc/src/3.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/ttk.py (original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/ttk.py Thu Jun 5 02:00:55 2008
@@ -1170,11 +1170,16 @@
anchor: anchor
Specifies how the heading text should be aligned. One of
the standard Tk anchor values
- command: script
- A script to evaluate when the heading label is pressed.
- This could be passed using Misc.register(callback).
+ command: callback
+ A callback to be invoked when the heading label is
+ pressed.
To configure the tree column heading, call this with column = "#0" """
+ cmd = kw.get('command')
+ if cmd and not isinstance(cmd, str):
+ # callback not registered yet, do it now
+ kw['command'] = self.master.register(cmd, self._substitute)
+
return self.tk.call(self._w, "heading", column, *(_format_optdict(kw)))
@@ -1317,14 +1322,11 @@
return res
- def tag_bind(self, tagname, sequence=None, script=None):
- """Bind a script for the event sequence to the tag tagname.
- script is possibly passed using Misc.register(callback) combined
- with substitutions.
-
- When an X event is delivered to an item, the script for each
+ def tag_bind(self, tagname, sequence=None, callback=None):
+ """Bind a callback for the given event sequence to the tag tagname.
+ When an event is delivered to an item, the callbacks for each
of the item's tags option are called."""
- self.tk.call(self._w, "tag", "bind", tagname, sequence, script)
+ self._bind((self._w, "tag", "bind", tagname), sequence, callback, add=0)
def tag_configure(self, tagname, **kw):
More information about the Python-checkins
mailing list