Custom session management plugin



I've written a plugin for custom session management that just has a text entry for each command in the plugin preferences. (These aren't very well aligned, though - is there anything that can be done about that?)

Because (apparently) the Gnome/Xfce plugins launch some dialogue for both log out/shut down with further options, I renamed the classes in session_support.py for these and created extra classes for each individual command they each cover. (That is, log out covers log out and switch user, and shut down covers shut down, reboot and suspend.)

I'm not too sure how icon names are meant to work - I just used what names seem to be used by the icon sets I have installed...
diff --git a/kupfer/plugin/session_custom.py b/kupfer/plugin/session_custom.py
new file mode 100644
index 0000000..1b852c2
--- /dev/null
+++ b/kupfer/plugin/session_custom.py
@@ -0,0 +1,58 @@
+__kupfer_name__ = _("Custom Session Management")
+__kupfer_sources__ = ("ItemSource",)
+__description__ = _("Run custom session management commands")
+__version__ = "1"
+__author__ = "J <J49137 gmail com"
+
+import shlex
+
+from kupfer.plugin_support import PluginSettings
+from kupfer.plugin import session_support as support
+
+__kupfer_settings__ = PluginSettings(
+	{
+		"key": "logout",
+		"label": _("Log out"),
+		"type": str,
+		"value": ""
+	}, {
+		"key": "switchuser",
+		"label": _("Switch user"),
+		"type": str,
+		"value": ""
+	}, {
+		"key": "lockscreen",
+		"label": _("Lock screen"),
+		"type": str,
+		"value": ""
+	}, {
+		"key": "shutdown",
+		"label": _("Shut down"),
+		"type": str,
+		"value": ""
+	}, {
+		"key": "reboot",
+		"label": _("Restart"),
+		"type": str,
+		"value": ""
+	}, {
+		"key": "suspend",
+		"label": _("Suspend"),
+		"type": str,
+		"value": ""
+	}
+)
+
+class ItemSource (support.CommonSource):
+
+	def __init__(self):
+		support.CommonSource.__init__(self, _("Custom Session Management"))
+
+	def get_items(self):
+		for item in (
+			"Logout", "SwitchUser", "LockScreen", "Shutdown", "Reboot",	"Suspend"
+		):
+			value = __kupfer_settings__[item.lower()]
+			if value:
+				argv = shlex.split(value)
+				yield getattr(support, item)((argv,))
diff --git a/kupfer/plugin/session_gnome.py b/kupfer/plugin/session_gnome.py
index 04c1240..3be28e0 100644
--- a/kupfer/plugin/session_gnome.py
+++ b/kupfer/plugin/session_gnome.py
@@ -20,8 +20,8 @@ class GnomeItemsSource (support.CommonSource):
 		support.CommonSource.__init__(self, _("GNOME Session Management"))
 	def get_items(self):
 		return (
-			support.Logout(LOGOUT_CMD),
+			support.LogoutBrowse(LOGOUT_CMD),
 			support.LockScreen(LOCKSCREEN_CMD),
-			support.Shutdown(SHUTDOWN_CMD),
+			support.ShutdownBrowse(SHUTDOWN_CMD),
 		)
 
diff --git a/kupfer/plugin/session_support.py b/kupfer/plugin/session_support.py
index 7a9b764..4af25b0 100644
--- a/kupfer/plugin/session_support.py
+++ b/kupfer/plugin/session_support.py
@@ -25,17 +25,37 @@ class CommandLeaf (RunnableLeaf):
 	def run(self):
 		launch_argv_with_fallbacks(self.object)
 
-class Logout (CommandLeaf):
-	"""Log out from desktop"""
+class LogoutBrowse (CommandLeaf):
+	"""Log out or switch user"""
 	def __init__(self, commands, name=None):
 		if not name: name = _("Log Out...")
 		CommandLeaf.__init__(self, commands, name)
 	def get_description(self):
-		return _("Log out or change user")
+		return _("Log out or switch user")
 	def get_icon_name(self):
 		return "system-log-out"
 
-class Shutdown (CommandLeaf):
+class Logout (CommandLeaf):
+	"""Log out"""
+	def __init__(self, commands, name=None):
+		if not name: name = _("Log Out")
+		CommandLeaf.__init__(self, commands, name)
+	def get_description(self):
+		return _("Log out")
+	def get_icon_name(self):
+		return "system-log-out"
+
+class SwitchUser (CommandLeaf):
+	"""Switch user"""
+	def __init__(self, commands, name=None):
+		if not name: name = _("Change User")
+		CommandLeaf.__init__(self, commands, name)
+	def get_description(self):
+		return _("Switch to another user")
+	def get_icon_name(self):
+		return "system-switch-user"
+
+class ShutdownBrowse (CommandLeaf):
 	"""Shutdown computer or reboot"""
 	def __init__(self, commands, name=None):
 		if not name: name = _("Shut Down...")
@@ -45,6 +65,36 @@ class Shutdown (CommandLeaf):
 	def get_icon_name(self):
 		return "system-shutdown"
 
+class Shutdown (CommandLeaf):
+	"""Shutdown computer"""
+	def __init__(self, commands, name=None):
+		if not name: name = _("Shut Down")
+		CommandLeaf.__init__(self, commands, name)
+	def get_description(self):
+		return _("Shut down computer")
+	def get_icon_name(self):
+		return "system-shutdown"
+
+class Reboot (CommandLeaf):
+	"""Reboot computer"""
+	def __init__(self, commands, name=None):
+		if not name: name = _("Restart")
+		CommandLeaf.__init__(self, commands, name)
+	def get_description(self):
+		return _("Restart computer")
+	def get_icon_name(self):
+		return "system-restart"
+
+class Suspend (CommandLeaf):
+	"""Suspend computer"""
+	def __init__(self, commands, name=None):
+		if not name: name = _("Suspend")
+		CommandLeaf.__init__(self, commands, name)
+	def get_description(self):
+		return _("Suspend computer")
+	def get_icon_name(self):
+		return "system-suspend"
+
 class LockScreen (CommandLeaf):
 	"""Lock screen"""
 	def __init__(self, commands, name=None):
diff --git a/kupfer/plugin/session_xfce.py b/kupfer/plugin/session_xfce.py
index 3b109ec..7cc3533 100644
--- a/kupfer/plugin/session_xfce.py
+++ b/kupfer/plugin/session_xfce.py
@@ -20,7 +20,7 @@ class XfceItemsSource (support.CommonSource):
 		support.CommonSource.__init__(self, _("XFCE Session Management"))
 	def get_items(self):
 		return (
-			support.Logout(LOGOUT_CMD),
+			support.LogoutBrowse(LOGOUT_CMD),
 			support.LockScreen(LOCKSCREEN_CMD),
-			support.Shutdown(SHUTDOWN_CMD),
+			support.ShutdownBrowse(SHUTDOWN_CMD),
 		)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]