Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for i, col in enumerate(PALETTE):
f = ttk.Frame(palette, borderwidth=1, relief="raised",
style="palette.TFrame")
l = tk.Label(f, background=col, width=2, height=1)
l.bind("<1>", self._palette_cmd)
f.bind("", lambda e: e.widget.configure(relief="raised"))
l.pack()
f.grid(row=i % 2, column=i // 2, padx=2, pady=2)
col_frame = ttk.Frame(self)
# --- hsv
hsv_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
hsv_frame.pack(pady=(0, 4), fill="x")
hsv_frame.columnconfigure(0, weight=1)
self.hue = LimitVar(0, 360, self)
self.saturation = LimitVar(0, 100, self)
self.value = LimitVar(0, 100, self)
# self.hue = tk.StringVar(self)
# self.saturation = tk.StringVar(self)
# self.value = tk.StringVar(self)
s_h = Spinbox(hsv_frame, from_=0, to=360, width=4, name='spinbox',
textvariable=self.hue, command=self._update_color_hsv)
s_s = Spinbox(hsv_frame, from_=0, to=100, width=4,
textvariable=self.saturation, name='spinbox',
command=self._update_color_hsv)
s_v = Spinbox(hsv_frame, from_=0, to=100, width=4, name='spinbox',
textvariable=self.value, command=self._update_color_hsv)
h, s, v = rgb_to_hsv(*self._old_color)
s_h.delete(0, 'end')
s_h.insert(0, h)
s_s.delete(0, 'end')
f = ttk.Frame(palette, borderwidth=1, relief="raised",
style="palette.TFrame")
l = tk.Label(f, background=col, width=2, height=1)
l.bind("<1>", self._palette_cmd)
f.bind("", lambda e: e.widget.configure(relief="raised"))
l.pack()
f.grid(row=i % 2, column=i // 2, padx=2, pady=2)
col_frame = ttk.Frame(self)
# --- hsv
hsv_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
hsv_frame.pack(pady=(0, 4), fill="x")
hsv_frame.columnconfigure(0, weight=1)
self.hue = LimitVar(0, 360, self)
self.saturation = LimitVar(0, 100, self)
self.value = LimitVar(0, 100, self)
# self.hue = tk.StringVar(self)
# self.saturation = tk.StringVar(self)
# self.value = tk.StringVar(self)
s_h = Spinbox(hsv_frame, from_=0, to=360, width=4, name='spinbox',
textvariable=self.hue, command=self._update_color_hsv)
s_s = Spinbox(hsv_frame, from_=0, to=100, width=4,
textvariable=self.saturation, name='spinbox',
command=self._update_color_hsv)
s_v = Spinbox(hsv_frame, from_=0, to=100, width=4, name='spinbox',
textvariable=self.value, command=self._update_color_hsv)
h, s, v = rgb_to_hsv(*self._old_color)
s_h.delete(0, 'end')
s_h.insert(0, h)
s_s.delete(0, 'end')
s_s.insert(0, s)
def test_limitvar_init(self):
var = color.limitvar.LimitVar(0, 100, self.window, 10)
self.window.update()
self.assertEqual(var.get(), 10)
del var
var = color.limitvar.LimitVar('0', '100', self.window)
self.window.update()
self.assertEqual(var.get(), 0)
del var
var = color.limitvar.LimitVar(0, 100, self.window, 200)
self.window.update()
self.assertEqual(var.get(), 100)
del var
var = color.limitvar.LimitVar(0, 100, self.window, -2)
self.window.update()
self.assertEqual(var.get(), 0)
del var
self.assertRaises(ValueError, color.limitvar.LimitVar, 'a', 0, self.window)
def test_limitvar_init(self):
var = color.limitvar.LimitVar(0, 100, self.window, 10)
self.window.update()
self.assertEqual(var.get(), 10)
del var
var = color.limitvar.LimitVar('0', '100', self.window)
self.window.update()
self.assertEqual(var.get(), 0)
del var
var = color.limitvar.LimitVar(0, 100, self.window, 200)
self.window.update()
self.assertEqual(var.get(), 100)
del var
var = color.limitvar.LimitVar(0, 100, self.window, -2)
self.window.update()
self.assertEqual(var.get(), 0)
del var
self.assertRaises(ValueError, color.limitvar.LimitVar, 'a', 0, self.window)
self.assertRaises(ValueError, color.limitvar.LimitVar, 0, 'b', self.window)
self.assertRaises(ValueError, color.limitvar.LimitVar, 100, 0, self.window)
def test_limitvar_init(self):
var = color.limitvar.LimitVar(0, 100, self.window, 10)
self.window.update()
self.assertEqual(var.get(), 10)
del var
var = color.limitvar.LimitVar('0', '100', self.window)
self.window.update()
self.assertEqual(var.get(), 0)
del var
var = color.limitvar.LimitVar(0, 100, self.window, 200)
self.window.update()
self.assertEqual(var.get(), 100)
del var
var = color.limitvar.LimitVar(0, 100, self.window, -2)
self.window.update()
self.assertEqual(var.get(), 0)
del var
self.assertRaises(ValueError, color.limitvar.LimitVar, 'a', 0, self.window)
self.assertRaises(ValueError, color.limitvar.LimitVar, 0, 'b', self.window)
self.assertRaises(ValueError, color.limitvar.LimitVar, 100, 0, self.window)
self.window.update()
self.assertEqual(var.get(), 10)
del var
var = color.limitvar.LimitVar('0', '100', self.window)
self.window.update()
self.assertEqual(var.get(), 0)
del var
var = color.limitvar.LimitVar(0, 100, self.window, 200)
self.window.update()
self.assertEqual(var.get(), 100)
del var
var = color.limitvar.LimitVar(0, 100, self.window, -2)
self.window.update()
self.assertEqual(var.get(), 0)
del var
self.assertRaises(ValueError, color.limitvar.LimitVar, 'a', 0, self.window)
self.assertRaises(ValueError, color.limitvar.LimitVar, 0, 'b', self.window)
self.assertRaises(ValueError, color.limitvar.LimitVar, 100, 0, self.window)
s_v.grid(row=2, column=1, sticky='w', padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Hue')).grid(row=0, column=0, sticky='e',
padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Saturation')).grid(row=1, column=0, sticky='e',
padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Value')).grid(row=2, column=0, sticky='e',
padx=4, pady=4)
# --- rgb
rgb_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
rgb_frame.pack(pady=4, fill="x")
rgb_frame.columnconfigure(0, weight=1)
# self.red = tk.StringVar(self)
# self.green = tk.StringVar(self)
# self.blue = tk.StringVar(self)
self.red = LimitVar(0, 255, self)
self.green = LimitVar(0, 255, self)
self.blue = LimitVar(0, 255, self)
s_red = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.red, command=self._update_color_rgb)
s_green = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.green, command=self._update_color_rgb)
s_blue = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.blue, command=self._update_color_rgb)
s_red.delete(0, 'end')
s_red.insert(0, self._old_color[0])
s_green.delete(0, 'end')
s_green.insert(0, self._old_color[1])
s_blue.delete(0, 'end')
s_blue.insert(0, self._old_color[2])
s_red.grid(row=0, column=1, sticky='e', padx=4, pady=4)
padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Saturation')).grid(row=1, column=0, sticky='e',
padx=4, pady=4)
ttk.Label(hsv_frame, text=_('Value')).grid(row=2, column=0, sticky='e',
padx=4, pady=4)
# --- rgb
rgb_frame = ttk.Frame(col_frame, relief="ridge", borderwidth=2)
rgb_frame.pack(pady=4, fill="x")
rgb_frame.columnconfigure(0, weight=1)
# self.red = tk.StringVar(self)
# self.green = tk.StringVar(self)
# self.blue = tk.StringVar(self)
self.red = LimitVar(0, 255, self)
self.green = LimitVar(0, 255, self)
self.blue = LimitVar(0, 255, self)
s_red = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.red, command=self._update_color_rgb)
s_green = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.green, command=self._update_color_rgb)
s_blue = Spinbox(rgb_frame, from_=0, to=255, width=4, name='spinbox',
textvariable=self.blue, command=self._update_color_rgb)
s_red.delete(0, 'end')
s_red.insert(0, self._old_color[0])
s_green.delete(0, 'end')
s_green.insert(0, self._old_color[1])
s_blue.delete(0, 'end')
s_blue.insert(0, self._old_color[2])
s_red.grid(row=0, column=1, sticky='e', padx=4, pady=4)
s_green.grid(row=1, column=1, sticky='e', padx=4, pady=4)
s_blue.grid(row=2, column=1, sticky='e', padx=4, pady=4)
ttk.Label(rgb_frame, text=_('Blue')).grid(row=2, column=0, sticky='e',
padx=4, pady=4)
# --- hexa
hexa_frame = ttk.Frame(col_frame)
hexa_frame.pack(fill="x")
self.hexa = ttk.Entry(hexa_frame, justify="center", width=10, name='entry')
self.hexa.insert(0, old_color.upper())
ttk.Label(hexa_frame, text="HTML").pack(side="left", padx=4, pady=(4, 1))
self.hexa.pack(side="left", padx=6, pady=(4, 1), fill='x', expand=True)
# --- alpha
if alpha:
alpha_frame = ttk.Frame(self)
alpha_frame.columnconfigure(1, weight=1)
# self.alpha = tk.StringVar(self)
self.alpha = LimitVar(0, 255, self)
alphabar = ttk.Frame(alpha_frame, borderwidth=2, relief='groove')
self.alphabar = AlphaBar(alphabar, alpha=self._old_alpha, width=200,
color=self._old_color, highlightthickness=0)
self.alphabar.pack()
s_alpha = Spinbox(alpha_frame, from_=0, to=255, width=4,
textvariable=self.alpha, command=self._update_alpha)
s_alpha.delete(0, 'end')
s_alpha.insert(0, self._old_alpha)
alphabar.grid(row=0, column=0, padx=(0, 4), pady=4, sticky='w')
ttk.Label(alpha_frame, text=_('Alpha')).grid(row=0, column=1, sticky='e',
padx=4, pady=4)
s_alpha.grid(row=0, column=2, sticky='w', padx=(4, 6), pady=4)
# --- validation
button_frame = ttk.Frame(self)
ttk.Button(button_frame, text="Ok",