def _makeColorTile(self, color): image = Tkinter.PhotoImage() self.menu.images.append(image) if type(color) == type([]): colors = [ scaleColor(self.menu, c, 1.0) for c in color ] else: colors = [ scaleColor(self.menu, color, 1.0), ] cols = max(8, len(colors)) for x in range(cols): i = x % len(colors) c = colors[i] for y in range(16): image.put('{%s %s}' % (c,c), to=(2*x,y)) return image
def scaleColorQuick(self, color, value, dict={}): if dict.get(color) is None: dict[color] = {} d = dict[color] if d.get(value) is None: color2 = scaleColor(self, color, value) d[value] = color2 return color2 else: return d[value]
def selectButton(self, i, doCallback=True): if i >= len(self.buttons): return button = self.buttons[i] if self.radio: self.state[i] = 0 if self.toggled: if not self.state[i]: self.state[i] = 1 if self.buttonRelief == 'sunken': relief = 'raised' else: relief = 'sunken' color = self.colors[i] fg = invertColor(self, color) or 'black' bg = color or self.cget('background') bg2 = scaleColor(self, bg, 0.8) if bg2 == bg: bg2 = scaleColor(self, bg, 1.2) fg2 = invertColor(self, bg2) or 'black' button.config(relief=relief, background=bg, fg=fg, activebackground=bg2, activeforeground=fg2) elif not self.radio: self.state[i] = 0 if self.buttonRelief == 'sunken': relief = 'sunken' else: relief = 'raised' color = self.colors[i] fg = self.toggledFg or 'black' bg = self.toggledBg or self.cget('background') fg2 = invertColor(self, color) or 'black' bg2 = color or self.cget('background') button.config(relief=relief, background=bg, fg=fg, activebackground=bg2, activeforeground=fg2) if self.radio: color = self.colors[i] fg = self.toggledFg or 'black' bg = self.toggledBg or self.cget('background') fg2 = invertColor(self, color) or 'black' bg2 = color or self.cget('background') self.states = [] for j in range(len(self.buttons)): if j == i: self.states.append(1) continue self.states.append(0) if self.buttonRelief == 'sunken': relief = 'sunken' else: relief = 'raised' self.buttons[j].config(relief=relief, background=bg, fg=fg, activebackground=bg2, activeforeground=fg2) if doCallback and self.callback: self.callback(self.objects[i])
def __init__(self, parent, numButtons, state=None, orient='h', background=None, selectColor='#C0C0FF', size=15, callback=None, label=None, grid=None, *args, **kw): self.numButtons = numButtons self.orient = orient self.selectColor = selectColor self.size = size self.callback = callback self.state = state or [False] * numButtons self.canvasDict = {} self.canvasNums = {} self.initialN = None self.initialS = None if (background is None): self.bg = parent.cget('bg') else: self.bg = background Frame.__init__(self, parent, grid=grid, *args, **kw) self.bgLight = scaleColor(self, self.bg, 1.5) self.bgDark = scaleColor(self, self.bg, 0.4) self.bgLight2 = scaleColor(self, self.bg, 1.2) self.bgDark2 = scaleColor(self, self.bg, 0.7) if label: self.label = Label(self, text=label, tipText=TOOL_TIP) self.label.grid(row=0, column=0, sticky=Tkinter.EW) if orient in (Tkinter.HORIZONTAL, 'horizontal', 'h'): c_row = 0 c_col = 1 else: c_row = 1 c_col = 0 else: self.label = None if orient in (Tkinter.HORIZONTAL, 'horizontal', 'h'): self.orient = 'h' self.canvas = c = Canvas(self, bg=self.bg, height=size) self.grid_columnconfigure(c_col, weight=1) else: self.orient = 'v' self.canvas = c = Canvas(self, bg=self.bg, width=size) self.grid_rowconfigure(c_row, weight=1) c.grid(row=c_row, column=c_col, sticky='nsew') c.bind('<Configure>', self.resizeCanvas) c.bind('<Button-1>', self.slideState) c.bind('<B1-Motion>', self.slideState) c.bind('<ButtonRelease-1>', self.slideStateDone) c.bind('<Button-2>', self.clickState) c.bind('<B2-Motion>', self.clickState) c.bind('<ButtonRelease-2>', self.clickStateDone)
def __init__(self, parent, # arguments below are Tkinter.Scrollbar options orient = Tkinter.HORIZONTAL, width = 15, borderwidth = 1, background = None, troughcolor = None, repeatdelay = 300, # msecs before repeat action on arrows and troughs repeatinterval = 100, # msecs between repeat action on arrows and troughs # arguments below are not Tkinter.Scrollbar options # callback is approximately same as Tkinter.Scrollbar command # option but has different (more convenient) arguments allow_resize = False, callback = None, relief='sunken', show_text = False, text_color = '#000000', text_func = None, units_scroll = 0.1, pages_scroll = 1.0, min_thickness = None, *args, **kw): assert orient in (Tkinter.HORIZONTAL, Tkinter.VERTICAL) if (show_text): assert text_func is not None self.relief = relief self.orient = orient self.callback = callback self.borderwidth = borderwidth self.repeatdelay = repeatdelay self.repeatinterval = repeatinterval self.show_text = show_text self.text_func = text_func self.units_scroll = units_scroll self.pages_scroll = pages_scroll self.min_thickness = min_thickness self.mode = 0 self.lo = 0.0 self.hi = 1.0 self.first_pass = True Frame.__init__(self, parent, *args, **kw) if (background is None): bg = parent.cget('bg') else: bg = background if (troughcolor is None): bg_trough = scaleColor(self, bg, 0.9) else: bg_trough = troughcolor # below are for shadows if relief == 'sunken': color1 = scaleColor(self, bg_trough, 0.7) color2 = scaleColor(self, bg_trough, 1.2) color3 = scaleColor(self, bg, 1.2) color4 = scaleColor(self, bg, 0.7) elif relief == 'raised': color1 = scaleColor(self, bg_trough, 1.2) color2 = scaleColor(self, bg_trough, 0.7) color3 = scaleColor(self, bg, 0.7) color4 = scaleColor(self, bg, 1.2) else: color1 = color2 = scaleColor(self, bg_trough, 0.7) color3 = color4 = scaleColor(self, bg, 1.2) self.brColor = color4 self.tlColor = color3 defaultSize = 10 # gets overriden by other widgets in container # but need to do something otherwise canvas asks for too much space kw2 = {} if (orient == Tkinter.HORIZONTAL): kw2['width'] = defaultSize kw2['height'] = width else: kw2['width'] = width kw2['height'] = defaultSize self.canvas = c = Canvas(self, bg=bg, **kw2) # grid does not seem to work because once canvas size specified # in any way it never seems to be resized c.pack(side=Tkinter.TOP, expand=Tkinter.YES, fill=Tkinter.BOTH) self.tlOuter = c.create_polygon(0, 0, 0, 0, 0, 0,0, 0,fill=color1, outline='') self.brOuter = c.create_polygon(0, 0, 0, 0, 0, 0,0, 0,fill=color2, outline='') self.bgOuter = c.create_rectangle(0, 0, 0, 0, fill=bg_trough, outline='') # self.arrowXTl,Br are for shadows of the arrows # self.arrowXFill is for triangle infill # arrow and rectangle boundaries which are colored the # same as (and so in some sense are part of) the trough # the main part of the arrow does not need its own polygon # because it is the same color as the main rectangle self.arrow1Tl = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color3, outline='') self.arrow1Br = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color4, outline='') self.arrow1Fill = c.create_polygon(0, 0, 0, 0, 0, 0, fill=bg, outline='') self.arrow2Tl = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color3, outline='') self.arrow2Br = c.create_polygon(0, 0, 0, 0, 0, 0, 0, 0, fill=color4, outline='') self.arrow2Fill = c.create_polygon(0, 0, 0, 0, 0, 0, fill=bg, outline='') # slider is the bit you grab in the middle # created with two triangles for the shadowsed border # with rectangle panel in middle self.tlSlider = c.create_polygon(0, 0, 0, 0, 0, 0,fill=color3, outline='') self.brSlider = c.create_polygon(0, 0, 0, 0, 0, 0,fill=color4, outline='') self.bgSlider = c.create_rectangle(0, 0, 0, 0, fill=bg, outline='') if (show_text): self.text0 = c.create_text(0, 0, fill=text_color) self.text1 = c.create_text(0, 0, fill=text_color) if (orient == Tkinter.HORIZONTAL): c.itemconfig(self.text0, anchor=Tkinter.W) c.itemconfig(self.text1, anchor=Tkinter.E) else: c.itemconfig(self.text0, anchor=Tkinter.S) c.itemconfig(self.text1, anchor=Tkinter.N) c.bind('<Configure>', self.configure) c.bind('<Button-1>', self.buttonPressMove) c.bind('<B1-Motion>', self.buttonMotionMove) c.bind('<ButtonRelease-1>', self.buttonReleaseMove) if (allow_resize): c.bind('<Button-2>', self.buttonPressResize) c.bind('<B2-Motion>', self.resize)