def test_clock(self, mock_datetime): """ Check that Clock works. """ # Check that Clock updates every second. screen = MagicMock(spec=Screen, colours=8, unicode_aware=False) mock_datetime.now.return_value = datetime mock_datetime.side_effect = lambda *args, **kw: datetime(*args, **kw) canvas = Canvas(screen, 10, 40, 0, 0) effect = Clock(canvas, 10, 5, 5) effect.reset() self.assert_blank(canvas) my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)] # Set a time for the next update and check it is drawn. mock_datetime.now.return_value = \ datetime(1900, 1, 2, 3, 59, 40) effect.update(0) mock_datetime.now.assert_called() self.assertEqual(self.check_canvas( canvas, my_buffer, lambda value: self.assertLess(value[0], 129)), True) # Check redrawing with the same time has no effect. mock_datetime.now.reset_mock() mock_datetime.now.return_value = \ datetime(1900, 1, 2, 3, 59, 40) effect.update(1) mock_datetime.now.assert_called() self.assertEqual(self.check_canvas( canvas, my_buffer, lambda value: self.assertLess(value[0], 129)), False) # Check a new time results in an update. mock_datetime.now.reset_mock() mock_datetime.now.return_value = \ datetime(1900, 1, 2, 3, 59, 41) effect.update(2) mock_datetime.now.assert_called() self.assertEqual(self.check_canvas( canvas, my_buffer, lambda value: self.assertLess(value[0], 129)), True) # Check there is no stop frame by default. self.assertEqual(effect.stop_frame, 0) # This effect should ignore events. event = object() self.assertEqual(event, effect.process_event(event))
def test_clock(self, mock_datetime): """ Check that Clock works. """ # Check that Clock updates every second. screen = MagicMock(spec=Screen, colours=8) mock_datetime.now.return_value = datetime mock_datetime.side_effect = lambda *args, **kw: datetime(*args, **kw) canvas = Canvas(screen, 10, 40, 0, 0) effect = Clock(canvas, 10, 5, 5) effect.reset() self.assert_blank(canvas) buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)] # Set a time for the next update and check it is drawn. mock_datetime.now.return_value = \ datetime(1900, 1, 2, 3, 59, 40) effect.update(0) mock_datetime.now.assert_called() self.assertEqual( self.check_canvas(canvas, buffer, lambda value: self.assertLess(value[0], 129)), True) # Check redrawing with the same time has no effect. mock_datetime.now.reset_mock() mock_datetime.now.return_value = \ datetime(1900, 1, 2, 3, 59, 40) effect.update(1) mock_datetime.now.assert_called() self.assertEqual( self.check_canvas(canvas, buffer, lambda value: self.assertLess(value[0], 129)), False) # Check a new time results in an update. mock_datetime.now.reset_mock() mock_datetime.now.return_value = \ datetime(1900, 1, 2, 3, 59, 41) effect.update(2) mock_datetime.now.assert_called() self.assertEqual( self.check_canvas(canvas, buffer, lambda value: self.assertLess(value[0], 129)), True) # Check there is no stop frame by default. self.assertEqual(effect.stop_frame, 0)
def __init__(self, screen, x, y): super(ClockFrame, self).__init__(screen, 13, 26, name="Clock", has_shadow=True, x=x, y=y) self.add_effect(Clock(self._canvas, 13, 7, 7, Screen.COLOUR_BLUE)) self.fix()
def demo(screen): effects = [ Print(screen, Rainbow(screen, FigletText("256 colours")), y=screen.height//2 - 8), Print(screen, Rainbow(screen, FigletText("for xterm users")), y=screen.height//2 + 3), Clock(screen, screen.width//2, screen.height//2, screen.height//2), ] screen.play([Scene(effects, -1)], stop_on_resize=True)
def demo(screen): effects = [ Print(screen, Rainbow(screen, FigletText("Hacktoberfest")), y=screen.height//2 - 8), Print(screen, Rainbow(screen, FigletText("ASCII Art 2020")), y=screen.height//2 + 3), Clock(screen, screen.width//2, screen.height//2, screen.height//2), ] screen.play([Scene(effects, -1)], stop_on_resize=True) screen.refresh()
def demo(wout, win): while True: screen = Screen.from_windows(wout, win) effects = [ Print(screen, Rainbow(screen, FigletText("256 colours")), y=screen.height//2 - 8), Print(screen, Rainbow(screen, FigletText("for xterm users")), y=screen.height//2 + 3), Clock(screen, screen.width//2, screen.height//2, screen.height//2), ] try: screen.play([Scene(effects, -1)], stop_on_resize=True) return except ResizeScreenError: pass
def demo(screen): scenes = [] preset_frame = Frame(screen, 11, 26, can_scroll=False, title="Tastenbelegung", x=SF_X, y=SF_Y, reduce_cpu=True) pr_layout = Layout([10, 90], fill_frame=True) preset_frame.add_layout(pr_layout) sender_frame = Frame(screen, 11, 26, can_scroll=False, title="Senderliste", x=27, y=6, reduce_cpu=True) sender_layout0 = Layout([10, 90, 10], fill_frame=True) sender_frame.add_layout(sender_layout0) optionen = [(" ", 1), ("Zweiter", 2), ("Dritter", 3), ("Vierter", 4), ("Deutschlandradio", 5), ("Absolut Relax", 6), ("Siebter", 7), ("hmm", 8)] sender = [ "123456789012345678901", "Erster", "Zweiter", "Dritter", "Vierter", "Fünfter", "Sechster" ] Senderkiste = ListBox(8, optionen, False) sender_layout0.add_widget(Senderkiste, 1) Senderkiste.blur() Senderkiste.start_line = 1 format_sl_layout(sender_layout0) # format_pr_layout(pr_layout) for i, s in zip(range(1, 6), sender): pr_layout.add_widget(Label(str(i), 1, align=u'^')) pr_layout.add_widget(Label(s, 1, align='^'), 1) preset_frame.fix() sender_frame.fix() effects = [ preset_frame, sender_frame, Print(screen, Box(26, 15, True), x=UHR_K_X, y=UHR_K_Y), Print(screen, Box(80, 8, True), x=0, y=17), Clock(screen, 67, 7, 6), Print(screen, FigletText("Retroradio!"), x=0, y=0), # Print(screen, BarChart(4, 80, [get_vol], colour=2, scale=100, # axes=BarChart.X_AXIS, intervals=25, labels=True, border=False), x=0, y=26, # transparent=False), # Print(screen, SpeechBubble("Lautstärke"), x=0, y=23), Print(screen, FigletText("Deutschlandradio"), x=1, y=18), Print(screen, BarChart(4, 80, [get_vol], colour=2, char=' ', bg=7, scale=100, axes=BarChart.X_AXIS, intervals=25, labels=True, border=False), x=0, y=26, transparent=False, speed=2) ] scenes.append(Scene(effects, -1)) screen.play(scenes)