From 831a7ec4d1343e8ec1364250ff8b0df1777fc78d Mon Sep 17 00:00:00 2001 From: hermanntoast Date: Tue, 24 May 2022 15:05:02 +0200 Subject: [PATCH] initial commit --- README.md | 16 +++++++ samples/sampleScript.sh | 15 ++++++ tripoli.py | 101 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 README.md create mode 100755 samples/sampleScript.sh create mode 100755 tripoli.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..d02c831 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# TRIPOLI - Create XFCE Shell extentions + +Inspired by https://github.com/p-e-w/argos I write this application. You can build a plugin with the content of any shell script for your xFCE desktop based on GTK. The hole project is written in python. If you have any idea to improve or extend the code, feel free to write me at dev@hermann-toast.de. + +## Installation + +1. Download DEB-File and install it `dpkg -i ` +2. Place your scripts in this location: `~/.config/tripoli/` + +## Roadmap +- add HTML support for the output +- add action on menuitem click +- improve error handling +- create service with automatic startup +- build package for easy installation +- create packageserver to provide package and updates \ No newline at end of file diff --git a/samples/sampleScript.sh b/samples/sampleScript.sh new file mode 100755 index 0000000..5f9ba32 --- /dev/null +++ b/samples/sampleScript.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# +# Here is the plugin configuration. Please do not change the formatting or variables! +# +##### PLUGININFO ##### +# PLUGIN_NAME = SampleScript +# PLUGIN_ICON = applications-games +# PLUGIN_INTERVAL = 10 +##### PLUGININFO ##### +# + +echo "Test" # print normal text +echo "---" # print seperator +echo "💩 Test 2" # Print all UTF8 characters \ No newline at end of file diff --git a/tripoli.py b/tripoli.py new file mode 100755 index 0000000..73fc285 --- /dev/null +++ b/tripoli.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 + +import gi +import os +import threading +import time +import logging + +gi.require_version('Gtk', '3.0') +gi.require_version('AppIndicator3', '0.1') + +from gi.repository import Gtk as gtk, AppIndicator3 as appindicator, GLib + +logging.basicConfig(format='%(levelname)s: %(asctime)s %(message)s', level=logging.CRITICAL) + +scriptPath = "~/.config/tripoli/" + +def __execute(command) -> list: + commandline = "" + for cmd in command: + commandline += str(cmd) + " " + stream = os.popen(commandline) + return stream.read().splitlines() + +def getScriptsFromDirectory() -> list: + scriptList = list() + for filename in os.listdir(scriptPath): + if ".sh" in filename: + scriptList.append(filename) + return scriptList + +def getPluginConfig(script): + with open(scriptPath + script) as f: + started = False + config = dict() + for line in f.readlines(): + if "##### PLUGININFO #####" in line: + started = True if started == False else False + continue + if started: + line = line.replace("#", "").replace("\n", "").strip().split("=") + config[line[0].strip()] = line[1].strip() + return config + +def menu(script): + logging.debug("Execute script " + script + "...") + menu = gtk.Menu() + + scriptResult = __execute([scriptPath + script]) + for line in scriptResult: + if "---" in line: + menuentry = gtk.SeparatorMenuItem() + menu.append(menuentry) + else: + menuentry = gtk.ImageMenuItem(label=line) + menu.append(menuentry) + + logging.debug("Script " + script + " finished!") + menu.show_all() + + return menu + +def start(script): + pluginConfig = getPluginConfig(script) + indicator = appindicator.Indicator.new(pluginConfig["PLUGIN_NAME"], pluginConfig["PLUGIN_ICON"], appindicator.IndicatorCategory.APPLICATION_STATUS) + indicator.set_status(appindicator.IndicatorStatus.ACTIVE) + + def start(): + logging.info("Start/Restart menu creation for " + script + "...") + indicator.set_menu(menu(script)) + return GLib.SOURCE_CONTINUE + + GLib.timeout_add_seconds(int(pluginConfig["PLUGIN_INTERVAL"]), start) + start() + + gtk.main_iteration_do(True) + gtk.main() + +def main(): + threadList = list() + for script in getScriptsFromDirectory(): + thread = threading.Thread(target=start, args=(script,)) + thread.start() + threadList.append(thread) + + while True: + for thread in threadList: + if thread.is_alive(): + logging.debug("Thread " + str(thread) + " is still running!") + time.sleep(5) + +if __name__ == "__main__": + try: + print("Start application...") + main() + except KeyboardInterrupt: + print() + exit() + except Exception as e: + print(e) + pass \ No newline at end of file