mintmenu/usr/lib/linuxmint/mintMenu/plugins/system_management.py

205 lines
8.8 KiB
Python
Raw Normal View History

#!/usr/bin/python3
import gettext
import os
import locale
2009-07-27 11:45:34 +01:00
2013-03-06 02:14:11 +00:00
import gi
2016-09-06 15:58:34 +01:00
gi.require_version("Gtk", "3.0")
2019-05-20 15:19:55 +01:00
from gi.repository import Gtk, Gio
2009-07-27 11:45:34 +01:00
from plugins.easybuttons import easyButton
from plugins.execute import Execute
2009-07-27 11:45:34 +01:00
# i18n
2009-11-03 11:29:52 +00:00
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
locale.bindtextdomain("mintmenu", "/usr/share/linuxmint/locale")
locale.textdomain("mintmenu")
2009-07-27 11:45:34 +01:00
class pluginclass(object):
2009-07-27 11:45:34 +01:00
def __init__(self, mintMenuWin, toggleButton, de):
2011-03-29 18:51:59 +01:00
self.mintMenuWin = mintMenuWin
self.toggleButton = toggleButton
self.de = de
2009-07-27 11:45:34 +01:00
2013-03-06 02:14:11 +00:00
self.builder = Gtk.Builder()
self.builder.set_translation_domain("mintmenu")
self.builder.add_from_file("/usr/share/linuxmint/mintmenu/system.ui")
2013-03-06 02:14:11 +00:00
self.systemBtnHolder = self.builder.get_object("system_button_holder")
self.editableBtnHolder = self.builder.get_object("editable_button_holder")
self.scrolledWindow = self.builder.get_object("scrolledwindow2")
2011-03-29 18:51:59 +01:00
# These properties are NECESSARY to maintain consistency
# Set 'window' property for the plugin (Must be the root widget)
self.window = self.builder.get_object("mainWindow")
2011-03-29 18:51:59 +01:00
# Set 'heading' property for plugin
self.heading = _("System")
# This should be the first item added to the window in glade
self.content_holder = self.builder.get_object("System")
2011-03-29 18:51:59 +01:00
# Gconf stuff
2019-05-20 15:19:55 +01:00
self.settings = Gio.Settings("com.linuxmint.mintmenu.plugins.system_management")
self.settings.connect("changed::icon-size", self.RegenPlugin)
self.settings.connect("changed::show-control-center", self.RegenPlugin)
self.settings.connect("changed::show-lock-screen", self.RegenPlugin)
self.settings.connect("changed::show-logout", self.RegenPlugin)
self.settings.connect("changed::show-package-manager", self.RegenPlugin)
self.settings.connect("changed::show-software-manager", self.RegenPlugin)
self.settings.connect("changed::show-terminal", self.RegenPlugin)
self.settings.connect("changed::show-quit", self.RegenPlugin)
self.settings.connect("changed::allow-scrollbar", self.RegenPlugin)
self.settings.connect("changed::height", self.changePluginSize)
self.settings.connect("changed::width", self.changePluginSize)
2013-03-06 02:14:11 +00:00
self.GetGSettingsEntries()
2011-03-29 18:51:59 +01:00
self.content_holder.set_size_request(self.width, self.height)
2011-03-29 18:51:59 +01:00
def wake(self):
2011-03-29 18:51:59 +01:00
pass
def changePluginSize(self, settings, key):
2019-05-20 15:19:55 +01:00
self.allowScrollbar = self.settings.get_boolean("allow-scrollbar")
2013-03-06 02:14:11 +00:00
if key == "width":
self.width = settings.get_int(key)
elif key == "height":
if not self.allowScrollbar:
2011-03-29 18:51:59 +01:00
self.height = -1
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
2011-03-29 18:51:59 +01:00
else:
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2013-03-06 02:14:11 +00:00
self.height = settings.get_int(key)
2011-03-29 18:51:59 +01:00
self.content_holder.set_size_request(self.width, self.height)
2011-03-29 18:51:59 +01:00
def RegenPlugin(self, *args, **kargs):
2013-03-06 02:14:11 +00:00
self.GetGSettingsEntries()
2011-03-29 18:51:59 +01:00
self.ClearAll()
self.do_standard_items()
def GetGSettingsEntries(self):
2011-03-29 18:51:59 +01:00
2019-05-20 15:19:55 +01:00
self.width = self.settings.get_int("width")
self.allowScrollbar = self.settings.get_boolean("allow-scrollbar")
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
2019-05-20 15:19:55 +01:00
self.height = self.settings.get_int("height")
self.content_holder.set_size_request(self.width, self.height)
if not self.allowScrollbar:
2011-03-29 18:51:59 +01:00
self.height = -1
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
self.content_holder.set_size_request(self.width, self.height)
2019-05-20 15:19:55 +01:00
self.iconsize = self.settings.get_int("icon-size")
2011-03-29 18:51:59 +01:00
# Check toggles
2019-05-20 15:19:55 +01:00
self.showSoftwareManager = self.settings.get_boolean("show-software-manager")
self.showPackageManager = self.settings.get_boolean("show-package-manager")
self.showControlCenter = self.settings.get_boolean("show-control-center")
self.showTerminal = self.settings.get_boolean("show-terminal")
self.showLockScreen = self.settings.get_boolean("show-lock-screen")
self.showLogout = self.settings.get_boolean("show-logout")
self.showQuit = self.settings.get_boolean("show-quit")
2011-03-29 18:51:59 +01:00
if self.de == "cinnamon":
self.lock_cmd = "cinnamon-screensaver-command --lock"
self.logout_cmd = "cinnamon-session-quit --logout"
self.shutdown_cmd = "cinnamon-session-quit --power-off"
self.terminal_cmd = "/usr/bin/gnome-terminal"
self.settings_cmd = "cinnamon-settings"
elif self.de == "xfce":
self.lock_cmd = "xdg-screensaver lock"
self.logout_cmd = "xfce4-session-logout"
self.shutdown_cmd = ""
self.terminal_cmd = "/usr/bin/gnome-terminal"
self.settings_cmd = "xfce4-settings-manager"
self.showLockScreen = False
self.showQuit = False
else:
self.lock_cmd = "mate-screensaver-command -l"
self.logout_cmd = "mate-session-save --logout-dialog"
self.shutdown_cmd = "mate-session-save --shutdown-dialog"
self.terminal_cmd = "/usr/bin/mate-terminal"
self.settings_cmd = "mate-control-center"
2011-03-29 18:51:59 +01:00
# Hide vertical dotted separator
2019-05-20 15:19:55 +01:00
self.hideseparator = self.settings.get_boolean("hide-separator")
2011-03-29 18:51:59 +01:00
# Plugin icon
2019-05-20 15:19:55 +01:00
self.icon = self.settings.get_string("icon")
2011-03-29 18:51:59 +01:00
def ClearAll(self):
for child in self.systemBtnHolder.get_children():
child.destroy()
for child in self.editableBtnHolder.get_children():
child.destroy()
#Add standard items
def do_standard_items(self):
2011-03-29 18:51:59 +01:00
if self.showSoftwareManager:
if os.path.exists("/usr/bin/mintinstall"):
Button1 = easyButton("mintinstall", self.iconsize, [_("Software Manager")], -1, -1)
Button1.connect("clicked", self.ButtonClicked, "mintinstall")
2011-03-29 18:51:59 +01:00
Button1.show()
self.systemBtnHolder.pack_start(Button1, False, False, 0)
self.mintMenuWin.setTooltip(Button1, _("Browse and install available software"))
2011-03-29 18:51:59 +01:00
if self.showPackageManager:
Button2 = easyButton("applications-system", self.iconsize, [_("Package Manager")], -1, -1)
Button2.connect("clicked", self.ButtonClicked, "synaptic-pkexec")
2011-03-29 18:51:59 +01:00
Button2.show()
self.systemBtnHolder.pack_start(Button2, False, False, 0)
self.mintMenuWin.setTooltip(Button2, _("Install, remove and upgrade software packages"))
2011-03-29 18:51:59 +01:00
if self.showControlCenter:
Button3 = easyButton("gtk-preferences", self.iconsize, [_("Control Center")], -1, -1)
Button3.connect("clicked", self.ButtonClicked, self.settings_cmd)
2011-03-29 18:51:59 +01:00
Button3.show()
self.systemBtnHolder.pack_start(Button3, False, False, 0)
self.mintMenuWin.setTooltip(Button3, _("Configure your system"))
2011-03-29 18:51:59 +01:00
if self.showTerminal:
Button4 = easyButton("terminal", self.iconsize, [_("Terminal")], -1, -1)
if os.path.exists(self.terminal_cmd):
Button4.connect("clicked", self.ButtonClicked, self.terminal_cmd)
else:
Button4.connect("clicked", self.ButtonClicked, "x-terminal-emulator")
2011-03-29 18:51:59 +01:00
Button4.show()
self.systemBtnHolder.pack_start(Button4, False, False, 0)
self.mintMenuWin.setTooltip(Button4, _("Use the command line"))
2017-08-26 16:35:45 +01:00
if self.showLockScreen:
Button5 = easyButton("system-lock-screen", self.iconsize, [_("Lock Screen")], -1, -1)
Button5.connect("clicked", self.ButtonClicked, self.lock_cmd)
Button5.show()
self.systemBtnHolder.pack_start(Button5, False, False, 0)
self.mintMenuWin.setTooltip(Button5, _("Requires password to unlock"))
if self.showLogout:
Button6 = easyButton("system-log-out", self.iconsize, [_("Logout")], -1, -1)
Button6.connect("clicked", self.ButtonClicked, self.logout_cmd)
2014-11-03 17:52:52 +00:00
Button6.show()
self.systemBtnHolder.pack_start(Button6, False, False, 0)
self.mintMenuWin.setTooltip(Button6, _("Log out or switch user"))
if self.showQuit:
Button7 = easyButton("system-shutdown", self.iconsize, [_("Quit")], -1, -1)
Button7.connect("clicked", self.ButtonClicked, self.shutdown_cmd)
Button7.show()
self.systemBtnHolder.pack_start(Button7, False, False, 0)
self.mintMenuWin.setTooltip(Button7, _("Shutdown, restart, suspend or hibernate"))
2011-03-29 18:51:59 +01:00
def ButtonClicked(self, widget, Exec):
2011-03-29 18:51:59 +01:00
self.mintMenuWin.hide()
if Exec:
Execute(Exec)
2011-03-29 18:51:59 +01:00
def do_plugin(self):
2011-03-29 18:51:59 +01:00
self.do_standard_items()