Skip to content

Commit

Permalink
PluginWindow: Add accels to close
Browse files Browse the repository at this point in the history
  • Loading branch information
infirit committed Dec 10, 2022
1 parent 84b1c81 commit c72d922
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 8 additions & 4 deletions blueman/gui/applet/PluginDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk
from gi.repository import Gtk, Gdk, Gio

if TYPE_CHECKING:
from blueman.main.Applet import BluemanApplet
Expand Down Expand Up @@ -89,9 +88,10 @@ def get_control_widget(self, opt: str, params: "Option") -> Gtk.Widget:
raise ValueError()


class PluginDialog(Gtk.Window):
def __init__(self, applet: "BluemanApplet") -> None:
class PluginDialog(Gtk.ApplicationWindow):
def __init__(self, applet: "BluemanApplet", application: Gtk.Application) -> None:
super().__init__(
application=application,
title=_("Plugins"),
icon_name="blueman",
name="PluginDialog",
Expand Down Expand Up @@ -163,6 +163,10 @@ def __init__(self, applet: "BluemanApplet") -> None:

self.list.set_cursor(0)

close_action = Gio.SimpleAction.new("close", None)
close_action.connect("activate", lambda x, y: self.close())
self.add_action(close_action)

def list_compare_func(self, _treemodel: Gtk.TreeModel, iter1: Gtk.TreeIter, iter2: Gtk.TreeIter, _user_data: object
) -> int:
a = self.list.get(iter1, "activatable", "name")
Expand Down
11 changes: 9 additions & 2 deletions blueman/main/Applet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from gi.repository import Gio, GLib
import gi
gi.require_version("Gtk", "3.0")

from gi.repository import Gio, GLib, Gtk
import logging
import signal
from typing import Any, cast
Expand All @@ -19,7 +22,7 @@
from blueman.plugins.applet.StatusIcon import StatusIcon


class BluemanApplet(Gio.Application):
class BluemanApplet(Gtk.Application):
def __init__(self) -> None:
super().__init__(application_id="org.blueman.Applet", flags=Gio.ApplicationFlags.FLAGS_NONE)
setup_icon_path()
Expand Down Expand Up @@ -60,6 +63,10 @@ def do_quit(_: object) -> bool:
self._any_device = AnyDevice()
self._any_device.connect_signal('property-changed', self._on_device_property_changed)

def do_startup(self) -> None:
Gtk.Application.do_startup(self)
self.set_accels_for_action("win.close", ["<Ctrl>w", "Escape"])

def do_activate(self) -> None:
if not self._active:
self.hold()
Expand Down
4 changes: 2 additions & 2 deletions blueman/plugins/applet/StandardItems.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StandardItems(AppletPlugin, PowerStateListener):
__author__ = "walmis"

def on_load(self) -> None:
self._plugin_window: Optional[Gtk.Window] = None
self._plugin_window: Optional[Gtk.ApplicationWindow] = None

self.parent.Plugins.Menu.add(self, 21)

Expand Down Expand Up @@ -107,6 +107,6 @@ def on_close(win: Gtk.Window, _event: Gdk.Event) -> bool:
if self._plugin_window:
self._plugin_window.present()
else:
self._plugin_window = PluginDialog(self.parent)
self._plugin_window = PluginDialog(self.parent, self.parent)
self._plugin_window.connect("delete-event", on_close)
self._plugin_window.show()

0 comments on commit c72d922

Please sign in to comment.