aboutsummaryrefslogtreecommitdiff
path: root/logout-manager-tcl.py
blob: c605dc09890129638d7c638814e9013f976b0bf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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