Skip to content

Commit 8863f81

Browse files
committed
- version 0.9.2.3
- fixing search function for Group Selection window (pressing "n" or "N" will now work) - random playback will not stop on a Group Header - do not put new selection in the middle of window if already visible (Group Selection window)
1 parent fcde291 commit 8863f81

File tree

6 files changed

+79
-41
lines changed

6 files changed

+79
-41
lines changed

Changelog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2023-04-01 s-n-g
2+
* version 0.9.2.3
3+
* fixing search function for Group Selection window (pressing
4+
"n" or "N" will now work)
5+
* random playback will not stop on a Group Header
6+
* do not put new selection in the middle of window if already
7+
visible (Group Selection window)
8+
19
2023-03-31 s-n-g
210
* version 0.9.2.2
311
* adding support for Groups in playlists

README.html

+8
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
202202
<h2 id="changelog">Changelog <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
203203
<pre style="height: 200px;">
204204

205+
2023-04-01 s-n-g
206+
* version 0.9.2.3
207+
* fixing search function for Group Selection window (pressing
208+
"n" or "N" will now work)
209+
* random playback will not stop on a Group Header
210+
* do not put new selection in the middle of window if already
211+
visible (Group Selection window)
212+
205213
2023-03-31 s-n-g
206214
* version 0.9.2.2
207215
* adding support for Groups in playlists

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyradio"
3-
version = "0.9.2.2"
3+
version = "0.9.2.3"
44
authors = [
55
{ name="Ben Dowling", email="[email protected]" },
66
{ name="Spiros Georgaras", email="[email protected]" },

pyradio/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" pyradio -- Console radio player. "
22

3-
version_info = (0, 9, 2, 2)
3+
version_info = (0, 9, 2, 3)
44

55
# Set it to True if new stations have been
66
# added to the package's stations.csv

pyradio/radio.py

+29-24
Original file line numberDiff line numberDiff line change
@@ -4721,7 +4721,11 @@ def get_active_encoding(self, an_encoding):
47214721
def play_random(self):
47224722
# Pick a random radio station
47234723
if self.number_of_items > 0:
4724-
self.setStation(random.randint(0, len(self.stations)))
4724+
while True:
4725+
rnd = random.randint(0, len(self.stations))
4726+
if self.stations[rnd][1] != '-':
4727+
break
4728+
self.setStation(rnd)
47254729
self.playSelection()
47264730
self._put_selection_in_the_middle(force=True)
47274731
self.refreshBody()
@@ -7765,28 +7769,6 @@ def keypress(self, char):
77657769
self.refreshBody()
77667770
return
77677771

7768-
elif self.ws.operation_mode == self.ws.GROUP_SELECTION_MODE:
7769-
ret = self._group_selection_window.keypress(char)
7770-
if ret <= 0:
7771-
if ret == 0:
7772-
ret = self._groups[self._group_selection_window.selection][0]
7773-
self.setStation(ret)
7774-
self._put_selection_in_the_middle(force=True)
7775-
self.refreshBody()
7776-
self.selections[self.ws.NORMAL_MODE] = [self.selection,
7777-
self.startPos,
7778-
self.playing,
7779-
self.stations]
7780-
self._group_selection_window = None
7781-
self._groups = None
7782-
self.ws.close_window()
7783-
self.refreshBody()
7784-
elif ret == 2:
7785-
''' show help '''
7786-
self._show_group_help()
7787-
pass
7788-
return
7789-
77907772
elif self.ws.operation_mode == self.ws.UPDATE_NOTIFICATION_OK_MODE:
77917773
if char in self._global_functions.keys():
77927774
self._global_functions[char]()
@@ -7816,9 +7798,10 @@ def keypress(self, char):
78167798
self.refreshBody()
78177799
return
78187800

7801+
# elif char in (ord('n'), ) and \
7802+
# self.ws.operation_mode in self._search_modes.keys():
78197803
elif char in (ord('n'), ) and \
78207804
self.ws.operation_mode in self._search_modes.keys():
7821-
# logger.error('DE n operation_mode = {}'.format(self.ws.operation_mode))
78227805
self._give_me_a_search_class(self.ws.operation_mode)
78237806
if self.ws.operation_mode == self.ws.NORMAL_MODE:
78247807
self._update_status_bar_right()
@@ -7948,6 +7931,28 @@ def keypress(self, char):
79487931
self.refreshBody()
79497932
return
79507933

7934+
elif self.ws.operation_mode == self.ws.GROUP_SELECTION_MODE:
7935+
ret = self._group_selection_window.keypress(char)
7936+
if ret <= 0:
7937+
if ret == 0:
7938+
ret = self._groups[self._group_selection_window.selection][0]
7939+
self.setStation(ret)
7940+
self._put_selection_in_the_middle(force=True)
7941+
self.refreshBody()
7942+
self.selections[self.ws.NORMAL_MODE] = [self.selection,
7943+
self.startPos,
7944+
self.playing,
7945+
self.stations]
7946+
self._group_selection_window = None
7947+
self._groups = None
7948+
self.ws.close_window()
7949+
self.refreshBody()
7950+
elif ret == 2:
7951+
''' show help '''
7952+
self._show_group_help()
7953+
pass
7954+
return
7955+
79517956
elif char in (ord('T'), ):
79527957
self._update_status_bar_right()
79537958
if self.ws.operation_mode == self.ws.SESSION_LOCKED_MODE:

pyradio/simple_curses_widgets.py

+32-15
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,6 @@ def __init__(self,
17261726
)
17271727
self._get_window()
17281728
self._calculate_max_height_max_width()
1729-
self._verify_selection_not_on_caption()
17301729
self._make_sure_selection_is_visible()
17311730

17321731
@property
@@ -1818,17 +1817,23 @@ def _set_selection(self, a_sel):
18181817
self._old_start_pos = self._start_pos
18191818

18201819
self._selection = a_sel
1821-
self._make_sure_selection_is_visible()
1822-
self._verify_selection_not_on_caption()
18231820

1824-
# log_it('last line = {}'.format(self._start_pos + self._maxY))
1825-
if a_sel < self._start_pos or a_sel >= self._start_pos + self._body_maxY:
1826-
self._start_pos = self._selection - int(self._body_maxY / 2) + 1
1821+
if self._make_sure_selection_is_visible():
18271822
self._refresh()
18281823
else:
18291824
self._toggle_selected_item()
18301825

18311826

1827+
# self._make_sure_selection_is_visible()
1828+
1829+
# # log_it('last line = {}'.format(self._start_pos + self._maxY))
1830+
# if a_sel < self._start_pos or a_sel >= self._start_pos + self._body_maxY:
1831+
# self._start_pos = self._selection - int(self._body_maxY / 2) + 1
1832+
# self._refresh()
1833+
# else:
1834+
# self._toggle_selected_item()
1835+
1836+
18321837
def _get_window(self):
18331838
Y, X = self._parent.getmaxyx()
18341839
# log_it('== WIN Y = {0}, X = {1}'.format(Y, X))
@@ -1959,7 +1964,6 @@ def show(self, parent=None):
19591964
return
19601965

19611966
if new_win:
1962-
self._verify_selection_not_on_caption()
19631967
self._make_sure_selection_is_visible()
19641968
self.show()
19651969
return
@@ -1987,6 +1991,7 @@ def _refresh(self):
19871991
self._start_pos = 0
19881992
elif self._start_pos > len(self._items) - 1 - self._body_maxY:
19891993
self._start_pos = len(self._items) - self._body_maxY
1994+
# logger.error('refresh (st={0}, sel={1})'.format(self._start_pos, self._selection))
19901995
for i in range(0, self._body_maxY):
19911996
item_id = i + self._start_pos
19921997
disp_item = self._format_line(i, active_item_length)
@@ -2063,19 +2068,28 @@ def _get_item_color(self, item_id):
20632068
# log_it('--- END ---')
20642069
return col
20652070

2066-
def _make_sure_selection_is_visible(self):
2071+
def _make_sure_selection_is_visible(self, mov=1):
2072+
''' adjust self._start_pos to make self._selection visible
2073+
Returns
2074+
True self._start_pos changed (use self._refresh)
2075+
False self._start_pos not changed (use self._toggle_selected_item)
2076+
'''
20672077
if len(self._items) <= self._body_maxY:
20682078
self._start_pos = 0
20692079
return
2080+
self._verify_selection_not_on_caption(mov)
2081+
self._old_start_pos = self._start_pos
20702082
meso = int(self._body_maxY / 2)
2071-
st = old_st = self._start_pos
2072-
en = st + self._body_maxY - 1
2083+
self._end_pos = self._start_pos + self._body_maxY - 1
2084+
2085+
if self._start_pos <= self._selection <= self._end_pos:
2086+
return False
20732087

2074-
st = self._selection - meso
2088+
self._start_pos = self._selection - meso
20752089

2076-
if st < 0:
2077-
st = 0
2078-
self._start_pos = st
2090+
if self._start_pos < 0:
2091+
self._start_pos = 0
2092+
return True
20792093

20802094
def _verify_selection_not_on_caption(self, movement=1):
20812095
# log_it('\n\n1 mov = {0}, sel = {1}, items = {2}'.format(movement, self._selection, len(self._items)))
@@ -2121,8 +2135,10 @@ def delete_item(self, target):
21212135
self.active = -1
21222136

21232137
self._verify_selection_not_on_caption(mov)
2124-
if not self._make_sure_selection_is_visible():
2138+
if self._make_sure_selection_is_visible():
21252139
self._refresh()
2140+
else:
2141+
self._toggle_selected_item()
21262142

21272143
return len(self._items)
21282144

@@ -2158,6 +2174,7 @@ def _toggle_selected_item(self):
21582174
# )
21592175
# log_it('_toggle_selection_item: X={0}, setting new selection: {1}, line: {2}'.format(self._X, selection_id, self._Y + selection_id))
21602176
update = True
2177+
# logger.error('toggle (st={0}, sel={1})'.format(self._start_pos, self._selection))
21612178
if update:
21622179
self._win.refresh()
21632180
return True

0 commit comments

Comments
 (0)