[IronPython] Groping in the dark
William Reade
william at resolversystems.com
Fri Dec 1 15:09:40 CET 2006
Hi Patrick
I haven't been able to see the anomalies you mention -- perhaps the
following sample will help.
---------------------------
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import (
Application, DockStyle, Form, Keys, MenuStrip, ToolStripMenuItem,
ToolStripSeparator
)
def SayHi(*_):
print "hi"
f = Form()
f.Text = "Hello multiverse!"
menuStrip = MenuStrip()
menuStrip.Dock = DockStyle.Top
f.Controls.Add(menuStrip)
menu = ToolStripMenuItem()
menu.Text = "SomeMenu"
menuStrip.Items.Add(menu)
menuItem = ToolStripMenuItem()
menuItem.Text = "SomeMenuItem"
menuItem.Click += SayHi
menuItem.ShortcutKeys = Keys.Control | Keys.Q
menu.DropDownItems.Add(menuItem)
menu.DropDownItems.Add(ToolStripSeparator())
Application.Run(f)
----------------------------
Cheers
William
Patrick O'Brien wrote:
> Am I missing something or is everyone else groping around in the dark
> as much as I am when it comes to figuring out acceptable syntax in
> IronPython versus other languages supported by the CLR. What I'm
> doing is building a simple app in Visual Studio C# 2005 Express to see
> what objects are available and what properties they have. I'm also
> looking at the generated code. But my translations into Python don't
> always work out as I expect. For example, here are some differences
> I've come across:
>
> For all of these examples I'm using this bit of code:
>
> import clr
> clr.AddReference('System.Windows.Forms')
> import System.Windows.Forms as SWF
>
>
> To add a separator to a menu you need to do this:
>
> Add('-')
>
> Whereas this raises an exception:
>
> Add(SWF.ToolStripSeparator())
>
> Various attempts at adding shortcut keys failed, but this works:
>
> open_item.Shortcut = SWF.Shortcut.CtrlO
>
> Apparently the .ShortcutKeys property does not exist on menu items in
> IronPython.
>
> So my basic question is how does one learn all these anomalies other
> than by trial and error?
>
> --
> Patrick K. O'Brien
> Orbtech http://www.orbtech.com
> Schevo http://www.schevo.org
> Louie http://www.pylouie.org <http://www.pylouie.org>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>users mailing list
>users at lists.ironpython.com
>http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
More information about the Ironpython-users
mailing list