Exemplo n.º 1
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())
Exemplo n.º 2
0
 def test_categories(self):
     TimeLine(self.window, categories=("category", ))
     TimeLine(self.window, categories={"category": {"text": "Category"}})
     self.assertRaises(
         TypeError, lambda: TimeLine(self.window, categories=[
             "category",
         ]))
Exemplo n.º 3
0
 def test_kwargs_errors(self):
     timeline = TimeLine(self.window)
     for option in timeline.options:
         self.assertRaises(
             (TypeError, ValueError),
             lambda: timeline.config(
                 # menu is the only kwarg that has an allowed None value
                 **{option: None if option != "menu" else tk.Frame()}))
Exemplo n.º 4
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])
Exemplo n.º 5
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")
Exemplo n.º 6
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)
Exemplo n.º 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)
Exemplo n.º 8
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))
Exemplo n.º 9
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)
Exemplo n.º 10
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")
Exemplo n.º 11
0
 def test_kwargs(self):
     alternates = {
         "background": "black",
         "marker_foreground": "white",
         "menu": tk.Menu(),
         "categories": ("category_a", "category_b"),
     }
     for key, value in alternates.items():
         TimeLine(self.window, **{key: value}).configure({key: value})
Exemplo n.º 12
0
 def test_timeline_zoom_in(self):
     timeline = TimeLine(self.window, categories=("category", ))
     zoom_factor = timeline.zoom_factor
     amount_ticks = len(timeline._ticks)
     amount_items = len(timeline._canvas_ticks.find_all())
     timeline._button_zoom_in.invoke()
     self.assertGreater(timeline.zoom_factor, zoom_factor)
     self.assertGreater(len(timeline._ticks), amount_ticks)
     self.assertGreater(len(timeline._canvas_ticks.find_all()),
                        amount_items)
Exemplo n.º 13
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")
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def test_marker_time_window(self):
     timeline = TimeLine(self.window)
     x, y = timeline._canvas_ticks.winfo_x(
     ), timeline._canvas_ticks.winfo_y()
     x += 20
     y += 10
     timeline.time_marker_move(MockEvent(x, y))
     self.assertIsInstance(timeline._time_window, tk.Toplevel)
     timeline.time_marker_release(MockEvent(x, y))
Exemplo n.º 16
0
 def test_timeline_zoom_reset(self):
     timeline = TimeLine(self.window,
                         zoom_factors=(1.0, 2.0, 5.0, 10.0),
                         zoom_default=5.0)
     zoom_factor = timeline.zoom_factor
     for i in range(4):
         timeline.zoom_in()
     timeline.zoom_reset()
     self.assertEqual(timeline.zoom_factor, zoom_factor)
     self.assertEqual(timeline.zoom_factor, 5.0)
Exemplo n.º 17
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"}, {})
Exemplo n.º 18
0
 def test_timeline_zoom(self):
     timeline = TimeLine(self.window)
     factor = timeline.zoom_factor
     timeline.zoom_in()
     timeline.zoom_out()
     self.assertEqual(factor, timeline.zoom_factor)
Exemplo n.º 19
0
 def test_timeline_content_generation(self):
     TimeLine(self.window,
              categories=("category", )).generate_timeline_contents()
Exemplo n.º 20
0
 def test_initialization(self):
     TimeLine(self.window)
Exemplo n.º 21
0
 def test_set_time(self):
     timeline = TimeLine(self.window)
     timeline.set_time(2.0)
     self.assertEqual(timeline.time, 2.0)
Exemplo n.º 22
0
# -*- coding: utf-8 -*-

# Copyright (c) RedFantom 2017
# For license see LICENSE

import tkinter as tk
from ttkwidgets import TimeLine

window = tk.Tk()
timeline = TimeLine(window,
                    categories={
                        str(key): {
                            "text": "Category {}".format(key)
                        }
                        for key in range(0, 5)
                    },
                    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,
Exemplo n.º 23
0
 def test_unit_formatting(self):
     for unit in ["m", "h"]:
         self.assertEqual(TimeLine.get_time_string(1.0, unit), "01:00")
         self.assertEqual(TimeLine.get_time_string(1.5, unit), "01:30")
         self.assertEqual(TimeLine.get_time_string(3.25, unit), "03:15")