예제 #1
0
    def test_dateentry_functions(self):
        widget = DateEntry(self.window,
                           width=12,
                           background='darkblue',
                           foreground='white',
                           borderwidth=2)
        widget.pack()
        self.window.update()

        widget.set_date(format_date(date(2018, 12, 31), 'short'))
        self.assertEqual(widget.get_date(), date(2018, 12, 31))
        with self.assertRaises(ValueError):
            widget.set_date("ab")
        widget.set_date(date(2015, 12, 31))
        self.assertEqual(widget.get_date(), date(2015, 12, 31))
        self.assertEqual(widget.get(), format_date(date(2015, 12, 31),
                                                   'short'))

        widget.delete(0, "end")
        widget.insert(0, "abc")
        self.window.focus_force()
        self.assertEqual(widget.get_date(), date(2015, 12, 31))

        widget._on_motion(TestEvent(x=10, y=20))
        widget._on_b1_press(TestEvent(x=10, y=20))
        widget._on_b1_press(TestEvent(x=widget.winfo_width() - 2, y=2))
        widget._on_focus_out_cal(TestEvent(x=10, y=20))

        widget.state(("disabled", ))
        self.window.update()
        self.assertIn("disabled", widget.state())

        widget.drop_down()
        self.window.update()
        widget._select()
        self.window.update()
        widget.drop_down()
        self.window.update()
        widget.drop_down()
        self.window.update()

        widget.configure(state='readonly')
        self.window.update()
        widget._select()
        self.assertIn('readonly', widget.state())
예제 #2
0
 def test_dateentry_drop_down(self):
     """Check whether drop down opens on click."""
     widget = DateEntry(self.window)
     widget.pack()
     self.window.update()
     w = widget.winfo_width()
     h = widget.winfo_height()
     widget.event_generate('<1>', x=w - 10, y=h // 2)
     self.window.update()
     self.assertTrue(widget._top_cal.winfo_ismapped())
     mouse = Controller()
     x = widget._top_cal.winfo_rootx() + widget._top_cal.winfo_width() + 10
     y = widget._top_cal.winfo_rooty() + widget._top_cal.winfo_height() + 10
     mouse.position = x, y
     widget._calendar.event_generate('<FocusOut>')
     widget._on_focus_out_cal(TestEvent(widget=widget._calendar,
                                        x='', y=''))
     self.window.update()
     self.assertFalse(widget._top_cal.winfo_ismapped())