aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRael Gugelmin Cunha <rael.gc@gmail.com>2015-10-21 21:57:03 -0200
committerRael Gugelmin Cunha <rael.gc@gmail.com>2015-10-21 21:57:03 -0200
commitff382f5693f1b16e5ea9ac66424ffe18300c14b5 (patch)
tree48a0b90a71827d7b4e0ae11c0e447e6f4bd5863d
parent1915584fb102cacbd783107bf2ef0febcac18d4c (diff)
parent63ab9e7d2ef4c81f85a230a9733c1c8779778451 (diff)
downloadscudcloud-ff382f5693f1b16e5ea9ac66424ffe18300c14b5.zip
scudcloud-ff382f5693f1b16e5ea9ac66424ffe18300c14b5.tar.gz
scudcloud-ff382f5693f1b16e5ea9ac66424ffe18300c14b5.tar.bz2
Merge pull request #269 from raelgc/66-restore-window-when-trying-to-run-again
Restore window when trying to run again (#66)
-rwxr-xr-xscudcloud-1.0/scudcloud37
1 files changed, 20 insertions, 17 deletions
diff --git a/scudcloud-1.0/scudcloud b/scudcloud-1.0/scudcloud
index f70222b..ebc6366 100755
--- a/scudcloud-1.0/scudcloud
+++ b/scudcloud-1.0/scudcloud
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import fcntl, os, sys, signal, tempfile
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
+from PyQt4.QtNetwork import QLocalServer, QLocalSocket
# Flexible install dir (we assume that 'lib' and 'resources' will be subdirs)
INSTALL_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -19,7 +20,14 @@ def main():
global win
Resources.INSTALL_DIR = INSTALL_DIR
signal.signal(signal.SIGINT, exit)
- lock()
+ appKey = "scudcloud.pid"
+ socket = QLocalSocket()
+ socket.connectToServer(appKey)
+ if socket.isOpen():
+ socket.close()
+ socket.deleteLater()
+ return 0
+ socket.deleteLater()
app = QtGui.QApplication(sys.argv)
app.setApplicationName(Resources.APP_NAME)
app.setWindowIcon(QtGui.QIcon(Resources.get_path('scudcloud.png')))
@@ -33,26 +41,21 @@ def main():
print("Configuration directory "+args.confdir+" could not be created! Exiting...")
raise SystemExit()
win = ScudCloud(settings_path=settings_path)
+ server = QLocalServer()
+ server.newConnection.connect(restore)
+ server.listen(appKey)
win.restore()
if win.minimized is None:
win.show()
sys.exit(app.exec_())
-def lock():
- global fp
- if 'XDG_RUNTIME_DIR' in os.environ and os.environ['XDG_RUNTIME_DIR']:
- runtime_dir = os.environ['XDG_RUNTIME_DIR']
- else:
- runtime_dir = tempfile.gettempdir()
- pid_file = runtime_dir+'/scudcloud.pid'
- fp = open(pid_file, 'w')
- try:
- fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
- except IOError:
- # Another instance is running
- warning = QtGui.QApplication(sys.argv)
- QtGui.QMessageBox.warning(None, "ScudCloud", warning.tr("Another instance of ScudCloud is already running."))
- sys.exit(0)
+def restore():
+ global win
+ win.setWindowFlags(win.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
+ win.showNormal()
+ win.setWindowFlags(win.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)
+ win.showNormal()
+ win.activateWindow()
def load_settings(confdir):
if not os.path.isdir(confdir):