win32all-131 at python.org

Mark Hammond mhammond at skippinet.com.au
Sat Apr 29 01:26:12 CEST 2000


"Matthias" <matthias_w at my-deja.com> wrote in message
news:8ecf70$766$1 at nnrp1.deja.com...
> 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
http://www.pythonpros.com/cgi-bin/cvsweb.cgi/PyWin32

David Ascher creates a nightly tarball:
http://starship.python.net/crew/da/pywin32dists/


> BTW
> 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 "intpyapp.py" (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
> splittst.py 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 intpyapp.py - either drop the creation of the
main frame from your C++ code, or from the custom app.py

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!

Mark.

# initapp.py
#
"The main startup code for my custom Pythonwin App."
#
import win32ui
try:
 debugging = win32ui.GetProfileVal("Whatever", "Debugging", 0)
except:
 debugging=1
# 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.HookCommand(self.OnViewBrowse,win32ui.ID_VIEW_BROWSE)
  f.HookCommand(self.OnFileImport,win32ui.ID_FILE_IMPORT)
  f.HookCommand(self.OnFileCheck,win32ui.ID_FILE_CHECK)
  f.HookCommandUpdate(self.OnUpdateFileCheck, win32ui.ID_FILE_CHECK)
  f.HookCommand(self.OnFileRun,win32ui.ID_FILE_RUN)
  f.HookCommand(self.OnFileLocate,win32ui.ID_FILE_LOCATE)
  f.HookCommand(self.OnInteractiveWindow, win32ui.ID_VIEW_INTERACTIVE)
  f.HookCommandUpdate(self.OnUpdateInteractiveWindow,
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)
  app.CApp.HookCommands(self)

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

  # Attach to (NOT CREATE) the main frame.
  # This code assumes the MFC app has ALREADY created the main frame
window,
  # 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!
  self.frame._CreateStatusBar()

  self.HookCommands()

  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
ID)
  self.AddDocTemplate( editor.EditorTemplate(something.IDR_HTML_FILE) )

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

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

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

appobj = MyApp()






More information about the Python-list mailing list