[Python.NET] problem with inheritance? ironpython ok, python.net - different
david lawler
djlawler at aol.com
Fri Oct 19 05:14:41 CEST 2007
To run this script you need to get Weifen Luo's Dock Panel Suite from Source
forge - just get the pre-compiled dll at
http://sourceforge.net/project/showfiles.php?group_id=110642 and stick it in the
same directory as the script.
-----------------------------------------beginning of script
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
clr.AddReference('WeifenLuo.WinFormsUI.Docking')
import System.Windows.Forms as Winforms
import WeifenLuo.WinFormsUI as DockSuite
from System.Drawing import (Font, Point, FontStyle, GraphicsUnit)
class EditForm(DockSuite.Docking.DockContent):
def __init__(self):
self.Text = "EditForm"
self.console = Winforms.TextBox()
self.console.Location = Point(0,0)
self.console.Enabled = True
self.console.Name = "EditForm console"
self.console.Multiline = True
self.console.WordWrap = True
self.console.ScrollBars = Winforms.ScrollBars.Both
self.console.Font = Font("Courier New", 10, FontStyle.Bold,
GraphicsUnit.Point, 0)
self.console.Dock = Winforms.DockStyle.Fill
self.Controls.Add(self.console)
def OnClosing(self, ev):
pass
class ExecuteForm(Winforms.Form):
def __init__(self):
self.IsMdiContainer = True
self.DockMain = DockSuite.Docking.DockPanel()
self.DockMain.Dock = Winforms.DockStyle.Fill
self.Controls.Add(self.DockMain)
self.eform = EditForm()
self.eform.ShowHint = DockSuite.Docking.DockState.DockBottomAutoHide
self.eform.Show(self.DockMain, DockSuite.Docking.DockState.Document)
# Create the menu
mainMenu1 = Winforms.MainMenu()
editMenu = Winforms.MenuItem()
editMenu.Text = "Edit"
menuItemTest = Winforms.MenuItem()
menuItemTest.Text = "Test"
menuItemTest.Click += self.TestMenuHandler
editMenu.MenuItems.Add(menuItemTest)
mainMenu1.MenuItems.Add(editMenu)
self.Menu = mainMenu1
def TestMenuHandler(self, source, ev):
print type(self.DockMain.ActiveContent)
form = ExecuteForm()
Winforms.Application.Run(form)
-------------------------------------------- end of script
The script runs under both IronPython and Python.net which is very cool - but
there is a different result when you select Edit - Test from the menu. For
IronPython it prints:
<class '__main__.EditForm'>
for python.net you get:
<class 'WeifenLuo.WinFormsUI.Docking.DockContent'>
It seems that python.net is printing the base class rather than the class
defined in the script. Is this a bug or am I being stupid?
Regards,
David
More information about the PythonDotNet
mailing list