Added chip selection stuff, strip label
This commit is contained in:
parent
93737b2da8
commit
bc6893062a
|
@ -80,6 +80,7 @@ class StripWidget(Pmw.MegaWidget):
|
||||||
('numchips', self._NUMCHIPS, Pmw.INITOPT),
|
('numchips', self._NUMCHIPS, Pmw.INITOPT),
|
||||||
('generator', None, Pmw.INITOPT),
|
('generator', None, Pmw.INITOPT),
|
||||||
('axis', None, Pmw.INITOPT),
|
('axis', None, Pmw.INITOPT),
|
||||||
|
('label', '', Pmw.INITOPT),
|
||||||
)
|
)
|
||||||
self.defineoptions(kw, options)
|
self.defineoptions(kw, options)
|
||||||
|
|
||||||
|
@ -93,13 +94,22 @@ class StripWidget(Pmw.MegaWidget):
|
||||||
numchips = self.__numchips = self['numchips']
|
numchips = self.__numchips = self['numchips']
|
||||||
|
|
||||||
canvaswidth = numchips * (chipwidth + 1)
|
canvaswidth = numchips * (chipwidth + 1)
|
||||||
canvasheight = chipheight + 35
|
canvasheight = chipheight + 43 # TBD: Kludge
|
||||||
|
|
||||||
|
# create the canvas and pack it
|
||||||
self.__canvas = Canvas(
|
self.__canvas = Canvas(
|
||||||
parent,
|
parent,
|
||||||
width=canvaswidth,
|
width=canvaswidth,
|
||||||
height=canvasheight)
|
height=canvasheight,
|
||||||
|
## borderwidth=2,
|
||||||
|
## relief=GROOVE
|
||||||
|
)
|
||||||
|
|
||||||
self.__canvas.pack()
|
self.__canvas.pack()
|
||||||
|
self.__canvas.bind('<ButtonRelease-1>',
|
||||||
|
self.__select_chip)
|
||||||
|
self.__canvas.bind('<B1-Motion>',
|
||||||
|
self.__select_chip)
|
||||||
|
|
||||||
# create the color strip
|
# create the color strip
|
||||||
chips = self.__chips = []
|
chips = self.__chips = []
|
||||||
|
@ -113,6 +123,12 @@ class StripWidget(Pmw.MegaWidget):
|
||||||
x = x + chipwidth + 1 # for outline
|
x = x + chipwidth + 1 # for outline
|
||||||
chips.append(rect)
|
chips.append(rect)
|
||||||
|
|
||||||
|
# create the string tag
|
||||||
|
self.__label = self.__canvas.create_text(
|
||||||
|
3, y + chipheight + 8,
|
||||||
|
text=self['label'],
|
||||||
|
anchor=W)
|
||||||
|
|
||||||
# create the arrow and text item
|
# create the arrow and text item
|
||||||
chipx = self.__arrow_x(0)
|
chipx = self.__arrow_x(0)
|
||||||
self.__leftarrow = LeftArrow(self.__canvas, chipx)
|
self.__leftarrow = LeftArrow(self.__canvas, chipx)
|
||||||
|
@ -127,6 +143,28 @@ class StripWidget(Pmw.MegaWidget):
|
||||||
|
|
||||||
def __set_color(self):
|
def __set_color(self):
|
||||||
rgbtuple = self['color']
|
rgbtuple = self['color']
|
||||||
|
self.set_color(self, rgbtuple)
|
||||||
|
|
||||||
|
def __arrow_x(self, chipnum):
|
||||||
|
coords = self.__canvas.coords(self.__chips[chipnum])
|
||||||
|
assert coords
|
||||||
|
x0, y0, x1, y1 = coords
|
||||||
|
return (x1 + x0) / 2.0
|
||||||
|
|
||||||
|
def __select_chip(self, event=None):
|
||||||
|
chip = self.__canvas.find_closest(event.x, event.y)
|
||||||
|
delegate = self['delegate']
|
||||||
|
if chip and delegate:
|
||||||
|
color = self.__canvas.itemcget(chip, 'fill')
|
||||||
|
rgbtuple = ColorDB.rrggbb_to_triplet(color)
|
||||||
|
delegate.set_color(self, rgbtuple)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# public interface
|
||||||
|
#
|
||||||
|
|
||||||
|
def set_color(self, obj, rgbtuple):
|
||||||
red, green, blue = rgbtuple
|
red, green, blue = rgbtuple
|
||||||
if self.__generator:
|
if self.__generator:
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -164,9 +202,3 @@ class StripWidget(Pmw.MegaWidget):
|
||||||
outline = 'black'
|
outline = 'black'
|
||||||
self.__canvas.itemconfigure(self.__chips[chip],
|
self.__canvas.itemconfigure(self.__chips[chip],
|
||||||
outline=outline)
|
outline=outline)
|
||||||
|
|
||||||
def __arrow_x(self, chipnum):
|
|
||||||
coords = self.__canvas.coords(self.__chips[chipnum])
|
|
||||||
assert coords
|
|
||||||
x0, y0, x1, y1 = coords
|
|
||||||
return (x1 + x0) / 2.0
|
|
||||||
|
|
Loading…
Reference in New Issue