Skip to content

Commit d120654

Browse files
committed
adding System / User title to theme window
1 parent 0e3b13e commit d120654

File tree

5 files changed

+75
-20
lines changed

5 files changed

+75
-20
lines changed

README.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ <h2 id="pyradio-themes">PyRadio Themes</h2>
233233
<li><strong>white_on_black</strong> or <strong>wob</strong> (256 color b&amp;w theme). A theme for dark terminal background settings.</li>
234234
<li><strong>black_on_white</strong> or <strong>bow</strong> (256 color b&amp;w theme). A theme for light terminal background settings.</li>
235235
</ol>
236+
<p>and three 256-color system themes (these are actual files saved in the <strong>themes</strong> installation directory): 1. <strong>brown_by_sng</strong>, <strong>pink_by_sng</strong> and <strong>purple_by_sng</strong>.</p>
236237
<p>The visual result of an applied theme greatly depends on the terminal settings (e.g. foreground and background color settings, palette used, number of colors supported, real or pseudo-transparency support, etc.)</p>
237238
<p>Pressing “<strong>t</strong>” will bring up the <em>Theme selection window</em>, which can be used to activate a theme and set the default one.</p>
238239
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> Themes that use more colors than those supported by the terminal in use, will not be present in the <em>Theme selection window</em>. Furthermore, if a such at theme is set as default (or requested using the “<strong>-t</strong>” command line option), <strong>PyRadio</strong> will silently fall-back to the “<strong>dark</strong>” theme (or the “<strong>light</strong>” theme, if the terminal supports 8 colors and default theme is set to “<em>light_16_colors</em>”).</p>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ Example:
332332
5. **white_on_black** or **wob** (256 color b&w theme). A theme for dark terminal background settings.
333333
6. **black_on_white** or **bow** (256 color b&w theme). A theme for light terminal background settings.
334334

335+
and three 256-color system themes (these are actual files saved in the **themes** installation directory): 1. **brown_by_sng**, **pink_by_sng** and **purple_by_sng**.
336+
335337
The visual result of an applied theme greatly depends on the terminal settings (e.g. foreground and background color settings, palette used, number of colors supported, real or pseudo-transparency support, etc.)
336338

337339
Pressing "**t**" will bring up the *Theme selection window*, which can be used to activate a theme and set the default one.

pyradio.1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Since we know \fBall stations\fR must comprise the third (encoding) column, we a
239239
\fIStation1\fB,\fIStation1_URL\fB,
240240

241241
.PP
242-
This way we add an empty encoding, forcing
242+
This way we add an empty encoding, forcing
243243
.PP
244244
Finally, we insert the new station to the playlist:
245245

@@ -358,6 +358,9 @@ A theme for dark terminal background settings.
358358
.IP \fBblack_on_white\fR\ or\ \fBbow\fR\ (256\ color\ b&w\ theme)
359359
A theme for light terminal background settings.
360360

361+
.PP
362+
and three 256-color system themes (these are actual files saved in the \fIthemes\fR installation directory): \fBbrown_by_sng\fR, \fBpink_by_sng\fR and \fBpurple_by_sng\fR.
363+
361364
.PP
362365
The visual result of an applied theme greatly depends on the terminal settings (e.g. foreground and background color settings, palette used, number of colors supported, real or pseudo-transparency support, etc.)
363366

@@ -375,7 +378,7 @@ The use of custom themes and theme editing is not implemented yet; theses are fe
375378

376379
\fBpyradio\fR themes are able to be used with a transparent background.
377380

378-
Pressing "\fBT\fR" will toggle the transparency setting (it is \fIoff\fR by default) and save this state in \fBpyradio\fR's configuration file.
381+
Pressing "\fBT\fR" will toggle the transparency setting (it is \fIoff\fR by default) and save this state in \fBpyradio\fR's configuration file.
379382

380383
Setting transparency on, will actually force \fBpyradio\fR to not use its own background color, effectively making it to display whatever is on the terminal (color/picture/transparency). The visual result depends on terminal settings and whether a compositor is running.
381384

pyradio/radio.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,10 @@ def _print_save_playlist_error_2(self):
11691169

11701170
def _print_ask_to_create_theme(self):
11711171
txt ='''You have requested to edit a |read-only| theme,
1172-
which is not possible.
1172+
which is not possible. Do you want to create a
1173+
new theme instead?
11731174
1174-
Do you want to create a new theme instead?
1175-
1176-
Press "|y|" to accept or "|n|" to reject'''
1175+
Press "|y|" to accept or any other key to cancel.'''
11771176
self._show_help(txt, ASK_TO_CREATE_NEW_THEME_MODE,
11781177
caption = ' Read-only theme ',
11791178
prompt = ' ',
@@ -1430,9 +1429,9 @@ def _redisplay_transient_window(self):
14301429
self._show_theme_selector_from_config()
14311430
else:
14321431
self._show_theme_selector()
1433-
self._print_ask_to_create_theme()
14341432
if self.theme_forced_selection:
14351433
self._theme_selector.set_theme(self.theme_forced_selection)
1434+
self._print_ask_to_create_theme()
14361435

14371436
def play_random(self):
14381437
# Pick a random radio station
@@ -1757,14 +1756,13 @@ def keypress(self, char):
17571756
#else:
17581757
# """ error """
17591758
# self._print_foreign_playlist_copy_error()
1760-
elif char in (ord('n'), ):
1761-
self.operation_mode = THEME_MODE
1762-
self.refreshBody()
1763-
if logger.isEnabledFor(logging.DEBUG):
1764-
logger.debug('MODE: Cancel ASK_TO_CREATE_NEW_THEME_MODE -> THEME_MODE')
17651759
elif not char in (ord('#'), curses.KEY_RESIZE):
1766-
# Do this here to properly resize
1767-
return
1760+
self.operation_mode = THEME_MODE
1761+
self.refreshBody()
1762+
if logger.isEnabledFor(logging.DEBUG):
1763+
logger.debug('MODE: Cancel ASK_TO_CREATE_NEW_THEME_MODE -> THEME_MODE')
1764+
# Do this here to properly resize
1765+
return
17681766

17691767
elif self.operation_mode == THEME_MODE:
17701768
if char not in (ord('m'), ord('v'), ord('.'),

pyradio/themes.py

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class PyRadioThemeSelector(object):
351351
selection = _selection = _start_pos = _items = 0
352352

353353
_themes = []
354+
_title_ids = []
354355

355356
# display the 2 internal 8 color themes
356357
_items = 2
@@ -421,6 +422,7 @@ def show(self):
421422
if themes_to_add:
422423
self._themes.extend(themes_to_add)
423424
self._items = len(self._themes)
425+
self._get_titles_ids()
424426

425427
for a_theme in self._themes:
426428
if len(a_theme[0]) > self._max_title_width:
@@ -439,18 +441,34 @@ def _scan_for_theme_files(self, cnf_path, user_themes_first=False):
439441
path.join(cnf_path, 'themes') ]
440442
if user_themes_first:
441443
theme_dirs.reverse()
442-
for theme_dir in theme_dirs:
444+
for i, theme_dir in enumerate(theme_dirs):
443445
logger.error('DE theme_dir = "{}"'.format(theme_dir))
444446
files = glob.glob(path.join(theme_dir, '*.pyradio-theme'))
445447
logger.error('DE {}'.format(files))
446448
if files:
449+
tmp_themes = []
447450
for a_file in files:
448451
theme_name, ret = self._can_use_theme(a_file)
449452
if ret:
450-
out_themes.append([ theme_name, a_file ])
453+
tmp_themes.append([ theme_name, a_file ])
454+
if tmp_themes:
455+
tmp_themes.sort()
456+
tmp_themes.reverse()
457+
if i == 0:
458+
tmp_themes.append(['System Themes', '-'])
459+
else:
460+
tmp_themes.append(['User Themes', '-'])
461+
tmp_themes.reverse()
462+
out_themes.extend(tmp_themes)
451463
logger.error('DE {}'.format(out_themes))
452464
return out_themes
453465

466+
def _get_titles_ids(self):
467+
for i, a_theme in enumerate(self._themes):
468+
if a_theme[1] == '-':
469+
self._title_ids.append(i)
470+
logger.info('DE self._title_ids = {}'.format(self._title_ids))
471+
454472
def _can_use_theme(self, a_theme):
455473
""" Check if theme name contains number of colors.
456474
If so, check if the theme can be used on this terminal
@@ -545,7 +563,7 @@ def _get_metrics(self):
545563

546564
self._page_jump = int(self._items / 2)
547565
self._win = None
548-
self._win=curses.newwin(self._height, self._width, self.Y, self.X)
566+
self._win = curses.newwin(self._height, self._width, self.Y, self.X)
549567
self._win.bkgdset(' ', curses.color_pair(self._box_color_pair))
550568
#self._win.erase()
551569
self._draw_box()
@@ -608,7 +626,9 @@ def refresh(self):
608626
self.log('{}\n'.format(self._themes))
609627
for i in range(self._start_pos, self._start_pos + self._items):
610628
token = ' '
611-
if self._start_pos + i == self.selection:
629+
if i in self._title_ids:
630+
col = curses.color_pair(self._title_color_pair)
631+
elif self._start_pos + i == self.selection:
612632
# on selection, display cursor
613633
if self._selection == self._applied_theme:
614634
col = curses.color_pair(self._applied_cursor_color_pair)
@@ -622,7 +642,27 @@ def refresh(self):
622642
self._win.hline(i + 1, 1, ' ', self._max_title_width + 2, col)
623643
if self._start_pos + i == self._config_theme:
624644
token = '*'
625-
self._win.addstr(i+1, 1, token + self._themes[i][0], col)
645+
if i in self._title_ids:
646+
self._win.move(i + 1, 0)
647+
try:
648+
self._win.addstr('├', curses.color_pair(3))
649+
self._win.move(i + 1, len(self._themes[i][0]) + 3)
650+
self._win.addstr('─' * (self._width - 2 - len(self._themes[i][0]) - 2), curses.color_pair(3))
651+
try:
652+
self._win.addstr('┤', curses.color_pair(3))
653+
except:
654+
pass
655+
except:
656+
self._win.addstr('├'.encode('utf-8'), curses.color_pair(3))
657+
self._win.move(i + 1, len(self._themes[i][0]) + 2)
658+
self._win.addstr('─'.encode('utf-8') * (self._width - 2 - len(self._themes[i][0]) - 2), curses.color_pair(3))
659+
try:
660+
self._win.addstr('┤'.encode('utf-8'), curses.color_pair(3))
661+
except:
662+
pass
663+
self._win.addstr(i+1, 1, token + self._themes[i][0], col)
664+
else:
665+
self._win.addstr(i+1, 1, token + self._themes[i][0], col)
626666

627667
try:
628668
self._win.move(sel, self._width - 2)
@@ -632,7 +672,8 @@ def refresh(self):
632672
if self._transparent:
633673
self._win.addstr(self._height-1, self._width -4, '[T]', curses.color_pair(self._box_color_pair))
634674
else:
635-
self._draw_box()
675+
pass
676+
#self._draw_box()
636677
self._win.refresh()
637678
curses.doupdate()
638679

@@ -643,6 +684,8 @@ def _draw_box(self):
643684

644685
def _go_up(self):
645686
self._selection -= 1
687+
if self._selection in self._title_ids:
688+
self._selection -= 1
646689
if self._selection < 0:
647690
self.selection = len(self._themes) - 1
648691
elif self._selection == self._start_pos -1:
@@ -651,6 +694,8 @@ def _go_up(self):
651694

652695
def _go_down(self):
653696
self._selection += 1
697+
if self._selection in self._title_ids:
698+
self._selection += 1
654699
if self._selection == len(self._themes):
655700
self.selection = 0
656701
elif self._selection == self._start_pos + self._items:
@@ -739,12 +784,16 @@ def keypress(self, char):
739784
self._go_end()
740785
else:
741786
num = int(self.jumpnr) - 1
787+
if num in self._title_ids:
788+
num += 1
742789
if num >= 0:
743790
self.selection = num
744791
self.jumpnr = ''
745792
elif char in (curses.KEY_NPAGE, ):
746793
self.jumpnr = ''
747794
sel = self._selection + self._page_jump
795+
if sel in self._title_ids:
796+
sel += 1
748797
if self._selection == len(self._themes) - 1:
749798
sel = 0
750799
elif sel >= len(self._themes):
@@ -753,6 +802,8 @@ def keypress(self, char):
753802
elif char in (curses.KEY_PPAGE, ):
754803
self.jumpnr = ''
755804
sel = self._selection - self._page_jump
805+
if sel in self._title_ids:
806+
sel -= 1
756807
if self._selection == 0:
757808
sel = len(self._themes) - 1
758809
elif sel < 0:

0 commit comments

Comments
 (0)