aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--[-rwxr-xr-x]lmlib.py10
-rwxr-xr-xlogout-manager-tcl.py90
2 files changed, 95 insertions, 5 deletions
diff --git a/lmlib.py b/lmlib.py
index 364dd9a..a5206e5 100755..100644
--- a/lmlib.py
+++ b/lmlib.py
@@ -19,27 +19,27 @@ logout_manager_version="2019-06-12b"
class Actions:
@staticmethod
- def hibernate(config):
+ def hibernate(config, event=None):
#print("need to run the /sys/power/state trick, if available")
print(config.get_hibernate_command())
@staticmethod
- def lock(config):
+ def lock(config, event=None):
#print("please lock the screen.")
print(config.get_lock_command())
@staticmethod
- def logout(config):
+ def logout(config, event=None):
#print("please log out of current session!")
print(config.get_logout_command())
@staticmethod
- def reboot(config):
+ def reboot(config, event=None):
#print("please reboot.")
print(config.get_reboot_command())
@staticmethod
- def shutdown(config):
+ def shutdown(config, event=None):
#print("please shut yourself down!")
print(config.get_shutdown_command())
diff --git a/logout-manager-tcl.py b/logout-manager-tcl.py
new file mode 100755
index 0000000..c605dc0
--- /dev/null
+++ b/logout-manager-tcl.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python3
+# Startdate: 2019-06-12 20:05
+# WORKHERE:
+# add icons
+# add full headers
+
+# References:
+# http://effbot.org/tkinterbook/button.htm
+# http://effbot.org/tkinterbook/tkinter-application-windows.htm
+# http://effbot.org/tkinterbook/
+# pass parameters to function of Button(command=) https://stackoverflow.com/questions/38749620/python-3-tkinter-button-commands#38750155
+# alternate for passing params https://stackoverflow.com/questions/6920302/how-to-pass-arguments-to-a-button-command-in-tkinter
+# https://stackoverflow.com/questions/18537918/set-window-icon#18538416
+# the exact syntax <Alt-k> for master.bind https://stackoverflow.com/questions/16082243/how-to-bind-ctrl-in-python-tkinter
+
+import os, sys
+sys.path.append("/home/bgirton/dev/logout-manager")
+import lmlib
+from tkinter import *
+from functools import partial
+
+config = lmlib.Initialize_config()
+actions = lmlib.Actions
+
+# graphical classes and functions
+print("Loading graphics...")
+
+def icon_bitmap(name = "", theme = "default", size = "48"):
+ # WORKHERE: can build some tool that loops through the icon theme dirs
+ # if name is a specific filename, just use it.
+ # if the only thing that is found during the looping is a svg, return None
+ # if the valid file provided is svg, then try a few derivations to get a png, else return None
+ imgicon = PhotoImage(file=os.path.join("/usr/share/icons/Adwaita/24x24/actions","system-log-out.png"))
+ return imgicon
+
+class App:
+ def __init__(self, master):
+ frame = Frame(master)
+ frame.grid(row=0)
+
+ self.buttonLock = Button(frame, text="Lock", underline=3, command=partial(actions.lock,config))
+ #self.buttonLock.pack(side=LEFT)
+ self.buttonLock.grid(row=0,column=0)
+ # WORKS master.bind_all("<Alt-k>", something)
+ # PASSES 2 params when expecting 1 master.bind_all("<Alt-k>", self.buttonLock.invoke)
+ master.bind_all("<Alt-k>", partial(actions.lock,config))
+
+ self.buttonLogout = Button(frame, text="Logout", underline=0, command=lambda: actions.logout(config))
+ self.buttonLogout.grid(row=0,column=1)
+ master.bind_all("<Alt-l>", partial(actions.logout,config))
+
+ self.buttonHibernate = Button(frame, text="Hibernate", underline=0, command=lambda: actions.hibernate(config))
+ self.buttonHibernate.grid(row=0,column=2)
+ master.bind_all("<Alt-h>", partial(actions.hibernate,config))
+
+ self.buttonShutdown = Button(frame, text="Shutdown", underline=0, command=lambda: actions.shutdown(config))
+ self.buttonShutdown.grid(row=0,column=3)
+ master.bind_all("<Alt-s>", partial(actions.shutdown,config))
+
+ self.buttonReboot = Button(frame, text="Reboot", underline=0, command=lambda: actions.reboot(config))
+ self.buttonReboot.grid(row=0,column=4)
+ master.bind_all("<Alt-r>", partial(actions.reboot,config))
+
+ #self.buttonCancel = Button(frame, text="Cancel", underline=0, command=frame.quit)
+ self.buttonCancel = Button(frame, text="Cancel", underline=0, command=self.quitaction)
+ self.buttonCancel.grid(row=1,columnspan=8,sticky=W+E)
+ master.bind_all("<Alt-c>", self.quitaction)
+
+ # Found this after trial and error.
+ def quitaction(self,b=None):
+ print("Cancel any logout action.")
+ root.destroy()
+
+# Left here as an example for a mster.bind_all that works.
+#def something(event=None):
+# print("Got here!")
+
+root = Tk()
+
+# MAIN LOOP
+root.title("Log out options")
+#root.iconbitmap(r'/usr/share/icons/Numix/48/actions/system-logout.svg')
+imgicon = PhotoImage(file=os.path.join("/usr/share/icons/Adwaita/24x24/actions","system-log-out.png"))
+root.tk.call('wm','iconphoto', root._w, imgicon)
+app = App(root)
+root.mainloop()
+try:
+ root.destroy()
+except:
+ pass
bgstack15