def _draw(self, color): """Draw the gradient and the selection cross on the canvas.""" width = self.winfo_width() height = self.winfo_height() self.delete("bg") self.delete("cross_h") self.delete("cross_v") del self.bg self.bg = tk.PhotoImage(width=width, height=height, master=self) self._fill() self.create_image(0, 0, image=self.bg, anchor="nw", tags="bg") self.tag_lower("bg") h, s, v = color x = v / 100. y = (1 - s / 100.) self.create_line(0, y * height, width, y * height, tags="cross_h", fill="#C2C2C2") self.create_line(x * width, 0, x * width, height, tags="cross_v", fill="#C2C2C2")
def __init__(self, parent, hue, color=None, cr=COLORCOR_MAX, cg=int(69 * COLORCOR_MAX / 100), cb=int(94 * COLORCOR_MAX / 100), height=256, width=256, **kwargs): """ Create a ColorSquare. Keyword arguments: * parent: parent window * hue: color square gradient for given hue (color in top right corner is (hue, 100, 100) in HSV * color: initially selected color given in HSV * width, height and any keyword option accepted by a tkinter Canvas """ tk.Canvas.__init__(self, parent, height=height, width=width, **kwargs) self.bg = tk.PhotoImage(width=width, height=height, master=self) self._hue = hue if not color: color = hue2col(self._hue) self.cr = cr self.cg = cg self.cb = cb self.bind('<Configure>', lambda e: self._draw(color)) self.bind('<ButtonPress-1>', self._on_click) self.bind('<B1-Motion>', self._on_move)
def _draw_gradient(self, hue): """Draw the gradient and put the cursor on hue.""" self.delete("gradient") self.delete("cursor") del self.gradient width = self.winfo_width() height = self.winfo_height() self.gradient = tk.PhotoImage(master=self, width=width, height=height) line = [] for i in range(width): #line.append(rgb_to_hexa(*hue2col(float(i) / width * 360))) gradval = round2(float(i) / width * 255) line.append(rgb_to_hexa(gradval, gradval, gradval)) line = "{" + " ".join(line) + "}" self.gradient.put(" ".join([line for j in range(height)])) self.create_image(0, 0, anchor="nw", tags="gardient", image=self.gradient) self.lower("gradient") x = hue / 100. * width self.create_line(x, 0, x, height, width=2, tags='cursor')
def _draw(self, color): """Draw the gradient and the selection cross on the canvas.""" width = self.winfo_width() height = self.winfo_height() self.delete("bg") self.delete("cross_h") self.delete("cross_v") del self.bg self.bg = tk.PhotoImage(width=width, height=height, master=self) self._fill() self.create_image(0, 0, image=self.bg, anchor="nw", tags="bg") self.tag_lower("bg") h, s, v = color h = self._correct_hue_for_disp(h) radius = min(height, width) / 2.0 centre = height / 2, width / 2 radh = math.radians(h) x = centre[1] - width * math.cos(radh) * s / 200 y = centre[0] - height * math.sin(radh) * s / 200 self.create_line(0, y, width, y, tags="cross_h", fill="#C2C2C2") self.create_line(x, 0, x, height, tags="cross_v", fill="#C2C2C2")
def _draw_gradient(self, tempColor): """Draw the gradient and put the cursor on tempColor.""" self.delete("gradient") self.delete("cursor") del self.gradient width = self.winfo_width() height = self.winfo_height() self.gradient = tk.PhotoImage(master=self, width=width, height=height) line = [] for i in range(width): line.append( rgb_to_hexa(*self.calcColor(int(i / width * 9000) + 1500))) line = "{" + " ".join(line) + "}" self.gradient.put(" ".join([line for j in range(height)])) self.create_image(0, 0, anchor="nw", tags="gardient", image=self.gradient) self.lower("gradient") x = tempColor / 5200. * width self.create_line(x, 0, x, height, width=2, tags='cursor')
def _draw_gradient(self, value): """Draw the gradient and put the cursor on hue.""" self.delete("gradient") self.delete("cursor") del self.gradient width = self.winfo_width() height = self.winfo_height() self.gradient = tk.PhotoImage(master=self, width=width, height=height) line = [] for i in range(width): col = int(float(i) / width * 255) rij = col gij = col bij = col line.append(rgb_to_hexa(rij, gij, bij)) line = "{" + " ".join(line) + "}" self.gradient.put(" ".join([line for j in range(height)])) self.create_image(0, 0, anchor="nw", tags="gradient", image=self.gradient) self.lower("gradient") x = value / max_value * width self.create_line(x, 0, x, height, width=4, tags='cursor', fill="RED")
def __init__(self, parent, tempColor=4000, height=11, width=500, variable=None, **kwargs): """ Create a TemperatureGradBar. Keyword arguments: * parent: parent window * tempColor: initially selected tempColor value * variable: IntVar linked to the alpha value * height, width, and any keyword argument accepted by a tkinter Canvas """ tk.Canvas.__init__(self, parent, width=width, height=height, **kwargs) self._variable = variable if variable is not None: try: tempColor = int(variable.get()) except Exception: pass else: self._variable = tk.IntVar(self) tempColor -= 1500 if tempColor > 5200: tempColor = 5200 elif tempColor < 1500: tempColor = 1500 try: self._variable.trace_add("write", self._update_temperature) except Exception: self._variable.trace("w", self._update_temperature) self.gradient = tk.PhotoImage(master=self, width=width, height=height) self.bind('<Configure>', lambda e: self._draw_gradient(tempColor)) self.bind('<ButtonPress-1>', self._on_click) self.bind('<B1-Motion>', self._on_move)
def __init__(self, parent, hue=0, value=0, height=11, width=256, variable=None, **kwargs): """ Create a GradientBar. Keyword arguments: * parent: parent window * hue: initially selected hue value * variable: IntVar linked to the alpha value * height, width, and any keyword argument accepted by a tkinter Canvas """ tk.Canvas.__init__(self, parent, width=width, height=height, **kwargs) self._variable = variable if variable is not None: try: hue = int(variable.get()) except Exception: pass else: self._variable = tk.IntVar(self) if hue > 360: hue = 360 elif hue < 0: hue = 0 self._variable.set(hue) try: self._variable.trace_add("write", self._update_hue) except Exception: self._variable.trace("w", self._update_hue) self.gradient = tk.PhotoImage(master=self, width=width, height=height) self.bind('<Configure>', lambda e: self._draw_gradient(hue)) self.bind('<ButtonPress-1>', self._on_click) self.bind('<B1-Motion>', self._on_move)
def __init__(self, parent, alpha=255, color=(255, 0, 0), height=11, width=256, variable=None, **kwargs): """ Create a bar to select the alpha value. Keyword arguments: * parent: parent window * alpha: initially selected alpha value * color: gradient color * variable: IntVar linked to the alpha value * height, width, and any keyword argument accepted by a tkinter Canvas """ tk.Canvas.__init__(self, parent, width=width, height=height, **kwargs) self.gradient = tk.PhotoImage(master=self, width=width, height=height) self._variable = variable if variable is not None: try: alpha = int(variable.get()) except Exception: pass else: self._variable = tk.IntVar(self) if alpha > 255: alpha = 255 elif alpha < 0: alpha = 0 self._variable.set(alpha) try: self._variable.trace_add("write", self._update_alpha) except Exception: self._variable.trace("w", self._update_alpha) self.bind('<Configure>', lambda e: self._draw_gradient(alpha, color)) self.bind('<ButtonPress-1>', self._on_click) self.bind('<B1-Motion>', self._on_move)