Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reopen GUI window if launcher script is executed a second time. #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys, os, thread, time, string, threading, subprocess
#!/usr/bin/env python

import sys, os, thread, time, string, threading, subprocess, signal
from PyQt4.QtGui import QApplication, QStandardItem, QDialog, QIcon, QMenu, QSystemTrayIcon, QStandardItemModel, QAction, QMainWindow, QListWidget, QListWidgetItem, QWidget, QIntValidator, QStyledItemDelegate, QPainter, QStyleOptionViewItem, QFont, QTableWidgetItem, QPalette, QColor, QSortFilterProxyModel
import resource
from PyQt4.QtCore import pyqtSignal, Qt, QModelIndex, QRect, pyqtSlot, QVariant, QString
from PyQt4.QtCore import pyqtSignal, Qt, QModelIndex, QRect, pyqtSlot, QVariant, QString, QTimer
from PyQt4.QtNetwork import QHostInfo
from multiprocessing import Pipe, Process, Lock
from base64 import b64encode, b64decode
Expand Down Expand Up @@ -493,10 +495,34 @@ def lessThan(self, left, right):
elif (sys.argv[1] != "debug"):
import wingdbstub

# handle pid file
fname = os.path.expanduser("~/.lpfw.pid")
if os.path.isfile(fname):
f = open(fname,'r')
pid = int(f.readline())
f.close()
# check if process still exists
if os.path.exists("/proc/%s" % pid):
os.kill(pid, signal.SIGUSR1)
exit(0)
else:
f = open(fname,'w')
f.write("%s" % os.getpid())
f.close()
else:
f = open(fname,'w')
f.write("%s" % os.getpid())
f.close()

app=QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)
window = myMainWindow()

# run interpreter from time to time (to catch signals)
timer = QTimer()
timer.start(1000)
timer.timeout.connect(lambda: None)

tray = QSystemTrayIcon(QIcon(":/pics/pic24.png"))
menu = QMenu()
actionShow = QAction("Show Leopard Flower",menu)
Expand Down Expand Up @@ -535,4 +561,12 @@ def lessThan(self, left, right):
thread.start()

window.show()

# handler for system signal
def reopen_window(signum, stack):
window.show()

# attach SIGUSR1 to handler
signal.signal(signal.SIGUSR1, reopen_window)

sys.exit(app.exec_())