Back to index

python3.2  3.2.2
Classes | Functions | Variables
pynche.StripViewer Namespace Reference

Classes

class  LeftArrow
class  RightArrow
class  StripWidget
class  StripViewer

Functions

def constant
def constant_red_generator
def constant_green_generator
def constant_blue_generator
def constant_cyan_generator
def constant_magenta_generator
def constant_yellow_generator
def __arrow_x
def __select_chip
def __trackarrow
def update_yourself
def set
def __togglehex
def __toblack
 def togglegentype(self, event=None): which = self.gentypevar.get() if which == 0: self.__reds.set(label='Red Variations', generator=constant_cyan_generator) self.__greens.set(label='Green Variations', generator=constant_magenta_generator) self.__blues.set(label='Blue Variations', generator=constant_yellow_generator) elif which == 1: self.__reds.set(label='Red Constant', generator=constant_red_generator) self.__greens.set(label='Green Constant', generator=constant_green_generator) self.__blues.set(label='Blue Constant', generator=constant_blue_generator) else: assert 0 self.__sb.update_views_current()
def __towhite
def save_options

Variables

string TCLPROC
int BTNDOWN = 4
int BTNUP = 5
int BTNDRAG = 6
string SPACE = ' '
list chips = self.__chips[]
 borderwidth=2, relief=GROOVE
int x = 1
int y = 30
tuple tags = ('chip',)
string color = 'grey'
 fill = color,outlinecolor,
 text = label,
 anchor = W)
tuple chipx = self.__arrow_x(0)
tuple whitebtn
 gentypevar = self.__gentypevar = IntVar() self.__variations = Radiobutton(frame, text='Variations', variable=gentypevar, value=0, command=self.__togglegentype) self.__variations.grid(row=0, column=1, sticky=W) self.__constants = Radiobutton(frame, text='Constants', variable=gentypevar, value=1, command=self.__togglegentype) self.__constants.grid(row=1, column=1, sticky=W)
 __lastchip
 __chips
 __generator

Detailed Description

Strip viewer and related widgets.

The classes in this file implement the StripViewer shown in the top two thirds
of the main Pynche window.  It consists of three StripWidgets which display
the variations in red, green, and blue respectively of the currently selected
r/g/b color value.

Each StripWidget shows the color variations that are reachable by varying an
axis of the currently selected color.  So for example, if the color is

  (R,G,B)=(127,163,196)

then the Red variations show colors from (0,163,196) to (255,163,196), the
Green variations show colors from (127,0,196) to (127,255,196), and the Blue
variations show colors from (127,163,0) to (127,163,255).

The selected color is always visible in all three StripWidgets, and in fact
each StripWidget highlights the selected color, and has an arrow pointing to
the selected chip, which includes the value along that particular axis.

Clicking on any chip in any StripWidget selects that color, and updates all
arrows and other windows.  By toggling on Update while dragging, Pynche will
select the color under the cursor while you drag it, but be forewarned that
this can be slow.

Function Documentation

def pynche.StripViewer.__arrow_x (   self,
  chipnum 
) [private]

Definition at line 233 of file StripViewer.py.

00233 
00234     def __arrow_x(self, chipnum):
00235         coords = self.__canvas.coords(chipnum+1)
00236         assert coords
00237         x0, y0, x1, y1 = coords
00238         return (x1 + x0) / 2.0

def pynche.StripViewer.__select_chip (   self,
  event = None 
) [private]

Definition at line 241 of file StripViewer.py.

00241 
00242     def __select_chip(self, event=None):
00243         x = event.x
00244         y = event.y
00245         canvas = self.__canvas
00246         chip = canvas.find_overlapping(x, y, x, y)
00247         if chip and (1 <= chip[0] <= self.__numchips):
00248             color = self.__chips[chip[0]-1]
00249             red, green, blue = ColorDB.rrggbb_to_triplet(color)
00250             etype = int(event.type)
00251             if (etype == BTNUP or self.__uwd.get()):
00252                 # update everyone
00253                 self.__sb.update_views(red, green, blue)
00254             else:
00255                 # just track the arrows
00256                 self.__trackarrow(chip[0], (red, green, blue))

def pynche.StripViewer.__toblack (   self,
  event = None 
) [private]

def togglegentype(self, event=None): which = self.gentypevar.get() if which == 0: self.__reds.set(label='Red Variations', generator=constant_cyan_generator) self.__greens.set(label='Green Variations', generator=constant_magenta_generator) self.__blues.set(label='Blue Variations', generator=constant_yellow_generator) elif which == 1: self.__reds.set(label='Red Constant', generator=constant_red_generator) self.__greens.set(label='Green Constant', generator=constant_green_generator) self.__blues.set(label='Blue Constant', generator=constant_blue_generator) else: assert 0 self.__sb.update_views_current()

Definition at line 425 of file StripViewer.py.

00425 
00426     def __toblack(self, event=None):
00427         self.__sb.update_views(0, 0, 0)

def pynche.StripViewer.__togglehex (   self,
  event = None 
) [private]

Definition at line 401 of file StripViewer.py.

00401 
00402     def __togglehex(self, event=None):
00403         red, green, blue = self.__sb.current_rgb()
00404         self.update_yourself(red, green, blue)

def pynche.StripViewer.__towhite (   self,
  event = None 
) [private]

Definition at line 428 of file StripViewer.py.

00428 
00429     def __towhite(self, event=None):
00430         self.__sb.update_views(255, 255, 255)

def pynche.StripViewer.__trackarrow (   self,
  chip,
  rgbtuple 
) [private]

Definition at line 257 of file StripViewer.py.

00257 
00258     def __trackarrow(self, chip, rgbtuple):
00259         # invert the last chip
00260         if self.__lastchip is not None:
00261             color = self.__canvas.itemcget(self.__lastchip, 'fill')
00262             self.__canvas.itemconfigure(self.__lastchip, outline=color)
00263         self.__lastchip = chip
00264         # get the arrow's text
00265         coloraxis = rgbtuple[self.__axis]
00266         if self.__hexp.get():
00267             # hex
00268             text = hex(coloraxis)
00269         else:
00270             # decimal
00271             text = repr(coloraxis)
00272         # move the arrow, and set its text
00273         if coloraxis <= 128:
00274             # use the left arrow
00275             self.__leftarrow.set_text(text)
00276             self.__leftarrow.move_to(self.__arrow_x(chip-1))
00277             self.__rightarrow.move_to(-100)
00278         else:
00279             # use the right arrow
00280             self.__rightarrow.set_text(text)
00281             self.__rightarrow.move_to(self.__arrow_x(chip-1))
00282             self.__leftarrow.move_to(-100)
00283         # and set the chip's outline
00284         brightness = ColorDB.triplet_to_brightness(rgbtuple)
00285         if brightness <= 128:
00286             outline = 'white'
00287         else:
00288             outline = 'black'
00289         self.__canvas.itemconfigure(chip, outline=outline)
00290 

def pynche.StripViewer.constant (   numchips)

Definition at line 52 of file StripViewer.py.

00052 
00053 def constant(numchips):
00054     step = 255.0 / (numchips - 1)
00055     start = 0.0
00056     seq = []
00057     while numchips > 0:
00058         seq.append(int(start))
00059         start = start + step
00060         numchips = numchips - 1
00061     return seq
00062 
# red variations, green+blue = cyan constant

Here is the caller graph for this function:

def pynche.StripViewer.constant_blue_generator (   numchips,
  red,
  green,
  blue 
)

Definition at line 73 of file StripViewer.py.

00073 
00074 def constant_blue_generator(numchips, red, green, blue):
00075     seq = constant(numchips)
00076     return list(zip(seq, seq, [blue] * numchips))
00077 
# red variations, green+blue = cyan constant
def pynche.StripViewer.constant_cyan_generator (   numchips,
  red,
  green,
  blue 
)

Definition at line 78 of file StripViewer.py.

00078 
00079 def constant_cyan_generator(numchips, red, green, blue):
00080     seq = constant(numchips)
00081     return list(zip(seq, [green] * numchips, [blue] * numchips))
00082 
# green variations, red+blue = magenta constant
def pynche.StripViewer.constant_green_generator (   numchips,
  red,
  green,
  blue 
)

Definition at line 68 of file StripViewer.py.

00068 
00069 def constant_green_generator(numchips, red, green, blue):
00070     seq = constant(numchips)
00071     return list(zip(seq, [green] * numchips, seq))
00072 
# blue variations, red+green = yellow constant
def pynche.StripViewer.constant_magenta_generator (   numchips,
  red,
  green,
  blue 
)

Definition at line 83 of file StripViewer.py.

00083 
00084 def constant_magenta_generator(numchips, red, green, blue):
00085     seq = constant(numchips)
00086     return list(zip([red] * numchips, seq, [blue] * numchips))
00087 
# blue variations, red+green = yellow constant
def pynche.StripViewer.constant_red_generator (   numchips,
  red,
  green,
  blue 
)

Definition at line 63 of file StripViewer.py.

00063 
00064 def constant_red_generator(numchips, red, green, blue):
00065     seq = constant(numchips)
00066     return list(zip([red] * numchips, seq, seq))
00067 
# green variations, red+blue = magenta constant
def pynche.StripViewer.constant_yellow_generator (   numchips,
  red,
  green,
  blue 
)

Definition at line 88 of file StripViewer.py.

00088 
00089 def constant_yellow_generator(numchips, red, green, blue):
00090     seq = constant(numchips)
00091     return list(zip([red] * numchips, [green] * numchips, seq))
00092 
00093 

def pynche.StripViewer.save_options (   self,
  optiondb 
)

Definition at line 431 of file StripViewer.py.

00431 
00432     def save_options(self, optiondb):
00433         optiondb['UPWHILEDRAG'] = self.__uwdvar.get()
00434         optiondb['HEXSTRIP'] = self.__hexpvar.get()
def pynche.StripViewer.set (   self,
  label,
  generator 
)

Definition at line 311 of file StripViewer.py.

00311 
00312     def set(self, label, generator):
00313         self.__canvas.itemconfigure(self.__label, text=label)
00314         self.__generator = generator
00315 

def pynche.StripViewer.update_yourself (   self,
  red,
  green,
  blue 
)

Definition at line 291 of file StripViewer.py.

00291 
00292     def update_yourself(self, red, green, blue):
00293         assert self.__generator
00294         i = 1
00295         chip = 0
00296         chips = self.__chips = []
00297         tk = self.__canvas.tk
00298         # get the red, green, and blue components for all chips
00299         for t in self.__generator(self.__numchips, red, green, blue):
00300             rrggbb = ColorDB.triplet_to_rrggbb(t)
00301             chips.append(rrggbb)
00302             tred, tgreen, tblue = t
00303             if tred <= red and tgreen <= green and tblue <= blue:
00304                 chip = i
00305             i = i + 1
00306         # call the raw tcl script
00307         colors = SPACE.join(chips)
00308         tk.eval('setcolor %s {%s}' % (self.__canvas._w, colors))
00309         # move the arrows around
00310         self.__trackarrow(chip, (red, green, blue))


Variable Documentation

Definition at line 295 of file StripViewer.py.

Definition at line 313 of file StripViewer.py.

Definition at line 262 of file StripViewer.py.

Definition at line 224 of file StripViewer.py.

Definition at line 44 of file StripViewer.py.

Definition at line 46 of file StripViewer.py.

Definition at line 45 of file StripViewer.py.

list pynche.StripViewer.chips = self.__chips[]

borderwidth=2, relief=GROOVE

Definition at line 207 of file StripViewer.py.

tuple pynche.StripViewer.chipx = self.__arrow_x(0)

Definition at line 227 of file StripViewer.py.

Definition at line 212 of file StripViewer.py.

pynche.StripViewer.fill = color,outlinecolor,

Definition at line 215 of file StripViewer.py.

Definition at line 48 of file StripViewer.py.

Definition at line 210 of file StripViewer.py.

Initial value:
00001 '''\
00002 proc setcolor {canv colors} {
00003     set i 1
00004     foreach c $colors {
00005         $canv itemconfigure $i -fill $c -outline $c
00006         incr i
00007     }
00008 }
00009 '''

Definition at line 33 of file StripViewer.py.

Definition at line 223 of file StripViewer.py.

Initial value:
00001 Button(frame2,
00002                           text='White',
00003                           command=self.__towhite)

gentypevar = self.__gentypevar = IntVar() self.__variations = Radiobutton(frame, text='Variations', variable=gentypevar, value=0, command=self.__togglegentype) self.__variations.grid(row=0, column=1, sticky=W) self.__constants = Radiobutton(frame, text='Constants', variable=gentypevar, value=1, command=self.__togglegentype) self.__constants.grid(row=1, column=1, sticky=W)

Definition at line 391 of file StripViewer.py.

Definition at line 208 of file StripViewer.py.

Definition at line 209 of file StripViewer.py.