aboutsummaryrefslogtreecommitdiff
path: root/ayatanasettings
diff options
context:
space:
mode:
Diffstat (limited to 'ayatanasettings')
-rwxr-xr-xayatanasettings/__init__.py1
-rwxr-xr-xayatanasettings/appdata.py16
-rw-r--r--ayatanasettings/builder.py80
-rw-r--r--ayatanasettings/logger.py25
-rw-r--r--ayatanasettings/psutil.py62
5 files changed, 184 insertions, 0 deletions
diff --git a/ayatanasettings/__init__.py b/ayatanasettings/__init__.py
new file mode 100755
index 0000000..8b13789
--- /dev/null
+++ b/ayatanasettings/__init__.py
@@ -0,0 +1 @@
+
diff --git a/ayatanasettings/appdata.py b/ayatanasettings/appdata.py
new file mode 100755
index 0000000..1decefa
--- /dev/null
+++ b/ayatanasettings/appdata.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+APPNAME = 'ayatana-settings'
+APPEXECUTABLE='/usr/bin/ayatana-settings'
+APPVERSION = '20.10.14'
+APPSHOWSETTINGS = 201014
+APPYEAR = '2020'
+APPTITLE = 'Ayatana Indicators Settings'
+APPDESCRIPTION = 'Ayatana Indicators Settings'
+APPLONGDESCRIPTION = 'Ayatana Settings allows you to configure all your Ayatana system indicators.'
+APPAUTHOR = 'Robert Tari'
+APPMAIL = 'robert@tari.in'
+APPURL = 'https://github.com/AyatanaIndicators/ayatana-settings'
+APPKEYWORDS = ['ayatana', 'indicator', 'settings']
+APPDEBUG = []
diff --git a/ayatanasettings/builder.py b/ayatanasettings/builder.py
new file mode 100644
index 0000000..1297ec9
--- /dev/null
+++ b/ayatanasettings/builder.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import gi
+
+gi.require_version('Gtk', '3.0')
+
+from gi.repository import Gtk
+from .appdata import APPNAME, APPTITLE, APPDEBUG, APPEXECUTABLE
+import os
+
+def getClassVar(sId):
+
+ return 'p' + sId[0:1].upper() + sId[1:]
+
+def getDataPath(sPath):
+
+ try:
+
+ sExecPath = os.path.split(APPEXECUTABLE)[0]
+ sDataPath = os.getcwd().replace(sExecPath, '')
+ sRelativePath = os.path.join(sDataPath, sPath.lstrip('/'))
+
+ if os.path.exists(sRelativePath):
+
+ return sRelativePath
+
+ except:
+
+ pass
+
+ return sPath
+
+def buildApp(pApp):
+
+ pBuilder = Gtk.Builder()
+ pBuilder.set_translation_domain(APPNAME)
+ pBuilder.add_from_file(getDataPath('/usr/share/' + APPNAME + '/' + APPNAME + '.glade'))
+ pBuilder.connect_signals(pApp)
+
+ for pObject in pBuilder.get_objects():
+
+ try:
+
+ pApp.__dict__[getClassVar(Gtk.Buildable.get_name(pObject))] = pObject
+
+ if isinstance(pObject, Gtk.Notebook):
+
+ def onNotebookPageSelected(pWidget, pEvent):
+
+ nMouseX, nMouseY = pEvent.get_coords()
+
+ for nPage in range(0, pWidget.get_n_pages()):
+
+ pLabel = pWidget.get_tab_label(pWidget.get_nth_page(nPage))
+ nX, nY = pLabel.translate_coordinates(pWidget, 0, 0)
+ rcSize = pLabel.get_allocation()
+
+ if nMouseX >= nX and nMouseY >= nY and nMouseX <= nX + rcSize.width and nMouseY <= nY + rcSize.height and pWidget.get_tab_label(pWidget.get_nth_page(nPage)).get_sensitive():
+
+ return False
+
+ return True
+
+ pObject.connect('button-press-event', onNotebookPageSelected)
+
+ except:
+
+ pass
+
+ pApp.pWindow.set_icon_from_file(getDataPath('/usr/share/icons/hicolor/scalable/apps/' + APPNAME + '.svg'))
+
+ sTitle = APPTITLE
+
+ if APPDEBUG:
+
+ sTitle += ' - DEBUGGING MODE'
+
+ pApp.pWindow.set_title(sTitle)
+ pApp.pWindow.show_all()
diff --git a/ayatanasettings/logger.py b/ayatanasettings/logger.py
new file mode 100644
index 0000000..4b8763e
--- /dev/null
+++ b/ayatanasettings/logger.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import logging
+from .appdata import APPNAME
+
+class Formatter(logging.Formatter):
+
+ def __init__(self):
+
+ logging.Formatter.__init__(self, '[%(asctime)s] %(levelname)s: %(message)s')
+ self.default_msec_format = '%s.%03d'
+
+ def format(self, record):
+
+ dColours = {'WARNING': '33', 'INFO': '32', 'DEBUG': '37', 'CRITICAL': '35', 'ERROR': '31'}
+ record.levelname = '\033[1;' + dColours[record.levelname] + 'm' + record.levelname + '\033[0m'
+
+ return logging.Formatter.format(self, record)
+
+logger = logging.getLogger(APPNAME)
+logger.setLevel(logging.DEBUG)
+pStreamHandler = logging.StreamHandler()
+pStreamHandler.setFormatter(Formatter())
+logger.addHandler(pStreamHandler)
diff --git a/ayatanasettings/psutil.py b/ayatanasettings/psutil.py
new file mode 100644
index 0000000..acdbe67
--- /dev/null
+++ b/ayatanasettings/psutil.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import psutil
+import os
+from .appdata import APPNAME
+
+def isRunning():
+
+ for pProc in psutil.process_iter():
+
+ sName = pProc.name
+
+ if not isinstance(sName, str):
+
+ sName = pProc.name()
+
+ if sName == 'python3' or sName == 'python':
+
+ lCmdLine = pProc.cmdline
+
+ if not isinstance(lCmdLine, list):
+
+ lCmdLine = pProc.cmdline()
+
+ for sCmd in lCmdLine:
+
+ if sCmd.endswith(APPNAME) and pProc.pid != os.getpid():
+
+ return True
+
+ elif sName.endswith(APPNAME) and pProc.pid != os.getpid():
+
+ return True
+
+ return False
+
+def isSystemd():
+
+ for pProc in psutil.process_iter():
+
+ sName = pProc.name
+
+ if not isinstance(sName, str):
+
+ sName = pProc.name()
+
+ if sName == 'systemd':
+
+ lCmdLine = pProc.cmdline
+
+ if not isinstance(lCmdLine, list):
+
+ lCmdLine = pProc.cmdline()
+
+ for sCmd in lCmdLine:
+
+ if sCmd == '--user':
+
+ return True
+
+ return False