Skip to content

Commit f2fa946

Browse files
committed
implementing theme selector
1 parent 8b063e1 commit f2fa946

File tree

3 files changed

+431
-17
lines changed

3 files changed

+431
-17
lines changed

pyradio/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,14 @@ def _check_config_file(self, usr):
543543
''' restore config from bck file '''
544544
if path.exists(user_config_file + '.restore'):
545545
try:
546-
copyfile(user_config_file + '.restore', user_config_file))
546+
copyfile(user_config_file + '.restore', user_config_file)
547547
remove(self.user_config_file + '.restore')
548548
except:
549549
pass
550550

551551
''' Copy package config into user dir '''
552552
if not path.exists(user_config_file):
553-
copyfile(package_config_file, user_config_file))
553+
copyfile(package_config_file, user_config_file)
554554

555555
def read_config(self):
556556
lines = []

pyradio/radio.py

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
FOREIGN_PLAYLIST_ASK_MODE = 300
5050
FOREIGN_PLAYLIST_MESSAGE_MODE = 301
5151
FOREIGN_PLAYLIST_COPY_ERROR_MODE = 302
52+
THEME_MODE = 400
53+
NOT_IMPLEMENTED_YET_MODE = 1000
5254

5355
def rel(path):
5456
return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)
@@ -90,6 +92,7 @@ class PyRadio(object):
9092

9193
_theme = PyRadioTheme()
9294
_theme_name = 'dark'
95+
_theme_slector = None
9396

9497
def __init__(self, pyradio_config, play=False, req_player='', theme=''):
9598
self.cnf = pyradio_config
@@ -526,6 +529,21 @@ def _format_player_string(self):
526529
return 'vlc'
527530
return self.player.PLAYER_CMD
528531

532+
def _show_theme_selector(self):
533+
self.jumpnr = ''
534+
self._theme_slector = None
535+
self._theme_slector = PyRadioThemeSelector(self.bodyWin,
536+
self._theme_name, self.cnf.theme,
537+
4, 3, 4, 5, 6, 9, self._theme.getTransparency())
538+
#'/home/spiros/edit.log')
539+
self._theme_slector.show()
540+
541+
if logger.isEnabledFor(logging.DEBUG):
542+
if self.operation_mode == NORMAL_MODE:
543+
logger.debug('MODE: NORMAL_MODE => THEME_MODE')
544+
else:
545+
logger.debug('MODE: PLAYLIST_MODE => THEME_MODE')
546+
529547
def _show_help(self, txt,
530548
mode_to_set=MAIN_HELP_MODE,
531549
caption=' Help ',
@@ -653,6 +671,14 @@ def _print_help(self):
653671
if logger.isEnabledFor(logging.DEBUG):
654672
logger.debug('MODE = MAIN_HELP_MODE')
655673

674+
def _print_not_implemented_yet(self):
675+
self.previous_operation_mode = self.operation_mode
676+
txt = '''This feature has not been implemented yet...
677+
'''
678+
self._show_help(txt, NOT_IMPLEMENTED_YET_MODE,
679+
caption = ' PyRadio ',
680+
prompt = ' Press any key... ')
681+
656682
def _print_handle_foreign_playlist(self):
657683
txt ='''This is a "foreign" playlist (i.e. it does not
658684
reside in PyRadio's config directory).
@@ -974,6 +1000,9 @@ def _redisplay_transient_window(self):
9741000
elif self.operation_mode == SEARCH_NORMAL_MODE or \
9751001
self.operation_mode == SEARCH_PLAYLIST_MODE:
9761002
self.search.show(self.bodyWin, repaint=True)
1003+
elif self.operation_mode == THEME_MODE:
1004+
self._theme_slector.parent = self.bodyWin
1005+
self._show_theme_selector()
9771006

9781007
def play_random(self):
9791008
# Pick a random radio station
@@ -984,12 +1013,61 @@ def play_random(self):
9841013

9851014
def _toggle_transparency(self):
9861015
self._theme.toggleTransparency()
1016+
if self.operation_mode == THEME_MODE:
1017+
self._theme_slector.transparent = self._theme.getTransparency()
9871018
self.headWin.refresh()
9881019
self.bodyWin.refresh()
9891020
self.footerWin.refresh()
990-
self.cnf.use_transparency = self._theme._transparent
1021+
self.cnf.use_transparency = self._theme.getTransparency()
9911022

9921023
def keypress(self, char):
1024+
1025+
if self.operation_mode == NOT_IMPLEMENTED_YET_MODE:
1026+
self.helpWin = None
1027+
self.operation_mode = self.previous_operation_mode
1028+
if logger.isEnabledFor(logging.DEBUG):
1029+
logger.debug('MODE: Exiting NOT_IMPLEMENTED_YET_MODE')
1030+
self.refreshBody()
1031+
return
1032+
1033+
if char in (ord('t'), ):
1034+
if self.window_mode != THEME_MODE and \
1035+
self.operation_mode != MAIN_HELP_MODE and \
1036+
self.operation_mode != PLAYLIST_HELP_MODE:
1037+
self.previous_operation_mode = self.operation_mode
1038+
self.operation_mode = self.window_mode = THEME_MODE
1039+
1040+
self._show_theme_selector()
1041+
return
1042+
1043+
if self.operation_mode == THEME_MODE:
1044+
if char not in (ord('m'), ord('v'), ord('.'),
1045+
ord(','), ord('+'), ord('-'), ord('T'),
1046+
ord('#'), curses.KEY_RESIZE):
1047+
theme_id, save_theme = self._theme_slector.keypress(char)
1048+
if theme_id == -1:
1049+
""" cancel or hide """
1050+
self._theme_slector = None
1051+
self.operation_mode = self.window_mode = self.previous_operation_mode
1052+
if logger.isEnabledFor(logging.DEBUG):
1053+
if self.operation_mode == NORMAL_MODE:
1054+
logger.debug('MODE: THEME_MODE => NORMAL_MODE')
1055+
else:
1056+
logger.debug('MODE: THEME_MODE => PLAYLIST_HELP_MODE')
1057+
self.refreshBody()
1058+
elif theme_id >= 0:
1059+
""" valid theme selection """
1060+
self._theme_name = self._theme_slector.theme_name(theme_id)
1061+
if logger.isEnabledFor(logging.INFO):
1062+
logger.info('Activating theme: {}'.format(self._theme_name))
1063+
self._theme.readAndApplyTheme(self._theme_name)
1064+
curses.doupdate()
1065+
if save_theme:
1066+
self.cnf.theme = self._theme_name
1067+
if logger.isEnabledFor(logging.INFO):
1068+
logger.info('Setting default theme: {}'.format(self._theme_name))
1069+
return
1070+
9931071
if char in (ord('#'), curses.KEY_RESIZE):
9941072
self.setupAndDrawScreen()
9951073
return

0 commit comments

Comments
 (0)