Skip to content

Commit 8b063e1

Browse files
committed
starting theming
1 parent c183952 commit 8b063e1

File tree

10 files changed

+409
-88
lines changed

10 files changed

+409
-88
lines changed

Changelog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-02-22 s-n-g
2+
3+
* Theme support added (4 hardcoded themes)
4+
* Command line option -t (--theme) THEME added
5+
* Config option "theme" added
6+
* Key "T" will toggle transparency / use terminal's background color
7+
* Alt keyboard combinations will not be considered as ESCAPE char
8+
19
2019-02-10 s-n-g
210

311
* Version 0.7.1

README.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ <h2 id="table-of-contents">Table of contents</h2>
3939
<li><a href="#specifying-stations-encoding">Specifying stations’ encoding</a></li>
4040
<li><a href="#player-detection-selection">Player detection / selection</a></li>
4141
<li><a href="#player-default-volume-level">Player default volume level</a></li>
42+
<li><a href="#pyradio-themes">PyRadio Themes</a></li>
4243
<li><a href="#debug-mode">Debug mode</a></li>
4344
</ul>
4445
<h2 id="requirements">Requirements</h2>
@@ -54,7 +55,7 @@ <h2 id="command-line-options">Command line options</h2>
5455
<pre>$ pyradio -h
5556

5657
usage: pyradio [-h] [-s STATIONS] [-p [PLAY]] [-u USE_PLAYER] [-a] [-ls] [-l]
57-
[-scd] [-ocd] [-d]
58+
[-t THEME] [-scd] [-ocd] [-d]
5859

5960
Curses based Internet radio player
6061

@@ -70,8 +71,11 @@ <h2 id="command-line-options">Command line options</h2>
7071
used to specify detection order. Supported players:
7172
mpv, mplayer, vlc.
7273
-a, --add Add station to list.
73-
-ls, --list-playlists List of available playlists in config dir.
74+
-ls, --list-playlists
75+
List of available playlists in config dir.
7476
-l, --list List of available stations in a playlist.
77+
-t THEME, --theme THEME
78+
Use specified theme.
7579
-scd, --show-config-dir
7680
Print config directory location and exit.
7781
-ocd, --open-config-dir
@@ -82,6 +86,7 @@ <h2 id="command-line-options">Command line options</h2>
8286
<li><strong>-s</strong> - parameter <strong>default_playlist</strong> (default value: <strong>stations</strong>)</li>
8387
<li><strong>-p</strong> - parameter <strong>default_station</strong> (default value: <strong>-1</strong>)</li>
8488
<li><strong>-u</strong> - parameter <strong>player</strong> (default value: <strong>mpv, mplayer, vlc</strong>)</li>
89+
<li><strong>-t</strong> - parameter <strong>theme</strong> (default value: <strong>dark</strong>)</li>
8590
</ul>
8691
<h2 id="controls">Controls</h2>
8792
<pre>Up/Down/j/k/PgUp/PgDown Change station selection.
@@ -95,6 +100,7 @@ <h2 id="controls">Controls</h2>
95100
v Save volume (not applicable for vlc).
96101
o s R Open / Save / Reload playlist.
97102
DEL,x Delete selected station.
103+
t T Load theme / Toggle transparency.
98104
? Show keys help.
99105
Esc/q Quit.</pre>
100106
<h2 id="config-file">Config file</h2>
@@ -212,6 +218,14 @@ <h3 id="mplayer">MPlayer</h3>
212218
[pyradio]
213219
volstep=1
214220
volume=28</pre>
221+
<h2 id="pyradio-themes">PyRadio Themes</h2>
222+
<p><strong>PyRadio</strong> comes with 4 preconfigured (hardcoded) themes:</p>
223+
<ol type="1">
224+
<li><strong>dark</strong> (8 color theme). This is the appearance <strong>PyRadio</strong> has always had. Enabled by default.</li>
225+
<li><strong>light</strong> (8 color thmem). A theme for light terminal background settings.</li>
226+
<li><strong>white_on_black</strong> or <strong>wob</strong> (256 color b&amp;w theme). A theme for dark terminal background settings.</li>
227+
<li><strong>black_on_white</strong> or <strong>bow</strong> (256 color b&amp;w theme). A theme for light terminal background settings.</li>
228+
</ol>
215229
<h2 id="debug-mode">Debug mode</h2>
216230
<p>Adding the <strong><em>-d</em></strong> option to the command line will instruct <strong>PyRadio</strong> to enter <em>Debug mode</em>, which means that it will print debug messages to a file. This file will always reside in the user’s home directory and will be named <em>pyradio.log</em>.</p>
217231
<p>In case of a bug or a glitch, please include this file to the issue you will <a href="https://github.com/coderholic/pyradio/issues">open in github</a>.</p>

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
1515
* [Specifying stations' encoding](#specifying-stations-encoding)
1616
* [Player detection / selection](#player-detection-selection)
1717
* [Player default volume level](#player-default-volume-level)
18+
* [PyRadio Themes](#pyradio-themes)
1819
* [Debug mode](#debug-mode)
1920

2021
## Requirements
@@ -35,7 +36,7 @@ In any other case, and since **PyRadio** is currently not available via pip, you
3536
$ pyradio -h
3637
3738
usage: pyradio [-h] [-s STATIONS] [-p [PLAY]] [-u USE_PLAYER] [-a] [-ls] [-l]
38-
[-scd] [-ocd] [-d]
39+
[-t THEME] [-scd] [-ocd] [-d]
3940
4041
Curses based Internet radio player
4142
@@ -51,8 +52,11 @@ optional arguments:
5152
used to specify detection order. Supported players:
5253
mpv, mplayer, vlc.
5354
-a, --add Add station to list.
54-
-ls, --list-playlists List of available playlists in config dir.
55+
-ls, --list-playlists
56+
List of available playlists in config dir.
5557
-l, --list List of available stations in a playlist.
58+
-t THEME, --theme THEME
59+
Use specified theme.
5660
-scd, --show-config-dir
5761
Print config directory location and exit.
5862
-ocd, --open-config-dir
@@ -65,6 +69,7 @@ The following options can also be set in **PyRadio**'s [configuration file](#con
6569
* **-s** - parameter **default_playlist** (default value: **stations**)
6670
* **-p** - parameter **default_station** (default value: **-1**)
6771
* **-u** - parameter **player** (default value: **mpv, mplayer, vlc**)
72+
* **-t** - parameter **theme** (default value: **dark**)
6873

6974
## Controls
7075

@@ -80,6 +85,7 @@ m Mute.
8085
v Save volume (not applicable for vlc).
8186
o s R Open / Save / Reload playlist.
8287
DEL,x Delete selected station.
88+
t T Load theme / Toggle transparency.
8389
? Show keys help.
8490
Esc/q Quit.
8591
```
@@ -304,6 +310,15 @@ Example:
304310
volstep=1
305311
volume=28
306312

313+
## PyRadio Themes
314+
315+
**PyRadio** comes with 4 preconfigured (hardcoded) themes:
316+
317+
1. **dark** (8 color theme). This is the appearance **PyRadio** has always had. Enabled by default.
318+
2. **light** (8 color thmem). A theme for light terminal background settings.
319+
3. **white_on_black** or **wob** (256 color b&w theme). A theme for dark terminal background settings.
320+
4. **black_on_white** or **bow** (256 color b&w theme). A theme for light terminal background settings.
321+
307322
## Debug mode
308323

309324
Adding the ***-d*** option to the command line will instruct **PyRadio** to enter *Debug mode*, which means that it will print debug messages to a file. This file will always reside in the user's home directory and will be named *pyradio.log*.

pyradio/config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ default_encoding = utf-8
5252
# Default value: 10
5353
connection_timeout = 10
5454

55+
# Default theme
56+
# Hardcooded themes:
57+
# dark (default) (8 colors)
58+
# light (8 colors
59+
# black_on_white (bow) (256 colors)
60+
# white_on_black (wob) (256 colors)
61+
# Default value = 'dark'
62+
theme = dark
63+
64+
# Transparency setting
65+
# If False, theme colors will be used.
66+
# If True and a compositor is running, the stations' window
67+
# background will be transparent. If True and a compositor is
68+
# not running, the terminal's background color will be used.
69+
# Valid values: True, true, False, false
70+
# Default value: False
71+
use_transparency = False
72+
5573

5674
# Playlist management
5775
#

pyradio/config.py

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from shutil import copyfile, move
99
from .log import Log
1010

11+
1112
logger = logging.getLogger(__name__)
1213

1314

@@ -269,7 +270,7 @@ def save_playlist_file(self, stationFile=''):
269270
else:
270271
st_file = self.stations_file
271272

272-
if self.dirty_playlist is False:
273+
if not self.dirty_playlist:
273274
if logger.isEnabledFor(logging.DEBUG):
274275
logger.debug('Playlist not modified...')
275276
return 0
@@ -415,6 +416,8 @@ def __init__(self):
415416
self.default_station = '-1'
416417
self.default_encoding = 'utf-8'
417418
self.connection_timeout = '10'
419+
self.theme = 'dark'
420+
self.use_transparency = False
418421

419422
self.dirty_config = False
420423

@@ -443,6 +446,15 @@ def player_to_use(self, val):
443446
self.__player_to_use = val
444447
self.__dirty_config = True
445448

449+
@property
450+
def use_transparency(self):
451+
return self.__use_transparency
452+
453+
@use_transparency.setter
454+
def use_transparency(self, val):
455+
self.__use_transparency = val
456+
self.__dirty_config = True
457+
446458
@property
447459
def default_encoding(self):
448460
return self.__default_encoding
@@ -506,6 +518,15 @@ def connection_timeout(self, val):
506518
self.__connection_timeout = val
507519
self.__dirty_config = True
508520

521+
@property
522+
def theme(self):
523+
return self.__theme
524+
525+
@theme.setter
526+
def theme(self, val):
527+
self.__theme = val
528+
self.__dirty_config = True
529+
509530
@property
510531
def dirty_config(self):
511532
return self.__dirty_config
@@ -515,13 +536,21 @@ def dirty_config(self, val):
515536
self.__dirty_config = val
516537

517538
def _check_config_file(self, usr):
518-
''' Make sure a config file exists in the config diro '''
539+
''' Make sure a config file exists in the config dir '''
540+
package_config_file = path.join(path.dirname(__file__), 'config')
541+
user_config_file = path.join(usr, 'config')
519542

520-
config_file = path.join(path.dirname(__file__), 'config')
521-
if path.exists(path.join(usr, 'config')):
522-
return
523-
else:
524-
copyfile(config_file, path.join(usr, 'config'))
543+
''' restore config from bck file '''
544+
if path.exists(user_config_file + '.restore'):
545+
try:
546+
copyfile(user_config_file + '.restore', user_config_file))
547+
remove(self.user_config_file + '.restore')
548+
except:
549+
pass
550+
551+
''' Copy package config into user dir '''
552+
if not path.exists(user_config_file):
553+
copyfile(package_config_file, user_config_file))
525554

526555
def read_config(self):
527556
lines = []
@@ -544,12 +573,14 @@ def read_config(self):
544573
self.__connection_timeout = sp[1].strip()
545574
elif sp[0] == 'default_encoding':
546575
self.__default_encoding = sp[1].strip()
576+
elif sp[0] == 'theme':
577+
self.__theme = sp[1].strip()
547578
elif sp[0] == 'default_playlist':
548579
self.__default_playlist = sp[1].strip()
549580
elif sp[0] == 'default_station':
550581
st = sp[1].strip()
551582
if st == '-1':
552-
self.__default_station = False
583+
self.__default_station = 'False'
553584
elif st == 'random':
554585
self.__default_station = None
555586
else:
@@ -569,11 +600,16 @@ def read_config(self):
569600
self.__auto_save_playlist = True
570601
else:
571602
self.__auto_save_playlist = False
603+
elif sp[0] == 'use_transparency':
604+
if sp[1].lower() == 'true':
605+
self.__use_transparency = True
606+
else:
607+
self.__use_transparency = False
572608
self.__dirty_config = False
573609
return 0
574610

575611
def _save_config(self):
576-
if self.__dirty_config is False:
612+
if not self.__dirty_config:
577613
if logger.isEnabledFor(logging.INFO):
578614
logger.info('Config not saved (not modified)')
579615
return 0
@@ -634,29 +670,48 @@ def _save_config(self):
634670
# Default value: 10
635671
connection_timeout = {4}
636672
673+
# Default theme
674+
# Hardcooded themes:
675+
# dark (default) (8 colors)
676+
# light (8 colors
677+
# black_on_white (bow) (256 colors)
678+
# white_on_black (wob) (256 colors)
679+
# Default value = 'dark'
680+
theme = {5}
681+
682+
# Transparency setting
683+
# If False, theme colors will be used.
684+
# If True and a compositor is running, the stations' window
685+
# background will be transparent. If True and a compositor is
686+
# not running, the terminal's background color will be used.
687+
# Valid values: True, true, False, false
688+
# Default value: False
689+
use_transparency = {6}
690+
691+
637692
# Playlist management
638693
#
639694
# Specify whether you will be asked to confirm
640695
# every station deletion action
641696
# Valid values: True, true, False, false
642697
# Default value: True
643-
confirm_station_deletion = {5}
698+
confirm_station_deletion = {7}
644699
645700
# Specify whether you will be asked to confirm
646701
# playlist reloading, when the playlist has not
647702
# been modified within Pyradio
648703
# Valid values: True, true, False, false
649704
# Default value: True
650-
confirm_playlist_reload = {6}
705+
confirm_playlist_reload = {8}
651706
652707
# Specify whether you will be asked to save a
653708
# modified playlist whenever it needs saving
654709
# Valid values: True, true, False, false
655710
# Default value: False
656-
auto_save_playlist = {7}
711+
auto_save_playlist = {9}
657712
658713
'''
659-
copyfile(self.config_file, self.config_file + '.bck')
714+
copyfile(self.config_file, self.config_file + '.restore')
660715
if self.__default_station is None:
661716
self.__default_station = '-1'
662717
try:
@@ -665,7 +720,9 @@ def _save_config(self):
665720
self.__default_playlist,
666721
self.__default_station,
667722
self.__default_encoding,
668-
self,__connection_timeout,
723+
self.__connection_timeout,
724+
self.__theme,
725+
self.__use_transparency,
669726
self.__confirm_station_deletion,
670727
self.__confirm_playlist_reload,
671728
self.__auto_save_playlist))
@@ -674,7 +731,7 @@ def _save_config(self):
674731
logger.error('Error saving config')
675732
return -1
676733
try:
677-
remove(self.config_file + '.bck')
734+
remove(self.config_file + '.restore')
678735
except:
679736
pass
680737
if logger.isEnabledFor(logging.INFO):

pyradio/edit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def show(self, parent_win, repaint=False):
3838
self._caption_win.addstr(0, x-1, u'\u2524'.encode('utf-8'), self.box_color)
3939
except:
4040
pass
41-
if repaint is False:
41+
if not repaint:
4242
self.string = ''
4343
self._curs_pos = 0
4444
self._input_history.reset_index()

0 commit comments

Comments
 (0)