|
26 | 26 | from .log import Log
|
27 | 27 | from .edit import PyRadioSearch, PyRadioEditor
|
28 | 28 | from .themes import *
|
| 29 | +from .simple_curses_widgets import cjklen |
29 | 30 | from . import player
|
30 | 31 | import logging
|
31 | 32 |
|
@@ -528,9 +529,10 @@ def __displayBodyLine(self, lineNum, pad, station):
|
528 | 529 | self.ws.operation_mode == self.ws.PLAYLIST_LOAD_ERROR_MODE or \
|
529 | 530 | self.ws.operation_mode == self.ws.PLAYLIST_NOT_FOUND_ERROR_MODE:
|
530 | 531 | line = self._format_playlist_line(lineNum, pad, station)
|
| 532 | + self.bodyWin.addstr(lineNum + 1, 1, line, col) |
531 | 533 | else:
|
532 |
| - line = "{0}. {1}".format(str(lineNum + self.startPos + 1).rjust(pad), station[0]) |
533 |
| - self.bodyWin.addstr(lineNum + 1, 1, line[:body_width], col) |
| 534 | + line = self._format_station_line("{0}. {1}".format(str(lineNum + self.startPos + 1).rjust(pad), station[0])) |
| 535 | + self.bodyWin.addstr(lineNum + 1, 1, line, col) |
534 | 536 |
|
535 | 537 | def run(self):
|
536 | 538 | if self.ws.operation_mode == self.ws.NO_PLAYER_ERROR_MODE:
|
@@ -1018,36 +1020,54 @@ def _format_playlist_line(self, lineNum, pad, station):
|
1018 | 1020 | line = "{0}. {1}".format(str(lineNum + self.startPos + 1).rjust(pad), station[0])
|
1019 | 1021 | f_data = ' [{0}, {1}]'.format(station[2], station[1])
|
1020 | 1022 | if version_info < (3, 0):
|
1021 |
| - if len(line.decode('utf-8', 'replace')) + len(f_data.decode('utf-8', 'replace')) > self.bodyMaxX -2: |
| 1023 | + if cjklen(line.decode('utf-8', 'replace')) + cjklen(f_data.decode('utf-8', 'replace')) > self.bodyMaxX -2: |
1022 | 1024 | """ this is too long, try to shorten it
|
1023 | 1025 | by removing file size """
|
1024 | 1026 | f_data = ' [{0}]'.format(station[1])
|
1025 |
| - if len(line.decode('utf-8', 'replace')) + len(f_data.decode('utf-8', 'replace')) > self.bodyMaxX - 2: |
| 1027 | + if cjklen(line.decode('utf-8', 'replace')) + cjklen(f_data.decode('utf-8', 'replace')) > self.bodyMaxX - 2: |
1026 | 1028 | """ still too long. start removing chars """
|
1027 |
| - while len(line.decode('utf-8', 'replace')) + len(f_data.decode('utf-8', 'replace')) > self.bodyMaxX - 3: |
| 1029 | + while cjklen(line.decode('utf-8', 'replace')) + cjklen(f_data.decode('utf-8', 'replace')) > self.bodyMaxX - 3: |
1028 | 1030 | f_data = f_data[:-1]
|
1029 | 1031 | f_data += ']'
|
1030 | 1032 | """ if too short, pad f_data to the right """
|
1031 |
| - if len(line.decode('utf-8', 'replace')) + len(f_data.decode('utf-8', 'replace')) < self.maxX - 2: |
1032 |
| - while len(line.decode('utf-8', 'replace')) + len(f_data.decode('utf-8', 'replace')) < self.maxX - 2: |
| 1033 | + if cjklen(line.decode('utf-8', 'replace')) + cjklen(f_data.decode('utf-8', 'replace')) < self.maxX - 2: |
| 1034 | + while cjklen(line.decode('utf-8', 'replace')) + cjklen(f_data.decode('utf-8', 'replace')) < self.maxX - 2: |
1033 | 1035 | line += ' '
|
1034 | 1036 | else:
|
1035 |
| - if len(line) + len(f_data) > self.bodyMaxX -2: |
| 1037 | + if cjklen(line) + cjklen(f_data) > self.bodyMaxX -2: |
1036 | 1038 | """ this is too long, try to shorten it
|
1037 | 1039 | by removing file size """
|
1038 | 1040 | f_data = ' [{0}]'.format(station[1])
|
1039 |
| - if len(line) + len(f_data) > self.bodyMaxX - 2: |
| 1041 | + if cjklen(line) + cjklen(f_data) > self.bodyMaxX - 2: |
1040 | 1042 | """ still too long. start removing chars """
|
1041 |
| - while len(line) + len(f_data) > self.bodyMaxX - 3: |
| 1043 | + while cjklen(line) + cjklen(f_data) > self.bodyMaxX - 3: |
1042 | 1044 | f_data = f_data[:-1]
|
1043 | 1045 | f_data += ']'
|
1044 | 1046 | """ if too short, pad f_data to the right """
|
1045 |
| - if len(line) + len(f_data) < self.maxX - 2: |
1046 |
| - while len(line) + len(f_data) < self.maxX - 2: |
| 1047 | + if cjklen(line) + cjklen(f_data) < self.maxX - 2: |
| 1048 | + while cjklen(line) + cjklen(f_data) < self.maxX - 2: |
1047 | 1049 | line += ' '
|
1048 | 1050 | line += f_data
|
1049 | 1051 | return line
|
1050 | 1052 |
|
| 1053 | + def _format_station_line(self, line): |
| 1054 | + if version_info < (3, 0): |
| 1055 | + if len(line.decode('utf-8', 'replace')) != cjklen(line.decode('utf-8', 'replace')): |
| 1056 | + while cjklen(line.decode('utf-8', 'replace')) > self.bodyMaxX - 2: |
| 1057 | + line = line[:-1] |
| 1058 | + return line |
| 1059 | + else: |
| 1060 | + return line[:self.bodyMaxX - 2] |
| 1061 | + |
| 1062 | + pass |
| 1063 | + else: |
| 1064 | + if len(line) != cjklen(line): |
| 1065 | + while cjklen(line) > self.bodyMaxX - 2: |
| 1066 | + line = line[:-1] |
| 1067 | + return line |
| 1068 | + else: |
| 1069 | + return line[:self.bodyMaxX - 2] |
| 1070 | + |
1051 | 1071 | def _print_help(self):
|
1052 | 1072 | #logger.error('DE \n\nself.ws.operation_mode = {}'.format(self.ws.operation_mode))
|
1053 | 1073 | if self.ws.operation_mode in self._display_help.keys():
|
|
0 commit comments