win32all-131 at

Mark Hammond mhammond at
Sat Apr 29 01:26:12 CEST 2000

"Matthias" <matthias_w at> wrote in message
news:8ecf70$766$1 at
> Hy Mark :-)
> Are the sources anywhere ??
> (You told me to include the new startup-code in my project)

Only from CVS - available via the web at

David Ascher creates a nightly tarball:

> I have the following problems:
> (1) I want to use python-win for the interface in my programm, but it
> is most important to hide the interactive windows for most of the users
> (they should not know that they are powered by python), and

Ultimately you will end up with your own "" (hopefully named
something else!)  This gives you full control over the app - eg, do you
want an editor, interactive, debugger, etc.

> (2) I have a conflict with my main windows. In the InitInstance() from
> my application the pyglue-code creates a new window and now visualc
> does not know which of them is the main window. (e.g. I open
> in my window, have to choose debug (go is disabled ??) from
> the python-window and the splitter - test window is a mdi-child in my
> own main window again (little confuseing, isn't it ;-) - the menus are
> quite the same, but in my window all python-related menus are diasbled)

You _definately_ need a new - either drop the creation of the
main frame from your C++ code, or from the custom

Here is some code taken from a real project that does the exact same
thing - the MFC app creates the frame, and Pythonwin attaches to it!


"The main startup code for my custom Pythonwin App."
import win32ui
 debugging = win32ui.GetProfileVal("Whatever", "Debugging", 0)
# Keep this as short as possible, cos error output is only redirected to
# the interactive window if this runs OK.
# Keep as much logic in imported modules, as errors in these are much
better -
# the messages go somewhere!

# Redirect to the debugging device!
if debugging:
 import win32traceutil
 import sys
 print "Starting up:", sys.path

import sys
import win32con

import pywin
from pywin.framework import intpyapp, app
from pywin.mfc import afxres

class MyApp(intpyapp.InteractivePythonApp):
 def HookCommands(self):
  f = win32ui.GetMainFrame()
  # Probably dont want most of these if you are not exposing the
  # interactive Window, or any Python IDE features.
  f.HookCommandUpdate(self.OnUpdateFileCheck, win32ui.ID_FILE_CHECK)
  f.HookCommand(self.OnInteractiveWindow, win32ui.ID_VIEW_INTERACTIVE)
  f.HookCommand(self.OnViewOptions, win32ui.ID_VIEW_OPTIONS)
  f.HookCommand(self.OnHelpIndex, afxres.ID_HELP_INDEX)
  f.HookCommand(self.OnFileSaveAll, win32ui.ID_FILE_SAVE_ALL)

 def InitInstance(self):
  self.ddeServer = None
  # Create the taskbar icon if necessary.
  if debugging:

  # Attach to (NOT CREATE) the main frame.
  # This code assumes the MFC app has ALREADY created the main frame
  # so win32ui.GetMainFrame() will return this window.  By passing this
window to the
  # app.MainFrame() constructor, we attach to the existing window.
  self.frame = app.MainFrame(win32ui.GetMainFrame())
  # However, in this example, our main app does not create the status bar!


  from editor import editor
  # Allow HTML files to be edited by Pythonwin!
  # ('something' is a module that exposes an MFC resource ID - there
  # should be a string, icon, menu etc entries in the resources for this
  self.AddDocTemplate( editor.EditorTemplate(something.IDR_HTML_FILE) )

  # Create the interactive window if we want.
  from pywin.framework import interact

  # Load internal modules we need (if you want :-)

  # Minimise the interactive window.
  interactiveFrame = interact.edit.currentView.GetParentFrame()
  if interactiveFrame != win32ui.GetMainFrame():

appobj = MyApp()

More information about the Python-list mailing list