ยปCore Development>Code coverage>Lib/turtledemo/clock.py

Python code coverage for Lib/turtledemo/clock.py

#countcontent
1n/a#!/usr/bin/env python3
2n/a# -*- coding: cp1252 -*-
3n/a""" turtle-example-suite:
4n/a
5n/a tdemo_clock.py
6n/a
7n/aEnhanced clock-program, showing date
8n/aand time
9n/a ------------------------------------
10n/a Press STOP to exit the program!
11n/a ------------------------------------
12n/a"""
13n/afrom turtle import *
14n/afrom datetime import datetime
15n/a
16n/adef jump(distanz, winkel=0):
17n/a penup()
18n/a right(winkel)
19n/a forward(distanz)
20n/a left(winkel)
21n/a pendown()
22n/a
23n/adef hand(laenge, spitze):
24n/a fd(laenge*1.15)
25n/a rt(90)
26n/a fd(spitze/2.0)
27n/a lt(120)
28n/a fd(spitze)
29n/a lt(120)
30n/a fd(spitze)
31n/a lt(120)
32n/a fd(spitze/2.0)
33n/a
34n/adef make_hand_shape(name, laenge, spitze):
35n/a reset()
36n/a jump(-laenge*0.15)
37n/a begin_poly()
38n/a hand(laenge, spitze)
39n/a end_poly()
40n/a hand_form = get_poly()
41n/a register_shape(name, hand_form)
42n/a
43n/adef clockface(radius):
44n/a reset()
45n/a pensize(7)
46n/a for i in range(60):
47n/a jump(radius)
48n/a if i % 5 == 0:
49n/a fd(25)
50n/a jump(-radius-25)
51n/a else:
52n/a dot(3)
53n/a jump(-radius)
54n/a rt(6)
55n/a
56n/adef setup():
57n/a global second_hand, minute_hand, hour_hand, writer
58n/a mode("logo")
59n/a make_hand_shape("second_hand", 125, 25)
60n/a make_hand_shape("minute_hand", 130, 25)
61n/a make_hand_shape("hour_hand", 90, 25)
62n/a clockface(160)
63n/a second_hand = Turtle()
64n/a second_hand.shape("second_hand")
65n/a second_hand.color("gray20", "gray80")
66n/a minute_hand = Turtle()
67n/a minute_hand.shape("minute_hand")
68n/a minute_hand.color("blue1", "red1")
69n/a hour_hand = Turtle()
70n/a hour_hand.shape("hour_hand")
71n/a hour_hand.color("blue3", "red3")
72n/a for hand in second_hand, minute_hand, hour_hand:
73n/a hand.resizemode("user")
74n/a hand.shapesize(1, 1, 3)
75n/a hand.speed(0)
76n/a ht()
77n/a writer = Turtle()
78n/a #writer.mode("logo")
79n/a writer.ht()
80n/a writer.pu()
81n/a writer.bk(85)
82n/a
83n/adef wochentag(t):
84n/a wochentag = ["Monday", "Tuesday", "Wednesday",
85n/a "Thursday", "Friday", "Saturday", "Sunday"]
86n/a return wochentag[t.weekday()]
87n/a
88n/adef datum(z):
89n/a monat = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June",
90n/a "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]
91n/a j = z.year
92n/a m = monat[z.month - 1]
93n/a t = z.day
94n/a return "%s %d %d" % (m, t, j)
95n/a
96n/adef tick():
97n/a t = datetime.today()
98n/a sekunde = t.second + t.microsecond*0.000001
99n/a minute = t.minute + sekunde/60.0
100n/a stunde = t.hour + minute/60.0
101n/a try:
102n/a tracer(False) # Terminator can occur here
103n/a writer.clear()
104n/a writer.home()
105n/a writer.forward(65)
106n/a writer.write(wochentag(t),
107n/a align="center", font=("Courier", 14, "bold"))
108n/a writer.back(150)
109n/a writer.write(datum(t),
110n/a align="center", font=("Courier", 14, "bold"))
111n/a writer.forward(85)
112n/a tracer(True)
113n/a second_hand.setheading(6*sekunde) # or here
114n/a minute_hand.setheading(6*minute)
115n/a hour_hand.setheading(30*stunde)
116n/a tracer(True)
117n/a ontimer(tick, 100)
118n/a except Terminator:
119n/a pass # turtledemo user pressed STOP
120n/a
121n/adef main():
122n/a tracer(False)
123n/a setup()
124n/a tracer(True)
125n/a tick()
126n/a return "EVENTLOOP"
127n/a
128n/aif __name__ == "__main__":
129n/a mode("logo")
130n/a msg = main()
131n/a print(msg)
132n/a mainloop()