Commit 9cf028c5 authored by Barry Warsaw's avatar Barry Warsaw

Implementation using TCLPROC loaded into the Tcl interpreter

parent 0e4a2215
...@@ -3,6 +3,20 @@ from Tkinter import * ...@@ -3,6 +3,20 @@ from Tkinter import *
import Pmw import Pmw
import ColorDB import ColorDB
# Load this script into the Tcl interpreter and call it in
# StripWidget.set_color(). This is about as fast as it can be with the
# current _tkinter.c interface, which doesn't support Tcl Objects.
TCLPROC = '''\
proc setcolor {canv colors} {
set i 1
foreach c $colors {
$canv itemconfigure $i -fill $c -outline $c
incr i
}
}
'''
class LeftArrow: class LeftArrow:
_ARROWWIDTH = 30 _ARROWWIDTH = 30
...@@ -113,6 +127,10 @@ class StripWidget(Pmw.MegaWidget): ...@@ -113,6 +127,10 @@ class StripWidget(Pmw.MegaWidget):
self.__canvas.bind('<B1-Motion>', self.__canvas.bind('<B1-Motion>',
self.__select_chip) self.__select_chip)
# Load a proc into the Tcl interpreter. This is used in the
# set_color() method to speed up setting the chip colors.
self.__canvas.tk.eval(TCLPROC)
# create the color strip # create the color strip
chips = self.__chips = [] chips = self.__chips = []
x = 1 x = 1
...@@ -187,27 +205,31 @@ class StripWidget(Pmw.MegaWidget): ...@@ -187,27 +205,31 @@ class StripWidget(Pmw.MegaWidget):
chip = 0 chip = 0
chips = self.__chips = [] chips = self.__chips = []
tclcmd = [] tclcmd = []
tk = self.__canvas.tk
for t in self.__generator(self.__numchips, rgbtuple): for t in self.__generator(self.__numchips, rgbtuple):
rrggbb = ColorDB.triplet_to_rrggbb(t) rrggbb = ColorDB.triplet_to_rrggbb(t)
chips.append(rrggbb) chips.append(rrggbb)
## self.__canvas.itemconfigure(i, ## self.__canvas.itemconfigure(i,
## fill=rrggbb, ## fill=rrggbb,
## outline=rrggbb) ## outline=rrggbb)
tclcmd.append(self.__canvas._w) ## tclcmd.append(self.__canvas._w)
tclcmd.append('itemconfigure') ## tclcmd.append('itemconfigure')
tclcmd.append(`i`) ## tclcmd.append(`i`)
tclcmd.append('-fill') ## tclcmd.append('-fill')
tclcmd.append(rrggbb) ## tclcmd.append(rrggbb)
tclcmd.append('-outline') ## tclcmd.append('-outline')
tclcmd.append(rrggbb) ## tclcmd.append(rrggbb)
tclcmd.append('\n') ## tclcmd.append('\n')
tred, tgreen, tblue = t tred, tgreen, tblue = t
if tred <= red and tgreen <= green and tblue <= blue: if tred <= red and tgreen <= green and tblue <= blue:
chip = i chip = i
i = i + 1 i = i + 1
# call the raw tcl script # call the raw tcl script
script = string.join(tclcmd, ' ') ## script = string.join(tclcmd, ' ')
self.__canvas.tk.eval(script) ## self.__canvas.tk.eval(script)
## colors = tk.merge(chips)
colors = string.join(chips)
tk.eval('setcolor %s {%s}' % (self.__canvas._w, colors))
# get the arrow's text # get the arrow's text
coloraxis = rgbtuple[self.__axis] coloraxis = rgbtuple[self.__axis]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment