From 919ec5e9d9bf3b69fc8e0aa69814d32e2647c702 Mon Sep 17 00:00:00 2001 From: jupiterbjy Date: Fri, 12 Feb 2021 18:36:22 +0900 Subject: [PATCH] changes to meet pylint requirement - 3 --- .pylintrc | 2 +- CUIAudioPlayer/Player.py | 41 +++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/.pylintrc b/.pylintrc index 63a0f1d..9fa6758 100644 --- a/.pylintrc +++ b/.pylintrc @@ -66,7 +66,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" disable=fixme -enable=assert-on-tuple,astroid-error,bad-except-order,bad-inline-option,bad-option-value,bad-reversed-sequence,bare-except,binary-op-exception,boolean-datetime,catching-non-exception,cell-var-from-loop,confusing-with-statement,consider-merging-isinstance,consider-using-enumerate,consider-using-ternary,continue-in-finally,cyclic-import,deprecated-pragma,django-not-available,duplicate-except,duplicate-key,eval-used,exec-used,expression-not-assigned,fatal,file-ignored,fixme,global-at-module-level,global-statement,global-variable-not-assigned,global-variable-undefined,http-response-with-content-type-json,http-response-with-json-dumps,invalid-all-object,invalid-characters-in-docstring,len-as-condition,literal-comparison,locally-disabled,locally-enabled,lost-exception,lowercase-l-suffix,misplaced-bare-raise,missing-final-newline,missing-kwoa,mixed-line-endings,model-has-unicode,model-missing-unicode,model-no-explicit-unicode,model-unicode-not-callable,multiple-imports,multiple-statements,new-db-field-with-default,no-else-return,no-else-raise,non-ascii-bytes-literals,nonexistent-operator,not-an-iterable,not-in-loop,notimplemented-raised,overlapping-except,parse-error,pointless-statement,pointless-string-statement,raising-bad-type,raising-non-exception,raw-checker-failed,redefine-in-handler,redefined-argument-from-local,redefined-builtin,redundant-content-type-for-json-response,reimported,relative-import,return-outside-function,simplifiable-if-statement,singleton-comparison,syntax-error,trailing-comma-tuple,trailing-newlines,unbalanced-tuple-unpacking,undefined-all-variable,undefined-loop-variable,unexpected-line-ending-format,unidiomatic-typecheck,unnecessary-lambda,unnecessary-pass,unnecessary-semicolon,unneeded-not,unpacking-non-sequence,unreachable,unrecognized-inline-option,used-before-assignment,useless-else-on-loop,using-constant-test,wildcard-import,yield-outside-function,useless-return +enable=assert-on-tuple,astroid-error,bad-except-order,bad-inline-option,bad-option-value,bad-reversed-sequence,bare-except,binary-op-exception,boolean-datetime,catching-non-exception,cell-var-from-loop,confusing-with-statement,consider-merging-isinstance,consider-using-enumerate,consider-using-ternary,continue-in-finally,cyclic-import,deprecated-pragma,django-not-available,duplicate-except,duplicate-key,eval-used,exec-used,expression-not-assigned,fatal,file-ignored,global-at-module-level,global-statement,global-variable-not-assigned,global-variable-undefined,http-response-with-content-type-json,http-response-with-json-dumps,invalid-all-object,invalid-characters-in-docstring,len-as-condition,literal-comparison,locally-disabled,locally-enabled,lost-exception,lowercase-l-suffix,misplaced-bare-raise,missing-final-newline,missing-kwoa,mixed-line-endings,model-has-unicode,model-missing-unicode,model-no-explicit-unicode,model-unicode-not-callable,multiple-imports,multiple-statements,new-db-field-with-default,no-else-return,no-else-raise,non-ascii-bytes-literals,nonexistent-operator,not-an-iterable,not-in-loop,notimplemented-raised,overlapping-except,parse-error,pointless-statement,pointless-string-statement,raising-bad-type,raising-non-exception,raw-checker-failed,redefine-in-handler,redefined-argument-from-local,redefined-builtin,redundant-content-type-for-json-response,reimported,relative-import,return-outside-function,simplifiable-if-statement,singleton-comparison,syntax-error,trailing-comma-tuple,trailing-newlines,unbalanced-tuple-unpacking,undefined-all-variable,undefined-loop-variable,unexpected-line-ending-format,unidiomatic-typecheck,unnecessary-lambda,unnecessary-pass,unnecessary-semicolon,unneeded-not,unpacking-non-sequence,unreachable,unrecognized-inline-option,used-before-assignment,useless-else-on-loop,using-constant-test,wildcard-import,yield-outside-function,useless-return [REPORTS] diff --git a/CUIAudioPlayer/Player.py b/CUIAudioPlayer/Player.py index 2380f2c..746697f 100644 --- a/CUIAudioPlayer/Player.py +++ b/CUIAudioPlayer/Player.py @@ -47,6 +47,7 @@ def extract_metadata(abs_file_dir): :return: OrderedDict[str, Any] """ + tag = TinyTag.get(abs_file_dir) filtered = sorted(((k, v) for k, v in tag.as_dict().items() if v)) return OrderedDict(filtered) @@ -60,6 +61,7 @@ def add_callback_patch(widget_: py_cui.widgets.Widget, callback: Callable, keypr :param callback: Any callables :param keypress_only: Decides whether to replace mouse input handler alongside with key input one. """ + # Sequence is _draw -> _handle_mouse_press, so patching on _draw results 1 update behind. # Therefore we need to patch both _handle_mouse_press and _handle_keyboard_press. @@ -217,30 +219,50 @@ def volume_callback(): # Primary callbacks def on_file_click(self): + """ + Callback for clicking an item from audio_list. + """ + if self.selected_track in self.path_wrapper.folder_list: self._clear_meta() else: self._update_meta() def on_next_track_click(self): + """ + Callback for clicking next track button. + """ + self.stream.stop_stream(run_finished_callback=False) def on_previous_track_click(self): + """ + Callback for clicking previous button. + """ + pass def on_stop_click(self): + """ + Callback for clicking stop button. + """ + try: self.stream.stop_stream() except (RuntimeError, FileNotFoundError): return - with self.maintain_current_view(): + with self._maintain_current_view(): # revert texts self._refresh_list(search_files=False) self.mark_as_stopped(self.currently_playing) self.write_info("") def on_reload_click(self): + """ + Callback for clicking reload button. + """ + self.on_stop_click() # clear widgets @@ -264,7 +286,7 @@ def play_cb_enter(self): self.on_reload_click() else: # force play audio - with self.maintain_current_view(): + with self._maintain_current_view(): try: self.stream.stop_stream() except RuntimeError as err: @@ -281,7 +303,7 @@ def play_cb_space_bar(self): Also a callback for Play Button. """ - with self.maintain_current_view(): + with self._maintain_current_view(): try: # assuming State: Paused self.stream.pause_stream() @@ -382,7 +404,7 @@ def write_info(self, text: str): if text: # Will have hard time to implement cycling texts. - fit_text = fit_to_actual_width(str(text), self.get_absolute_size(self.info_box)[-1]) + fit_text = fit_to_actual_width(str(text), self._get_absolute_size(self.info_box)[-1]) self.info_box.set_text(fit_text) else: self.info_box.clear() @@ -398,7 +420,7 @@ def _write_to_scroll_widget(self, lines: Iterable, widget: py_cui.widgets.Scroll widget.clear() offset = -1 - _, usable_x = self.get_absolute_size(widget) + _, usable_x = self._get_absolute_size(widget) for line_ in lines: widget.add_item(fit_to_actual_width(line_, usable_x + offset)) @@ -527,7 +549,7 @@ def play_next(self): logger.debug(f"Playing Next - {next_}") - with self.maintain_current_view(): + with self._maintain_current_view(): if not self.play_stream(next_): logger.warning("Error playing next track. Moving on.") self.play_next() @@ -536,7 +558,7 @@ def play_next(self): # Helper functions ----------------------------------------- - def get_absolute_size(self, widget: py_cui.widgets.Widget) -> Tuple[int, int]: + def _get_absolute_size(self, widget: py_cui.widgets.Widget) -> Tuple[int, int]: """ Get absolute dimensions of widget including borders. @@ -579,7 +601,7 @@ def currently_playing(self) -> int: return self.path_wrapper.index(file_name) @contextmanager - def maintain_current_view(self): + def _maintain_current_view(self): """ Remembers indices of both `selected / visible top item` and restores it. Will not be necessary when directly manipulating ScrollWidget's internal item list. @@ -606,7 +628,8 @@ def draw_player(): # this don't have to be a second. Might be an example of downside of ABC player_ref = AudioPlayer(root) - assert player_ref # Preventing unused variable check + assert player_ref + # Preventing unused variable check root.start()