88from shutil import copyfile , move
99from copy import deepcopy
1010from .log import Log
11-
11+ from . common import *
1212
1313logger = logging .getLogger (__name__ )
1414
15- FOREGROUND = 0
16- BACKGROUND = 1
17- # for pop up window
18- CAPTION = 2
19- BORDER = 3
20-
2115
2216class PyRadioTheme (object ):
2317 _colors = {}
@@ -39,28 +33,28 @@ def __del__(self):
3933
4034 def _do_init_pairs (self ):
4135 # not used
42- curses .init_pair (1 , curses .COLOR_CYAN , self ._active_colors ['Stations' ][ BACKGROUND ])
36+ curses .init_pair (1 , curses .COLOR_CYAN , self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ])
4337 # PyRadio URL
44- curses .init_pair (2 , self ._active_colors ['PyRadio URL' ][ FOREGROUND ], self ._active_colors ['Stations' ][ BACKGROUND ])
38+ curses .init_pair (2 , self ._active_colors [THEME_ITEMS [ 0 ][ 0 ]][ FOREGROUND () ], self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ])
4539 # help border
46- curses .init_pair (3 , self ._active_colors ['Messages Border' ][ FOREGROUND ], self ._active_colors ['Stations' ][ BACKGROUND ])
40+ curses .init_pair (3 , self ._active_colors [THEME_ITEMS [ 1 ][ 0 ]][ FOREGROUND () ], self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ])
4741 # station playing no cursor
48- curses .init_pair (4 , self ._active_colors ['Active Station' ][ FOREGROUND ], self ._active_colors ['Stations' ][ BACKGROUND ])
42+ curses .init_pair (4 , self ._active_colors [THEME_ITEMS [ 4 ][ 0 ]][ FOREGROUND () ], self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ])
4943 # body win
50- curses .init_pair (5 , self ._active_colors ['Stations' ][ FOREGROUND ], self ._active_colors ['Stations' ][ BACKGROUND ])
44+ curses .init_pair (5 , self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ FOREGROUND () ], self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ])
5145 # cursor
52- curses .init_pair (6 , self ._active_colors ['Normal Cursor' ][ FOREGROUND ], self ._active_colors ['Normal Cursor' ][ BACKGROUND ])
46+ curses .init_pair (6 , self ._active_colors [THEME_ITEMS [ 5 ][ 0 ]][ FOREGROUND () ], self ._active_colors [THEME_ITEMS [ 5 ][ 0 ]][ BACKGROUND () ])
5347 # status bar
54- curses .init_pair (7 , self ._active_colors ['Status Bar' ][ FOREGROUND ], self ._active_colors ['Status Bar' ][ BACKGROUND ])
48+ curses .init_pair (7 , self ._active_colors [THEME_ITEMS [ 2 ][ 0 ]][ FOREGROUND () ], self ._active_colors [THEME_ITEMS [ 2 ][ 0 ]][ BACKGROUND () ])
5549 # search cursor
56- curses .init_pair (8 , self ._active_colors ['Normal Cursor' ][ BACKGROUND ], self ._active_colors ['Stations' ][ BACKGROUND ])
50+ curses .init_pair (8 , self ._active_colors [THEME_ITEMS [ 5 ][ 0 ]][ BACKGROUND () ], self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ])
5751 # cursor when playing
58- curses .init_pair (9 , self ._active_colors ['Active Cursor' ][ FOREGROUND ], self ._active_colors ['Active Cursor' ][ BACKGROUND ])
52+ curses .init_pair (9 , self ._active_colors [THEME_ITEMS [ 6 ][ 0 ]][ FOREGROUND () ], self ._active_colors [THEME_ITEMS [ 6 ][ 0 ]][ BACKGROUND () ])
5953
6054 def restoreActiveTheme (self ):
6155 self ._active_colors = deepcopy (self ._read_colors )
6256 if self ._transparent :
63- self ._active_colors ['Stations' ][ BACKGROUND ] = - 1
57+ self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] = - 1
6458 self ._do_init_pairs ()
6559
6660 def readAndApplyTheme (self , a_theme , use_transparency = None ):
@@ -75,10 +69,10 @@ def readAndApplyTheme(self, a_theme, use_transparency=None):
7569 self ._active_colors = deepcopy (self ._colors )
7670 if use_transparency is None :
7771 if self ._transparent :
78- self ._active_colors ['Stations' ][ BACKGROUND ] = - 1
72+ self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] = - 1
7973 else :
8074 if use_transparency :
81- self ._active_colors ['Stations' ][ BACKGROUND ] = - 1
75+ self ._active_colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] = - 1
8276 self ._do_init_pairs ()
8377 self ._read_colors = deepcopy (self ._colors )
8478
@@ -95,108 +89,108 @@ def open_theme(self, a_theme = ''):
9589 a_theme = 'dark'
9690
9791 if a_theme == 'dark' or a_theme == 'default' :
98- self ._colors ['Stations' ] = [ curses .COLOR_WHITE , curses .COLOR_BLACK ]
99- self ._colors ['Status Bar' ] = [ curses .COLOR_BLACK , curses .COLOR_GREEN ]
92+ self ._colors [THEME_ITEMS [ 3 ][ 0 ] ] = [ curses .COLOR_WHITE , curses .COLOR_BLACK ]
93+ self ._colors [THEME_ITEMS [ 2 ][ 0 ] ] = [ curses .COLOR_BLACK , curses .COLOR_GREEN ]
10094 # selection
101- self ._colors ['Normal Cursor' ] = [ curses .COLOR_BLACK , curses .COLOR_MAGENTA ]
102- self ._colors ['Active Cursor' ] = [ curses .COLOR_BLACK , curses .COLOR_GREEN ]
103- self ._colors ['Active Station' ] = [ curses .COLOR_GREEN , self ._colors ['Stations' ][ BACKGROUND ] ]
95+ self ._colors [THEME_ITEMS [ 5 ][ 0 ] ] = [ curses .COLOR_BLACK , curses .COLOR_MAGENTA ]
96+ self ._colors [THEME_ITEMS [ 6 ][ 0 ] ] = [ curses .COLOR_BLACK , curses .COLOR_GREEN ]
97+ self ._colors [THEME_ITEMS [ 4 ][ 0 ]] = [ curses .COLOR_GREEN , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
10498 # Titles
105- self ._colors ['Titles' ] = [ curses . COLOR_GREEN , self ._colors ['Stations' ][ BACKGROUND ] ]
106- self ._colors ['PyRadio URL' ] = [ curses .COLOR_BLUE , self ._colors ['Stations' ][ BACKGROUND ] ]
99+ # calculated value: self._colors['Titles'] = self._colors[THEME_ITEMS[4][0] ]
100+ self ._colors [THEME_ITEMS [ 0 ][ 0 ]] = [ curses .COLOR_BLUE , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
107101 # help window
108- self ._colors ['Messages' ] = [ self ._colors ['Titles' ][ FOREGROUND ], curses . COLOR_YELLOW ]
109- self ._colors ['Messages Border ' ] = [ curses . COLOR_YELLOW , self ._colors ['Stations' ][ BACKGROUND ] ]
102+ self ._colors [THEME_ITEMS [ 1 ][ 0 ]] = [ curses . COLOR_YELLOW , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND ()] ]
103+ # calculated value: self._colors['Messages'] = [ self._colors[THEME_ITEMS[4][0]][FOREGROUND()] , self._colors[THEME_ITEMS[2][0]][FOREGROUND() ] ]
110104 # info
111105 self ._colors ['Colors' ] = 8
112106 self ._colors ['Name' ] = 'dark'
113107 self ._colors ['Path' ] = ''
114108
115109 elif a_theme == 'dark_16_colors' :
116- self ._colors ['Stations' ] = [ 15 , 8 ]
117- self ._colors ['Status Bar' ] = [ curses .COLOR_BLACK , 10 ]
110+ self ._colors [THEME_ITEMS [ 3 ][ 0 ] ] = [ 15 , 8 ]
111+ self ._colors [THEME_ITEMS [ 2 ][ 0 ] ] = [ curses .COLOR_BLACK , 10 ]
118112 # selection
119- self ._colors ['Normal Cursor' ] = [ curses .COLOR_BLACK , 13 ]
120- self ._colors ['Active Cursor' ] = [ curses .COLOR_BLACK , 10 ]
121- self ._colors ['Active Station' ] = [ 10 , self ._colors ['Stations' ][ BACKGROUND ] ]
113+ self ._colors [THEME_ITEMS [ 5 ][ 0 ] ] = [ curses .COLOR_BLACK , 13 ]
114+ self ._colors [THEME_ITEMS [ 6 ][ 0 ] ] = [ curses .COLOR_BLACK , 10 ]
115+ self ._colors [THEME_ITEMS [ 4 ][ 0 ]] = [ 10 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
122116 # Titles
123- self ._colors ['Titles' ] = [ 10 , self ._colors ['Stations' ][ BACKGROUND ] ]
124- self ._colors ['PyRadio URL' ] = [ 12 , self ._colors ['Stations' ][ BACKGROUND ] ]
117+ # calculated value: self._colors['Titles'] = self._colors[THEME_ITEMS[4][0] ]
118+ self ._colors [THEME_ITEMS [ 0 ][ 0 ]] = [ 12 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
125119 # help window
126- self ._colors ['Messages' ] = [ self ._colors ['Titles' ][ FOREGROUND ], 11 ]
127- self ._colors ['Messages Border ' ] = [ 11 , self ._colors ['Stations' ][ BACKGROUND ] ]
120+ self ._colors [THEME_ITEMS [ 1 ][ 0 ]] = [ 11 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND ()] ]
121+ # calculated value: self._colors['Messages'] = [ self._colors[THEME_ITEMS[4][0]][FOREGROUND()] , self._colors[THEME_ITEMS[2][0]][FOREGROUND() ] ]
128122 # info
129123 self ._colors ['Colors' ] = 16
130124 self ._colors ['Name' ] = 'dark_16_colors'
131125 self ._colors ['Path' ] = ''
132126
133127 elif a_theme == 'light' :
134- self ._colors ['Stations' ] = [ curses .COLOR_BLACK , curses .COLOR_WHITE ]
135- self ._colors ['Status Bar' ] = [ curses .COLOR_WHITE , curses .COLOR_BLUE ]
128+ self ._colors [THEME_ITEMS [ 3 ][ 0 ] ] = [ curses .COLOR_BLACK , curses .COLOR_WHITE ]
129+ self ._colors [THEME_ITEMS [ 2 ][ 0 ] ] = [ curses .COLOR_WHITE , curses .COLOR_BLUE ]
136130 # selection
137- self ._colors ['Normal Cursor' ] = [ curses .COLOR_WHITE , curses .COLOR_MAGENTA ]
138- self ._colors ['Active Cursor' ] = [ curses .COLOR_WHITE , curses .COLOR_BLUE ]
139- self ._colors ['Active Station' ] = [ curses .COLOR_RED , self ._colors ['Stations' ][ BACKGROUND ] ]
131+ self ._colors [THEME_ITEMS [ 5 ][ 0 ] ] = [ curses .COLOR_WHITE , curses .COLOR_MAGENTA ]
132+ self ._colors [THEME_ITEMS [ 6 ][ 0 ] ] = [ curses .COLOR_WHITE , curses .COLOR_BLUE ]
133+ self ._colors [THEME_ITEMS [ 4 ][ 0 ]] = [ curses .COLOR_RED , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
140134 # Titles
141- self ._colors ['Titles' ] = [ curses . COLOR_RED , self ._colors ['Stations' ][ BACKGROUND ] ]
142- self ._colors ['PyRadio URL' ] = [ curses .COLOR_BLUE , self ._colors ['Stations' ][ BACKGROUND ] ]
135+ # calculated value: self._colors['Titles'] = self._colors[THEME_ITEMS[4][0] ]
136+ self ._colors [THEME_ITEMS [ 0 ][ 0 ]] = [ curses .COLOR_BLUE , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
143137 # help window
144- self ._colors ['Messages' ] = [ self ._colors ['Titles' ][ FOREGROUND ], curses . COLOR_RED ]
145- self ._colors ['Messages Border ' ] = [ curses . COLOR_MAGENTA , self ._colors ['Stations' ][ BACKGROUND ] ]
138+ self ._colors [THEME_ITEMS [ 1 ][ 0 ]] = [ curses . COLOR_MAGENTA , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND ()] ]
139+ # calculated value: self._colors['Messages'] = [ self._colors[THEME_ITEMS[4][0]][FOREGROUND()] , self._colors[THEME_ITEMS[2][0]][FOREGROUND() ] ]
146140 # info
147141 self ._colors ['Colors' ] = 8
148142 self ._colors ['Name' ] = 'dark'
149143 self ._colors ['Path' ] = ''
150144
151145 elif a_theme == 'light_16_colors' :
152- self ._colors ['Stations' ] = [ 8 , 15 ]
153- self ._colors ['Status Bar' ] = [ 15 , 12 ]
146+ self ._colors [THEME_ITEMS [ 3 ][ 0 ] ] = [ 8 , 15 ]
147+ self ._colors [THEME_ITEMS [ 2 ][ 0 ] ] = [ 15 , 12 ]
154148 # selection
155- self ._colors ['Normal Cursor' ] = [ 15 , 13 ]
156- self ._colors ['Active Cursor' ] = [ 15 , 12 ]
157- self ._colors ['Active Station' ] = [ 9 , self ._colors ['Stations' ][ BACKGROUND ] ]
149+ self ._colors [THEME_ITEMS [ 5 ][ 0 ] ] = [ 15 , 13 ]
150+ self ._colors [THEME_ITEMS [ 6 ][ 0 ] ] = [ 15 , 12 ]
151+ self ._colors [THEME_ITEMS [ 4 ][ 0 ]] = [ 9 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
158152 # Titles
159- self ._colors ['Titles' ] = [ 9 , self ._colors ['Stations' ][ BACKGROUND ] ]
160- self ._colors ['PyRadio URL' ] = [ 12 , self ._colors ['Stations' ][ BACKGROUND ] ]
153+ # calculated value: self._colors['Titles'] = self._colors[THEME_ITEMS[4][0] ]
154+ self ._colors [THEME_ITEMS [ 0 ][ 0 ]] = [ 12 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
161155 # help window
162- self ._colors ['Messages' ] = [ self ._colors ['Titles' ][ FOREGROUND ], 9 ]
163- self ._colors ['Messages Border ' ] = [ 13 , self ._colors ['Stations' ][ BACKGROUND ] ]
156+ self ._colors [THEME_ITEMS [ 1 ][ 0 ]] = [ 13 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND ()] ]
157+ # calculated value: self._colors['Messages'] = [ self._colors[THEME_ITEMS[4][0]][FOREGROUND()] , self._colors[THEME_ITEMS[2][0]][FOREGROUND() ] ]
164158 # info
165159 self ._colors ['Colors' ] = 16
166160 self ._colors ['Name' ] = 'light_16_colors'
167161 self ._colors ['Path' ] = ''
168162
169163 elif a_theme == 'black_on_white' or a_theme == 'bow' :
170- self ._colors ['Stations' ] = [ 245 , 15 ]
171- self ._colors ['Status Bar' ] = [ 15 , 245 ]
164+ self ._colors [THEME_ITEMS [ 3 ][ 0 ] ] = [ 245 , 15 ]
165+ self ._colors [THEME_ITEMS [ 2 ][ 0 ] ] = [ 15 , 245 ]
172166 # selection
173- self ._colors ['Normal Cursor' ] = [ 15 , 245 ]
174- self ._colors ['Active Cursor' ] = [ 0 , 245 ]
175- self ._colors ['Active Station' ] = [ 0 , self ._colors ['Stations' ][ BACKGROUND ] ]
167+ self ._colors [THEME_ITEMS [ 5 ][ 0 ] ] = [ 15 , 245 ]
168+ self ._colors [THEME_ITEMS [ 6 ][ 0 ] ] = [ 0 , 245 ]
169+ self ._colors [THEME_ITEMS [ 4 ][ 0 ]] = [ 0 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
176170 # Titles
177- self ._colors ['Titles' ] = [ 0 , self ._colors ['Stations' ][ BACKGROUND ] ]
178- self ._colors ['PyRadio URL' ] = [ 0 , self ._colors ['Stations' ][ BACKGROUND ] ]
171+ # calculated value: self._colors['Titles'] = self._colors[THEME_ITEMS[4][0] ]
172+ self ._colors [THEME_ITEMS [ 0 ][ 0 ]] = [ 0 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
179173 # help window
180- self ._colors ['Messages' ] = [ self ._colors ['Titles' ][ FOREGROUND ], 245 ]
181- self ._colors ['Messages Border ' ] = [ 245 , self ._colors ['Stations' ][ BACKGROUND ] ]
174+ self ._colors [THEME_ITEMS [ 1 ][ 0 ]] = [ 245 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND ()] ]
175+ # calculated value: self._colors['Messages'] = [ self._colors[THEME_ITEMS[4][0]][FOREGROUND()] , self._colors[THEME_ITEMS[2][0]][FOREGROUND() ] ]
182176 # info
183177 self ._colors ['Colors' ] = 256
184178 self ._colors ['Name' ] = 'black_on_white'
185179 self ._colors ['Path' ] = ''
186180
187181 elif a_theme == 'white_on_black' or a_theme == 'wob' :
188- self ._colors ['Stations' ] = [ 247 , 235 ]
189- self ._colors ['Status Bar' ] = [ 234 , 253 ]
182+ self ._colors [THEME_ITEMS [ 3 ][ 0 ] ] = [ 247 , 235 ]
183+ self ._colors [THEME_ITEMS [ 2 ][ 0 ] ] = [ 234 , 253 ]
190184 # selection
191- self ._colors ['Normal Cursor' ] = [ 235 , 247 , ]
192- self ._colors ['Active Cursor' ] = [ 235 , 253 ]
193- self ._colors ['Active Station' ] = [ 255 , self ._colors ['Stations' ][ BACKGROUND ] ]
185+ self ._colors [THEME_ITEMS [ 5 ][ 0 ] ] = [ 235 , 247 , ]
186+ self ._colors [THEME_ITEMS [ 6 ][ 0 ] ] = [ 235 , 253 ]
187+ self ._colors [THEME_ITEMS [ 4 ][ 0 ]] = [ 255 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
194188 # Titles
195- self ._colors ['Titles' ] = [ 255 , self ._colors ['Stations' ][ BACKGROUND ] ]
196- self ._colors ['PyRadio URL' ] = [ 253 , self ._colors ['Stations' ][ BACKGROUND ] ]
189+ # calculated value: self._colors['Titles'] = self._colors[THEME_ITEMS[4][0] ]
190+ self ._colors [THEME_ITEMS [ 0 ][ 0 ]] = [ 253 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND () ] ]
197191 # help window
198- self ._colors ['Messages' ] = [ self ._colors ['Titles' ][ FOREGROUND ], 235 ]
199- self ._colors ['Messages Border ' ] = [ 247 , self ._colors ['Stations' ][ BACKGROUND ] ]
192+ self ._colors [THEME_ITEMS [ 1 ][ 0 ]] = [ 247 , self ._colors [THEME_ITEMS [ 3 ][ 0 ]][ BACKGROUND ()] ]
193+ # calculated value: self._colors['Messages'] = [ self._colors[THEME_ITEMS[4][0]][FOREGROUND()] , self._colors[THEME_ITEMS[2][0]][FOREGROUND() ] ]
200194 # info
201195 self ._colors ['Colors' ] = 256
202196 self ._colors ['Name' ] = 'white_on_black'
0 commit comments