import聽os
import聽time
import聽wx
from聽md5聽import聽md5
from聽binascii聽import聽b2a_hex
from聽Debug聽import聽error
class聽Tool(object):
聽聽聽聽__slots__聽=聽['checker',聽'key',聽'file']
聽聽聽聽def聽__init__(self):
聽聽聽聽聽聽聽聽key="NewEdit-%s"聽%聽(wx.GetUserId())
聽聽聽聽聽聽聽聽self.checker聽=聽聽wx.SingleInstanceChecker(key)
聽聽聽聽聽聽聽聽self.key聽=聽b2a_hex(md5(key).digest())
聽聽聽聽聽聽聽聽self.file聽=聽os.path.join(wx.GetHomeDir(),聽self.key)
聽聽聽聽def聽IsAnotherRunning(self):
聽聽聽聽聽聽聽聽return聽self.checker.IsAnotherRunning()
聽聽聽聽def聽recvdata(self):
聽聽聽聽聽聽聽聽if聽not聽os.path.exists(self.file):
聽聽聽聽聽聽聽聽聽聽聽聽return
聽聽聽聽聽聽聽聽checker聽=聽聽wx.SingleInstanceChecker(self.key)
聽聽聽聽聽聽聽聽while聽checker.IsAnotherRunning():
聽聽聽聽聽聽聽聽聽聽聽聽checker聽=聽聽wx.SingleInstanceChecker(self.key)
聽聽聽聽聽聽聽聽data聽=聽open(self.file,聽'rb').read()
聽聽聽聽聽聽聽聽os.remove(self.file)
聽聽聽聽聽聽聽聽return聽data
聽聽聽聽def聽senddata(self,聽data):
聽聽聽聽聽聽聽聽checker聽=聽聽wx.SingleInstanceChecker(self.key)
聽聽聽聽聽聽聽聽while聽checker.IsAnotherRunning():
聽聽聽聽聽聽聽聽聽聽聽聽checker聽=聽聽wx.SingleInstanceChecker(self.key)
聽聽聽聽聽聽聽聽file聽=聽open(self.file,聽'ab')
聽聽聽聽聽聽聽聽file.write(data)
tool聽=聽Tool()
def聽senddata(data):
聽聽聽聽if聽tool.IsAnotherRunning():
聽聽聽聽聽聽聽聽tool.senddata(data+'\n')
聽聽聽聽聽聽聽聽return聽True
聽聽聽聽return聽False
def聽on_idle(win,聽event):
聽聽聽聽data聽=聽tool.recvdata()
聽聽聽聽if聽not聽data:
聽聽聽聽聽聽聽聽return
聽聽聽聽lines聽=聽unicode(data,聽'utf-8').splitlines()
聽聽聽聽win.openfiles(lines)
def聽run(app=None,聽port=None):
聽聽聽聽from聽modules聽import聽Mixin
聽聽聽聽Mixin.setPlugin('mainframe',聽'on_idle',聽on_idle)