[Zope-CVS] CVS: PythonNet/demo - wordpad.py:1.1
Brian Lloyd
brian at zope.com
Mon Oct 20 23:05:14 EDT 2003
Update of /cvs-repository/PythonNet/demo
In directory cvs.zope.org:/tmp/cvs-serv26410/demo
Added Files:
wordpad.py
Log Message:
Check in the Great Type Refactoring before I go and break it again. All of
the tests pass again (well, except for two that were failing before the
refactoring).
The end result is a nice net reduction of C# code, letting the Python
runtime handle much more of the work of creating types.
The refactored version also plays nicely with the Python GC, so the
Python GC no longer needs to be disabled to run things under Python
for .NET. :) Also added some very preliminary leak and stress testing
scripts.
=== Added File PythonNet/demo/wordpad.py ===
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
#
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
import CLR.System.Windows.Forms as WinForms
from CLR.System.Drawing import Color, Size, Point
from CLR import System
class Wordpad(WinForms.Form):
"""A simple example application similar to wordpad."""
def __init__(self):
self.word_wrap = 1
self.doctype = 1
self.changed = 0
self.InitializeComponent()
def InitializeComponent(self):
"""Initialize form components."""
self.components = System.ComponentModel.Container()
self.openFileDialog = WinForms.OpenFileDialog()
self.saveFileDialog = WinForms.SaveFileDialog()
self.mainMenu = WinForms.MainMenu()
self.fileMenu = WinForms.MenuItem()
self.menuFileNew = WinForms.MenuItem()
self.menuFileOpen = WinForms.MenuItem()
self.menuFileSave = WinForms.MenuItem()
self.menuFileSaveAs = WinForms.MenuItem()
self.menuFileSep_1 = WinForms.MenuItem()
self.menuFileExit = WinForms.MenuItem()
self.editMenu = WinForms.MenuItem()
self.menuEditUndo = WinForms.MenuItem()
self.menuEditRedo = WinForms.MenuItem()
self.menuEditSep_1 = WinForms.MenuItem()
self.menuEditCut = WinForms.MenuItem()
self.menuEditCopy = WinForms.MenuItem()
self.menuEditPaste = WinForms.MenuItem()
self.menuEditSep_2 = WinForms.MenuItem()
self.menuEditSelectAll = WinForms.MenuItem()
self.formatMenu = WinForms.MenuItem()
self.menuFormatFont = WinForms.MenuItem()
self.menuFormatWordWrap = WinForms.MenuItem()
self.aboutMenu = WinForms.MenuItem()
self.menuHelpAbout = WinForms.MenuItem()
self.richTextBox = WinForms.RichTextBox()
self.statusBarPanel1 = WinForms.StatusBarPanel()
self.statusBar = WinForms.StatusBar()
self.fontDialog = WinForms.FontDialog()
self.statusBarPanel1.BeginInit()
# ===================================================================
# File Menu
# ===================================================================
self.menuFileNew.Text = "&New"
self.menuFileNew.Shortcut = WinForms.Shortcut.CtrlN
self.menuFileNew.ShowShortcut = 0
self.menuFileNew.Index = 0
self.menuFileNew.Click += self.OnClickFileNew
self.menuFileOpen.Text = "&Open"
self.menuFileOpen.Shortcut = WinForms.Shortcut.CtrlO
self.menuFileOpen.ShowShortcut = 0
self.menuFileOpen.Index = 1
self.menuFileOpen.Click += self.OnClickFileOpen
self.menuFileSave.Text = "&Save"
self.menuFileSave.Shortcut = WinForms.Shortcut.CtrlS
self.menuFileSave.ShowShortcut = 0
self.menuFileSave.Index = 2
self.menuFileSave.Click += self.OnClickFileSave
self.menuFileSaveAs.Text = "Save &As"
self.menuFileSaveAs.Index = 3
self.menuFileSaveAs.Click += self.OnClickFileSaveAs
self.menuFileSep_1.Text = "-"
self.menuFileSep_1.Index = 4
self.menuFileExit.Text = "E&xit"
self.menuFileExit.Shortcut = WinForms.Shortcut.AltF4
self.menuFileExit.ShowShortcut = 0
self.menuFileExit.Index = 5
self.menuFileExit.Click += self.OnClickFileExit
self.fileMenu.Text = "&File"
self.fileMenu.Index = 0
items = (self.menuFileNew, self.menuFileOpen,
self.menuFileSave, self.menuFileSaveAs,
self.menuFileSep_1, self.menuFileExit)
self.fileMenu.MenuItems.AddRange(items)
# ===================================================================
# Edit menu
# ===================================================================
self.menuEditUndo.Text = "&Undo"
self.menuEditUndo.Shortcut = WinForms.Shortcut.CtrlZ
self.menuEditUndo.Index = 0
self.menuEditUndo.Click += self.OnClickEditUndo
self.menuEditRedo.Text = "&Redo"
self.menuEditRedo.Shortcut = WinForms.Shortcut.CtrlY
self.menuEditRedo.Index = 1
self.menuEditRedo.Click += self.OnClickEditRedo
self.menuEditSep_1.Text = "-"
self.menuEditSep_1.Index = 2
self.menuEditCut.Text = "Cut"
self.menuEditCut.Shortcut = WinForms.Shortcut.CtrlX
self.menuEditCut.Index = 3
self.menuEditCut.Click += self.OnClickEditCut
self.menuEditCopy.Text = "Copy"
self.menuEditCopy.Shortcut = WinForms.Shortcut.CtrlC
self.menuEditCopy.Index = 4
self.menuEditCopy.Click += self.OnClickEditCopy
self.menuEditPaste.Text = "Paste"
self.menuEditPaste.Shortcut = WinForms.Shortcut.CtrlV
self.menuEditPaste.Index = 5
self.menuEditPaste.Click += self.OnClickEditPaste
self.menuEditSelectAll.Text = "Select All"
self.menuEditSelectAll.Shortcut = WinForms.Shortcut.CtrlA
self.menuEditSelectAll.Index = 7
self.menuEditSelectAll.Click += self.OnClickEditSelectAll
self.menuEditSep_2.Text = "-"
self.menuEditSep_2.Index = 6
self.editMenu.Text = "&Edit"
self.editMenu.Index = 1
items = (self.menuEditUndo, self.menuEditRedo,
self.menuEditSep_1, self.menuEditCut,
self.menuEditCopy, self.menuEditPaste,
self.menuEditSep_2, self.menuEditSelectAll)
self.editMenu.MenuItems.AddRange(items)
# ===================================================================
# Format Menu
# ===================================================================
self.menuFormatFont.Text = "Fo&nt"
self.menuFormatFont.Index = 0
self.menuFormatFont.Click += self.OnClickFormatFont
self.menuFormatWordWrap.Text = "Word Wrap"
self.menuFormatWordWrap.Checked = self.word_wrap
self.menuFormatWordWrap.Index = 1
self.menuFormatWordWrap.Click += self.OnClickFormatWordWrap
self.formatMenu.Text = "F&ormat"
self.formatMenu.Index = 2
items = (self.menuFormatFont, self.menuFormatWordWrap)
self.formatMenu.MenuItems.AddRange(items)
# ===================================================================
# About menu
# ===================================================================
self.menuHelpAbout.Text = "&About"
self.menuHelpAbout.Index = 0
self.menuHelpAbout.Click += self.OnClickHelpAbout
self.aboutMenu.Text = "&Help"
self.aboutMenu.Index = 3
self.aboutMenu.MenuItems.Add(self.menuHelpAbout)
self.statusBarPanel1.Text = "Ready"
self.statusBarPanel1.Width = 755
self.richTextBox.Size = System.Drawing.Size(795, 485)
self.richTextBox.TabIndex = 0
self.richTextBox.AutoSize = 1
self.richTextBox.ScrollBars = WinForms.RichTextBoxScrollBars.ForcedBoth
self.richTextBox.Font = System.Drawing.Font("Tahoma", 10)
self.richTextBox.AcceptsTab = 1
self.richTextBox.Location = System.Drawing.Point(0, 0)
self.statusBar.BackColor = System.Drawing.SystemColors.Control
self.statusBar.Location = System.Drawing.Point(0, 518)
self.statusBar.Size = System.Drawing.Size(775, 19)
self.statusBar.TabIndex = 1
self.statusBar.ShowPanels = 1
self.statusBar.Panels.Add(self.statusBarPanel1)
items = (self.fileMenu, self.editMenu, self.formatMenu, self.aboutMenu)
self.mainMenu.MenuItems.AddRange(items)
self.openFileDialog.Filter = "Text documents|*.txt|RTF document|*.rtf"
self.openFileDialog.Title = "Open document"
self.saveFileDialog.Filter = "Text Documents|*.txt|" \
"Rich Text Format|*.rtf"
self.saveFileDialog.Title = "Save document"
self.saveFileDialog.FileName = "Untitled"
self.AutoScaleBaseSize = System.Drawing.Size(5, 13)
self.ClientSize = System.Drawing.Size(775, 537)
self.Menu = self.mainMenu
self.Text = "Python Wordpad"
self.Controls.Add(self.statusBar)
self.Controls.Add(self.richTextBox)
self.statusBarPanel1.EndInit()
def Dispose(self):
self.components.Dispose()
#WinForms.Form.Dispose(self, 1)
def OnClickFileNew(self, sender, args):
pass
def OnClickFileOpen(self, sender, args):
pass
def OnClickFileSave(self, sender, args):
pass
def OnClickFileSaveAs(self, sender, args):
pass
def OnClickFileExit(self, sender, args):
pass
def OnClickEditUndo(self, sender, args):
pass
def OnClickEditRedo(self, sender, args):
pass
def OnClickEditCut(self, sender, args):
pass
def OnClickEditCopy(self, sender, args):
pass
def OnClickEditPaste(self, sender, args):
pass
def OnClickEditSelectAll(self, sender, args):
pass
def OnClickFormatWordWrap(self, sender, args):
value = not self.word_wrap
self.richTextBox.WordWrap = value
self.menuFormatWordWrap.Checked = value
self.word_wrap = value
def OnClickFormatFont(self, sender, args):
pass
def OnClickHelpAbout(self, sender, args):
AboutForm().ShowDialog(self)
class AboutForm(WinForms.Form):
def __init__(self):
self.InitializeComponent()
def InitializeComponent(self):
"""Initialize form components."""
self.Text = "Python Wordpad"
self.components = System.ComponentModel.Container()
self.btnClose = WinForms.Button()
self.label1 = WinForms.Label()
self.SuspendLayout()
self.btnClose.Location = System.Drawing.Point(360, 181)
self.btnClose.Name = "bnClose"
self.btnClose.TabIndex = 1
self.btnClose.Text = "&Close"
self.btnClose.Click += self.OnClickClose
self.label1.Location = System.Drawing.Point(20, 20)
self.label1.Name = "label1"
self.label1.Size = System.Drawing.Size(156, 16)
self.label1.TabIndex = 2
self.label1.Text = "Wordpad example application"
self.AutoScaleBaseSize = System.Drawing.Size(5, 13)
self.ClientSize = System.Drawing.Size(300, 150)
self.Controls.AddRange((self.label1, self.btnClose))
self.FormBorderStyle = WinForms.FormBorderStyle.FixedDialog
self.MaximizeBox = 0
self.MinimizeBox = 0
self.Name = "AboutForm"
self.ShowInTaskbar = 0
self.StartPosition = WinForms.FormStartPosition.CenterScreen
self.Text = "About"
self.ResumeLayout(0)
def OnClickClose(self, sender, args):
self.Close()
def main():
app = Wordpad()
WinForms.Application.Run(app)
app.Dispose()
if __name__ == '__main__':
main()
More information about the Zope-CVS
mailing list