コード例 #1
0
 def test_out_of_bounds(self):
     timeline = TimeLine(self.window,
                         categories=("category", ),
                         start=0.0,
                         finish=1.0)
     self.assertRaises(ValueError,
                       lambda: timeline.create_marker("category", 2.0, 3.0))
     self.assertRaises(ValueError,
                       lambda: timeline.create_marker("category", -1, -2))
コード例 #2
0
 def test_marker_tags(self):
     timeline = TimeLine(self.window, categories=("category", ))
     self.assertRaises(
         ValueError, lambda: timeline.create_marker(
             "category", 1.0, 2.0, tags=("tag", )))
     timeline.tag_configure("tag", background="cyan")
     iid = timeline.create_marker("category", 1.0, 2.0, tags=("tag", ))
     self.assertTrue("tag" in timeline.marker_tags(iid))
     rectangle_id = timeline.markers[iid]["rectangle_id"]
     color = timeline._timeline.itemcget(rectangle_id, "fill")
     self.assertEqual(color, "cyan")
コード例 #3
0
 def test_delete_marker(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category", 1.0, 2.0)
     rectangle_id = timeline.markers[iid]["rectangle_id"]
     timeline.delete_marker(iid)
     self.assertTrue(iid not in timeline.markers)
     self.assertTrue(rectangle_id not in timeline._timeline.find_all())
コード例 #4
0
 def test_timeline_contents(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category", 1.0, 2.0, text="Test")
     timeline.generate_timeline_contents()
     ids = timeline._timeline.find_all()
     rectangle = timeline.markers[iid]["rectangle_id"]
     text = timeline.markers[iid]["text_id"]
     self.assertTrue(rectangle in ids)
     self.assertTrue(text in ids)
コード例 #5
0
 def test_markers_property(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category", 1.0, 2.0)
     markers = timeline.markers
     self.assertIsInstance(markers, dict)
     self.assertTrue(iid in markers)
     self.assertIsInstance(markers[iid], dict)
     for option in timeline.marker_options:
         self.assertTrue(option in markers[iid])
コード例 #6
0
 def test_update_marker(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category", 1.0, 2.0)
     self.assertTrue(iid in timeline.markers)
     timeline.update_marker(iid, text="New Text")
     self.assertTrue(iid in timeline.markers)
     text_id = timeline.markers[iid]["text_id"]
     text = timeline._timeline.itemcget(text_id, "text")
     self.assertEqual(text, "New Text")
コード例 #7
0
 def test_text_shortening(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category",
                                  1.0,
                                  2.0,
                                  text="This is a very long sentence.")
     text_id = timeline.markers[iid]["text_id"]
     text = timeline._timeline.itemcget(text_id, "text")
     self.assertTrue("..." in text)
コード例 #8
0
 def test_marker_creation(self):
     timeline = TimeLine(self.window,
                         categories={
                             "category": {
                                 "foreground": "cyan",
                                 "text": "Category"
                             }
                         })
     iid = timeline.create_marker("category", 1.0, 2.0)
     self.assertTrue(iid in timeline.markers)
コード例 #9
0
 def test_update_state(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category",
                                  1.0,
                                  2.0,
                                  hover_background="yellow")
     timeline.update_state(iid, "hover")
     rectangle_id = timeline.markers[iid]["rectangle_id"]
     color = timeline._timeline.itemcget(rectangle_id, "fill")
     self.assertEqual(color, "yellow")
コード例 #10
0
 def test_timeline_click(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category", 1.0, 2.0)
     # calculate the coordinates of the marker
     marker = timeline.markers[iid]
     rectangle, text = marker["rectangle_id"], marker["text_id"]
     xr, yr, _, _ = timeline._timeline.bbox(rectangle)
     xw, yw = timeline._timeline.winfo_x(), timeline._timeline.winfo_y()
     event = MockEvent(xr + xw, yr + yw)
     timeline.left_click(event)
     timeline.right_click(event)
コード例 #11
0
                    height=100,
                    extend=True)
menu = tk.Menu(window, tearoff=False)
menu.add_command(label="Some Action",
                 command=lambda: print("Command Executed"))
timeline.tag_configure("1",
                       right_callback=lambda *args: print(args),
                       menu=menu,
                       foreground="green",
                       active_background="yellow",
                       hover_border=2,
                       move_callback=lambda *args: print(args))
timeline.create_marker("1",
                       1.0,
                       2.0,
                       background="white",
                       text="Change Color",
                       tags=("1", ),
                       iid="1")
timeline.create_marker("2",
                       2.0,
                       3.0,
                       background="green",
                       text="Change Category",
                       foreground="white",
                       iid="2",
                       change_category=True)
timeline.create_marker("3", 1.0, 2.0, text="Show Menu", tags=("1", ))
timeline.create_marker("4", 4.0, 5.0, text="Do nothing", move=False)
timeline.generate_timeline_contents()
timeline.grid()
コード例 #12
0
 def test_direct_configure(self):
     timeline = TimeLine(self.window, categories=("category", ))
     iid = timeline.create_marker("category", 1.0, 2.0)
     timeline.itemconfigure(iid, {"fill": "black"}, {})