Example #1
0
 def test_time_from_utc(self):
     self.assertEqual(a1.time_from_utc(+0, 12.0), 12.0)
     self.assertEqual(a1.time_from_utc(+1, 12.0), 13.0)
     self.assertEqual(a1.time_from_utc(-1, 12.0), 11.0)
     self.assertEqual(a1.time_from_utc(+6, 6.0), 12.0)
     self.assertEqual(a1.time_from_utc(-7, 6.0), 23.0)
     self.assertEqual(a1.time_from_utc(-1, 0.0), 23.0)
     self.assertEqual(a1.time_from_utc(-1, 23.0), 22.0)
     self.assertEqual(a1.time_from_utc(+1, 23.0), 0.0)
Example #2
0
def test_time_form_utc():
    function_result_1 = a1.time_from_utc(+0, 12.0)
    function_result_2 = a1.time_from_utc(+1, 12.0)
    function_result_3 = a1.time_from_utc(-1, 12.0)
    function_result_4 = a1.time_from_utc(+6, 6.0)
    function_result_5 = a1.time_from_utc(-7, 6.0)
    function_result_6 = a1.time_from_utc(-1, 0.0)
    function_result_7 = a1.time_from_utc(-1, 23.0)
    function_result_8 = a1.time_from_utc(+1, 23.0)
    assert type(function_result_1) is float
    assert function_result_1 == 12.0
    assert function_result_2 == 13.0
    assert function_result_3 == 11.0
    assert function_result_4 == 12.0
    assert function_result_5 == 23.0
    assert function_result_6 == 23.0
    assert function_result_7 == 22.0
    assert function_result_8 == 0.0
    def refresh(self, forced=False):
        '''Redraw the clock. If forced is True, display it now. If forced is
        False, register a redraw for later.'''

        self.now = self.now + self.interval / 1000 * self.time_scale
        self.canvas.delete(tkinter.ALL)

        # Draw the clock rim.
        self.canvas.create_oval(10,
                                10,
                                self.width - 10,
                                self.height - 10,
                                width=2,
                                fill="#334455")

        # Draw the tick marks around the clock.
        for i in range(0, 12):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 80
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                fill='white',
                width=3)

        # Draw a light or dark face depending on whether it's before noon or
        # after.
        utc_hour = (self.now / 60 / 60) % 24
        hour = int(a1.time_from_utc(utc_hour, self.diff))
        self.canvas.create_oval(15,
                                15,
                                self.width - 15,
                                self.height - 15,
                                width=2,
                                fill="#e0e8ff" if hour < 12 else "#334")

        hands_colour = "black" if hour < 12 else "white"

        # Draw the hour hand.
        hours_angle = (hour % 12) / 12 * 360
        self._draw_hand(hours_angle,
                        30,
                        arrow=tkinter.FIRST,
                        arrowshape=(50, 2, 2),
                        fill=hands_colour)
        self._draw_hand(hours_angle + 180, 5, fill=hands_colour)

        # Draw the minute hand.
        minutes_angle = a1.get_minutes(int(self.now)) / 60 * 360
        if a1.time_from_utc(0, self.diff) % 1 == 0.5:
            minutes_angle += 180
        elif a1.time_from_utc(0, self.diff) % 1 == 0.75:
            minutes_angle += 270
        self._draw_hand(minutes_angle,
                        30,
                        arrow=tkinter.FIRST,
                        arrowshape=(80, 2, 2),
                        fill=hands_colour)
        self._draw_hand(minutes_angle + 180, 5, fill=hands_colour)

        # Draw the second hand.
        seconds_angle = int(a1.get_seconds(int(self.now))) / 60 * 360
        self._draw_hand(seconds_angle,
                        70,
                        fill='red',
                        width=2,
                        arrow=tkinter.FIRST,
                        arrowshape=(70, 9, 2))
        self._draw_hand(seconds_angle + 180,
                        18,
                        fill='red',
                        arrow=tkinter.LAST,
                        arrowshape=(8, 5, 5),
                        width=2)
        self._draw_hand(seconds_angle + 180, 20, fill='red')

        # Draw the four larger tick marks at noon, 3, 6, and 9.
        for i in range(0, 12, 3):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 70
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                width=5)

        if not forced:
            self.canvas.after(self.interval, self.refresh)
Example #4
0
    def refresh(self, forced=False):
        '''Redraw the clock. If forced is True, display it now. If forced is
        False, register a redraw for later.'''

        self.now = self.now + self.interval / 1000 * self.time_scale
        self.canvas.delete(tkinter.ALL)

        # Draw the clock rim.
        self.canvas.create_oval(10, 10, self.width - 10,
            self.height - 10, width=2, fill="#334455")

        # Draw the tick marks around the clock.
        for i in range(0, 12):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 80
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                fill='white', width=3
            )

        # Draw a light or dark face depending on whether it's before noon or
        # after.
        utc_hour = (self.now / 60 / 60) % 24
        hour = int(a1.time_from_utc(utc_hour, self.diff))
        self.canvas.create_oval(15, 15, self.width - 15, self.height - 15,
            width=2, fill="#e0e8ff" if hour < 12 else "#334")

        hands_colour = "black" if hour < 12 else "white"
        
        # Draw the hour hand.
        hours_angle = (hour % 12) / 12 * 360
        self._draw_hand(hours_angle, 30, arrow=tkinter.FIRST,
            arrowshape=(50, 2, 2), fill=hands_colour)
        self._draw_hand(hours_angle + 180, 5, fill=hands_colour)

        # Draw the minute hand.
        minutes_angle = a1.get_minutes(int(self.now)) / 60 * 360
        if a1.time_from_utc(0, self.diff) % 1 == 0.5:
            minutes_angle += 180
        elif a1.time_from_utc(0, self.diff) % 1 == 0.75:
            minutes_angle += 270
        self._draw_hand(minutes_angle, 30, arrow=tkinter.FIRST, arrowshape=(80, 2, 2), fill=hands_colour)
        self._draw_hand(minutes_angle + 180, 5, fill=hands_colour)

        # Draw the second hand.
        seconds_angle = int(a1.get_seconds(int(self.now))) / 60 * 360
        self._draw_hand(seconds_angle, 70, fill='red', width=2, arrow=tkinter.FIRST, arrowshape=(70, 9, 2))
        self._draw_hand(seconds_angle + 180, 18, fill='red', arrow=tkinter.LAST, arrowshape=(8, 5, 5), width=2)
        self._draw_hand(seconds_angle + 180, 20, fill='red')
        
        # Draw the four larger tick marks at noon, 3, 6, and 9.
        for i in range(0, 12, 3):
            angle = math.radians(i / 12 * 360)
            outer_length = 90
            inner_length = 70
            self.canvas.create_line(
                math.cos(angle) * inner_length + self.width / 2,
                math.sin(angle) * inner_length + self.width / 2,
                math.cos(angle) * outer_length + self.width / 2,
                math.sin(angle) * outer_length + self.width / 2,
                width = 5
           )

        if not forced:
            self.canvas.after(self.interval, self.refresh)