使用 IronPython 开发跨平台 GUI:wx.NET 以获得真正的本机外观和感觉?

发布于 2024-10-10 17:36:37 字数 375 浏览 5 评论 0原文

显然,使用 IronPython,可以通过为每个平台编写不同的 GUI 层(Linux 上的 GTK#,Windows 上的 WinForms...)来创建一流的用户体验,

尽管我正在认真考虑这样做,尽管这个小小的计算机科学家我的头在尖叫。避免这种重复的一种选择是使用 wxWidgets 工具包,它能够在多个平台上提供真正的本机外观和感觉。由于我计划使用 IronPython,因此我想这将涉及 wx.NET 包装器的使用。

我的问题是:是否可以在 IronPython 中使用 wx.NET 包装器?更重要的是:在 IronPython 中使用 wx.NET 容易吗?我四处搜寻,没有发现太多人们在其他地方使用这种组合的证据。有人同时使用这两种技术吗?或者听说过这样的项目吗?

谢谢!

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 the 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼泪 2024-10-17 17:36:37

我花了一些时间研究 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文