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)