Skip to content

Commit

Permalink
不是单一实例时提醒用户并退出,避免重复实例。
Browse files Browse the repository at this point in the history
  • Loading branch information
oldj committed Dec 27, 2012
1 parent dd43246 commit 512d5cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/SwitchHosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def run(self):

app = wx.App()

name = app.GetAppName() + "-" + wx.GetUserId()
single_instance_checker = wx.SingleInstanceChecker(name)
print(dir(single_instance_checker))
name = "%s-%s" % (app.GetAppName(), wx.GetUserId())
single_instance_checker = wx.SingleInstanceChecker(name, self.working_path)
if single_instance_checker.IsAnotherRunning():
wx.MessageBox(u"SwitchHosts! 已经在运行了!")
open(os.path.join(self.working_path, ".active"), "w").write("1")
return

frame = MainFrame(
Expand Down
21 changes: 21 additions & 0 deletions src/libs/MainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import traceback
import random
import Queue
import time
from Hosts import Hosts
from TaskbarIcon import TaskBarIcon
from BackThreads import BackThreads
Expand Down Expand Up @@ -85,13 +86,16 @@ def __init__(self, mainjob,
if not os.path.isdir(self.hosts_path):
os.makedirs(self.hosts_path)

self.active_fn = os.path.join(self.working_path, ".active")
self.task_qu = Queue.Queue(4096)
self.startBackThreads(2)
self.makeHostsContextMenu()

self.init2()
self.initBind()

self.task_qu.put(self.chkActive)


def init2(self):

Expand Down Expand Up @@ -1230,3 +1234,20 @@ def OnActiveApp(self, event):
print "---"
# self.GetTopWindow().Raise()
self.Raise()


def chkActive(self):
u"""循环查看工作目录下是否有 .active 文件,有则激活主窗口"""

if os.path.isfile(self.active_fn):
print("active..")
os.remove(self.active_fn)
# print(dir(self.mainjob.app))
self.Raise()
wx.TopLevelWindow.RequestUserAttention(self)
# self.mainjob.app.SetTopWindow(self)

time.sleep(0.5)
# wx.CallAfter(self.chkActive)
self.task_qu.put(self.chkActive)

2 changes: 1 addition & 1 deletion src/libs/VERSION.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# email: [email protected]
#

VERSION = "0.2.2.1790"
VERSION = "0.2.2.1791"

0 comments on commit 512d5cd

Please sign in to comment.