Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanntoast committed May 24, 2022
0 parents commit 831a7ec
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 [email protected].

## Installation

1. Download DEB-File and install it `dpkg -i <FILENAME>`
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
15 changes: 15 additions & 0 deletions samples/sampleScript.sh
Original file line number Diff line number Diff line change
@@ -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
101 changes: 101 additions & 0 deletions tripoli.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 831a7ec

Please sign in to comment.