Developing cross-platform GUIs with IronPython: wx.NET for true native look and feel?
Obviously, with IronPython it's possible to create a first-class user experience by writing a different GUI layer for each platform (GTK# on Linux, WinForms on Windows...)
I'm seriously considering doing this, though the little Computer Scientist in my head is screaming. One option to avoid this duplication would be to use the wxWidgets toolkit, which is capable of providing a truly native look and feel on multiple platforms. Since I'm planning to use IronPython, I would imagine that this would involve the use of th开发者_Go百科e wx.NET wrapper.
My question is this: is it possible to use the wx.NET wrapper in IronPython? More importantly: is it EASY to use wx.NET in IronPython? I've searched around, and haven't found much evidence of people using this combination elsewhere. Has anyone used these two technologies together, or heard of a project that does?
Thanks!
I've spent some time playing around with IronPython and the wx.NET library, and I've found that it is possible to use wx.NET from IronPython. I've created a little sample application that demonstrates the basic idea (tested with Mono 2.8.1 and IronPython 2.6.1 on Linux). The XRC file was created using wxFormBuilder. It seems as though it should be pretty easy to create a wx.NET GUI using IronPython; it looks about the same as the equivalent C# code.
hello_frame.pyw:
import clr
clr.AddReference("wx.NET.dll")
from wx import *
class MyFrame1(Frame):
def __init__(self):
XmlResource.Get().LoadFrame(self, None, "MyFrame1")
self.EVT_BUTTON( XmlResource.XRCID("m_button1"), EventListener(self.OnMyButtonClicked) )
def OnMyButtonClicked(self, sender, e):
MessageDialog.ShowModal( self, "HELLO WORLD!", "", WindowStyles.DIALOG_OK | WindowStyles.ICON_INFORMATION )
class HelloWorldDemo(App):
def OnInit(self):
XmlResource.Get().InitAllHandlers()
XmlResource.Get().Load( "hello_frame.xrc" )
f = MyFrame1()
f.Show()
return True
def main():
app = HelloWorldDemo()
app.Run()
if __name__ == '__main__':
main()
hello_frame.xrc:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
<object class="wxFrame" name="MyFrame1">
<style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
<size>500,300</size>
<title>Demo</title>
<centered>1</centered>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="m_staticText1">
<label>My Super Program</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxTextCtrl" name="m_textCtrl1">
<value></value>
<maxlength>0</maxlength>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxButton" name="m_button1">
<label>Press Me!</label>
<default>0</default>
</object>
</object>
</object>
</object>
</resource>
精彩评论