Skip to content

Commit

Permalink
changes to meet pylint requirement - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jupiterbjy committed Feb 12, 2021
1 parent 0c7f99f commit 919ec5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
41 changes: 32 additions & 9 deletions CUIAudioPlayer/Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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))

Expand Down Expand Up @@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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()

Expand Down

0 comments on commit 919ec5e

Please sign in to comment.