mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
Merge pull request #276 from dmitmel/master
[pull] master from dmitmel:master
This commit is contained in:
commit
56b7476a42
2 changed files with 103 additions and 79 deletions
|
@ -6,10 +6,14 @@ ignore =
|
||||||
E114
|
E114
|
||||||
# Indent for continuation lines is smaller than expected
|
# Indent for continuation lines is smaller than expected
|
||||||
E121
|
E121
|
||||||
|
# Hanging indent on a continuation line is unaligned
|
||||||
|
E131
|
||||||
# Import not at the top of the file
|
# Import not at the top of the file
|
||||||
E402
|
E402
|
||||||
# Line too long
|
# Line too long
|
||||||
E501
|
E501
|
||||||
|
# `except` without an exception type
|
||||||
|
E722
|
||||||
# Newline before a binary operator
|
# Newline before a binary operator
|
||||||
W503
|
W503
|
||||||
# Newline after a binary operator
|
# Newline after a binary operator
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import gi
|
import gi
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
gi.require_version("Playerctl", "2.0")
|
gi.require_version("Playerctl", "2.0")
|
||||||
|
@ -167,11 +168,22 @@ def iter_actions_for_player(player):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
root_menu = Gtk.Menu()
|
is_already_activated = False
|
||||||
|
|
||||||
player_names = Playerctl.list_players()
|
|
||||||
|
|
||||||
if len(player_names) > 0:
|
def on_activate(application):
|
||||||
|
global is_already_activated
|
||||||
|
if is_already_activated:
|
||||||
|
# Ignore activations triggered by remote instances. See this:
|
||||||
|
# <https://stackoverflow.com/a/42044391/12005228>
|
||||||
|
return
|
||||||
|
is_already_activated = True
|
||||||
|
|
||||||
|
root_menu = Gtk.Menu()
|
||||||
|
|
||||||
|
player_names = Playerctl.list_players()
|
||||||
|
|
||||||
|
if len(player_names) > 0:
|
||||||
players = []
|
players = []
|
||||||
for player_name in player_names:
|
for player_name in player_names:
|
||||||
player = Playerctl.Player.new_from_name(player_name)
|
player = Playerctl.Player.new_from_name(player_name)
|
||||||
|
@ -205,7 +217,6 @@ if len(player_names) > 0:
|
||||||
|
|
||||||
actions_menu = Gtk.Menu()
|
actions_menu = Gtk.Menu()
|
||||||
|
|
||||||
track_metadata = player.props.metadata
|
|
||||||
any_metadata_was_added = False
|
any_metadata_was_added = False
|
||||||
for meta_entry_text in iter_metadata_entries_for_player(player):
|
for meta_entry_text in iter_metadata_entries_for_player(player):
|
||||||
meta_menu_item = Gtk.MenuItem.new_with_label(meta_entry_text)
|
meta_menu_item = Gtk.MenuItem.new_with_label(meta_entry_text)
|
||||||
|
@ -237,7 +248,7 @@ if len(player_names) > 0:
|
||||||
if action_fn is not None:
|
if action_fn is not None:
|
||||||
action_menu_item.connect(
|
action_menu_item.connect(
|
||||||
"activate",
|
"activate",
|
||||||
lambda _menu_item, action_fn, action_fn_args: action_fn(*action_fn_args),
|
lambda _target, action_fn, action_fn_args: action_fn(*action_fn_args),
|
||||||
action_fn,
|
action_fn,
|
||||||
action_fn_args,
|
action_fn_args,
|
||||||
)
|
)
|
||||||
|
@ -246,16 +257,25 @@ if len(player_names) > 0:
|
||||||
|
|
||||||
player_menu_item.set_submenu(actions_menu)
|
player_menu_item.set_submenu(actions_menu)
|
||||||
root_menu.append(player_menu_item)
|
root_menu.append(player_menu_item)
|
||||||
else:
|
else:
|
||||||
menu_item = Gtk.MenuItem.new_with_label("No players were detected!")
|
menu_item = Gtk.MenuItem.new_with_label("No players were detected!")
|
||||||
menu_item.set_sensitive(False)
|
menu_item.set_sensitive(False)
|
||||||
root_menu.append(menu_item)
|
root_menu.append(menu_item)
|
||||||
|
|
||||||
root_menu.connect("selection-done", Gtk.main_quit)
|
root_menu.connect("selection-done", lambda _target: application.quit())
|
||||||
root_menu.connect("deactivate", Gtk.main_quit)
|
root_menu.connect("deactivate", lambda _target: application.quit())
|
||||||
root_menu.connect("destroy", Gtk.main_quit)
|
root_menu.connect("destroy", lambda _target: application.quit())
|
||||||
|
|
||||||
root_menu.show_all()
|
root_menu.show_all()
|
||||||
root_menu.popup(None, None, None, None, 0, Gdk.CURRENT_TIME)
|
root_menu.popup(None, None, None, None, 0, Gdk.CURRENT_TIME)
|
||||||
|
|
||||||
Gtk.main()
|
Gdk.notify_startup_complete()
|
||||||
|
|
||||||
|
# `hold` needs to be done last, so that if an exception occurs during the
|
||||||
|
# initialization the application doesn't hang.
|
||||||
|
application.hold()
|
||||||
|
|
||||||
|
|
||||||
|
application = Gtk.Application(application_id="com.github.dmitmel.dotfiles.playerctl-simple-menu")
|
||||||
|
application.connect("activate", on_activate)
|
||||||
|
sys.exit(application.run(sys.argv))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue