dde?

Mark Hadfield m.hadfield at niwa.co.nz
Thu Mar 20 23:56:28 EST 2003


"Matt Neuber" <mneuber at attbi.com> wrote in message
news:8fc3c459.0303202034.457f18c8 at posting.google.com...
> I've been totally unable to find any 'real' documentation on how to
> send a DDE mesage to another application within python... so I was
> wondering if someone could help me out.

Below my sig, verbatim, is some code I use to open files in XEmacs using
DDE. I think some of what you want is illustrates in there.

Sorry not to strip out the irrelevant stuff, but I thought I might
inadvertently take out something important in the attempt. Plus, I couldn't
be bothered.

--
Mark Hadfield            "Ka puwaha te tai nei, Hoea tatou"
m.hadfield at niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)

-------------------------------
import sys
import os
import win32ui
import dde
import time

def main():
    from optik import OptionParser
    usage = __doc__ + "\n\nusage: %prog [options] files"
    parser = OptionParser(usage=usage)
    parser.add_option("-n", "--new",
                      action="store_true", default=0,
                      help="Allow creation of new files. Not working")
    parser.add_option("-v", "--verbose",
                      action="store_true", default=0,
                      help="Print information about progress. Not working")
    (opts, args) = parser.parse_args()
    # Initialiase DDE
    server = dde.CreateServer()
    server.Create("")
    conversation = dde.CreateConversation(server)
    # Attempt to make contact with Xemacs. If this fails,
    # start an Xemacs process and try again until successful
    try:
        conversation.ConnectTo("Xemacs", "System")
    except:
        import win32api
        import win32con
        xemacs = 'D:\\local\\bin\\i686-pc-cygwin\\xemacs-21.4.11.exe'
        win32api.WinExec(xemacs, win32con.SW_SHOWNORMAL)
        for i in range(20):
            time.sleep(0.25)
            try:
                conversation.ConnectTo("Xemacs", "System")
                break
            except:
                pass
    # Open file(s). Should check here for file existence depending on "new"
parameter.
    for a in args:
        conversation.Exec('[Open("'+a+'")]')

if __name__ == '__main__':
    main()







More information about the Python-list mailing list