示例#1
0
    def test_colorpicker_bindings(self):
        cp = tkc.ColorPicker(self.window,
                             color=(0, 255, 0),
                             title='Test',
                             alpha=True)
        self.window.update()
        event = TestEvent(x=0, y=1)
        cp.bar._on_click(event)
        self.window.update()
        self.assertEqual(cp.bar.get(), 0)
        cp._change_color(event)
        self.window.update()
        self.assertEqual(cp.hue.get(), 0)

        self.window.update()
        event = TestEvent(x=0, y=1)
        cp.alphabar._on_click(event)
        self.window.update()
        self.assertEqual(cp.alphabar.get(), 0)
        cp._change_alpha(event)
        self.window.update()
        self.assertEqual(cp.alpha.get(), 0)
        event.x = cp.alphabar.winfo_width()
        cp.alphabar._on_click(event)
        cp._change_alpha(event)
        self.window.update()

        cp.color_preview.focus_force()
        cp._unfocus(event)
        self.assertEqual(cp.focus_get(), cp)
        cp.hexa.focus_force()
        cp._unfocus(event)
        self.assertNotEqual(cp.focus_get(), cp)
        self.window.update()

        event = TestEvent(x=cp.square.winfo_width(),
                          y=cp.square.winfo_height())
        cp.square._on_click(event)
        self.window.update()
        cp._change_sel_color(event)
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 255), (0, 0, 100), '#FFFFFF'))
        self.assertEqual(cp.alpha.get(), 255)
        self.window.update()
        event = TestEvent(widget=tk.Label(self.window, bg='white'))
        cp._palette_cmd(event)
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 255), (0, 0, 100), '#FFFFFF'))
        cp._reset_preview(event)
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((0, 255, 0), (120, 100, 100), '#00FF00'))
示例#2
0
    def test_colorpicker_functions(self):
        # with alpha
        cp = tkc.ColorPicker(self.window,
                             color=(255, 0, 0, 100),
                             title='Test',
                             alpha=True)
        self.window.update()
        # RGB
        cp.green.set(255)
        self.window.update()
        cp._update_color_rgb()
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 0), (60, 100, 100), '#FFFF00'))
        self.window.update()
        # HSV
        cp.value.set(0)
        self.window.update()
        cp._update_color_hsv()
        self.window.update()
        self.assertEqual(cp.square.get(), ((0, 0, 0), (60, 100, 0), '#000000'))
        self.window.update()
        # HTML
        cp.hexa.delete(0, 'end')
        cp.hexa.insert(0, '#FF0000')
        self.window.update()
        cp._update_color_hexa()
        self.window.update()
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 0, 0), (0, 100, 100), '#FF0000'))
        self.assertEqual(cp.alpha.get(), 100)
        cp.hexa.delete(0, 'end')
        cp.hexa.insert(0, '#FFFF00FF')
        self.window.update()
        cp._update_color_hexa()
        self.window.update()
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 0), (60, 100, 100), '#FFFF00'))
        self.assertEqual(cp.alpha.get(), 255)
        cp.hexa.delete(0, 'end')
        cp.hexa.insert(0, '#AAA')
        self.window.update()
        cp._update_color_hexa()
        self.window.update()
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 0), (60, 100, 100), '#FFFF00'))
        self.assertEqual(cp.alpha.get(), 255)
        # ALPHA
        cp.alpha.set(0)
        self.window.update()
        cp._update_alpha()
        self.window.update()
        self.assertEqual(cp.get_color(), "")
        self.window.update()
        cp.ok()
        self.assertEqual(cp.get_color(),
                         ((255, 255, 0, 0), (60, 100, 100), "#FFFF0000"))
        self.window.update()

        # without alpha
        cp = tkc.ColorPicker(self.window, color=(255, 0, 0), title='Test')
        self.window.update()
        self.window.update()
        # RGB
        cp.green.set(255)
        self.window.update()
        cp._update_color_rgb()
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 0), (60, 100, 100), '#FFFF00'))
        self.window.update()
        # HSV
        cp.value.set(0)
        self.window.update()
        cp._update_color_hsv()
        self.window.update()
        self.assertEqual(cp.square.get(), ((0, 0, 0), (60, 100, 0), '#000000'))
        self.window.update()
        # HTML
        cp.hexa.delete(0, 'end')
        cp.hexa.insert(0, '#FF0000')
        self.window.update()
        cp._update_color_hexa()
        self.window.update()
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 0, 0), (0, 100, 100), '#FF0000'))
        cp.hexa.delete(0, 'end')
        cp.hexa.insert(0, '#AAA')
        self.window.update()
        cp._update_color_hexa()
        self.window.update()
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 0, 0), (0, 100, 100), '#FF0000'))
        self.assertEqual(cp.get_color(), "")
        self.window.update()
        cp.ok()
        self.assertEqual(cp.get_color(),
                         ((255, 0, 0), (0, 100, 100), "#FF0000"))
        self.window.update()
示例#3
0
 def test_colorpicker_init(self):
     c = tkc.ColorPicker(self.window, color="red", title='Test')
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0), (0, 100, 100), '#FF0000'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window, color="red", title='Test', alpha=True)
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0, 255), (0, 100, 100), '#FF0000FF'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window, color="#ff0000", title='Test')
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0), (0, 100, 100), '#FF0000'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window,
                         color="#ff0000",
                         title='Test',
                         alpha=True)
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0, 255), (0, 100, 100), '#FF0000FF'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window,
                         color="#ff000000",
                         title='Test',
                         alpha=True)
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0, 0), (0, 100, 100), '#FF000000'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window, color="#ff000000", title='Test')
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0), (0, 100, 100), '#FF0000'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window, color=(255, 0, 0), title='Test')
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0), (0, 100, 100), '#FF0000'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window,
                         color=(255, 0, 0),
                         title='Test',
                         alpha=True)
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0, 255), (0, 100, 100), '#FF0000FF'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window,
                         color=(255, 0, 0, 0),
                         title='Test',
                         alpha=True)
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0, 0), (0, 100, 100), '#FF000000'))
     c.destroy()
     self.window.update()
     c = tkc.ColorPicker(self.window, color=(255, 0, 0, 0), title='Test')
     self.window.update()
     c.ok()
     self.assertEqual(c.get_color(),
                      ((255, 0, 0), (0, 100, 100), '#FF0000'))
     c.destroy()
     self.window.update()
示例#4
0
    def test_colorpicker_bindings(self):
        cp = tkc.ColorPicker(self.window,
                             color=(0, 255, 0),
                             title='Test',
                             alpha=True)
        self.window.update()
        event = TestEvent(x=0, y=1)
        cp.bar._on_click(event)
        self.window.update()
        self.assertEqual(cp.bar.get(), 0)
        cp._change_color(event)
        self.window.update()
        self.assertEqual(cp.hue.get(), 0)

        self.window.update()
        event = TestEvent(x=0, y=1)
        cp.alphabar._on_click(event)
        self.window.update()
        self.assertEqual(cp.alphabar.get(), 0)
        cp._change_alpha(event)
        self.window.update()
        self.assertEqual(cp.alpha.get(), 0)
        event.x = cp.alphabar.winfo_width()
        cp.alphabar._on_click(event)
        cp._change_alpha(event)
        self.window.update()

        cp.color_preview.focus_force()
        cp._unfocus(event)
        self.assertEqual(cp.focus_get(), cp)
        cp.hexa.focus_force()
        cp._unfocus(event)
        self.assertNotEqual(cp.focus_get(), cp)
        self.window.update()

        event = TestEvent(x=cp.square.winfo_width(),
                          y=cp.square.winfo_height())
        cp.square._on_click(event)
        self.window.update()
        cp._change_sel_color(event)
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 255), (0, 0, 100), '#FFFFFF'))
        self.assertEqual(cp.alpha.get(), 255)
        self.window.update()
        event = TestEvent(widget=tk.Label(self.window, bg='white'))
        cp._palette_cmd(event)
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((255, 255, 255), (0, 0, 100), '#FFFFFF'))
        cp._reset_preview(event)
        self.window.update()
        self.assertEqual(cp.square.get(),
                         ((0, 255, 0), (120, 100, 100), '#00FF00'))

        cp.hexa.focus_set()
        self.window.update()
        self.assertFalse(cp.hexa.selection_present())
        cp.hexa.event_generate('<Control-a>')
        self.assertEqual(cp.hexa.selection_get(), cp.hexa.get())

        s = tk.Spinbox(self.window, from_=0, to=100)
        s.insert(0, '20')
        s.pack()
        s.focus_set()
        cp._select_all_spinbox(TestEvent(widget=s))
        self.assertEqual(s.selection_get(), s.get())