diff options
author | B Stack <bgstack15@gmail.com> | 2019-06-12 21:42:27 -0400 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2019-06-12 21:42:27 -0400 |
commit | a7ac543719070a28545e354ff54c585af426df46 (patch) | |
tree | b69e00c8e4804be1b849b40c073f0b706b2d4295 /logout-manager-tcl.py | |
parent | split program into lib and gtk frontend (diff) | |
download | logout-manager-a7ac543719070a28545e354ff54c585af426df46.tar.gz logout-manager-a7ac543719070a28545e354ff54c585af426df46.tar.bz2 logout-manager-a7ac543719070a28545e354ff54c585af426df46.zip |
add main components for tcl frontend
The tcl version now accepts button presses and key presses. It has
the buttons in the same layout as the gtk frontend.
Also had to modify the action functions, to accept an additional
useless parameter because of how tkinter was calling the functions.
Still need to add icons.
Diffstat (limited to 'logout-manager-tcl.py')
-rwxr-xr-x | logout-manager-tcl.py | 90 |
1 files changed, 90 insertions, 0 deletions
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 |