Skip to content

Commit bba6c6e

Browse files
committed
fixing presentation
1 parent a075c4c commit bba6c6e

File tree

4 files changed

+132
-53
lines changed

4 files changed

+132
-53
lines changed

pyradio/browser.py

+91-48
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from .widechar import cjklen, PY3
88
#from os import get_terminal_size
99

10+
import locale
11+
locale.setlocale(locale.LC_ALL, '') # set your locale
12+
1013
logger = logging.getLogger(__name__)
1114

1215

@@ -320,44 +323,19 @@ def format_station_line(self, id_in_list, pad, width):
320323
empty string
321324
"""
322325

323-
if PY3:
324-
info = ('',
325-
' {0} {1}kb',
326-
' {0}{1} v│{2} cl│{3}kb',
327-
' {0} {1}│ {2}│ {3}kb',
328-
' {0} {1}│ {2}│ {3}kb│{4}',
329-
' {0} {1}│ {2}│ {3}kb│{4}│{5}',
330-
)
331-
else:
332-
info = ('',
333-
' {0} {1}kb',
334-
' {0}{1} v|{2} cl|{3}kb',
335-
' {0} {1}| {2}| {3}kb',
336-
' {0} {1}| {2}| {3}kb|{4}',
337-
' {0} {1}| {2}| {3}kb|{4}|{5}',
338-
)
339-
# now_width = get_terminal_size().columns - 2
340-
now_width = width
341-
if now_width <= 45:
342-
self._output_format = 0
343-
elif now_width <= 55:
344-
self._output_format = 1
345-
elif now_width <= 78:
346-
self._output_format = 2
347-
elif now_width <= 100:
348-
self._output_format = 3
349-
elif now_width <= 125:
350-
self._output_format = 4
351-
else:
352-
self._output_format = 5
353-
326+
info = (u'',
327+
u' {0} {1}kb',
328+
u' {0} {1}│ {2}kb',
329+
u' {0} {1}│ {2}│ {3}kb',
330+
u' {0} {1}│ {2}│ {3}kb│{4}',
331+
u' {0} {1}│ {2}│ {3}kb│{4}│{5}',
332+
)
333+
self._get_output_format(width)
334+
#logger.error('DE self._output_format = {}'.format(self._output_format))
354335
out = ['{0}. '.format(str(id_in_list + 1).rjust(pad)), '', '']
355336

356337
# format info field
357-
if PY3:
358-
pl = u'┼' if self._raw_stations[id_in_list]['played'] else u'│'
359-
else:
360-
pl = '+' if self._raw_stations[id_in_list]['played'] else '|'
338+
pl = u'├' if self._raw_stations[id_in_list]['played'] else u'│'
361339
if self._output_format == 5:
362340
# full with state
363341
out[2] = ' ' + info[self._output_format].format(
@@ -377,7 +355,13 @@ def format_station_line(self, id_in_list, pad, width):
377355
self._raw_stations[id_in_list]['bitrate'].rjust(7)[:7],
378356
self._raw_stations[id_in_list]['country'].ljust(14)[:14]
379357
)
380-
elif self._output_format in (2, 3):
358+
elif self._output_format == 2:
359+
out[2] = ' ' + info[self._output_format].format(
360+
pl,
361+
self._raw_stations[id_in_list]['votes'].rjust(self._max_len[0]),
362+
self._raw_stations[id_in_list]['bitrate'].rjust(7)[:7]
363+
)
364+
elif self._output_format == 3:
381365
out[2] = ' ' + info[self._output_format].format(
382366
pl,
383367
self._raw_stations[id_in_list]['votes'].rjust(self._max_len[0]),
@@ -394,13 +378,17 @@ def format_station_line(self, id_in_list, pad, width):
394378
name_width = width-len(out[0])-len(out[2])
395379
out[1] = self._fix_cjk_string_width(self._raw_stations[id_in_list]['name'].ljust(name_width)[:name_width], name_width)
396380
if PY3:
397-
return '{0}{1}{2}'.format(*out)
381+
# if pl == '╞':
382+
# out[2] += '╡'
383+
return (self._raw_stations[id_in_list]['played'],
384+
'{0}{1}{2}'.format(*out))
398385
else:
399386
# on python 2, strings are already in utf-8
400-
return '{0}{1}{2}'.format(
387+
return (self._raw_stations[id_in_list]['played'],
388+
'{0}{1}{2}'.format(
401389
out[0].encode('utf-8', 'replace'),
402390
out[1].encode('utf-8', 'replace'),
403-
out[2].encode('utf-8', 'replace'))
391+
out[2].encode('utf-8', 'replace')))
404392

405393
def set_encoding(self, id_in_list, new_encoding):
406394
if id_in_list < len(self._raw_stations):
@@ -439,20 +427,16 @@ def _get_max_len(self, votes, clicks):
439427
440428
Parameters
441429
----------
442-
string_data
443-
A tuple (name, country) - (uses cjklen)
444-
country
445-
A string (uses cjklen)
430+
votes
431+
Number of station's vote
432+
clicks
433+
Number of station's clicks
446434
numeric_data
447-
A tuple (bitrate, votes, clickcount)
448435
449436
Returns
450437
-------
451438
self._max_len
452-
A list [max name length (max is 50),
453-
max country length (max is 14),
454-
max bitrate length,
455-
max votes length,
439+
A list [max votes length,
456440
max clickcount length]
457441
"""
458442

@@ -462,6 +446,65 @@ def _get_max_len(self, votes, clicks):
462446
if len(n) > self._max_len[i]:
463447
self._max_len[i] = len(n) if len(n) > min_data[i] else min_data[i]
464448

449+
def _get_output_format(self, width):
450+
""" Return output format based on window width
451+
452+
Paramaters
453+
----------
454+
width
455+
Window width
456+
457+
Returns
458+
-------
459+
self._output_format
460+
A number 0..5
461+
"""
462+
463+
# now_width = get_terminal_size().columns - 2
464+
if width <= 50:
465+
self._output_format = 0
466+
elif width < 57:
467+
self._output_format = 1
468+
elif width < 65:
469+
self._output_format = 2
470+
elif width < 80:
471+
self._output_format = 3
472+
elif width < 95:
473+
self._output_format = 4
474+
else:
475+
self._output_format = 5
476+
477+
def get_columns_separators(self, width, force_py2=False):
478+
if not force_py2 and not PY3:
479+
return []
480+
self._get_output_format(width)
481+
if self._output_format == 0:
482+
return []
483+
elif self._output_format == 1:
484+
return [ width - 10 ]
485+
elif self._output_format == 2:
486+
return [width -18,
487+
width -10
488+
]
489+
elif self._output_format == 3:
490+
return [width -27,
491+
width -19,
492+
width -10
493+
]
494+
elif self._output_format == 4:
495+
return [width -42,
496+
width -34,
497+
width -25,
498+
width -14
499+
]
500+
elif self._output_format == 5:
501+
return [width -58,
502+
width -50,
503+
width -41,
504+
width -30,
505+
width -15
506+
]
507+
465508

466509
class PyRadioBrowserInfoData(object):
467510
""" Read search parameters for radio.browser.info service

pyradio/log.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ def write(self, msg, thread_lock=None, help_msg=False):
3232
thread_lock.acquire()
3333
self.cursesScreen.erase()
3434
try:
35-
self.msg = msg.strip()
36-
self.cursesScreen.addstr(0, 1, self.msg[0: self.width].replace("\r", "").replace("\n", ""))
35+
self.msg = msg.strip()[0: self.width].replace("\r", "").replace("\n", "")
36+
self.cursesScreen.addstr(0, 1, self.msg)
3737
except:
38-
self.msg = msg.encode('utf-8', 'replace').strip()
39-
self.cursesScreen.addstr(0, 1, self.msg[0: self.width].replace("\r", "").replace("\n", ""))
38+
logger.error('DE **** status update python 2 ****')
39+
try:
40+
self.msg = msg.encode('utf-8', 'replace').strip()[0: self.width].replace("\r", "").replace("\n", "")
41+
self.cursesScreen.addstr(0, 1, self.msg)
42+
except:
43+
logger.error('DE **** status update ERROR ****')
44+
pass
4045
if logger.isEnabledFor(logging.DEBUG):
4146
logger.debug('Status: "{}"'.format(self.msg))
4247
self.cursesScreen.refresh()

pyradio/player.py

+8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def updateStatus(self, *args):
197197
subsystemOut = subsystemOutRaw.decode("utf-8", "replace")
198198
if subsystemOut == '':
199199
break
200+
logger.error('DE subsystemOut = "{}"'.format(subsystemOut))
200201
if not self._is_accepted_input(subsystemOut):
201202
continue
202203
subsystemOut = subsystemOut.strip()
@@ -346,10 +347,14 @@ def play(self, name, streamUrl, encoding = ''):
346347
logger.error("playback detection thread start failed")
347348
if logger.isEnabledFor(logging.INFO):
348349
logger.info("Player started")
350+
if self.process and self.PLAYER_CMD == 'mpv':
351+
self._sendCommand('{ "command": ["observe_property", 1, "volume"] }')
349352

350353
def _sendCommand(self, command):
351354
""" send keystroke command to player """
352355

356+
logger.error('DE command to execute: "{}"'.format(command))
357+
353358
if(self.process is not None):
354359
try:
355360
if logger.isEnabledFor(logging.DEBUG):
@@ -428,6 +433,7 @@ def _get_volume(self):
428433
def volumeUp(self):
429434
""" increase volume """
430435
if self.muted is not True:
436+
logger.error('DE self._volumeUp')
431437
self._volume_up()
432438

433439
def _volume_up(self):
@@ -566,7 +572,9 @@ def _stop(self):
566572

567573
def _volume_up(self):
568574
""" increase mpv's volume """
575+
logger.error('DE mpv volume up')
569576
os.system("echo 'cycle volume' | socat - " + self.mpvsocket + " 2>/dev/null");
577+
os.system("echo '{ \"command\": [\"get_property\", \"volume\"] }' | socat - " + self.mpvsocket + " 2>/dev/null");
570578

571579
def _volume_down(self):
572580
""" decrease mpv's volume """

pyradio/radio.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,17 @@ def _print_body_header(self):
492492
if cur_mode == self.ws.THEME_MODE:
493493
cur_mode = self.ws.previous_operation_mode
494494
if cur_mode == self.ws.NORMAL_MODE:
495+
if self._cnf.browsing_station_service:
496+
ticks = self._cnf.online_browser.get_columns_separators(self.bodyMaxX - 2, force_py2=True)
497+
if ticks:
498+
for n in ticks:
499+
if version_info < (3, 0):
500+
self.bodyWin.addstr(0, n, u'┬'.encode('utf-8', 'replace'), curses.color_pair(5))
501+
self.bodyWin.addstr(self.bodyMaxY - 1, n, u'┴'.encode('utf-8', 'replace'), curses.color_pair(5))
502+
else:
503+
self.bodyWin.addstr(0, n, '┬', curses.color_pair(5))
504+
self.bodyWin.addstr(self.bodyMaxY - 1, n, '┴', curses.color_pair(5))
505+
495506
align = 1
496507
w_header = self._cnf.stations_filename_only_no_extension
497508
if self._cnf.dirty_playlist:
@@ -517,31 +528,40 @@ def _print_body_header(self):
517528

518529
def __displayBodyLine(self, lineNum, pad, station):
519530
col = curses.color_pair(5)
531+
sep_col = None
520532
body_width = self.bodyMaxX - 2
521533
if lineNum + self.startPos == self.selection and \
522534
self.selection == self.playing:
523535
col = curses.color_pair(9)
536+
# sep_col = curses.color_pair(5)
524537
self.bodyWin.hline(lineNum + 1, 1, ' ', body_width, col)
525538
elif lineNum + self.startPos == self.selection:
526539
col = curses.color_pair(6)
527540
self.bodyWin.hline(lineNum + 1, 1, ' ', body_width, col)
528541
elif lineNum + self.startPos == self.playing:
529542
col = curses.color_pair(4)
543+
sep_col = curses.color_pair(5)
530544
self.bodyWin.hline(lineNum + 1, 1, ' ', body_width, col)
531545

532546
# self.maxY, self.maxX = self.stdscr.getmaxyx()
547+
#logger.error('DE ==== width = {}'.format(self.maxX - 2))
533548
if self.ws.operation_mode == self.ws.PLAYLIST_MODE or \
534549
self.ws.operation_mode == self.ws.PLAYLIST_LOAD_ERROR_MODE or \
535550
self.ws.operation_mode == self.ws.PLAYLIST_NOT_FOUND_ERROR_MODE:
536551
line = self._format_playlist_line(lineNum, pad, station)
537552
self.bodyWin.addstr(lineNum + 1, 1, line, col)
538553
else:
539554
if self._cnf.browsing_station_service:
540-
line = self._cnf.online_browser.format_station_line(lineNum + self.startPos, pad, self.maxX - 2)
555+
played, line = self._cnf.online_browser.format_station_line(lineNum + self.startPos, pad, self.maxX - 2)
541556
else:
542557
line = self._format_station_line("{0}. {1}".format(str(lineNum + self.startPos + 1).rjust(pad), station[0]))
543558
self.bodyWin.addstr(lineNum + 1, 1, line, col)
544559

560+
if self._cnf.browsing_station_service and sep_col:
561+
ticks = self._cnf.online_browser.get_columns_separators(self.bodyMaxX - 2, force_py2=True)
562+
for n in ticks:
563+
self.bodyWin.chgat(lineNum + 1, n, 1, sep_col)
564+
545565
def run(self):
546566
if self.ws.operation_mode == self.ws.NO_PLAYER_ERROR_MODE:
547567
if platform.startswith('win'):
@@ -3285,11 +3305,14 @@ def keypress(self, char):
32853305
self.refreshBody()
32863306

32873307
def _volume_up(self):
3308+
logger.error('DE entering radio._volume_up')
32883309
self.jumpnr = ''
32893310
self._random_requested = False
32903311
if self.player.isPlaying():
3312+
logger.error('DE isPlaying radio._volume_up')
32913313
if self.player.playback_is_on:
32923314
self.player.volumeUp()
3315+
logger.error('DE playback_is_on radio._volume_up')
32933316
else:
32943317
if self.ws.operation_mode in self.ws.PASSIVE_WINDOWS:
32953318
self.ws.close_window()

0 commit comments

Comments
 (0)