Skip to content

Commit

Permalink
reimplement tendo to prevent console flashes
Browse files Browse the repository at this point in the history
  • Loading branch information
gogodr committed May 14, 2022
1 parent 6f26a40 commit 0c21d71
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 39 additions & 1 deletion modules/single_instance.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pytesseract
opencv-python
PySide6
google-cloud-firestore
simpleaudio
watchdog
python-slugify
thefuzz[speedup]
lxml
pycaw

0 comments on commit 0c21d71

Please sign in to comment.