forked from saschaludwig/OnAirScreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaults.py
More file actions
292 lines (265 loc) · 10.7 KB
/
defaults.py
File metadata and controls
292 lines (265 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#############################################################################
#
# OnAirScreen
# Copyright (c) 2012-2026 Sascha Ludwig, astrastudio.de
# All rights reserved.
#
# defaults.py
# This file is part of OnAirScreen
#
# You may use this file under the terms of the BSD license as follows:
#
# "Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
#
#############################################################################
"""
Default Values Configuration for OnAirScreen
This module contains all default values used throughout the application.
All default values should be defined here to avoid duplication and improve maintainability.
"""
from typing import Dict, Any
# General Settings
DEFAULT_STATION_NAME: str = "Radio Eriwan"
DEFAULT_SLOGAN: str = "Your question is our motivation"
DEFAULT_STATION_COLOR: str = "#FFAA00"
DEFAULT_SLOGAN_COLOR: str = "#FFAA00"
DEFAULT_REPLACE_NOW: bool = False
DEFAULT_REPLACE_NOW_TEXT: str = ""
DEFAULT_FULLSCREEN: bool = True
# LED Settings
DEFAULT_LED_TEXTS: Dict[int, str] = {
1: "ON AIR",
2: "PHONE",
3: "DOORBELL",
4: "EAS ACTIVE"
}
DEFAULT_LED_USED: bool = True
DEFAULT_LED_ACTIVE_TEXT_COLOR: str = "#FFFFFF"
DEFAULT_LED_ACTIVE_BG_COLOR: str = "#FF0000"
DEFAULT_LED_INACTIVE_TEXT_COLOR: str = "#555555"
DEFAULT_LED_INACTIVE_BG_COLOR: str = "#222222"
DEFAULT_LED_AUTOFLASH: bool = False
DEFAULT_LED_TIMEDFLASH: bool = False
# Clock Settings
DEFAULT_CLOCK_DIGITAL: bool = True
DEFAULT_CLOCK_SHOW_SECONDS: bool = False
DEFAULT_CLOCK_SECONDS_IN_ONE_LINE: bool = False
DEFAULT_CLOCK_STATIC_COLON: bool = False
DEFAULT_CLOCK_DIGITAL_HOUR_COLOR: str = "#3232FF"
DEFAULT_CLOCK_DIGITAL_SECOND_COLOR: str = "#FF9900"
DEFAULT_CLOCK_DIGITAL_DIGIT_COLOR: str = "#3232FF"
DEFAULT_CLOCK_LOGO_PATH: str = ":/astrastudio_logo/images/astrastudio_transparent.png"
DEFAULT_CLOCK_LOGO_UPPER: bool = False
DEFAULT_CLOCK_USE_TEXT_CLOCK: bool = True
# Timer/AIR Settings
DEFAULT_TIMER_AIR_ENABLED: bool = True
DEFAULT_TIMER_AIR_TEXTS: Dict[int, str] = {
1: "Mic",
2: "Phone",
3: "Timer",
4: "Stream"
}
DEFAULT_TIMER_AIR_ACTIVE_TEXT_COLOR: str = "#FFFFFF"
DEFAULT_TIMER_AIR_ACTIVE_BG_COLOR: str = "#FF0000"
DEFAULT_TIMER_AIR_INACTIVE_TEXT_COLOR: str = "#555555"
DEFAULT_TIMER_AIR_INACTIVE_BG_COLOR: str = "#222222"
DEFAULT_TIMER_AIR_MIN_WIDTH: int = 200
DEFAULT_TIMER_AIR_ICON_PATHS: Dict[int, str] = {
1: ":/mic_icon/images/mic_icon.png",
2: ":/phone_icon/images/phone_icon.png",
3: ":/timer_icon/images/timer_icon.png",
4: ":/stream_icon/images/antenna2.png"
}
# Network Settings
DEFAULT_UDP_PORT: int = 3310
DEFAULT_HTTP_PORT: int = 8010
DEFAULT_MULTICAST_ADDRESS: str = "239.194.0.1"
# Formatting Settings
DEFAULT_DATE_FORMAT: str = "dddd, dd. MMMM yyyy"
DEFAULT_TEXT_CLOCK_LANGUAGE: str = "English"
DEFAULT_IS_AM_PM: bool = False
# Font Settings
DEFAULT_FONT_NAME: str = "FreeSans"
DEFAULT_FONT_SIZE_LED: int = 24
DEFAULT_FONT_SIZE_STATION: int = 24
DEFAULT_FONT_SIZE_SLOGAN: int = 18
DEFAULT_FONT_SIZE_TIMER: int = 24
DEFAULT_FONT_WEIGHT_BOLD: int = 1 # QFont.Weight.Bold
# NTP Settings
DEFAULT_NTP_CHECK: bool = True
DEFAULT_NTP_CHECK_SERVER: str = "pool.ntp.org"
# Update Settings
DEFAULT_UPDATE_CHECK: bool = False
DEFAULT_UPDATE_KEY: str = ""
DEFAULT_UPDATE_INCLUDE_BETA: bool = False
# Logging Settings
DEFAULT_LOG_LEVEL: str = "INFO"
# Weather Widget Settings
DEFAULT_WEATHER_WIDGET_ENABLED: bool = False
DEFAULT_WEATHER_API_KEY: str = ""
DEFAULT_WEATHER_CITY_ID: str = "2643743" # Default: London, UK
DEFAULT_WEATHER_LANGUAGE: str = "English" # Display name, not language code
DEFAULT_WEATHER_UNIT: str = "Celsius" # Display name, not unit code
# Helper function to get default value by key path
def get_default(group: str, key: str, default: Any = None) -> Any:
"""
Get default value by group and key
Args:
group: Settings group name (e.g., "General", "LED1", "Clock")
key: Settings key name (e.g., "stationname", "text", "digital")
default: Fallback default value if not found
Returns:
Default value for the given group and key, or provided default
"""
# General group
if group == "General":
defaults = {
"stationname": DEFAULT_STATION_NAME,
"slogan": DEFAULT_SLOGAN,
"stationcolor": DEFAULT_STATION_COLOR,
"slogancolor": DEFAULT_SLOGAN_COLOR,
"replacenow": DEFAULT_REPLACE_NOW,
"replacenowtext": DEFAULT_REPLACE_NOW_TEXT,
"fullscreen": DEFAULT_FULLSCREEN,
"loglevel": DEFAULT_LOG_LEVEL,
}
return defaults.get(key, default)
# LED groups
if group.startswith("LED") and group[3:].isdigit():
led_num = int(group[3:])
if key == "text":
return DEFAULT_LED_TEXTS.get(led_num, default)
elif key == "used":
return DEFAULT_LED_USED
elif key == "activebgcolor":
return DEFAULT_LED_ACTIVE_BG_COLOR
elif key == "activetextcolor":
return DEFAULT_LED_ACTIVE_TEXT_COLOR
elif key == "inactivebgcolor":
return DEFAULT_LED_INACTIVE_BG_COLOR
elif key == "inactivetextcolor":
return DEFAULT_LED_INACTIVE_TEXT_COLOR
elif key == "autoflash":
return DEFAULT_LED_AUTOFLASH
elif key == "timedflash":
return DEFAULT_LED_TIMEDFLASH
# Clock group
if group == "Clock":
defaults = {
"digital": DEFAULT_CLOCK_DIGITAL,
"showSeconds": DEFAULT_CLOCK_SHOW_SECONDS,
"showSecondsInOneLine": DEFAULT_CLOCK_SECONDS_IN_ONE_LINE,
"staticColon": DEFAULT_CLOCK_STATIC_COLON,
"digitalhourcolor": DEFAULT_CLOCK_DIGITAL_HOUR_COLOR,
"digitalsecondcolor": DEFAULT_CLOCK_DIGITAL_SECOND_COLOR,
"digitaldigitcolor": DEFAULT_CLOCK_DIGITAL_DIGIT_COLOR,
"logopath": DEFAULT_CLOCK_LOGO_PATH,
"logoUpper": DEFAULT_CLOCK_LOGO_UPPER,
"useTextClock": DEFAULT_CLOCK_USE_TEXT_CLOCK,
}
return defaults.get(key, default)
# Timers group
if group == "Timers":
if key.startswith("TimerAIR") and key.endswith("Enabled"):
return DEFAULT_TIMER_AIR_ENABLED
elif key.startswith("TimerAIR") and key.endswith("Text"):
# Extract AIR number from key like "TimerAIR1Text"
try:
air_num = int(key[8:-4])
return DEFAULT_TIMER_AIR_TEXTS.get(air_num, default)
except (ValueError, IndexError):
return default
elif key.startswith("AIR") and key.endswith("activebgcolor"):
return DEFAULT_TIMER_AIR_ACTIVE_BG_COLOR
elif key.startswith("AIR") and key.endswith("activetextcolor"):
return DEFAULT_TIMER_AIR_ACTIVE_TEXT_COLOR
elif key.startswith("AIR") and key.endswith("inactivebgcolor"):
return DEFAULT_TIMER_AIR_INACTIVE_BG_COLOR
elif key.startswith("AIR") and key.endswith("inactivetextcolor"):
return DEFAULT_TIMER_AIR_INACTIVE_TEXT_COLOR
elif key == "TimerAIRMinWidth":
return DEFAULT_TIMER_AIR_MIN_WIDTH
elif key.startswith("AIR") and key.endswith("iconpath"):
try:
air_num = int(key[3:-8])
return DEFAULT_TIMER_AIR_ICON_PATHS.get(air_num, default)
except (ValueError, IndexError):
return default
# Network group
if group == "Network":
defaults = {
"udpport": str(DEFAULT_UDP_PORT),
"httpport": str(DEFAULT_HTTP_PORT),
"multicast_address": DEFAULT_MULTICAST_ADDRESS,
}
return defaults.get(key, default)
# Formatting group
if group == "Formatting":
defaults = {
"dateFormat": DEFAULT_DATE_FORMAT,
"textClockLanguage": DEFAULT_TEXT_CLOCK_LANGUAGE,
"isAmPm": DEFAULT_IS_AM_PM,
}
return defaults.get(key, default)
# NTP group
if group == "NTP":
defaults = {
"ntpcheck": DEFAULT_NTP_CHECK,
"ntpcheckserver": DEFAULT_NTP_CHECK_SERVER,
}
return defaults.get(key, default)
# WeatherWidget group
if group == "WeatherWidget":
defaults = {
"owmWidgetEnabled": DEFAULT_WEATHER_WIDGET_ENABLED,
"owmAPIKey": DEFAULT_WEATHER_API_KEY,
"owmCityID": DEFAULT_WEATHER_CITY_ID,
"owmLanguage": DEFAULT_WEATHER_LANGUAGE,
"owmUnit": DEFAULT_WEATHER_UNIT,
}
return defaults.get(key, default)
# Fonts group
if group == "Fonts":
if key.endswith("FontName"):
return DEFAULT_FONT_NAME
elif key.endswith("FontSize"):
font_prefix = key[:-8] # Remove "FontSize" suffix
# Map font prefixes to their default sizes
size_map = {
"LED1": DEFAULT_FONT_SIZE_LED,
"LED2": DEFAULT_FONT_SIZE_LED,
"LED3": DEFAULT_FONT_SIZE_LED,
"LED4": DEFAULT_FONT_SIZE_LED,
"AIR1": DEFAULT_FONT_SIZE_TIMER,
"AIR2": DEFAULT_FONT_SIZE_TIMER,
"AIR3": DEFAULT_FONT_SIZE_TIMER,
"AIR4": DEFAULT_FONT_SIZE_TIMER,
"StationName": DEFAULT_FONT_SIZE_STATION,
"Slogan": DEFAULT_FONT_SIZE_SLOGAN,
}
return size_map.get(font_prefix, DEFAULT_FONT_SIZE_LED)
elif key.endswith("FontWeight") or key.endswith("FontBold"):
return DEFAULT_FONT_WEIGHT_BOLD
return default