docview.py :  » Windows » pyExcelerator » pywin32-214 » pythonwin » pywin » mfc » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » pythonwin » pywin » mfc » docview.py
# document and view classes for MFC.
import win32ui
import win32con
import object
import window

class View(window.Wnd):
  def __init__(self, initobj):
    window.Wnd.__init__(self, initobj)
  def OnInitialUpdate(self):
    pass

# Simple control based views.
class CtrlView(View):
  def __init__(self, doc, wndclass, style=0):
    View.__init__(self, win32ui.CreateCtrlView(doc, wndclass, style))

class EditView(CtrlView):
  def __init__(self,  doc):
    View.__init__(self, win32ui.CreateEditView(doc))

class RichEditView(CtrlView):
  def __init__(self,  doc):
    View.__init__(self, win32ui.CreateRichEditView(doc))

class ListView(CtrlView):
  def __init__(self,  doc):
    View.__init__(self, win32ui.CreateListView(doc))

class TreeView(CtrlView):
  def __init__(self,  doc):
    View.__init__(self, win32ui.CreateTreeView(doc))

# Other more advanced views.
class ScrollView(View):
  def __init__(self,  doc):
    View.__init__(self, win32ui.CreateView(doc))

class FormView(View):
  def __init__(self,  doc, id):
    View.__init__(self, win32ui.CreateFormView(doc, id))

class Document(object.CmdTarget):
  def __init__(self, template, docobj=None):
    if docobj is None:
      docobj = template.DoCreateDoc()
    object.CmdTarget.__init__(self, docobj)

class RichEditDoc(object.CmdTarget):
  def __init__(self, template):
    object.CmdTarget.__init__(self, template.DoCreateRichEditDoc())

class CreateContext:
  "A transient base class used as a CreateContext"
  def __init__(self, template, doc = None):
    self.template = template
    self.doc = doc
  def __del__(self):
    self.close()
  def close(self):
    self.doc = None
    self.template = None

class DocTemplate(object.CmdTarget):
  def __init__(self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None):
    if resourceId is None: resourceId = win32ui.IDR_PYTHONTYPE
    object.CmdTarget.__init__(self, self._CreateDocTemplate(resourceId))
    self.MakeDocument=MakeDocument
    self.MakeFrame=MakeFrame
    self.MakeView=MakeView
    self._SetupSharedMenu_()
# todo - _SetupSharedMenu should be moved to a framework class.
  def _SetupSharedMenu_(self):
    sharedMenu = self.GetSharedMenu()
    from pywin.framework import toolmenu
    toolmenu.SetToolsMenu(sharedMenu)
    from pywin.framework import help
    help.SetHelpMenuOtherHelp(sharedMenu)

  def _CreateDocTemplate(self, resourceId):
    return win32ui.CreateDocTemplate(resourceId)
  def __del__(self):
    object.CmdTarget.__del__(self)
  def CreateCreateContext(self, doc=None):
    return CreateContext(self, doc)
  def CreateNewFrame(self, doc):
    makeFrame = self.MakeFrame
    if makeFrame is None: makeFrame = window.MDIChildWnd
    wnd = makeFrame()
    context = self.CreateCreateContext(doc)
    wnd.LoadFrame(self.GetResourceID(), -1, None, context)  # triggers OnCreateClient...
    return wnd
  def CreateNewDocument(self):
    makeDocument = self.MakeDocument
    if makeDocument is None:
      makeDocument = Document
    return makeDocument(self)
  def CreateView(self, frame, context):
    makeView = self.MakeView
    if makeView is None: makeView = EditView
    view = makeView(context.doc)
    view.CreateWindow(frame)

class RichEditDocTemplate(DocTemplate):
  def __init__(self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None):
    if MakeView is None: MakeView = RichEditView
    if MakeDocument is None: MakeDocument = RichEditDoc
    DocTemplate.__init__(self, resourceId, MakeDocument, MakeFrame, MakeView)

  def _CreateDocTemplate(self, resourceId):
    return win32ui.CreateRichEditDocTemplate(resourceId)

def t():
  class FormTemplate(DocTemplate):
    def CreateView(self, frame, context):
      makeView = self.MakeView
#      view = FormView(context.doc, win32ui.IDD_PROPDEMO1)
      view = ListView(context.doc)
      view.CreateWindow(frame)

  t=FormTemplate()
  return t.OpenDocumentFile(None)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.