Unity launcher indicator to change sides and autohiding
#!/usr/bin/env python3
import os
import gi
from subprocess import call
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
gi.require_version('Notify', '0.7')
from gi.repository import Gtk
from gi.repository import AppIndicator3
from gi.repository import Notify
scriptlen = len(os.path.basename(__file__))
if os.path.islink(__file__):
root = os.readlink(__file__)[:-int(scriptlen)]
else:
root = os.path.dirname(__file__)
APPINDICATOR_ID = 'changelauncherlocation'
APP_NAME = 'Change Launcher Location'
APP_VERSION = '1.0.0'
APP_INDICATOR_ICON = os.path.abspath(os.path.join(root, 'indicator.svg'))
# Commands
# --------
#
# Set the launcher to the BOTTOM
# $ gsettings set com.canonical.Unity.Launcher launcher-position Bottom
#
# Set the launcher to the LEFT
# $ gsettings set com.canonical.Unity.Launcher launcher-position Left
#
# Set the launcher autohide to ON
# $ gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ launcher-hide-mode 1
#
# Set the launcher autohide to OFF
# $ gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ launcher-hide-mode 0
class ChangeLauncherLocationApp():
def __init__(self, *args, **kwargs):
indicator = AppIndicator3.Indicator.new(
APPINDICATOR_ID,
APP_INDICATOR_ICON,
AppIndicator3.IndicatorCategory.SYSTEM_SERVICES
)
indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
indicator.set_menu(self._build_menu())
Notify.init(APPINDICATOR_ID)
Gtk.main()
def quit(self):
Notify.uninit()
Gtk.main_quit()
def _build_menu(self):
menu = Gtk.Menu()
# Add "left" item
item_left = Gtk.MenuItem('Left')
item_left.connect('activate', self._set_menu_left)
menu.append(item_left)
# Add "bottom" item
item_bottom = Gtk.MenuItem('Bottom')
item_bottom.connect('activate', self._set_menu_bottom)
menu.append(item_bottom)
# Add "separator"
separator1 = Gtk.SeparatorMenuItem()
separator1.show()
menu.append(separator1)
# Add "autohide ON" item
item_autohide_on = Gtk.MenuItem('Autohide ON')
item_autohide_on.connect('activate', self._set_menu_autohide_on)
menu.append(item_autohide_on)
# Add "autohide OFF" item
item_autohide_off = Gtk.MenuItem('Autohide OFF')
item_autohide_off.connect('activate', self._set_menu_autohide_off)
menu.append(item_autohide_off)
# Add "separator"
separator2 = Gtk.SeparatorMenuItem()
separator2.show()
menu.append(separator2)
# Add "quit" item
item_quit = Gtk.MenuItem('Quit')
item_quit.connect('activate', quit)
menu.append(item_quit)
menu.show_all()
return menu
def _set_menu_left(self, event):
call(["gsettings", "set", "com.canonical.Unity.Launcher", "launcher-position", "Left"])
Notify.Notification.new("Launcher Change", "The launcher was repositioned to the LEFT.").show()
def _set_menu_bottom(self, event):
call(["gsettings", "set", "com.canonical.Unity.Launcher", "launcher-position", "Bottom"])
Notify.Notification.new("Launcher Change", "The launcher was repositioned to the BOTTOM.").show()
def _set_menu_autohide_on(self, event):
call(["gsettings", "set", "org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/", "launcher-hide-mode", "1"])
Notify.Notification.new("Launcher Change", "The launcher autohide setting was set to ON.").show()
def _set_menu_autohide_off(self, event):
call(["gsettings", "set", "org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/", "launcher-hide-mode", "0"])
Notify.Notification.new("Launcher Change", "The launcher autohide setting was set to OFF.").show()
# Create the app
app = ChangeLauncherLocationApp()