Skip to content

Commit

Permalink
- version 0.8.9.25 (0.9-beta22)
Browse files Browse the repository at this point in the history
- fixing global shorcuts inside RadioBrowser search window (as per #164)
  • Loading branch information
s-n-g committed Aug 14, 2022
1 parent 30f8581 commit d432d76
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2022-08-14 s-n-g
* version 0.8.9.25 (0.9-beta22)
* fixing global shorcuts inside RadioBrowser search window
(as per #164)

2022-08-12 s-n-g
* version 0.8.9.24 (0.9-beta21)
* fixing several theme issues (exchanging cursors background color
Expand Down
5 changes: 5 additions & 0 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
<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></style></h2>
<pre style="height: 200px;">

2022-08-14 s-n-g
* version 0.8.9.25 (0.9-beta22)
* fixing global shorcuts inside RadioBrowser search window
(as per #164)

2022-08-12 s-n-g
* version 0.8.9.24 (0.9-beta21)
* fixing several theme issues (exchanging cursors background color
Expand Down
2 changes: 1 addition & 1 deletion pyradio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" pyradio -- Console radio player. "

version_info = (0, 8, 9, 24)
version_info = (0, 8, 9, 25)

# Set it to True if new stations have been
# added to the package's stations.csv
Expand Down
60 changes: 53 additions & 7 deletions pyradio/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,9 @@ def read_config(self):
except:
if logger.isEnabledFor(logging.ERROR):
logger.error('RadioBrowser: error inserting serch item id {}'.format(n))
if 'limit' in self.terms[-1]['post_data'].keys():
if self.terms[-1]['post_data']['limit'] == str(self.limit):
self.terms[-1]['post_data'].pop('limit')
else:
if logger.isEnabledFor(logging.DEBUG):
logger.debug('RadioBrowser: no search terms found, reverting to defaults')
Expand Down Expand Up @@ -2289,6 +2292,8 @@ class RadioBrowserSearchWindow(object):

_global_functions = {}

_backslash_pressed = False

def __init__(self,
parent,
config,
Expand Down Expand Up @@ -2502,6 +2507,8 @@ def _widgets_to_search_term(self):
''' get limit (term)'''
if self._widgets[-self.NUMBER_OF_WIDGETS_AFTER_SEARCH_SECTION].value != self._default_limit:
ret['post_data']['limit'] = str(self._widgets[-self.NUMBER_OF_WIDGETS_AFTER_SEARCH_SECTION].value)
# else:
# ret['post_data']['limit'] = str(self._default_limit)

''' get order '''
self._order_to_term(ret)
Expand Down Expand Up @@ -2917,28 +2924,28 @@ def _get_search_term_index(self, new_search_term):
''' search for a search term in history
if found return True, index
if not found return False, len(self._history) - 1
and append the search term in the history
if not found return False, len(self._history) - 1
and append the search term in the history
'''
found = False
for a_search_term_index, a_search_term in enumerate(self._history):
if new_search_term == a_search_term:
# self._history_id = self._selected_history_id
index = a_search_term_index
ret_index = a_search_term_index
found = True
if logger.isEnabledFor(logging.DEBUG):
logger.debug('New search term already in history, id = {}'.format(self._selected_history_id))
logger.debug('New search term already in history, id = {}'.format(ret_index))
break

if not found:
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Adding new search term to history, id = {}'.format(len(self._history)))
self._history.append(new_search_term)
# self._history_id = self._selected_history_id = len(self._history) - 1
index = len(self._history) - 1
ret_index = len(self._history) - 1
self._cnf.dirty = True

return found, index
return found, ret_index

def _goto_first_history_item(self):
self._handle_new_or_existing_search_term()
Expand Down Expand Up @@ -2971,6 +2978,7 @@ def _jump_history_down(self):
def _ctrl_n(self):
''' ^N - Next history item '''
cur_history_id = self._selected_history_id
logger.error('cur_history_id = {}'.format(cur_history_id))
self._handle_new_or_existing_search_term()
if abs(self._selected_history_id - cur_history_id) > 1:
self._selected_history_id = cur_history_id
Expand Down Expand Up @@ -3055,29 +3063,36 @@ def keypress(self, char):
return -1

if self._too_small:
self._backslash_pressed = False
return 1

class_name = type(self._widgets[self._focus]).__name__

if char == ord('0') and \
type(self._widgets[self._focus]).__name__ != 'SimpleCursesLineEdit':
self._goto_first_history_item()
self._backslash_pressed = False

elif char == ord('$') and \
type(self._widgets[self._focus]).__name__ != 'SimpleCursesLineEdit':
self._goto_last_history_item()
self._backslash_pressed = False

elif char in (curses.KEY_PPAGE, ) and self._focus != len(self._widgets) -3:
self._jump_history_up()
self._backslash_pressed = False

elif char in (curses.KEY_NPAGE, ) and self._focus != len(self._widgets) -3:
self._jump_history_down()
self._backslash_pressed = False

elif char in (ord('\t'), 9):
self._focus_next()
self._backslash_pressed = False

elif char in (curses.KEY_BTAB, ):
self._focus_previous()
self._backslash_pressed = False

elif char in (ord(' '), curses.KEY_ENTER, ord('\n'),
ord('\r')) and self._focus == len(self._widgets) - 1:
Expand All @@ -3087,39 +3102,47 @@ def keypress(self, char):
elif char in (ord(' '), curses.KEY_ENTER, ord('\n'),
ord('\r')) and self._focus == len(self._widgets) - 2:
''' enter on ok button '''
self._backslash_pressed = False
ret = self._handle_new_or_existing_search_term()
return 0 if ret == 1 else ret

elif char in (curses.ascii.SO, ):
''' ^N - Next history item '''
self._ctrl_n()
self._backslash_pressed = False

elif char in (curses.ascii.DLE, ):
''' ^P - Previous history item '''
self._ctrl_p()
self._backslash_pressed = False

# elif char in (curses.ascii.ETB, ):
elif char in (curses.ascii.ENQ, ):
''' ^E - Save search history '''
self._backslash_pressed = False
self._handle_new_or_existing_search_term()
''' Save search history '''
return 5

elif char in (curses.ascii.EM, ):
''' ^Y - Add history item '''
self._handle_new_or_existing_search_term()
self._backslash_pressed = False

elif char in (curses.ascii.CAN, ):
''' ^X - Delete history item '''
self._ctrl_x()
self._backslash_pressed = False

elif char in (curses.ascii.STX, ):
''' ^B - Set default item '''
self._ctrl_b()
self._backslash_pressed = False

elif char in (curses.ascii.ACK, ):
''' ^F - Go to template (item 0) '''
self._ctrl_f()
self._backslash_pressed = False

else:
if class_name == 'SimpleCursesWidgetColumns':
Expand All @@ -3130,8 +3153,10 @@ def keypress(self, char):
elif ret == 2:
# cursor moved
self._win.refresh()
self._backslash_pressed = False

elif self._focus in self._checkbox_to_enable_widgets:
self._backslash_pressed = False
ret = self._widgets[self._focus].keypress(char)
if not ret:
tp = list(self._checkbox_to_enable_widgets)
Expand All @@ -3143,17 +3168,37 @@ def keypress(self, char):
return 1

elif class_name == 'SimpleCursesCheckBox':
self._backslash_pressed = False
ret = self._widgets[self._focus].keypress(char)
if not ret:
return 1

elif class_name == 'SimpleCursesCounter':
self._backslash_pressed = False
ret = self._widgets[self._focus].keypress(char)
if ret == 0:
self._win.refresh()
return 1

elif class_name == 'SimpleCursesLineEdit':
if char == ord('\\'):
self._backslash_pressed = True
# return 1

if self._backslash_pressed:
if char in self._global_functions.keys():
self._backslash_pressed = False
self._global_functions[char]()
return 1
elif char == ord('0'):
self._backslash_pressed = False
self._goto_first_history_item()
return 1
elif char == ord('$'):
self._backslash_pressed = False
self._goto_last_history_item()
return 1

ret = self._widgets[self._focus].keypress(self._win, char)
if ret == -1:
# Cancel
Expand All @@ -3164,6 +3209,7 @@ def keypress(self, char):
elif ret < 2:
return 1

self._backslash_pressed = False
if char in (ord('s'), ):
''' prerform search '''
ret = self._handle_new_or_existing_search_term()
Expand Down Expand Up @@ -3243,7 +3289,7 @@ def keypress(self, char):
return 1

def _handle_new_or_existing_search_term(self):
''' read alla widgets and create a search term
''' read all widgets and create a search term
if it does not exist add it to history
'''
test_search_term = self._widgets_to_search_term()
Expand Down
10 changes: 6 additions & 4 deletions pyradio/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6067,11 +6067,13 @@ def keypress(self, char):
''' browser config save canceled '''
self._exit_browser_config()

elif self.ws.operation_mode == self.ws.BROWSER_SEARCH_MODE and \
(char not in self._chars_to_bypass_on_editor or \
self._cnf._online_browser.line_editor_has_focus()):
# elif self.ws.operation_mode == self.ws.BROWSER_SEARCH_MODE and \
# (char not in self._chars_to_bypass_on_editor or \
# self._cnf._online_browser.line_editor_has_focus()):
elif self.ws.operation_mode == self.ws.BROWSER_SEARCH_MODE:

if char in self._global_functions.keys():
if char in self._global_functions.keys() and \
not self._cnf._online_browser.line_editor_has_focus():
self._global_functions[char]()
return

Expand Down

0 comments on commit d432d76

Please sign in to comment.