3×7=51

做最好的自己

 

【python】替换掉NewEdit自带的DDE模块

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)

posted on 2006-08-16 22:00 3×7=51 阅读(3118) 评论(2)  编辑 收藏 引用 所属分类: Python

评论

# re: 【python】替换掉NewEdit自带的DDE模块 2006-08-18 14:17 g

干~!东西不要写一半一半的。  回复  更多评论   

# re: 【python】替换掉NewEdit自带的DDE模块 2006-08-20 19:59 3×7=51

太粗鲁了……最近火气真大,你。
我这文章是写给自己看的^_^  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

常用链接

留言簿(3)

随笔分类

随笔档案

blog

积分与排名

最新评论