intpydde.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # DDE support for Pythonwin
  2. #
  3. # Seems to work fine (in the context that IE4 seems to have broken
  4. # DDE on _all_ NT4 machines I have tried, but only when a "Command Prompt" window
  5. # is open. Strange, but true. If you have problems with this, close all Command Prompts!
  6. import win32ui
  7. import win32api, win32con
  8. from pywin.mfc import object
  9. from dde import *
  10. import sys, traceback
  11. class DDESystemTopic(object.Object):
  12. def __init__(self, app):
  13. self.app = app
  14. object.Object.__init__(self, CreateServerSystemTopic())
  15. def Exec(self, data):
  16. try:
  17. # print "Executing", cmd
  18. self.app.OnDDECommand(data)
  19. except:
  20. t,v,tb = sys.exc_info()
  21. # The DDE Execution failed.
  22. print("Error executing DDE command.")
  23. traceback.print_exception(t,v,tb)
  24. return 0
  25. class DDEServer(object.Object):
  26. def __init__(self, app):
  27. self.app = app
  28. object.Object.__init__(self, CreateServer())
  29. self.topic = self.item = None
  30. def CreateSystemTopic(self):
  31. return DDESystemTopic(self.app)
  32. def Shutdown(self):
  33. self._obj_.Shutdown()
  34. self._obj_.Destroy()
  35. if self.topic is not None:
  36. self.topic.Destroy()
  37. self.topic = None
  38. if self.item is not None:
  39. self.item.Destroy()
  40. self.item = None
  41. def OnCreate(self):
  42. return 1
  43. def Status(self, msg):
  44. try:
  45. win32ui.SetStatusText(msg)
  46. except win32ui.error:
  47. pass