Browse Source

wordclock plugin

master
Manfraid 3 years ago
parent
commit
8fad31b3e0

+ 21
- 0
screens/wordclock/README View File

@@ -0,0 +1,21 @@
Wordclock
---------

Simple wordclock screen which is the default screen for this project.

There are two available parameters:
- "language": selects layout for various languages (default: english)
- "colour": RGB colour code for displaying the time

Languages
---------

Currently the following languages are available:
- English
- Spanish
- Portuguese
- French
- Swedish
- Finnish

Anybody is welcome to submit further languages!

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

@@ -0,0 +1,10 @@
{
"screen": "WordClockScreen",
"kv": "wordclock.kv",
"dependencies": [],
"enabled": true,
"params": {
"language": "french",
"colour": [0, 200, 200]
}
}

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


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

@@ -0,0 +1,78 @@
'''This is a custom layout for the RPi InfoScreen wordclock screen.

Custom layouts can be created for the screen by creating a new file in the
"layouts" folder.

Each layout must have the following variables:
LAYOUT: The grid layout. Must be a single string.
MAP: The mapping required for various times (see notes below)
COLS: The number of columns required for the grid layout
SIZE: The size of the individual box containing your letter.
Tuple in (x, y) format.
FONTSIZE: Font size for the letter
'''

# Layout is a single string variable which will be looped over by the parser.
LAYOUT = ("ITQISHCUBMWLRPI"
"AOQUARTERFDHALF"
"TWENTYSFIVEGTEN"
"TOXPASTNYTWELVE"
"ONESIXTHREENINE"
"SEVENTWOXELEVEN"
"EIGHTENFOURFIVE"
"RPIO'CLOCKHAMPM")

# Map instructions:
# The clock works by rounding the time to the nearest 5 minutes.
# This means that you need to have settngs for each five minute interval "m00"
# "m00", "m05".
# The clock also works on a 12 hour basis rather than 24 hour:
# "h00", "h01" etc.
# There are three optional parameters:
# "all": Anything that is always shown regardless of the time e.g. "It is..."
# "am": Wording/symbol to indicate morning.
# "pm": Wording/symbol to indicate afternoon/evening
MAP = {
"all": [0, 1, 3, 4],
"m00": [108, 109, 110, 111, 112, 113, 114],
"m05": [37,38, 39, 40, 48, 49, 50, 51],
"m10": [42, 43, 44, 48, 49, 50, 51],
"m15": [15, 17, 18, 19, 20, 21, 22, 23, 48, 49, 50, 51],
"m20": [30, 31, 32, 33, 34, 35, 48, 49, 50, 51],
"m25": [30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 48, 49, 50, 51],
"m30": [26, 27, 28, 29, 48, 49, 50, 51],
"m35": [30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 45, 46],
"m40": [30, 31, 32, 33, 34, 35, 45, 46],
"m45": [15, 17, 18, 19, 20, 21, 22, 23, 45, 46],
"m50": [42, 43, 44, 45, 46],
"m55": [37, 38, 39, 40, 45, 46],
"h01": [60, 61, 62],
"h02": [80, 81, 82],
"h03": [66, 67, 68, 69, 70],
"h04": [97, 98, 99, 100],
"h05": [101, 102, 103, 104],
"h06": [63, 64, 65],
"h07": [75, 76, 77, 78, 79],
"h08": [90, 91, 92, 93, 94],
"h09": [71, 72, 73, 74],
"h10": [94, 95, 96],
"h11": [84, 85, 86, 87, 88, 89],
"h12": [54, 55, 56, 57, 58, 59],
"am": [116, 117],
"pm": [118, 119]
}

# Number of columns in grid layout
COLS = 15

# Size of letter in grid (x, y)
SIZE = (53, 60)

# Font size of letter
FONTSIZE = 40

# Is our language one where we need to increment the hour after 30 mins
# e.g. 9:40 is "Twenty to ten"
HOUR_INCREMENT = True

HOUR_INCREMENT_TIME = 30

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

@@ -0,0 +1,80 @@
# This Python file uses the following encoding: utf-8
'''This is a custom layout for the RPi InfoScreen wordclock screen.

Custom layouts can be created for the screen by creating a new file in the
"layouts" folder.

Each layout must have the following variables:
LAYOUT: The grid layout. Must be a single string.
MAP: The mapping required for various times (see notes below)
COLS: The number of columns required for the grid layout
SIZE: The size of the individual box containing your letter.
Tuple in (x, y) format.
FONTSIZE: Font size for the letter
'''

# Layout is a single string variable which will be looped over by the parser.
LAYOUT = (u"KELLOQONYPUOLIWPWKL" #0
u"AKYMMENTÄXVARTTIAZC" #19
u"KAHTAKYMMENTÄVIITTÄ" #38
u"VAILLEYLIBSEITSEMÄN" #57
u"YKSITOISTAKAHDEKSAN" #76
u"KAKSITOISTAYHDEKSÄN" #95
u"KYMMENENTKOLMENELJÄ" #114
u"KUUSIVIISIIIVAAPIIP") #133

# Map instructions:
# The clock works by rounding the time to the nearest 5 minutes.
# This means that you need to have settngs for each five minute interval "m00"
# "m00", "m05".
# The clock also works on a 12 hour basis rather than 24 hour:
# "h00", "h01" etc.
# There are three optional parameters:
# "all": Anything that is always shown regardless of the time e.g. "It is..."
# "am": Wording/symbol to indicate morning.
# "pm": Wording/symbol to indicate afternoon/evening
MAP = {
"all": [0, 1, 2, 3, 4, 6, 7],
"m00": [],
"m05": [51, 52, 53, 54, 55, 56, 63, 64, 65],
"m10": [20, 21, 22, 23, 24, 25, 26, 27, 63, 64, 65],
"m15": [29, 30, 31, 32, 33, 34, 35, 63, 64, 65],
"m20": [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 63, 64, 65],
"m25": [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 63, 64, 65],
"m30": [9, 10, 11, 12, 13],
"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],
"m40": [38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 57, 58, 59, 60, 61, 62],
"m45": [29, 30, 31, 32, 33, 34, 35, 57, 58, 59, 60, 61, 62],
"m50": [20, 21, 22, 23, 24, 25, 26, 27, 57, 58, 59, 60, 61, 62],
"m55": [51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62],
"h01": [76, 77, 78, 79],
"h02": [95, 96, 97, 98, 99],
"h03": [123, 124, 125, 126, 127],
"h04": [128, 129, 130, 131, 132],
"h05": [138, 139, 140, 141, 142],
"h06": [133, 134, 135, 136, 137],
"h07": [67, 68, 69, 70, 71, 72, 73, 74, 75],
"h08": [86, 87, 88, 89, 90, 91, 92, 93, 94],
"h09": [106, 107, 108, 109, 110, 111, 112, 113],
"h10": [114, 115, 116, 117, 118, 119, 120, 121],
"h11": [76, 77, 78, 79, 80, 81, 82, 83, 84, 85],
"h12": [95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105],
"am": [147, 148],
"pm": [150, 151]
}

# Number of columns in grid layout
COLS = 19

# Size of letter in grid (x, y)
SIZE = (42, 60)

# Font size of letter
FONTSIZE = 40

# Is our language one where we need to increment the hour after 30 mins
# e.g. 9:40 is "Twenty to ten"
HOUR_INCREMENT = True

HOUR_INCREMENT_TIME = 29


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

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
'''This is a custom layout for the RPi InfoScreen wordclock screen.

Custom layouts can be created for the screen by creating a new file in the
"layouts" folder.

Each layout must have the following variables:
LAYOUT: The grid layout. Must be a single string.
MAP: The mapping required for various times (see notes below)
COLS: The number of columns required for the grid layout
SIZE: The size of the individual box containing your letter.
Tuple in (x, y) format.
FONTSIZE: Font size for the letter
'''

# Layout is a single string variable which will be looped over by the parser.
LAYOUT = ("ILNESTHUNEDEUXP"
"TROISIXOQUATREM"
"CINQHUITNEUFDIX"
"ONZEBDOUZERSEPT"
"HEURESRASPBERRY"
"ETMOINSUCINQDIX"
"LEJQUARTFDEMIEL"
"RPIVINGT-CINQKU"
)

# Map instructions:
# The clock works by rounding the time to the nearest 5 minutes.
# This means that you need to have settngs for each five minute interval "m00"
# "m00", "m05".
# The clock also works on a 12 hour basis rather than 24 hour:
# "h00", "h01" etc.
# There are three optional parameters:
# "all": Anything that is always shown regardless of the time e.g. "It is..."
# "am": Wording/symbol to indicate morning.
# "pm": Wording/symbol to indicate afternoon/evening
MAP = {
"all": [0, 1, 3, 4, 5, 60, 61, 62, 63, 64],
"m00": [],
"m05": [83, 84, 85, 86],
"m10": [87, 88, 89],
"m15": [75, 76, 93, 94, 95, 96, 97],
"m20": [108, 109, 110, 111, 112],
"m25": [108, 109, 110, 111, 112, 113, 114, 115, 116, 117],
"m30": [75, 76, 99, 100, 101, 102, 103],
"m35": [77, 78, 79, 80, 81, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117],
"m40": [77, 78, 79, 80, 81, 108, 109, 110, 111, 112],
"m45": [77, 78, 79, 80, 81, 90, 91, 93, 94, 95, 96, 97],
"m50": [77, 78, 79, 80, 81, 87, 88, 89],
"m55": [77, 78, 79, 80, 81, 83, 84, 85, 86],
"h01": [7, 8, 9],
"h02": [65, 10, 11, 12, 13],
"h03": [65, 15, 16, 17, 18,19],
"h04": [65, 23, 24, 25, 26, 27, 28],
"h05": [65, 30, 31, 32, 33],
"h06": [65, 19, 20, 21],
"h07": [65, 56, 57, 58, 59],
"h08": [65, 34, 35, 36, 37],
"h09": [65, 38, 39, 40, 41],
"h10": [65, 42, 43, 44],
"h11": [65, 45, 46, 47, 48],
"h12": [65, 50, 51, 52, 53, 54],
"am": [],
"pm": [],
}

# Number of columns in grid layout
COLS = 15

# Size of letter in grid (x, y)
SIZE = (53, 50)

# Font size of letter
FONTSIZE = 40

# Is our language one where we need to increment the hour after 30 mins
# e.g. 9:40 is "Twenty to ten"
HOUR_INCREMENT = True

HOUR_INCREMENT_TIME = 30

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

@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
'''This is a custom layout for the RPi InfoScreen wordclock screen.

Custom layouts can be created for the screen by creating a new file in the
"layouts" folder.

Each layout must have the following variables:
LAYOUT: The grid layout. Must be a single string.
MAP: The mapping required for various times (see notes below)
COLS: The number of columns required for the grid layout
SIZE: The size of the individual box containing your letter.
Tuple in (x, y) format.
FONTSIZE: Font size for the letter
'''

# Layout is a single string variable which will be looped over by the parser.
LAYOUT = (u"ESÃORUMAPDUASNT"
u"TRESQUATROCINCO"
u"SEISGSETEVOITOM"
u"NOVEDEZONZEDOZE"
u"HORASOEÃMENOSLP"
u"UMXQUARTOSRPDEZ"
u"VINTEZEJCINCORX"
u"ETMEIAEMUPONTOP"
)

# Map instructions:
# The clock works by rounding the time to the nearest 5 minutes.
# This means that you need to have settngs for each five minute interval "m00"
# "m00", "m05".
# The clock also works on a 12 hour basis rather than 24 hour:
# "h00", "h01" etc.
# There are three optional parameters:
# "all": Anything that is always shown regardless of the time e.g. "It is..."
# "am": Wording/symbol to indicate morning.
# "pm": Wording/symbol to indicate afternoon/evening
MAP = {
"all": [60, 61, 62, 63],
"m00": [111, 112, 114, 115, 116, 117, 118],
"m05": [66, 98, 99, 100, 101, 102],
"m10": [66, 87, 88, 89],
"m15": [66, 75, 76, 78, 79, 80, 81, 82, 83],
"m20": [66, 90, 91, 92, 93, 94],
"m25": [66, 90, 91, 92, 93, 94, 96, 98, 99, 100, 101, 102],
"m30": [66, 107, 108, 109, 110],
"m35": [68, 69, 70, 71, 72, 90, 91, 92, 93, 94, 96, 98, 99, 100, 101, 102],
"m40": [68, 69, 70, 71, 72, 90, 91, 92, 93, 94],
"m45": [68, 69, 70, 71, 72, 75, 76, 78, 79, 80, 81, 82, 83],
"m50": [68, 69, 70, 71, 72, 87, 88, 89],
"m55": [68, 69, 70, 71, 72, 98, 99, 100, 101, 102],
"h01": [0, 5, 6, 7],
"h02": [1, 2, 3, 64, 9, 10, 11, 12],
"h03": [1, 2, 3, 64, 15, 16, 17, 18],
"h04": [1, 2, 3, 64, 19, 20, 21, 22, 23, 24],
"h05": [1, 2, 3, 64, 25, 26, 27, 28, 29],
"h06": [1, 2, 3, 64, 30, 31, 32, 33],
"h07": [1, 2, 3, 64, 35, 36, 37, 38],
"h08": [1, 2, 3, 64, 40, 41, 42, 43],
"h09": [1, 2, 3, 64, 45, 46, 47, 48],
"h10": [1, 2, 3, 64, 49, 50, 51],
"h11": [1, 2, 3, 64, 52, 53, 54, 55],
"h12": [1, 2, 3, 64, 56, 57, 58, 59],
"am": [],
"pm": []
}

# Number of columns in grid layout
COLS = 15

# Size of letter in grid (x, y)
SIZE = (53, 60)

# Font size of letter
FONTSIZE = 40

# Is our language one where we need to increment the hour after 30 mins
# e.g. 9:40 is "Twenty to ten"
HOUR_INCREMENT = True

HOUR_INCREMENT_TIME = 30

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

@@ -0,0 +1,91 @@
'''This is a custom layout for the RPi InfoScreen wordclock screen.

Custom layouts can be created for the screen by creating a new file in the
"layouts" folder.

Each layout must have the following variables:
LAYOUT: The grid layout. Must be a single string.
MAP: The mapping required for various times (see notes below)
COLS: The number of columns required for the grid layout
SIZE: The size of the individual box containing your letter.
Tuple in (x, y) format.
FONTSIZE: Font size for the letter
'''

# Layout is a single string variable which will be looped over by the parser.
LAYOUT = ("ESONPLASWUNADOS"
"TRESCUATROCINCO"
"SEISIETEOCHONCE"
"NUEVESDIEZVDOCE"
"YMENOSQCINCORPI"
"DIEZTRCUARTOELP"
"VEINTEBMEDIALZI"
"RPIVEINTICINCOR"
)

# Map instructions:
# The clock works by rounding the time to the nearest 5 minutes.
# This means that you need to have settngs for each five minute interval "m00"
# "m00", "m05".
# The clock also works on a 12 hour basis rather than 24 hour:
# "h00", "h01" etc.
# There are three optional parameters:
# "all": Anything that is always shown regardless of the time e.g. "It is..."
# "am": Wording/symbol to indicate morning.
# "pm": Wording/symbol to indicate afternoon/evening
MAP = {
"all": [],
"m00": [],
"m05": [60, 67, 68, 69, 70, 71],
"m10": [60, 75, 76, 77, 78],
"m15": [60, 81, 82, 83, 84, 85, 86],
"m20": [60, 90, 91, 92, 93, 94, 95],
"m25": [60, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
"m30": [60, 97, 98, 99, 100, 101],
"m35": [61, 62, 63, 64, 65, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
"m40": [61, 62, 63, 64, 65, 90, 91, 92, 93, 94, 95],
"m45": [61, 62, 63, 64, 65, 81, 82, 83, 84, 85, 86],
"m50": [61, 62, 63, 64, 65, 75, 76, 77, 78],
"m55": [61, 62, 63, 64, 65, 67, 68, 69, 70, 71],
"h01": [0, 1, 5, 6, 9, 10, 11],
"h02": [1, 2, 3, 5, 6, 7, 12, 13, 14],
"h03": [1, 2, 3, 5, 6, 7, 15, 16, 17, 18],
"h04": [1, 2, 3, 5, 6, 7, 19, 20, 21, 22, 23, 24],
"h05": [1, 2, 3, 5, 6, 7, 25, 26, 27, 28, 29],
"h06": [1, 2, 3, 5, 6, 7, 30, 31, 32, 33],
"h07": [1, 2, 3, 5, 6, 7, 33, 34, 35, 36, 37],
"h08": [1, 2, 3, 5, 6, 7, 38, 39, 40, 41],
"h09": [1, 2, 3, 5, 6, 7, 45, 46, 47, 48, 49],
"h10": [1, 2, 3, 5, 6, 7, 51, 52, 53, 54],
"h11": [1, 2, 3, 5, 6, 7, 41, 42, 43, 44],
"h12": [1, 2, 3, 5, 6, 7, 56, 57, 58, 59],
"m00": [],
"m05": [60, 67, 68, 69, 70, 71],
"m10": [60, 75, 76, 77, 78],
"m15": [60, 81, 82, 83, 84, 85, 86],
"m20": [60, 90, 91, 92, 93, 94, 95],
"m25": [60, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
"m30": [60, 97, 98, 99, 100, 101],
"m35": [61, 62, 63, 64, 65, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118],
"m40": [61, 62, 63, 64, 65, 90, 91, 92, 93, 94, 95],
"m45": [61, 62, 63, 64, 65, 81, 82, 83, 84, 85, 86],
"m50": [61, 62, 63, 64, 65, 75, 76, 77, 78],
"m55": [61, 62, 63, 64, 65, 67, 68, 69, 70, 71],
"am": [],
"pm": []
}

# Number of columns in grid layout
COLS = 15

# Size of letter in grid (x, y)
SIZE = (53, 60)

# Font size of letter
FONTSIZE = 40

# Is our language one where we need to increment the hour after 30 mins
# e.g. 9:40 is "Twenty to ten"
HOUR_INCREMENT = True

HOUR_INCREMENT_TIME = 30

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

@@ -0,0 +1,79 @@
# This Python file uses the following encoding: utf-8
'''This is a custom layout for the RPi InfoScreen wordclock screen.

Custom layouts can be created for the screen by creating a new file in the
"layouts" folder.

Each layout must have the following variables:
LAYOUT: The grid layout. Must be a single string.
MAP: The mapping required for various times (see notes below)
COLS: The number of columns required for the grid layout
SIZE: The size of the individual box containing your letter.
Tuple in (x, y) format.
FONTSIZE: Font size for the letter
'''

# Layout is a single string variable which will be looped over by the parser.
LAYOUT = (u"HONIÄRCUBMWLRPI"
u"ENQKVARTRFDHALV"
u"ELTJUGOFEMEGTIO"
u"IOXÖVERIYTOLVVE"
u"ETTSEXTREEENIOE"
u"SJUENTVÅXELVAEN"
u"ÅTTATIOFYRAFEME"
u"RPIO'CLOCKHFMEM")

# Map instructions:
# The clock works by rounding the time to the nearest 5 minutes.
# This means that you need to have settngs for each five minute interval "m00"
# "m00", "m05".
# The clock also works on a 12 hour basis rather than 24 hour:
# "h00", "h01" etc.
# There are three optional parameters:
# "all": Anything that is always shown regardless of the time e.g. "It is..."
# "am": Wording/symbol to indicate morning.
# "pm": Wording/symbol to indicate afternoon/evening
MAP = {
"all": [0, 1, 2, 4, 5],
"m00": [],
"m05": [37,38, 39, 48, 49, 50, 51],
"m10": [42, 43, 44, 48, 49, 50, 51],
"m15": [18, 19, 20, 21, 22, 48, 49, 50, 51],
"m20": [32, 33, 34, 35, 36, 48, 49, 50, 51],
"m25": [32, 33, 34, 35, 36, 37, 38, 39, 48, 49, 50, 51],
"m30": [26, 27, 28, 29],
"m35": [32, 33, 34, 35, 36, 37, 38, 39, 52],
"m40": [32, 33, 34, 35, 36, 52],
"m45": [18, 19, 20, 21, 22, 52],
"m50": [42, 43, 44, 52],
"m55": [37, 38, 39, 52],
"h01": [60, 61, 62],
"h02": [80, 81, 82],
"h03": [66, 67, 68],
"h04": [97, 98, 99, 100],
"h05": [101, 102, 103],
"h06": [63, 64, 65],
"h07": [75, 76, 77],
"h08": [90, 91, 92, 93],
"h09": [71, 72, 73],
"h10": [94, 95, 96],
"h11": [84, 85, 86, 87],
"h12": [54, 55, 56, 57],
"am": [116, 117],
"pm": [118, 119]
}

# Number of columns in grid layout
COLS = 15

# Size of letter in grid (x, y)
SIZE = (53, 60)

# Font size of letter
FONTSIZE = 40

# Is our language one where we need to increment the hour after 30 mins
# e.g. 9:40 is "Twenty to ten"
HOUR_INCREMENT = True

HOUR_INCREMENT_TIME = 29

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

@@ -0,0 +1,175 @@
import imp
import os
import sys
from datetime import datetime as DT

from kivy.animation import Animation
from kivy.clock import Clock
from kivy.properties import BooleanProperty, StringProperty, ListProperty
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.screenmanager import Screen



def round_down(num, divisor):
return num - (num % divisor)


class WordClockLetter(Label):
"""Word clock letter object. The colour of the letter is changed by calling
the "toggle" method.
"""
textcol = ListProperty([0.05, 0.05, 0.05, 1])

def __init__(self, **kwargs):

# Flag for determining whether the state of the letter has changed
self.oldstate = False

# Variable for the duration of the animated fade
self.fadetime = 1

self.off_colour = [0.05, 0.05, 0.05, 1]
self.on_colour = kwargs["colour"]
del kwargs["colour"]
super(WordClockLetter, self).__init__(**kwargs)

def toggle(self, on):
if on:
colour = self.on_colour
else:
colour = self.off_colour

# Add some animation effect to fade between different times.
if on != self.oldstate:
self.oldstate = on
anim = Animation(textcol=colour, duration=self.fadetime)
anim.start(self)


class WordClockScreen(Screen):
def __init__(self,params,**kwargs):
self.running = False
self.timer = None
self.oldtime = None

# Set up some variables to help load the chosen layout.
self.basepath = os.path.dirname(os.path.abspath(__file__))
self.layouts = os.path.join(self.basepath, "layouts")
self.lang = params["language"].lower()
self.colour = self.get_colour(params["colour"])
Screen.__init__(self,**kwargs)

def get_colour(self, colour):
return [x/255.0 for x in colour] + [1]

def on_enter(self):
# We only want to set up the screen once
if not self.running:
self.setup()
self.running = True

# Set the interval timer
self.timer = Clock.schedule_interval(self.update, 1)

def on_leave(self):
Clock.unschedule(self.timer)

def update(self, *args):
# What time is it?
nw = DT.now()
hour = nw.hour
minute = round_down(nw.minute, 5)

# Is our language one where we need to increment the hour after 30 mins
# e.g. 9:40 is "Twenty to ten"
if self.config.HOUR_INCREMENT and (minute > self.config.HOUR_INCREMENT_TIME):
hour += 1

# Convert rounded time to string
tm = "{:02d}:{:02d}".format(hour, minute)

# If it's the same as the last update then we don't need to do anything
if tm != self.oldtime:

# Change to 12 hour clock
if hour == 24:
hour = 0
elif hour > 12:
hour -= 12

if hour == 0:
hour = 12

# Morning or afternoon?
ampm = "am" if nw.hour < 12 else "pm"

# Get necessary key names
h = "h{:02d}".format(hour)
m = "m{:02d}".format(minute)

# Load the map
d = self.config.MAP

# Build list of the letters we need
tm = d.get("all", []) + d[h] + d[m] + d.get(ampm, [])

# Build a map of all letters saying whether they're on or off
st = [x in tm for x in range(len(self.config.LAYOUT))]

# Create a list of tuples of (letter, state)
updt = zip(self.letters, st)

# Loop over the list and toggle the letter
for z in updt:
z[0].toggle(z[1])

def loadLayout(self):
"""Simple method to import the layout. If the module can't be found
then it defaults to loading the English layout.
"""
module = os.path.join(self.layouts, "{}.py".format(self.lang))

try:
config = imp.load_source("layouts.{}".format(self.lang), module)

except ImportError:
self.lang = "english"
config = imp.load_source("layouts.{}".format(self.lang), module)

return config

def setup(self):
# Get the layout
self.config = self.loadLayout()

# We'll want to keep a list of all the letter objects
self.letters = []

# Create a grid layout that's the right size
grid = GridLayout(cols=self.config.COLS)

# Loop over the letters
for ltr in self.config.LAYOUT:

# Create a letter object
word = WordClockLetter(text=ltr,
size=self.config.SIZE,
font_size=self.config.FONTSIZE,
colour=self.colour)

# add it to our list...
grid.add_widget(word)

# ...and to the grid layout
self.letters.append(word)

# Clear the screen
self.clear_widgets()

# add the clock layout
self.add_widget(grid)

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

@@ -0,0 +1,8 @@
<WordClockLetter>
size_hint: None, None
color: self.textcol

<WordClockScreen>:
Label:
pos: 0, 0
text: "Loading Word Clock."

Loading…
Cancel
Save