Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes from PR #14 #15

Merged
merged 3 commits into from
Sep 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions i3blocks_mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def __init__(self, bus_name, config=None):
self._last_info = None
self._last_status = None
self._last_metadata = None
# a dict set of well-known names with unique instance suffixes
self._instances = set()
# a dict used as an ordered set, keys — well-known names with unique
# instance suffixes, values — True
self._instances = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! sorry about this part of the change, my understanding was that dictonaries had no guaranteed order! but that was an old thing (prev to 3.7).

https://docs.python.org/3.7/library/stdtypes.html#dict

At the moment of writting, at the very bottom of this section there is this note:

Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6.


@classmethod
def create_loop(cls):
Expand Down Expand Up @@ -255,22 +256,22 @@ def _maybe_add_instance(self, name: str) -> bool:
maybe_prefix, _, _ = name.rpartition('.')
if maybe_prefix != name_prefix:
return False
self._instances.add(name)
self._instances[name] = True
return True

def _maybe_remove_instance(self, name: str) -> None:
name_prefix = self._bus_name_prefix
if not name.startswith(name_prefix):
return
maybe_prefix, _, _ = name.rpartition('.' )
if maybe_prefix == name_prefix and name in self._instances:
self._instances.remove(name)
maybe_prefix, _, _ = name.rpartition('.')
if maybe_prefix == name_prefix:
self._instances.pop(name, None)

def _pick_instance(self) -> str | None:
for bus_name in sorted(self._instances, reverse=True):
for bus_name in reversed(tuple(self._instances)):
if self.bus_name_has_owner(bus_name):
return bus_name
self._instances.remove(bus_name)
del self._instances[bus_name]
return None

def start_stdin_read_loop(self):
Expand All @@ -286,6 +287,7 @@ def stop_stdin_read_loop(self):
io_priority=GLib.PRIORITY_DEFAULT,
callback=lambda *args: self._loop.quit(),
)
self._loop.run()
self._stdin_stream = None

def _read_stdin_once(self):
Expand Down Expand Up @@ -348,7 +350,7 @@ def _connect_to_specific_name_owner_changed_signal(self):
)
self._specific_name_owner_changed_signal_match = signal_match

def _on_specific_name_owner_changed(self, unused_name, old_owner, new_owner):
def _on_specific_name_owner_changed(self, _name, old_owner, new_owner):
if not old_owner and new_owner:
if not self._player_connected:
self._connect_to_player()
Expand Down