Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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])
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)
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)
def test_initialization(self):
TimeLine(self.window)
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")
def test_set_time(self):
timeline = TimeLine(self.window)
timeline.set_time(2.0)
self.assertEqual(timeline.time, 2.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)
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")
# -*- 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, 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.draw_timeline()
timeline.grid()
window.after(2500, lambda: timeline.configure(marker_background="cyan"))