-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move status icon into separate blueman-tray appliction
Instead of handling the icon itself, the StatusIcon plugin now only reveals the necessary information via D-Bus and the AppIndicator plugin only changes the implementation to use. blueman-tray uses that information to show a status icon using the requested implementation.
- Loading branch information
Showing
14 changed files
with
281 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
# coding=utf-8 | ||
|
||
from __future__ import print_function | ||
from __future__ import division | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
import os | ||
import sys | ||
import signal | ||
|
||
# support running uninstalled | ||
_dirname = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | ||
if 'BLUEMAN_SOURCE' in os.environ: | ||
sys.path.insert(0, _dirname) | ||
|
||
from blueman.Functions import set_proc_title, create_parser, create_logger | ||
from blueman.main.Tray import BluemanTray | ||
|
||
# Workaround introspection bug, gnome bug 622084 | ||
signal.signal(signal.SIGINT, signal.SIG_DFL) | ||
signal.signal(signal.SIGTERM, signal.SIG_DFL) | ||
|
||
if __name__ == '__main__': | ||
parser = create_parser() | ||
args = parser.parse_args() | ||
|
||
if args.LEVEL.upper() == "DEBUG": | ||
log_level = logging.DEBUG | ||
elif args.LEVEL.upper() == "INFO": | ||
log_level = logging.INFO | ||
elif args.LEVEL.upper() == "WARNING": | ||
log_level = logging.WARNING | ||
elif args.LEVEL.upper() == "ERROR": | ||
log_level = logging.ERROR | ||
elif args.LEVEL.upper() == "CRITICAL": | ||
log_level = logging.CRITICAL | ||
else: | ||
log_level = logging.WARNING | ||
|
||
create_logger(log_level, "blueman-tray", syslog=args.syslog) | ||
|
||
set_proc_title() | ||
BluemanTray() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from importlib import import_module | ||
|
||
import logging | ||
|
||
from blueman.Functions import check_single_instance | ||
from blueman.main.AppletService import AppletService | ||
|
||
import gi | ||
gi.require_version('Gtk', '3.0') | ||
from gi.repository import GLib, Gio | ||
|
||
|
||
class BluemanTray(object): | ||
def __init__(self): | ||
check_single_instance("blueman-tray") | ||
|
||
applet = AppletService() | ||
|
||
main_loop = GLib.MainLoop() | ||
|
||
Gio.bus_watch_name(Gio.BusType.SESSION, 'org.blueman.Applet', | ||
Gio.BusNameWatcherFlags.NONE, None, lambda _connection, _name: main_loop.quit()) | ||
|
||
indicator_name = applet.GetStatusIconImplementation() | ||
logging.info('Using indicator "%s"' % indicator_name) | ||
indicator_class = getattr(import_module('blueman.main.indicators.' + indicator_name), indicator_name) | ||
self.indicator = indicator_class(applet.GetIconName(), self._activate_menu_item, self._activate_status_icon) | ||
|
||
applet.connect('g-signal', self.on_signal) | ||
|
||
self.indicator.set_text(applet.GetText()) | ||
self.indicator.set_visibility(applet.GetVisibility()) | ||
self.indicator.set_menu(applet.GetMenu()) | ||
|
||
main_loop.run() | ||
|
||
def _activate_menu_item(self, *indexes): | ||
return AppletService().ActivateMenuItem('(ai)', indexes) | ||
|
||
def _activate_status_icon(self): | ||
return AppletService().Activate() | ||
|
||
def on_signal(self, _applet, sender_name, signal_name, args): | ||
if signal_name == 'IconNameChanged': | ||
self.indicator.set_icon(*args) | ||
elif signal_name == 'TextChanged': | ||
self.indicator.set_text(*args) | ||
elif signal_name == 'VisibilityChanged': | ||
self.indicator.set_visibility(*args) | ||
elif signal_name == 'MenuChanged': | ||
self.indicator.set_menu(*args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# coding=utf-8 | ||
from __future__ import print_function | ||
from __future__ import division | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import gi | ||
|
||
gi.require_version('AppIndicator3', '0.1') | ||
from gi.repository import AppIndicator3 | ||
from blueman.main.indicators.GtkStatusIcon import build_menu | ||
|
||
|
||
class AppIndicator(object): | ||
def __init__(self, icon_name, on_activate_menu_item, _on_activate_status_icon): | ||
self._on_activate = on_activate_menu_item | ||
self.indicator = AppIndicator3.Indicator.new('blueman', icon_name, | ||
AppIndicator3.IndicatorCategory.APPLICATION_STATUS) | ||
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) | ||
|
||
def set_icon(self, icon_name): | ||
self.indicator.set_icon(icon_name) | ||
self.indicator.set_status(AppIndicator3.IndicatorStatus.ATTENTION) | ||
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) | ||
|
||
def set_text(self, text): | ||
self.indicator.props.title = text | ||
|
||
def set_visibility(self, visible): | ||
status = AppIndicator3.IndicatorStatus.ACTIVE if visible else AppIndicator3.IndicatorStatus.PASSIVE | ||
self.indicator.set_status(status) | ||
|
||
def set_menu(self, menu): | ||
self.indicator.set_menu(build_menu(menu, self._on_activate)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# coding=utf-8 | ||
from __future__ import print_function | ||
from __future__ import division | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
import gi | ||
|
||
gi.require_version("Gtk", "3.0") | ||
from gi.repository import Gtk, GLib, GObject | ||
from blueman.Functions import create_menuitem | ||
|
||
|
||
def build_menu(items, activate): | ||
menu = Gtk.Menu() | ||
for index, item in enumerate(items): | ||
if 'text' in item and 'icon_name' in item: | ||
gtk_item = create_menuitem(item['text'], item['icon_name']) | ||
label = gtk_item.get_child() | ||
if item['markup']: | ||
label.set_markup_with_mnemonic(item['text']) | ||
else: | ||
label.set_text_with_mnemonic(item['text']) | ||
gtk_item.connect('activate', lambda _, idx=index: activate(idx)) | ||
if 'submenu' in item: | ||
gtk_item.set_submenu(build_menu(item['submenu'], lambda subid, idx=index: activate(idx, subid))) | ||
if 'tooltip' in item: | ||
gtk_item.props.tooltip_text = item['tooltip'] | ||
gtk_item.props.sensitive = item['sensitive'] | ||
else: | ||
gtk_item = Gtk.SeparatorMenuItem() | ||
gtk_item.show() | ||
menu.append(gtk_item) | ||
return menu | ||
|
||
|
||
class GtkStatusIcon(object): | ||
def __init__(self, icon_name, on_activate_menu_item, on_activate_status_icon): | ||
self._on_activate = on_activate_menu_item | ||
self.indicator = Gtk.StatusIcon(icon_name=icon_name) | ||
self.indicator.set_title('blueman') | ||
self.indicator.connect('popup-menu', self.on_popup_menu) | ||
self.indicator.connect('activate', lambda _status_icon: on_activate_status_icon()) | ||
self._menu = None | ||
|
||
def on_popup_menu(self, status_icon, button, activate_time): | ||
if self._menu: | ||
self._menu.popup(None, None, Gtk.StatusIcon.position_menu, status_icon, button, activate_time) | ||
|
||
def set_icon(self, icon_name): | ||
self.indicator.props.icon_name = icon_name | ||
|
||
def set_text(self, text): | ||
self.indicator.props.tooltip_markup = text | ||
|
||
def set_visibility(self, visible): | ||
self.indicator.props.visible = visible | ||
|
||
def set_menu(self, menu): | ||
self._menu = build_menu(menu, self._on_activate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
bluemandir = $(pythondir)/blueman/main/indicators | ||
blueman_PYTHON = \ | ||
__init__.py \ | ||
AppIndicator.py \ | ||
GtkStatusIcon.py | ||
|
||
CLEANFILES = \ | ||
$(BUILT_SOURCES) | ||
|
||
DISTCLEANFILES = \ | ||
$(CLEANFILES) | ||
|
||
clean-local: | ||
rm -rf *.pyc *.pyo | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.