aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lmlib.py6
-rwxr-xr-xlogout-manager-gtk.py23
-rwxr-xr-xlogout-manager-ncurses.py38
-rwxr-xr-xlogout-manager-tcl.py29
4 files changed, 70 insertions, 26 deletions
diff --git a/lmlib.py b/lmlib.py
index fe6d4a4..7c9dc1e 100644
--- a/lmlib.py
+++ b/lmlib.py
@@ -15,7 +15,7 @@
import configparser, platform, os
-logout_manager_version="2019-06-21a"
+logout_manager_version="2020-03-10a"
class Actions:
@@ -192,10 +192,10 @@ def get_gtk3_default_icon_theme():
print("Found gtk3 default theme:",name)
return name
-def Initialize_config():
+def Initialize_config(infile):
# Read config
config_in = configparser.ConfigParser()
- config_in.read('logout-manager.conf')
+ config_in.read(infile)
config = Config()
try:
ci = config_in['logout-manager']
diff --git a/logout-manager-gtk.py b/logout-manager-gtk.py
index c6f7a6b..553fc41 100755
--- a/logout-manager-gtk.py
+++ b/logout-manager-gtk.py
@@ -24,15 +24,31 @@
# only show debug info when DEBUG=1 or similar.
# support global conf file, and user conf file
# far future: provide graphical way to change commands run
+# Dependencies:
+# Devuan: python3-dotenv
# Documentation:
-import gi, sys
+import gi, os, platform, sys
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository.GdkPixbuf import Pixbuf
from pathlib import Path
-sys.path.append("/home/bgirton/dev/logout-manager")
+from dotenv import load_dotenv
+
+# all this to load the libpath
+try:
+ defaultdir="/etc/sysconfig"
+ thisplatform = platform.platform().lower()
+ if 'debian' in thisplatform or 'devuan' in thisplatform:
+ defaultdir="/etc/default"
+ # load_dotenv keeps existing environment variables as higher precedent
+ load_dotenv(os.path.join(defaultdir,"logout-manager"))
+except:
+ pass
+if 'LOGOUT_MANAGER_LIBPATH' in os.environ:
+ for i in os.environ['LOGOUT_MANAGER_LIBPATH'].split(":"):
+ sys.path.append(i)
import lmlib
# graphical classes and functions
@@ -225,7 +241,8 @@ class MainWindow(Gtk.Window):
print("Cancel any logout action.")
Gtk.main_quit()
-config = lmlib.Initialize_config()
+# load configs
+config = lmlib.Initialize_config(os.environ['LOGOUT_MANAGER_CONF'])
actions = lmlib.Actions
# MAIN LOOP
diff --git a/logout-manager-ncurses.py b/logout-manager-ncurses.py
index 99801d7..ab3b99b 100755
--- a/logout-manager-ncurses.py
+++ b/logout-manager-ncurses.py
@@ -1,25 +1,41 @@
#!/usr/bin/env python3
-# File: logout-manager-tui.py
+# File: logout-manager-ncurses.py
# License: MIT
# Author: adamlamers, bgstack15
# Startdate: 2020-03-09 17:06
# Title: ncurses based logout manager
# Usage:
-#
+# logout-manager-ncurses.py
# Reference:
# https://docs.python.org/3/howto/curses.html
# ripped straight from http://adamlamers.com/post/FTPD9KNRA8CT
# https://stackoverflow.com/questions/3061/calling-a-function-of-a-module-by-using-its-name-a-string/12025554#12025554
+# https://robinislam.me/blog/reading-environment-variables-in-python/
# Improve:
-# add "disabled" option in menu, with default=enabled
+# Dependencies:
+# Devuan: python3-dotenv
# Documentation:
# Improvements for CursesMenu class over origin:
# accepts number key inputs
# accepts enabled attribute
# add "zeroindex" bool
-import curses, sys, os
-sys.path.append("/home/bgirton/dev/logout-manager")
+import curses, os, platform, sys
+from dotenv import load_dotenv
+
+# all this to load the libpath
+try:
+ defaultdir="/etc/sysconfig"
+ thisplatform = platform.platform().lower()
+ if 'debian' in thisplatform or 'devuan' in thisplatform:
+ defaultdir="/etc/default"
+ # load_dotenv keeps existing environment variables as higher precedent
+ load_dotenv(os.path.join(defaultdir,"logout-manager"))
+except:
+ pass
+if 'LOGOUT_MANAGER_LIBPATH' in os.environ:
+ for i in os.environ['LOGOUT_MANAGER_LIBPATH'].split(":"):
+ sys.path.append(i)
import lmlib
class CursesMenu(object):
@@ -146,19 +162,16 @@ class CursesMenu(object):
self.running = False
return {'title' : 'Cancel', 'type' : 'exitmenu'}
-option_1 = {'title' : 'Hello World',
- 'type' : 'command',
- 'command' : 'echo Hello World!'}
-
-# build menu object from config.
-config = lmlib.Initialize_config()
+# load configs
+config = lmlib.Initialize_config(os.environ['LOGOUT_MANAGER_CONF'])
actions = lmlib.Actions
+# MAIN LOOP
menu = {
'title' : 'Logout Manager',
'type' : 'menu',
'subtitle' : 'Use arrows or number keys',
- 'zeroindex' : True,
+ 'zeroindex' : False,
'options' : [
{'title': 'Lock', 'type': 'action', 'action': 'lock'},
{'title': 'Logout', 'type': 'action', 'action': 'logout'},
@@ -167,7 +180,6 @@ menu = {
{'title': 'Reboot', 'type': 'action', 'action': 'reboot'}
]
}
-
m = CursesMenu(menu)
selected_action = m.display()
diff --git a/logout-manager-tcl.py b/logout-manager-tcl.py
index 8c4bc6a..127bd54 100755
--- a/logout-manager-tcl.py
+++ b/logout-manager-tcl.py
@@ -7,6 +7,7 @@
# Purpose: A tcl/tk graphical program for selecting shutdown, logout, etc.
# History:
# Usage:
+# logout-manager-tcl.py
# References:
# http://effbot.org/tkinterbook/button.htm
# http://effbot.org/tkinterbook/tkinter-application-windows.htm
@@ -22,18 +23,17 @@
# tooltips https://stackoverflow.com/questions/3221956/how-do-i-display-tooltips-in-tkinter/41381685#41381685
# Improve:
# Dependencies:
-# devuan: python3-tk python3-pil.imagetk python3-cairosvg
+# Devuan: python3-tk python3-pil.imagetk python3-cairosvg
# el7: python36-tkinter python36-pillow-tk ( pip3 install cairosvg )
-import glob, re
+import glob, os, platform, re, sys
import tkinter as tk
from functools import partial
from pathlib import Path
from sys import path
+from dotenv import load_dotenv
# loading PIL.ImageTk after tkinter makes ImageTk use the PIL version, which supports PNG. This is important on tcl < 8.6 (that is, el7)
from PIL import Image, ImageTk
-path.append("/home/bgirton/dev/logout-manager")
-import lmlib
LM_USE_SVG = 0
try:
@@ -43,8 +43,20 @@ except:
print("WARNING: Unable to import cairosvg. No svg images will be displayed.")
LM_USE_SVG = 0
-config = lmlib.Initialize_config()
-actions = lmlib.Actions
+# all this to load the libpath
+try:
+ defaultdir="/etc/sysconfig"
+ thisplatform = platform.platform().lower()
+ if 'debian' in thisplatform or 'devuan' in thisplatform:
+ defaultdir="/etc/default"
+ # load_dotenv keeps existing environment variables as higher precedent
+ load_dotenv(os.path.join(defaultdir,"logout-manager"))
+except:
+ pass
+if 'LOGOUT_MANAGER_LIBPATH' in os.environ:
+ for i in os.environ['LOGOUT_MANAGER_LIBPATH'].split(":"):
+ sys.path.append(i)
+import lmlib
# graphical classes and functions
print("Loading graphics...")
@@ -388,9 +400,12 @@ class App:
#def something(event=None):
# print("Got here!")
-root = tk.Tk()
+# load configs
+config = lmlib.Initialize_config(os.environ['LOGOUT_MANAGER_CONF'])
+actions = lmlib.Actions
# MAIN LOOP
+root = tk.Tk()
root.title("Log out options")
imgicon = get_scaled_icon(config.get_logout_icon(),24,config.get_icon_theme())
root.tk.call('wm','iconphoto', root._w, imgicon)
bgstack15