Skip to content

Commit 92e26bd

Browse files
committed
Fixing _max_chars_to_display
1 parent b79ca46 commit 92e26bd

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

Changelog

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Main help window separated to two pages (navigation with "n" / "p")
44
* Changing "e" to "E" to change a station's encoding
55
* Changing "p" to "P" to jump to playing station / loaded playlist
6+
* Adding H, L to jump to top / bottom of screen
7+
* Canging M to jump to middle of screen
68
* Changing volume, saving volume and muting is now available on most
79
windows (pop up and questions)
810
* Manipulating volume (keys m,v) on a help window, will close it

pyradio.1

+35-5
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 "July 2019"
4+
.TH PYRADIO 1 "September 2019"
55

66
.SH NAME
77
.PP
@@ -68,6 +68,16 @@ Play selected station
6868
Select and play a random station
6969
.IP \fBSpace\fR/\fBLeft\fR/\fBh
7070
Stop/start playing selected station
71+
.IP \fBP\fR
72+
Jump to playing station
73+
.IP \fBH\ M\ L
74+
Jump to top / middle / bottom of screen
75+
.IP \fBg
76+
Jump to the start of the playlist
77+
.IP \fI<n>\fBG
78+
Jump to the end of the playlist
79+
.br
80+
If \fI<n>\fR (line number) was entered, jump to it
7181
.IP \fB-\fR/\fB+\fR\ or\ \fB,\fR/\fB.
7282
Change volume
7383
.IP \fBm
@@ -76,8 +86,26 @@ Mute
7686
Save volume (\fIMPV\fR and \fIMPlayer\fR only)
7787
.IP \fBo\ s\ R
7888
\fBO\fIpen\fR / \fBS\fIave\fR / \fBR\fIeload\fR playlist
89+
.IP \fBa\ A\fR
90+
Add / append a new station
91+
.IP \fBe\fR
92+
Edit current station
93+
.IP \fBE\fR
94+
Change current station's encoding
7995
.IP \fBDEL\fR,\fBx
8096
Delete selected station
97+
.IP \fBJ
98+
Create a \fIJump tag
99+
.IP \fI<n>\fB^U\fR,\fI<n>\fB^D
100+
Move current station up / down
101+
.br
102+
If \fI<n>\fR (line number) was entered, or a \fIJump tag\fR has been defined, move the station there
103+
.IP \fBt
104+
Open the \fITheme Selection\fR window
105+
.IP \fBT
106+
Toggle background transparency
107+
.IP \fBc
108+
Open the \fIConfiguration window
81109
.IP \fB?
82110
Show keys help
83111
.IP \fBEsc\fR/\fBq
@@ -178,12 +206,14 @@ Once \fBpyradio\fR has been loaded, one can perform a series of actions on the c
178206

179207
Currently, the following actions are available:
180208

181-
One thing you may want to do is remove a station from a playlist, e.g. when found that it not longer works. You can do that by pressing "\fIDEL\fR" or "\fIx\fR".
209+
Pressing "\fIa\fR" or "\fIA\fR" will enable you to add a new station (either below the currently selected station or at the end of the list), while "\fIe\fR" will edit the currently selected station. All of these actions will open the "\fIStation Editor\fR".
182210

183-
Pressing "\fIe\fR" will enable you to change the encoding of the selected station. If the station is currently playing, playback will be restarted so that the encoding's change takes effect (hopefully correctly displaying the station/song title).
211+
If you just want to change the encoding of the selected station, just press "\fIE\fR". If the station is currently playing, playback will be restarted so that the encoding's change takes effect (hopefully correctly displaying the station/song title).
184212

185213
Then, when this is done, you can either save the modified playlist, by pressing "\fIs\fR", or reload the playlist from disk, by pressing "\fIR\fR". A modified playlist will \fIautomatically\fR be saved when \fBpyradio\fR exits (or Ctrl-C is pressed).
186214

215+
One thing you may also want to do is remove a station from a playlist, e.g. when found that it not longer works. You can do that by pressing "\fIDEL\fR" or "\fIx\fR".
216+
187217
Finally, opening another playlist is also possible. Just press "\fIo\fR" and you will be presented with a list of saved playists to choose from. These playlists must be saved beforehand in \fBpyradio\fR's configuration directory.
188218

189219
While executing any of the previous actions, you may get confirmation messages (when opening a playlist while the current one is modified but not saved, for example) or error messages (when an action fails). Just follow the on screen information, keeping in mind that a capital letter as an answer will save this answer in \fBpyradio\fR's configuration file for future reference.
@@ -403,7 +433,7 @@ When the \fITheme selection window\fR is visible, a "\fI[T]\fR" string displayed
403433

404434
\fBpyradio\fR uses session locking, which actually means that only the first instance executed within a given session will be able to write to the configuration file.
405435

406-
Subsequent instances will be "\fIlocked\fR. This means that the user can still play stations, load and edit playlists, load and test themes, but any changes will \fBnot\fR be recorded in the configuration file.
436+
Subsequent instances will be "\fIlocked\fR. This means that the user can still play stations, load and edit playlists, load and test themes, but any changes will \fBnot\fR be recorded in the configuration file.
407437

408438
\fBSeeeion unlocking\fR
409439

@@ -436,7 +466,7 @@ Let's see what \fBpyradio\fR files exist there:
436466

437467
.HP
438468

439-
\fI$ \fBls -d /usr/lib/python3.7/site-packages
469+
\fI$ \fBls -d /usr/lib/python3.7/site-packages/pyradio*
440470

441471
\fI/usr/lib/python3.7/site-packages/pyradio-\fB0.7.6.2\fI-py3.7.egg
442472
.br

pyradio/radio.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -2051,26 +2051,35 @@ def keypress(self, char):
20512051
(self.ws.NORMAL_MODE, self.ws.PLAYLIST_MODE):
20522052
self.jumpnr = ''
20532053
self._random_requested = False
2054-
self.selection = self.startPos
2055-
self.refreshBody()
2054+
if self.number_of_items > 0:
2055+
self.selection = self.startPos
2056+
self.refreshBody()
20562057
return
20572058

20582059
elif char == ord('M'):
20592060
if self.ws.operation_mode in \
20602061
(self.ws.NORMAL_MODE, self.ws.PLAYLIST_MODE):
20612062
self.jumpnr = ''
20622063
self._random_requested = False
2063-
self.selection = self.startPos + int((self.bodyMaxY - 3) / 2)
2064-
self.refreshBody()
2064+
if self.number_of_items > 0:
2065+
if self.number_of_items < self.bodyMaxY - 2:
2066+
self.selection = int(self.number_of_items / 2)
2067+
else:
2068+
self.selection = self.startPos + int((self.bodyMaxY - 3) / 2)
2069+
self.refreshBody()
20652070
return
20662071

20672072
elif char == ord('L'):
20682073
if self.ws.operation_mode in \
20692074
(self.ws.NORMAL_MODE, self.ws.PLAYLIST_MODE):
20702075
self.jumpnr = ''
20712076
self._random_requested = False
2072-
self.selection = self.startPos + self.bodyMaxY - 3
2073-
self.refreshBody()
2077+
if self.number_of_items > 0:
2078+
if self.number_of_items < self.bodyMaxY - 2:
2079+
self.setStation(-1)
2080+
else:
2081+
self.selection = self.startPos + self.bodyMaxY - 3
2082+
self.refreshBody()
20742083
return
20752084

20762085
elif char in (ord('t'), ) and \

pyradio/simple_curses_widgets.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class SimpleCursesLineEdit(object):
2626
""" Default value for string length """
2727
_max_chars_to_display = 0
2828

29+
""" Cursor position within _max_chars_to_display """
2930
_curs_pos = 0
30-
#_max_width = 0
31+
""" First char of sting to display """
32+
_first = 0
3133

3234
""" init values """
3335
y = x = 0
@@ -195,14 +197,19 @@ def _calculate_window_metrics(self):
195197
else:
196198
self._disp_caption = ''
197199
width = len(self._disp_caption) + self._max_chars_to_display + 4
200+
logger.error('DE 0 width = {0}, max_chars_to_display = {1}'.format(width, self._max_chars_to_display))
198201
self._max_chars_to_display = self.width - len(self._disp_caption) - 4
202+
logger.error('DE 1 width = {0}, max_chars_to_display = {1}'.format(width, self._max_chars_to_display))
199203
if self._boxed:
200204
self._height = 3
201205
else:
202206
self._height = 1
203-
self._max_chars_to_display -= 2
207+
self._max_chars_to_display += 2
208+
if not self.bracket:
209+
self._max_chars_to_display += 1
204210
if self.log is not None:
205211
self.log('string_len = {}'.format(self._max_chars_to_display))
212+
logger.error('DE 2 width = {0}, max_chars_to_display = {1}'.format(width, self._max_chars_to_display))
206213
return
207214

208215
def _prepare_to_show(self):
@@ -252,13 +259,14 @@ def refreshEditWindow(self, opening=False):
252259
self._curs_pos = 0
253260
else:
254261
if self._string:
255-
self._edit_win.addstr(0, 0, self._string, active_edit_color)
262+
self._edit_win.addstr(0, 0, self._string[self._first:self._first+self._max_chars_to_display], active_edit_color)
256263
else:
257264
self._curs_pos = 0
258265
if self.log is not None:
259266
self.log(' - curs_pos = {}\n'.format(self._curs_pos))
260267
if self.focused:
261268
self._edit_win.chgat(0, self._curs_pos, 1, self.cursor_color)
269+
logger.error('DE string length = {}'.format(len(self.string)))
262270

263271
self._edit_win.refresh()
264272

@@ -404,9 +412,13 @@ def keypress(self, win, char):
404412
elif char in (curses.KEY_HOME, curses.ascii.SOH):
405413
""" KEY_HOME, ^A """
406414
self._curs_pos = 0
415+
self._first = 0
407416
elif char in (curses.KEY_END, curses.ascii.ENQ):
408417
""" KEY_END, ^E """
409418
self._curs_pos = len(self._string)
419+
self._first = len(self.string) - self._max_chars_to_display
420+
if self._first < 0:
421+
self._first = 0
410422
elif char in (curses.ascii.ETB, ):
411423
""" ^W, clear to start of line """
412424
self.string = self._string[self._curs_pos:]
@@ -490,6 +502,8 @@ def keypress(self, win, char):
490502
self.log('====================\n')
491503
#if len(self._string) + 1 == self._max_width:
492504
if len(self._string) == self._max_chars_to_display:
505+
logger.error('DE max width reached {0} - {1}'.format(len(self._string), self._max_chars_to_display))
506+
#self._first += 1
493507
return 1
494508
if version_info < (3, 0):
495509
if 32 <= char < 127:

0 commit comments

Comments
 (0)