From 0c21d712af9139a6386c58f72673f2a481a2fa65 Mon Sep 17 00:00:00 2001 From: Gogodr Date: Sat, 14 May 2022 18:52:07 -0500 Subject: [PATCH] reimplement tendo to prevent console flashes --- README.md | 1 + modules/single_instance.py | 40 +++++++++++++++++++++++++++++++++++++- requirements.txt | 10 ++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 requirements.txt diff --git a/README.md b/README.md index c104a29..19e7759 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Audio files from [MixKit](https://mixkit.co/) ### Changelog ### 0.7.1 - Fix win32api dependency, changed to ctypes windll +- Remove window flashes ### 0.7.0 - Add Threading controls to config diff --git a/modules/single_instance.py b/modules/single_instance.py index f3e2c8c..495150e 100644 --- a/modules/single_instance.py +++ b/modules/single_instance.py @@ -1,10 +1,48 @@ import os -from tendo.singleton import SingleInstance +import sys +import tempfile from PySide6.QtWidgets import QApplication, QMessageBox from PySide6.QtGui import QIcon from modules.sound import playError +class SingleInstanceException(BaseException): + pass + +class SingleInstance(object): + def __init__(self, flavor_id="", lockfile=""): + self.initialized = False + if lockfile: + self.lockfile = lockfile + else: + basename = os.path.splitext(os.path.abspath(sys.argv[0]))[0].replace( + "/", "-").replace(":", "").replace("\\", "-") + '-%s' % flavor_id + '.lock' + self.lockfile = os.path.normpath( + tempfile.gettempdir() + '/' + basename) + try: + if os.path.exists(self.lockfile): + os.unlink(self.lockfile) + self.fd = os.open( + self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR) + except OSError: + type, e, tb = sys.exc_info() + if e.errno == 13: + raise SingleInstanceException() + print(e.errno) + raise + self.initialized = True + + def __del__(self): + if not self.initialized: + return + try: + if hasattr(self, 'fd'): + os.close(self.fd) + os.unlink(self.lockfile) + except Exception as e: + print("Unloggable error: %s" % e) + sys.exit(-1) + try: me = SingleInstance() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..99d98b0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +pytesseract +opencv-python +PySide6 +google-cloud-firestore +simpleaudio +watchdog +python-slugify +thefuzz[speedup] +lxml +pycaw \ No newline at end of file