Skip to content

Commit e460967

Browse files
committed
- Disabling station editing for python 2 when station name contains
non-ASCII characters - Starting CJK editing
1 parent 446ec69 commit e460967

File tree

7 files changed

+454
-114
lines changed

7 files changed

+454
-114
lines changed

README.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ <h2 id="table-of-contents">Table of contents <span style="padding-left: 10px;"><
4747
<li><a href="#cleaning-up">Cleaning up</a></li>
4848
<li><a href="#debug-mode">Debug mode</a></li>
4949
<li><a href="#reporting-bugs">Reporting bugs</a></li>
50+
<li><a href="#acknowlegement">Acknowlegement</a></li>
5051
</ul>
5152
<h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
5253
<ul>
@@ -211,7 +212,7 @@ <h3 id="station-by-station-encoding-declaration">Station by station encoding dec
211212
<p>Finally, we insert the new station to the playlist:</p>
212213
<pre>Station1,Station1_URL,
213214
Station2,Station2_URL,iso-8859-7</pre>
214-
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> Using the <strong><em>-a</em></strong> command line option will save you all this trouble, as it will automatically take care of creating a valid <strong><em>CSV</em></strong> file. Alternatively, you can change the selected station’s encoding by pressing “<strong><em>e</em></strong>” while in <strong>PyRadio</strong>.</p>
215+
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> Using the <strong><em>-a</em></strong> command line option will save you all this trouble, as it will automatically take care of creating a valid <strong><em>CSV</em></strong> file. Alternatively, you can change the selected station’s encoding by pressing “<strong><em>E</em></strong>” while in <strong>PyRadio</strong>.</p>
215216
<h3 id="global-encoding-declaration">Global encoding declaration</h3>
216217
<p><strong>PyRadio</strong>’s configuration file contains the parameter <strong><em>default_encoding</em></strong>, which by default is set to <strong>utf-8</strong>.</p>
217218
<p>Setting this parameter to a different encoding, will permit <strong>PyRadio</strong> to successfully decode such stations.</p>
@@ -315,5 +316,10 @@ <h2 id="reporting-bugs">Reporting bugs <span style="padding-left: 10px;"><sup st
315316
$ pyradio -d</pre>
316317
<p>Then try to reproduce the bug and exit <strong>pyradio</strong>.</p>
317318
<p>Finally, include the file produced in your report.</p>
319+
<h2 id="acknowlegement">Acknowlegement <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></style></h2>
320+
<p><strong>PyRadio</strong> uses code frorm the following projects:</p>
321+
<ol type="1">
322+
<li><a target="_blank" href="https://gitlab.com/fgallaire/cjkwrap">CJKwrap</a> by Florent Gallaire - A library for wrapping and filling UTF-8 CJK text.</li>
323+
</ol>
318324
</body>
319325
</html>

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic)
2323
* [Cleaning up](#cleaning-up)
2424
* [Debug mode](#debug-mode)
2525
* [Reporting bugs](#reporting-bugs)
26+
* [Acknowlegement](#acknowlegement)
2627

2728
## Requirements
2829

@@ -280,7 +281,7 @@ Station2,Station2_URL,iso-8859-7
280281
```
281282

282283
**Note:**
283-
Using the ***-a*** command line option will save you all this trouble, as it will automatically take care of creating a valid ***CSV*** file. Alternatively, you can change the selected station's encoding by pressing "***e***" while in **PyRadio**.
284+
Using the ***-a*** command line option will save you all this trouble, as it will automatically take care of creating a valid ***CSV*** file. Alternatively, you can change the selected station's encoding by pressing "***E***" while in **PyRadio**.
284285

285286
### Global encoding declaration
286287

@@ -464,3 +465,9 @@ To create it, enter the following commands in a terminal:
464465
Then try to reproduce the bug and exit **pyradio**.
465466

466467
Finally, include the file produced in your report.
468+
469+
## Acknowlegement
470+
471+
**PyRadio** uses code frorm the following projects:
472+
473+
1. [CJKwrap](https://gitlab.com/fgallaire/cjkwrap) by Florent Gallaire - A library for wrapping and filling UTF-8 CJK text.

pyradio.1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Copyright (C) 2011 Ben Dowling <http://www.coderholic.com/pyradio>
22
.\" This manual is freely distributable under the terms of the GPL.
33
.\"
4-
.TH PYRADIO 1 "September 2019"
4+
.TH PYRADIO 1 "October 2019"
55

66
.SH NAME
77
.PP
@@ -321,7 +321,7 @@ Finally, we insert the new station to the playlist:
321321
Station2\fB,\fIStation2_URL\fB,\fIiso-8859-7
322322

323323
.IP \fBNote\fR
324-
Using the \fB-a\fR command line option will save you all this trouble, as it will automatically take care of creating a valid \fBCSV\fR file. Alternatively, you can change the selected station's encoding by pressing "\fIe\fR" while in \fBpyradio\fR.
324+
Using the \fB-a\fR command line option will save you all this trouble, as it will automatically take care of creating a valid \fBCSV\fR file. Alternatively, you can change the selected station's encoding by pressing "\fIE\fR" while in \fBpyradio\fR.
325325

326326

327327
.PP
@@ -536,6 +536,16 @@ Then try to reproduce the bug and exit pyradio.
536536

537537
Finally, include the file produced in your report.
538538

539+
.SH ACKNOWLEGEMENT
540+
541+
.PP
542+
\fBpyradio\fR uses code frorm the following projects:
543+
544+
.RS 5
545+
546+
.IP 1.
547+
\fBCJKwrap\fR (\fIhttps://gitlab.com/fgallaire/cjkwrap\fR) by Florent Gallaire - A library for wrapping and filling UTF-8 CJK text.
548+
539549
.SH FILES
540550
.PP
541551
.I /usr/share/doc/pyradio/README.md

pyradio/edit.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ def show(self, parent_win, repaint=False):
5252
except:
5353
pass
5454
if not repaint:
55-
self.string = ''
56-
self._curs_pos = 0
55+
self.string = self._displayed_string = ''
56+
self._curs_pos = self._disp_curs_pos = 0
57+
self._edit_win.erase()
58+
self._edit_win.chgat(0, 0, 1, self.cursor_color)
5759
if self._has_history:
5860
self._input_history.reset_index()
5961
self._caption_win.refresh()
@@ -62,16 +64,12 @@ def show(self, parent_win, repaint=False):
6264
def _get_history_next(self):
6365
""" callback function for key down """
6466
if self._has_history:
65-
ret = self._input_history.return_history(1)
66-
self.string = ret
67-
self._curs_pos = len(ret)
67+
self.string = self._input_history.return_history(1)
6868

6969
def _get_history_previous(self):
7070
""" callback function for key up """
7171
if self._has_history:
72-
ret = self._input_history.return_history(-1)
73-
self.string = ret
74-
self._curs_pos = len(ret)
72+
self.string = self._input_history.return_history(-1)
7573

7674
def get_next(self, a_list, start=0, stop=None):
7775
if self.string:
@@ -379,7 +377,6 @@ def _show_title(self):
379377
self._win.chgat(0, x, 2, curses.color_pair(3))
380378
self._win.refresh()
381379

382-
383380
def _show_buttons(self):
384381
sid = 3
385382
if self._focus == sid:

pyradio/radio.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
def rel(path):
4747
return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)
4848

49+
50+
def is_ascii(s):
51+
return all(ord(c) < 128 for c in s)
52+
4953
class PyRadio(object):
5054
ws = Window_Stack()
5155

@@ -190,6 +194,7 @@ def __init__(self, pyradio_config, play=False, req_player='', theme=''):
190194
self.ws.LINE_EDITOR_HELP: self._show_line_editor_help,
191195
self.ws.EDIT_STATION_NAME_ERROR: self._print_editor_name_error,
192196
self.ws.EDIT_STATION_URL_ERROR: self._print_editor_url_error,
197+
self.ws.PY2_EDITOR_ERROR: self._print_py2_editor_error,
193198
}
194199

195200
""" list of help functions """
@@ -1404,6 +1409,23 @@ def _print_playlist_reload_error(self):
14041409
prompt = ' Press any key ',
14051410
is_message=True)
14061411

1412+
def _print_py2_editor_error(self):
1413+
txt ='''Non-ASCII characters editing is |not supported!|
1414+
1415+
You running |PyRadio| on |Python 2|. As a result, the
1416+
station editor only supports |ASCII characters|, but
1417+
the station name you are trying to edit contains
1418+
|non-ASCII| characters.
1419+
1420+
To edit this station, either run |PyRadio| on |Python 3|,
1421+
or edit the playlist with an external editor and then
1422+
reload the playlist.
1423+
'''
1424+
self._show_help(txt, self.ws.PY2_EDITOR_ERROR,
1425+
caption = ' Error ',
1426+
prompt = ' Press any key ',
1427+
is_message=True)
1428+
14071429
def _print_playlist_reload_confirmation(self):
14081430
if self._cnf.locked:
14091431
txt ='''This playlist has not been modified within
@@ -2912,6 +2934,10 @@ def keypress(self, char):
29122934
self.ws.operation_mode = self.ws.ADD_STATION_MODE
29132935

29142936
elif char == ord('e'):
2937+
if python_version[0] == '2':
2938+
if not is_ascii(self.stations[self.selection][0]):
2939+
self._print_py2_editor_error()
2940+
return
29152941
self._station_editor = PyRadioEditor(self.stations, self.selection, self.bodyWin, adding=False)
29162942
self._station_editor.show(self.stations[self.selection])
29172943
self.ws.operation_mode = self.ws.EDIT_STATION_MODE

0 commit comments

Comments
 (0)