Browse Source

wordclock plugin

master
Manfraid 3 years ago
parent
commit
8fad31b3e0

+ 21
- 0
screens/wordclock/README View File

@@ -0,0 +1,21 @@
1
+Wordclock
2
+---------
3
+
4
+Simple wordclock screen which is the default screen for this project.
5
+
6
+There are two available parameters:
7
+  - "language": selects layout for various languages (default: english)
8
+  - "colour":   RGB colour code for displaying the time
9
+
10
+Languages
11
+---------
12
+
13
+Currently the following languages are available:
14
+  - English
15
+  - Spanish
16
+  - Portuguese
17
+  - French
18
+  - Swedish
19
+  - Finnish
20
+
21
+Anybody is welcome to submit further languages!

+ 10
- 0
screens/wordclock/conf.json View File

@@ -0,0 +1,10 @@
1
+{
2
+    "screen": "WordClockScreen",
3
+    "kv": "wordclock.kv",
4
+    "dependencies": [],
5
+    "enabled": true,
6
+    "params": {
7
+        "language": "french",
8
+        "colour": [0, 200, 200]
9
+    }
10
+}

+ 0
- 0
screens/wordclock/layouts/__init__.py View File


+ 78
- 0
screens/wordclock/layouts/english.py View File

@@ -0,0 +1,78 @@
1
+'''This is a custom layout for the RPi InfoScreen wordclock screen.
2
+
3
+    Custom layouts can be created for the screen by creating a new file in the
4
+    "layouts" folder.
5
+
6
+    Each layout must have the following variables:
7
+        LAYOUT:   The grid layout. Must be a single string.
8
+        MAP:      The mapping required for various times (see notes below)
9
+        COLS:     The number of columns required for the grid layout
10
+        SIZE:     The size of the individual box containing your letter.
11
+                  Tuple in (x, y) format.
12
+        FONTSIZE: Font size for the letter
13
+'''
14
+
15
+# Layout is a single string variable which will be looped over by the parser.
16
+LAYOUT = ("ITQISHCUBMWLRPI"
17
+          "AOQUARTERFDHALF"
18
+          "TWENTYSFIVEGTEN"
19
+          "TOXPASTNYTWELVE"
20
+          "ONESIXTHREENINE"
21
+          "SEVENTWOXELEVEN"
22
+          "EIGHTENFOURFIVE"
23
+          "RPIO'CLOCKHAMPM")
24
+
25
+# Map instructions:
26
+# The clock works by rounding the time to the nearest 5 minutes.
27
+# This means that you need to have settngs for each five minute interval "m00"
28
+# "m00", "m05".
29
+# The clock also works on a 12 hour basis rather than 24 hour:
30
+# "h00", "h01" etc.
31
+# There are three optional parameters:
32
+#   "all": Anything that is always shown regardless of the time e.g. "It is..."
33
+#   "am":  Wording/symbol to indicate morning.
34
+#   "pm":  Wording/symbol to indicate afternoon/evening
35
+MAP = {
36
+       "all": [0, 1, 3, 4],
37
+       "m00": [108, 109, 110, 111, 112, 113, 114],
38
+       "m05": [37,38, 39, 40, 48, 49, 50, 51],
39
+       "m10": [42, 43, 44, 48, 49, 50, 51],
40
+       "m15": [15, 17, 18, 19, 20, 21, 22, 23, 48, 49, 50, 51],
41
+       "m20": [30, 31, 32, 33, 34, 35, 48, 49, 50, 51],
42
+       "m25": [30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 48, 49, 50, 51],
43
+       "m30": [26, 27, 28, 29, 48, 49, 50, 51],
44
+       "m35": [30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 45, 46],
45
+       "m40": [30, 31, 32, 33, 34, 35, 45, 46],
46
+       "m45": [15, 17, 18, 19, 20, 21, 22, 23, 45, 46],
47
+       "m50": [42, 43, 44, 45, 46],
48
+       "m55": [37, 38, 39, 40, 45, 46],
49
+       "h01": [60, 61, 62],
50
+       "h02": [80, 81, 82],
51
+       "h03": [66, 67, 68, 69, 70],
52
+       "h04": [97, 98, 99, 100],
53
+       "h05": [101, 102, 103, 104],
54
+       "h06": [63, 64, 65],
55
+       "h07": [75, 76, 77, 78, 79],
56
+       "h08": [90, 91, 92, 93, 94],
57
+       "h09": [71, 72, 73, 74],
58
+       "h10": [94, 95, 96],
59
+       "h11": [84, 85, 86, 87, 88, 89],
60
+       "h12": [54, 55, 56, 57, 58, 59],
61
+       "am": [116, 117],
62
+       "pm": [118, 119]
63
+  }
64
+
65
+# Number of columns in grid layout
66
+COLS = 15
67
+
68
+# Size of letter in grid (x, y)
69
+SIZE = (53, 60)
70
+
71
+# Font size of letter
72
+FONTSIZE = 40
73
+
74
+# Is our language one where we need to increment the hour after 30 mins
75
+# e.g. 9:40 is "Twenty to ten"
76
+HOUR_INCREMENT = True
77
+
78
+HOUR_INCREMENT_TIME = 30

+ 80
- 0
screens/wordclock/layouts/finnish.py View File

@@ -0,0 +1,80 @@
1
+# This Python file uses the following encoding: utf-8
2
+'''This is a custom layout for the RPi InfoScreen wordclock screen.
3
+
4
+    Custom layouts can be created for the screen by creating a new file in the
5
+    "layouts" folder.
6
+
7
+    Each layout must have the following variables:
8
+        LAYOUT:   The grid layout. Must be a single string.
9
+        MAP:      The mapping required for various times (see notes below)
10
+        COLS:     The number of columns required for the grid layout
11
+        SIZE:     The size of the individual box containing your letter.
12
+                  Tuple in (x, y) format.
13
+        FONTSIZE: Font size for the letter
14
+'''
15
+
16
+# Layout is a single string variable which will be looped over by the parser.
17
+LAYOUT = (u"KELLOQONYPUOLIWPWKL" #0
18
+          u"AKYMMENTÄXVARTTIAZC" #19
19
+          u"KAHTAKYMMENTÄVIITTÄ" #38
20
+          u"VAILLEYLIBSEITSEMÄN" #57
21
+          u"YKSITOISTAKAHDEKSAN" #76
22
+          u"KAKSITOISTAYHDEKSÄN" #95
23
+          u"KYMMENENTKOLMENELJÄ" #114
24
+          u"KUUSIVIISIIIVAAPIIP") #133
25
+
26
+# Map instructions:
27
+# The clock works by rounding the time to the nearest 5 minutes.
28
+# This means that you need to have settngs for each five minute interval "m00"
29
+# "m00", "m05".
30
+# The clock also works on a 12 hour basis rather than 24 hour:
31
+# "h00", "h01" etc.
32
+# There are three optional parameters:
33
+#   "all": Anything that is always shown regardless of the time e.g. "It is..."
34
+#   "am":  Wording/symbol to indicate morning.
35
+#   "pm":  Wording/symbol to indicate afternoon/evening
36
+MAP = {
37
+       "all": [0, 1, 2, 3, 4, 6, 7],
38
+       "m00": [],
39
+       "m05": [51, 52, 53, 54, 55, 56, 63, 64, 65],
40
+       "m10": [20, 21, 22, 23, 24, 25, 26, 27, 63, 64, 65],
41
+       "m15": [29, 30, 31, 32, 33, 34, 35, 63, 64, 65],
42
+       "m20": [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 63, 64, 65],
43
+       "m25": [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 63, 64, 65],
44
+       "m30": [9, 10, 11, 12, 13],
45
+       "m35": [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
46
+       "m40": [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 57, 58, 59, 60, 61, 62],
47
+       "m45": [29, 30, 31, 32, 33, 34, 35, 57, 58, 59, 60, 61, 62],
48
+       "m50": [20, 21, 22, 23, 24, 25, 26, 27, 57, 58, 59, 60, 61, 62],
49
+       "m55": [51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
50
+       "h01": [76, 77, 78, 79],
51
+       "h02": [95, 96, 97, 98, 99],
52
+       "h03": [123, 124, 125, 126, 127],
53
+       "h04": [128, 129, 130, 131, 132],
54
+       "h05": [138, 139, 140, 141, 142],
55
+       "h06": [133, 134, 135, 136, 137],
56
+       "h07": [67, 68, 69, 70, 71, 72, 73, 74, 75],
57
+       "h08": [86, 87, 88, 89, 90, 91, 92, 93, 94],
58
+       "h09": [106, 107, 108, 109, 110, 111, 112, 113],
59
+       "h10": [114, 115, 116, 117, 118, 119, 120, 121],
60
+       "h11": [76, 77, 78, 79, 80, 81, 82, 83, 84, 85],
61
+       "h12": [95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105],
62
+       "am": [147, 148],
63
+       "pm": [150, 151]
64
+  }
65
+
66
+# Number of columns in grid layout
67
+COLS = 19
68
+
69
+# Size of letter in grid (x, y)
70
+SIZE = (42, 60)
71
+
72
+# Font size of letter
73
+FONTSIZE = 40
74
+
75
+# Is our language one where we need to increment the hour after 30 mins
76
+# e.g. 9:40 is "Twenty to ten"
77
+HOUR_INCREMENT = True
78
+
79
+HOUR_INCREMENT_TIME = 29
80
+

+ 80
- 0
screens/wordclock/layouts/french.py View File

@@ -0,0 +1,80 @@
1
+# -*- coding: utf-8 -*-
2
+'''This is a custom layout for the RPi InfoScreen wordclock screen.
3
+
4
+    Custom layouts can be created for the screen by creating a new file in the
5
+    "layouts" folder.
6
+
7
+    Each layout must have the following variables:
8
+        LAYOUT:   The grid layout. Must be a single string.
9
+        MAP:      The mapping required for various times (see notes below)
10
+        COLS:     The number of columns required for the grid layout
11
+        SIZE:     The size of the individual box containing your letter.
12
+                  Tuple in (x, y) format.
13
+        FONTSIZE: Font size for the letter
14
+'''
15
+
16
+# Layout is a single string variable which will be looped over by the parser.
17
+LAYOUT = ("ILNESTHUNEDEUXP"
18
+          "TROISIXOQUATREM"
19
+          "CINQHUITNEUFDIX"
20
+          "ONZEBDOUZERSEPT"
21
+          "HEURESRASPBERRY"
22
+          "ETMOINSUCINQDIX"
23
+          "LEJQUARTFDEMIEL"
24
+          "RPIVINGT-CINQKU"
25
+          )
26
+
27
+# Map instructions:
28
+# The clock works by rounding the time to the nearest 5 minutes.
29
+# This means that you need to have settngs for each five minute interval "m00"
30
+# "m00", "m05".
31
+# The clock also works on a 12 hour basis rather than 24 hour:
32
+# "h00", "h01" etc.
33
+# There are three optional parameters:
34
+#   "all": Anything that is always shown regardless of the time e.g. "It is..."
35
+#   "am":  Wording/symbol to indicate morning.
36
+#   "pm":  Wording/symbol to indicate afternoon/evening
37
+MAP = {
38
+        "all": [0, 1, 3, 4, 5, 60, 61, 62, 63, 64],
39
+        "m00": [],
40
+        "m05": [83, 84, 85, 86],
41
+        "m10": [87, 88, 89],
42
+        "m15": [75, 76, 93, 94, 95, 96, 97],
43
+        "m20": [108, 109, 110, 111, 112],
44
+        "m25": [108, 109, 110, 111, 112, 113, 114, 115, 116, 117],
45
+        "m30": [75, 76, 99, 100, 101, 102, 103],
46
+        "m35": [77, 78, 79, 80, 81, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117],
47
+        "m40": [77, 78, 79, 80, 81, 108, 109, 110, 111, 112],
48
+        "m45": [77, 78, 79, 80, 81, 90, 91, 93, 94, 95, 96, 97],
49
+        "m50": [77, 78, 79, 80, 81, 87, 88, 89],
50
+        "m55": [77, 78, 79, 80, 81, 83, 84, 85, 86],
51
+        "h01": [7, 8, 9],
52
+        "h02": [65, 10, 11, 12, 13],
53
+        "h03": [65, 15, 16, 17, 18,19],
54
+        "h04": [65, 23, 24, 25, 26, 27, 28],
55
+        "h05": [65, 30, 31, 32, 33],
56
+        "h06": [65, 19, 20, 21],
57
+        "h07": [65, 56, 57, 58, 59],
58
+        "h08": [65, 34, 35, 36, 37],
59
+        "h09": [65, 38, 39, 40, 41],
60
+        "h10": [65, 42, 43, 44],
61
+        "h11": [65, 45, 46, 47, 48],
62
+        "h12": [65, 50, 51, 52, 53, 54],
63
+        "am": [],
64
+        "pm": [],
65
+        }
66
+
67
+# Number of columns in grid layout
68
+COLS = 15
69
+
70
+# Size of letter in grid (x, y)
71
+SIZE = (53, 50)
72
+
73
+# Font size of letter
74
+FONTSIZE = 40
75
+
76
+# Is our language one where we need to increment the hour after 30 mins
77
+# e.g. 9:40 is "Twenty to ten"
78
+HOUR_INCREMENT = True
79
+
80
+HOUR_INCREMENT_TIME = 30

+ 80
- 0
screens/wordclock/layouts/portuguese.py View File

@@ -0,0 +1,80 @@
1
+# -*- coding: utf-8 -*-
2
+'''This is a custom layout for the RPi InfoScreen wordclock screen.
3
+
4
+    Custom layouts can be created for the screen by creating a new file in the
5
+    "layouts" folder.
6
+
7
+    Each layout must have the following variables:
8
+        LAYOUT:   The grid layout. Must be a single string.
9
+        MAP:      The mapping required for various times (see notes below)
10
+        COLS:     The number of columns required for the grid layout
11
+        SIZE:     The size of the individual box containing your letter.
12
+                  Tuple in (x, y) format.
13
+        FONTSIZE: Font size for the letter
14
+'''
15
+
16
+# Layout is a single string variable which will be looped over by the parser.
17
+LAYOUT = (u"ESÃORUMAPDUASNT"
18
+          u"TRESQUATROCINCO"
19
+          u"SEISGSETEVOITOM"
20
+          u"NOVEDEZONZEDOZE"
21
+          u"HORASOEÃMENOSLP"
22
+          u"UMXQUARTOSRPDEZ"
23
+          u"VINTEZEJCINCORX"
24
+          u"ETMEIAEMUPONTOP"
25
+          )
26
+
27
+# Map instructions:
28
+# The clock works by rounding the time to the nearest 5 minutes.
29
+# This means that you need to have settngs for each five minute interval "m00"
30
+# "m00", "m05".
31
+# The clock also works on a 12 hour basis rather than 24 hour:
32
+# "h00", "h01" etc.
33
+# There are three optional parameters:
34
+#   "all": Anything that is always shown regardless of the time e.g. "It is..."
35
+#   "am":  Wording/symbol to indicate morning.
36
+#   "pm":  Wording/symbol to indicate afternoon/evening
37
+MAP = {
38
+       "all": [60, 61, 62, 63],
39
+       "m00": [111, 112, 114, 115, 116, 117, 118],
40
+       "m05": [66, 98, 99, 100, 101, 102],
41
+       "m10": [66, 87, 88, 89],
42
+       "m15": [66, 75, 76, 78, 79, 80, 81, 82, 83],
43
+       "m20": [66, 90, 91, 92, 93, 94],
44
+       "m25": [66, 90, 91, 92, 93, 94, 96, 98, 99, 100, 101, 102],
45
+       "m30": [66, 107, 108, 109, 110],
46
+       "m35": [68, 69, 70, 71, 72, 90, 91, 92, 93, 94, 96, 98, 99, 100, 101, 102],
47
+       "m40": [68, 69, 70, 71, 72, 90, 91, 92, 93, 94],
48
+       "m45": [68, 69, 70, 71, 72, 75, 76, 78, 79, 80, 81, 82, 83],
49
+       "m50": [68, 69, 70, 71, 72, 87, 88, 89],
50
+       "m55": [68, 69, 70, 71, 72, 98, 99, 100, 101, 102],
51
+       "h01": [0, 5, 6, 7],
52
+       "h02": [1, 2, 3, 64, 9, 10, 11, 12],
53
+       "h03": [1, 2, 3, 64, 15, 16, 17, 18],
54
+       "h04": [1, 2, 3, 64, 19, 20, 21, 22, 23, 24],
55
+       "h05": [1, 2, 3, 64, 25, 26, 27, 28, 29],
56
+       "h06": [1, 2, 3, 64, 30, 31, 32, 33],
57
+       "h07": [1, 2, 3, 64, 35, 36, 37, 38],
58
+       "h08": [1, 2, 3, 64, 40, 41, 42, 43],
59
+       "h09": [1, 2, 3, 64, 45, 46, 47, 48],
60
+       "h10": [1, 2, 3, 64, 49, 50, 51],
61
+       "h11": [1, 2, 3, 64, 52, 53, 54, 55],
62
+       "h12": [1, 2, 3, 64, 56, 57, 58, 59],
63
+       "am": [],
64
+       "pm": []
65
+  }
66
+
67
+# Number of columns in grid layout
68
+COLS = 15
69
+
70
+# Size of letter in grid (x, y)
71
+SIZE = (53, 60)
72
+
73
+# Font size of letter
74
+FONTSIZE = 40
75
+
76
+# Is our language one where we need to increment the hour after 30 mins
77
+# e.g. 9:40 is "Twenty to ten"
78
+HOUR_INCREMENT = True
79
+
80
+HOUR_INCREMENT_TIME = 30

+ 91
- 0
screens/wordclock/layouts/spanish.py View File

@@ -0,0 +1,91 @@
1
+'''This is a custom layout for the RPi InfoScreen wordclock screen.
2
+
3
+    Custom layouts can be created for the screen by creating a new file in the
4
+    "layouts" folder.
5
+
6
+    Each layout must have the following variables:
7
+        LAYOUT:   The grid layout. Must be a single string.
8
+        MAP:      The mapping required for various times (see notes below)
9
+        COLS:     The number of columns required for the grid layout
10
+        SIZE:     The size of the individual box containing your letter.
11
+                  Tuple in (x, y) format.
12
+        FONTSIZE: Font size for the letter
13
+'''
14
+
15
+# Layout is a single string variable which will be looped over by the parser.
16
+LAYOUT = ("ESONPLASWUNADOS"
17
+          "TRESCUATROCINCO"
18
+          "SEISIETEOCHONCE"
19
+          "NUEVESDIEZVDOCE"
20
+          "YMENOSQCINCORPI"
21
+          "DIEZTRCUARTOELP"
22
+          "VEINTEBMEDIALZI"
23
+          "RPIVEINTICINCOR"
24
+          )
25
+
26
+# Map instructions:
27
+# The clock works by rounding the time to the nearest 5 minutes.
28
+# This means that you need to have settngs for each five minute interval "m00"
29
+# "m00", "m05".
30
+# The clock also works on a 12 hour basis rather than 24 hour:
31
+# "h00", "h01" etc.
32
+# There are three optional parameters:
33
+#   "all": Anything that is always shown regardless of the time e.g. "It is..."
34
+#   "am":  Wording/symbol to indicate morning.
35
+#   "pm":  Wording/symbol to indicate afternoon/evening
36
+MAP = {
37
+       "all": [],
38
+       "m00": [],
39
+       "m05": [60, 67, 68, 69, 70, 71],
40
+       "m10": [60, 75, 76, 77, 78],
41
+       "m15": [60, 81, 82, 83, 84, 85, 86],
42
+       "m20": [60, 90, 91, 92, 93, 94, 95],
43
+       "m25": [60, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
44
+       "m30": [60, 97, 98, 99, 100, 101],
45
+       "m35": [61, 62, 63, 64, 65, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
46
+       "m40": [61, 62, 63, 64, 65, 90, 91, 92, 93, 94, 95],
47
+       "m45": [61, 62, 63, 64, 65, 81, 82, 83, 84, 85, 86],
48
+       "m50": [61, 62, 63, 64, 65, 75, 76, 77, 78],
49
+       "m55": [61, 62, 63, 64, 65, 67, 68, 69, 70, 71],
50
+       "h01": [0, 1, 5, 6, 9, 10, 11],
51
+       "h02": [1, 2, 3, 5, 6, 7, 12, 13, 14],
52
+       "h03": [1, 2, 3, 5, 6, 7, 15, 16, 17, 18],
53
+       "h04": [1, 2, 3, 5, 6, 7, 19, 20, 21, 22, 23, 24],
54
+       "h05": [1, 2, 3, 5, 6, 7, 25, 26, 27, 28, 29],
55
+       "h06": [1, 2, 3, 5, 6, 7, 30, 31, 32, 33],
56
+       "h07": [1, 2, 3, 5, 6, 7, 33, 34, 35, 36, 37],
57
+       "h08": [1, 2, 3, 5, 6, 7, 38, 39, 40, 41],
58
+       "h09": [1, 2, 3, 5, 6, 7, 45, 46, 47, 48, 49],
59
+       "h10": [1, 2, 3, 5, 6, 7, 51, 52, 53, 54],
60
+       "h11": [1, 2, 3, 5, 6, 7, 41, 42, 43, 44],
61
+       "h12": [1, 2, 3, 5, 6, 7, 56, 57, 58, 59],
62
+       "m00": [],
63
+       "m05": [60, 67, 68, 69, 70, 71],
64
+       "m10": [60, 75, 76, 77, 78],
65
+       "m15": [60, 81, 82, 83, 84, 85, 86],
66
+       "m20": [60, 90, 91, 92, 93, 94, 95],
67
+       "m25": [60, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
68
+       "m30": [60, 97, 98, 99, 100, 101],
69
+       "m35": [61, 62, 63, 64, 65, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
70
+       "m40": [61, 62, 63, 64, 65, 90, 91, 92, 93, 94, 95],
71
+       "m45": [61, 62, 63, 64, 65, 81, 82, 83, 84, 85, 86],
72
+       "m50": [61, 62, 63, 64, 65, 75, 76, 77, 78],
73
+       "m55": [61, 62, 63, 64, 65, 67, 68, 69, 70, 71],
74
+       "am": [],
75
+       "pm": []
76
+  }
77
+
78
+# Number of columns in grid layout
79
+COLS = 15
80
+
81
+# Size of letter in grid (x, y)
82
+SIZE = (53, 60)
83
+
84
+# Font size of letter
85
+FONTSIZE = 40
86
+
87
+# Is our language one where we need to increment the hour after 30 mins
88
+# e.g. 9:40 is "Twenty to ten"
89
+HOUR_INCREMENT = True
90
+
91
+HOUR_INCREMENT_TIME = 30

+ 79
- 0
screens/wordclock/layouts/swedish.py View File

@@ -0,0 +1,79 @@
1
+# This Python file uses the following encoding: utf-8
2
+'''This is a custom layout for the RPi InfoScreen wordclock screen.
3
+
4
+    Custom layouts can be created for the screen by creating a new file in the
5
+    "layouts" folder.
6
+
7
+    Each layout must have the following variables:
8
+        LAYOUT:   The grid layout. Must be a single string.
9
+        MAP:      The mapping required for various times (see notes below)
10
+        COLS:     The number of columns required for the grid layout
11
+        SIZE:     The size of the individual box containing your letter.
12
+                  Tuple in (x, y) format.
13
+        FONTSIZE: Font size for the letter
14
+'''
15
+
16
+# Layout is a single string variable which will be looped over by the parser.
17
+LAYOUT = (u"HONIÄRCUBMWLRPI"
18
+          u"ENQKVARTRFDHALV"
19
+          u"ELTJUGOFEMEGTIO"
20
+          u"IOXÖVERIYTOLVVE"
21
+          u"ETTSEXTREEENIOE"
22
+          u"SJUENTVÅXELVAEN"
23
+          u"ÅTTATIOFYRAFEME"
24
+          u"RPIO'CLOCKHFMEM")
25
+
26
+# Map instructions:
27
+# The clock works by rounding the time to the nearest 5 minutes.
28
+# This means that you need to have settngs for each five minute interval "m00"
29
+# "m00", "m05".
30
+# The clock also works on a 12 hour basis rather than 24 hour:
31
+# "h00", "h01" etc.
32
+# There are three optional parameters:
33
+#   "all": Anything that is always shown regardless of the time e.g. "It is..."
34
+#   "am":  Wording/symbol to indicate morning.
35
+#   "pm":  Wording/symbol to indicate afternoon/evening
36
+MAP = {
37
+       "all": [0, 1, 2, 4, 5],
38
+       "m00": [],
39
+       "m05": [37,38, 39, 48, 49, 50, 51],
40
+       "m10": [42, 43, 44, 48, 49, 50, 51],
41
+       "m15": [18, 19, 20, 21, 22, 48, 49, 50, 51],
42
+       "m20": [32, 33, 34, 35, 36, 48, 49, 50, 51],
43
+       "m25": [32, 33, 34, 35, 36, 37, 38, 39, 48, 49, 50, 51],
44
+       "m30": [26, 27, 28, 29],
45
+       "m35": [32, 33, 34, 35, 36, 37, 38, 39, 52],
46
+       "m40": [32, 33, 34, 35, 36, 52],
47
+       "m45": [18, 19, 20, 21, 22, 52],
48
+       "m50": [42, 43, 44, 52],
49
+       "m55": [37, 38, 39, 52],
50
+       "h01": [60, 61, 62],
51
+       "h02": [80, 81, 82],
52
+       "h03": [66, 67, 68],
53
+       "h04": [97, 98, 99, 100],
54
+       "h05": [101, 102, 103],
55
+       "h06": [63, 64, 65],
56
+       "h07": [75, 76, 77],
57
+       "h08": [90, 91, 92, 93],
58
+       "h09": [71, 72, 73],
59
+       "h10": [94, 95, 96],
60
+       "h11": [84, 85, 86, 87],
61
+       "h12": [54, 55, 56, 57],
62
+       "am": [116, 117],
63
+       "pm": [118, 119]
64
+  }
65
+
66
+# Number of columns in grid layout
67
+COLS = 15
68
+
69
+# Size of letter in grid (x, y)
70
+SIZE = (53, 60)
71
+
72
+# Font size of letter
73
+FONTSIZE = 40
74
+
75
+# Is our language one where we need to increment the hour after 30 mins
76
+# e.g. 9:40 is "Twenty to ten"
77
+HOUR_INCREMENT = True
78
+
79
+HOUR_INCREMENT_TIME = 29

+ 175
- 0
screens/wordclock/screen.py View File

@@ -0,0 +1,175 @@
1
+import imp
2
+import os
3
+import sys
4
+from datetime import datetime as DT
5
+
6
+from kivy.animation import Animation
7
+from kivy.clock import Clock
8
+from kivy.properties import BooleanProperty, StringProperty, ListProperty
9
+from kivy.uix.gridlayout import GridLayout
10
+from kivy.uix.label import Label
11
+from kivy.uix.screenmanager import Screen
12
+
13
+
14
+
15
+def round_down(num, divisor):
16
+    return num - (num % divisor)
17
+
18
+
19
+class WordClockLetter(Label):
20
+    """Word clock letter object. The colour of the letter is changed by calling
21
+       the "toggle" method.
22
+    """
23
+    textcol = ListProperty([0.05, 0.05, 0.05, 1])
24
+
25
+    def __init__(self, **kwargs):
26
+        
27
+
28
+        # Flag for determining whether the state of the letter has changed
29
+        self.oldstate = False
30
+
31
+        # Variable for the duration of the animated fade
32
+        self.fadetime = 1
33
+
34
+        self.off_colour = [0.05, 0.05, 0.05, 1]
35
+        self.on_colour = kwargs["colour"]
36
+        del kwargs["colour"]
37
+        super(WordClockLetter, self).__init__(**kwargs)
38
+
39
+    def toggle(self, on):
40
+        if on:
41
+            colour = self.on_colour
42
+        else:
43
+            colour = self.off_colour
44
+
45
+        # Add some animation effect to fade between different times.
46
+        if on != self.oldstate:
47
+            self.oldstate = on
48
+            anim = Animation(textcol=colour, duration=self.fadetime)
49
+            anim.start(self)
50
+
51
+
52
+class WordClockScreen(Screen):
53
+    def __init__(self,params,**kwargs):
54
+        
55
+        self.running = False
56
+        self.timer = None
57
+        self.oldtime = None
58
+
59
+        # Set up some variables to help load the chosen layout.
60
+        self.basepath = os.path.dirname(os.path.abspath(__file__))
61
+        self.layouts = os.path.join(self.basepath, "layouts")
62
+        self.lang = params["language"].lower()
63
+        self.colour = self.get_colour(params["colour"])
64
+        
65
+        Screen.__init__(self,**kwargs)
66
+
67
+    def get_colour(self, colour):
68
+        return [x/255.0 for x in colour] + [1]
69
+
70
+    def on_enter(self):
71
+        # We only want to set up the screen once
72
+        if not self.running:
73
+            self.setup()
74
+            self.running = True
75
+
76
+        # Set the interval timer
77
+        self.timer = Clock.schedule_interval(self.update, 1)
78
+
79
+    def on_leave(self):
80
+        Clock.unschedule(self.timer)
81
+
82
+    def update(self, *args):
83
+        # What time is it?
84
+        nw = DT.now()
85
+        hour = nw.hour
86
+        minute = round_down(nw.minute, 5)
87
+
88
+        # Is our language one where we need to increment the hour after 30 mins
89
+        # e.g. 9:40 is "Twenty to ten"
90
+        if self.config.HOUR_INCREMENT and (minute > self.config.HOUR_INCREMENT_TIME):
91
+            hour += 1
92
+
93
+        # Convert rounded time to string
94
+        tm = "{:02d}:{:02d}".format(hour, minute)
95
+
96
+        # If it's the same as the last update then we don't need to do anything
97
+        if tm != self.oldtime:
98
+
99
+            # Change to 12 hour clock
100
+            if hour == 24:
101
+                hour = 0
102
+            elif hour > 12:
103
+                hour -= 12
104
+
105
+            if hour == 0:
106
+                hour = 12
107
+
108
+            # Morning or afternoon?
109
+            ampm = "am" if nw.hour < 12 else "pm"
110
+
111
+            # Get necessary key names
112
+            h = "h{:02d}".format(hour)
113
+            m = "m{:02d}".format(minute)
114
+
115
+            # Load the map
116
+            d = self.config.MAP
117
+
118
+            # Build list of the letters we need
119
+            tm = d.get("all", []) + d[h] + d[m] + d.get(ampm, [])
120
+
121
+            # Build a map of all letters saying whether they're on or off
122
+            st = [x in tm for x in range(len(self.config.LAYOUT))]
123
+
124
+            # Create a list of tuples of (letter, state)
125
+            updt = zip(self.letters, st)
126
+
127
+            # Loop over the list and toggle the letter
128
+            for z in updt:
129
+                z[0].toggle(z[1])
130
+
131
+    def loadLayout(self):
132
+        """Simple method to import the layout. If the module can't be found
133
+           then it defaults to loading the English layout.
134
+        """
135
+        module = os.path.join(self.layouts, "{}.py".format(self.lang))
136
+
137
+        try:
138
+            config = imp.load_source("layouts.{}".format(self.lang), module)
139
+
140
+        except ImportError:
141
+            self.lang = "english"
142
+            config = imp.load_source("layouts.{}".format(self.lang), module)
143
+
144
+        return config
145
+
146
+    def setup(self):
147
+        # Get the layout
148
+        self.config = self.loadLayout()
149
+
150
+        # We'll want to keep a list of all the letter objects
151
+        self.letters = []
152
+
153
+        # Create a grid layout that's the right size
154
+        grid = GridLayout(cols=self.config.COLS)
155
+
156
+        # Loop over the letters
157
+        for ltr in self.config.LAYOUT:
158
+
159
+            # Create a letter object
160
+            word = WordClockLetter(text=ltr,
161
+                                   size=self.config.SIZE,
162
+                                   font_size=self.config.FONTSIZE,
163
+                                   colour=self.colour)
164
+
165
+            # add it to our list...
166
+            grid.add_widget(word)
167
+
168
+            # ...and to the grid layout
169
+            self.letters.append(word)
170
+
171
+        # Clear the screen
172
+        self.clear_widgets()
173
+
174
+        # add the clock layout
175
+        self.add_widget(grid)

+ 8
- 0
screens/wordclock/wordclock.kv View File

@@ -0,0 +1,8 @@
1
+<WordClockLetter>
2
+    size_hint: None, None
3
+    color: self.textcol
4
+
5
+<WordClockScreen>:
6
+    Label:
7
+        pos: 0, 0
8
+        text: "Loading Word Clock."

Loading…
Cancel
Save