【问题标题】:Developing cross-platform GUIs with IronPython: wx.NET for true native look and feel?使用 IronPython 开发跨平台 GUI:wx.NET 以获得真正的原生外观?
【发布时间】:2011-01-07 16:28:59
【问题描述】:
显然,使用 IronPython,可以通过为每个平台(Linux 上的 GTK#、Windows 上的 WinForms...)编写不同的 GUI 层来创建一流的用户体验。
我正在认真考虑这样做,尽管我脑海中的小计算机科学家正在尖叫。避免这种重复的一种选择是使用 wxWidgets 工具包,它能够在多个平台上提供真正的原生外观。由于我打算使用 IronPython,我想这将涉及到 wx.NET 包装器的使用。
我的问题是:是否可以在 IronPython 中使用 wx.NET 包装器?更重要的是:在 IronPython 中使用 wx.NET 容易吗?我四处搜寻,并没有发现很多人在其他地方使用这种组合的证据。有没有人同时使用这两种技术,或者听说过有这样的项目?
谢谢!
【问题讨论】:
标签:
.net
mono
wxpython
ironpython
wxwidgets
【解决方案1】:
我花了一些时间玩弄 IronPython 和 wx.NET 库,我发现可以从 IronPython 使用 wx.NET。我创建了一个小示例应用程序来演示基本思想(在 Linux 上使用 Mono 2.8.1 和 IronPython 2.6.1 进行了测试)。 XRC 文件是使用 wxFormBuilder 创建的。使用 IronPython 创建 wx.NET GUI 似乎应该很容易;它看起来与等效的 C# 代码大致相同。
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>