Skip to content

Commit c8e47a7

Browse files
committed
speeding up empty Radio Browser lines rendering
1 parent c88bdda commit c8e47a7

File tree

2 files changed

+56
-45
lines changed

2 files changed

+56
-45
lines changed

pyradio/player.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,13 +1632,7 @@ def _connect_to_socket(self, server_address):
16321632
try:
16331633
sock.connect(server_address)
16341634
return sock
1635-
except socket.gaierror as gaierror:
1636-
sock.close()
1637-
return None
1638-
except socket.herror as herror:
1639-
sock.close()
1640-
return None
1641-
except socket.error as err:
1635+
except:
16421636
sock.close()
16431637
return None
16441638

pyradio/radio.py

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def _print_body_header(self):
813813
w_header, curses.color_pair(4)
814814
)
815815

816-
def __displayBodyLine(self, lineNum, pad, station):
816+
def __displayBodyLine(self, lineNum, pad, station, return_line=False):
817817
col = curses.color_pair(5)
818818
sep_col = None
819819
# logger.error('DE selection = {0},{1},{2},{3}'.format(
@@ -826,31 +826,33 @@ def __displayBodyLine(self, lineNum, pad, station):
826826
# self.selections[0][0],
827827
# self.selections[0][1],
828828
# self.selections[0][2]))
829-
if station:
830-
if lineNum + self.startPos == self.selection and \
831-
self.selection == self.playing:
832-
col = curses.color_pair(9)
833-
''' initialize col_sep here to have separated cursor '''
834-
sep_col = curses.color_pair(5)
835-
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
836-
elif lineNum + self.startPos == self.selection:
837-
col = curses.color_pair(6)
838-
''' initialize col_sep here to have separated cursor '''
839-
sep_col = curses.color_pair(5)
840-
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
841-
elif lineNum + self.startPos == self.playing:
842-
col = curses.color_pair(4)
843-
sep_col = curses.color_pair(5)
844-
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
845-
else:
846-
''' this is only for a browser service '''
847-
col = curses.color_pair(5)
829+
if not return_line:
830+
if station:
831+
if lineNum + self.startPos == self.selection and \
832+
self.selection == self.playing:
833+
col = curses.color_pair(9)
834+
''' initialize col_sep here to have separated cursor '''
835+
sep_col = curses.color_pair(5)
836+
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
837+
elif lineNum + self.startPos == self.selection:
838+
col = curses.color_pair(6)
839+
''' initialize col_sep here to have separated cursor '''
840+
sep_col = curses.color_pair(5)
841+
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
842+
elif lineNum + self.startPos == self.playing:
843+
col = curses.color_pair(4)
844+
sep_col = curses.color_pair(5)
845+
self.bodyWin.hline(lineNum, 0, ' ', self.bodyMaxX, col)
846+
else:
847+
''' this is only for a browser service '''
848+
col = curses.color_pair(5)
848849

849850
## self.maxY, self.maxX = self.stdscr.getmaxyx()
850851
## logger.error('DE ==== width = {}'.format(self.maxX - 2))
851852
#if self.ws.operation_mode == self.ws.PLAYLIST_MODE or \
852853
# self.ws.operation_mode == self.ws.PLAYLIST_LOAD_ERROR_MODE or \
853854
# self.ws.operation_mode == self.ws.PLAYLIST_NOT_FOUND_ERROR_MODE:
855+
854856
if self.ws.window_mode == self.ws.PLAYLIST_MODE:
855857
line = self._format_playlist_line(lineNum, pad, station)
856858
try:
@@ -864,18 +866,25 @@ def __displayBodyLine(self, lineNum, pad, station):
864866
else:
865867
played, line = self._cnf.online_browser.format_empty_line(self.bodyMaxX)
866868
else:
867-
line = self._format_station_line("{0}. {1}".format(str(lineNum + self.startPos + 1).rjust(pad), station[0]))
869+
if station:
870+
line = self._format_station_line("{0}. {1}".format(str(lineNum + self.startPos + 1).rjust(pad), station[0]))
871+
else:
872+
line = ' ' * (self.bodyMaxX - 2)
873+
874+
if return_line:
875+
''' return empty line '''
876+
return line
877+
868878
try:
869879
self.bodyWin.addstr(lineNum, 0, line, col)
870880
except:
871881
pass
872882

873-
if station:
874-
if self._cnf.browsing_station_service and sep_col:
875-
ticks = self._cnf.online_browser.get_columns_separators(self.bodyMaxX, adjust_for_body=True)
876-
if ticks:
877-
for n in ticks:
878-
self.bodyWin.chgat(lineNum, n, 1, sep_col)
883+
if station and self._cnf.browsing_station_service and sep_col:
884+
ticks = self._cnf.online_browser.get_columns_separators(self.bodyMaxX, adjust_for_body=True)
885+
if ticks:
886+
for n in ticks:
887+
self.bodyWin.chgat(lineNum, n, 1, sep_col)
879888

880889
def run(self):
881890
self._register_signals_handlers()
@@ -2997,7 +3006,8 @@ def _show_connect_to_server_message(self):
29973006
29983007
To be used with onlines services only
29993008
'''
3000-
txt = '''Connecting to service. Please wait...'''
3009+
txt = '''Connecting to service.
3010+
____Please wait...'''
30013011
self._show_help(txt, self.ws.NORMAL_MODE, caption=' ', prompt=' ', is_message=True)
30023012

30033013
def _open_playlist(self, a_url=None):
@@ -6466,22 +6476,21 @@ def _find_renamed_selection(self, mode, search_path, search_file):
64666476
def _redisplay_stations_and_playlists(self):
64676477
if self._limited_height_mode:
64686478
return
6469-
self.bodyWin.erase()
64706479
self.outerBodyWin.erase()
6480+
if self._redisplay_list[-1][0] ==self.ws.BROWSER_SEARCH_MODE and \
6481+
self._redisplay_list[-2][0] == self.ws.NORMAL_MODE:
6482+
if logger.isEnabledFor(logging.DEBUG):
6483+
logger.debug('---=== Not displaying stations (Radio Browser window follows) ===---')
6484+
self.outerBodyWin.refresh()
6485+
return
6486+
self.bodyWin.erase()
64716487
if self.maxY > 2:
64726488
self.outerBodyWin.box()
64736489
try:
64746490
self.bodyWin.move(1, 1)
64756491
self.bodyWin.move(0, 0)
64766492
except:
64776493
pass
6478-
if self._redisplay_list[-1][0] ==self.ws.BROWSER_SEARCH_MODE and \
6479-
self._redisplay_list[-2][0] == self.ws.NORMAL_MODE:
6480-
if logger.isEnabledFor(logging.DEBUG):
6481-
logger.debug('---=== Not displaying stations (Radio Browser window follows) ===---')
6482-
self.outerBodyWin.refresh()
6483-
self.bodyWin.refresh()
6484-
return
64856494
self._print_body_header()
64866495
pad = len(str(self.startPos + self.bodyMaxY))
64876496

@@ -6493,17 +6502,25 @@ def _redisplay_stations_and_playlists(self):
64936502
self.__displayBodyLine(lineNum, pad, self.stations[i])
64946503
else:
64956504
''' display browser empty lines (station=None) '''
6505+
line = self.__displayBodyLine(0, pad, None, return_line = True)
64966506
if self._cnf.browsing_station_service:
64976507
for n in range(i+1, self.bodyMaxY + 1):
6498-
self.__displayBodyLine(lineNum, pad, None)
6508+
try:
6509+
self.bodyWin.addstr(lineNum, 0, line, curses.color_pair(5))
6510+
except:
6511+
pass
64996512
lineNum += 1
65006513
break
65016514
else:
65026515
''' we have no stations to display '''
65036516
if self._cnf.browsing_station_service:
65046517
''' we have to display emplty lines '''
6518+
line = self.__displayBodyLine(0, pad, None, return_line = True)
65056519
for n in range(0, self.bodyMaxY + 1):
6506-
self.__displayBodyLine(n, pad, None)
6520+
try:
6521+
self.bodyWin.addstr(n, 0, line, curses.color_pair(5))
6522+
except:
6523+
pass
65076524

65086525
if self._cnf.browsing_station_service:
65096526
if self._cnf.internal_header_height > 0:

0 commit comments

Comments
 (0)