用于 Perl 程序的 Windows GUI 工具包有哪些好的选择?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1454894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are good options for Windows GUI toolkits for a Perl program?
提问by DVK
I am considering doing some automation of tasks on my Windows desktop (e.g. sorting through large collections of music/text/photo files, etc...).
我正在考虑在我的 Windows 桌面上执行一些任务自动化(例如,对大量音乐/文本/照片文件等进行排序......)。
Seeing how my main area of developer expertise is Perl on Unix, I'd prefer to stick to Perl for coding the business logic of whatever I need done, just for the sake of development efficiency.
看到我的主要开发人员专业领域是 Unix 上的 Perl,我更愿意坚持使用 Perl 来编码我需要完成的任何业务逻辑,只是为了提高开发效率。
The question is, if I want to slap some GUI on top of the work (ala Perl::Tk on Unix), what are my GUI toolkit options and which one would you recommend using?
问题是,如果我想在工作之上添加一些 GUI(在 Unix 上是 Perl::Tk),我的 GUI 工具包选项是什么,您会推荐使用哪一个?
Please note that I'd like this question to be a good learning opportunity to other SO users, so I would welcome ANY answers even if they don't necessarily satisfy my own limitations/needs listed below, although notes elaborating on how your solution relates to these considerations would be very welcome.
请注意,我希望这个问题成为其他 SO 用户的一个很好的学习机会,所以我欢迎任何答案,即使它们不一定满足我下面列出的限制/需求,尽管注释详细说明了您的解决方案如何相关对这些考虑将非常受欢迎。
My considerations are mostly driven by the fact that I want a quickly developed tool for personal use to save myself time on tasks I now do manually.
我的考虑主要是因为我想要一个快速开发的供个人使用的工具,以节省我现在手动完成的任务的时间。
Main consideration is Perlishness of development - "Easy things should be easy and hard things should be possible" as a Perl slogan goes. Especially the first part :)
Prefer (but not insist) to be as native as possible as far as components used. E.g. rather re-use Windows' file open dialog vs. having some custom Java dialog.
I would prefer to use something that would have a small learning curve (e.g. no need to learn intricacies of OLE/COM), since the goal here is speedy development of tools I need to simplify my life as opposed to developer education which I concentrate on areas more relevant to my day job :).
But I definitely would love to get exposure to something new/cool while doing this, e.g. if some nice Monad based GUI components are suggested I'm definitely curious.
Performance matters (e.g. I may need to display a directory listing with >10000 files), but is not of paramount concern - I am a pretty good GUI designer and developer and can always architect my app and design a GUI to scale well if needed).
I would strongly prefer (though not insist on) a framework that does not force me to compile stuff. e.g. Perl libraries are more preferable to custom Java stuff I need to compile. But if the framework is perfect in all other respects, I'm open to a compiled solution (as long as it doesn't required me to purchase Visual Studio or somesuch - I want to build a Windows GUI front-end for personal use, not invest in becoming a Windows developer).
主要考虑的是开发的 Perlishness - Perl 的口号是“简单的事情应该很容易,困难的事情应该成为可能”。尤其是第一部分:)
尽可能(但不坚持)尽可能使用原生组件。例如,宁可重用 Windows 的文件打开对话框,也不要使用一些自定义 Java 对话框。
我更喜欢使用一些学习曲线很小的东西(例如不需要学习 OLE/COM 的复杂性),因为这里的目标是快速开发我需要简化生活的工具,而不是我专注的开发人员教育与我的日常工作更相关的领域:)。
但是我绝对希望在这样做时接触到一些新的/很酷的东西,例如,如果建议使用一些不错的基于 Monad 的 GUI 组件,我肯定很好奇。
性能很重要(例如,我可能需要显示包含 >10000 个文件的目录列表),但不是最重要的问题 - 我是一个非常好的 GUI 设计师和开发人员,并且总是可以构建我的应用程序并设计一个 GUI 以在需要时很好地扩展) .
我非常喜欢(虽然不坚持)一个不强迫我编译东西的框架。例如,Perl 库比我需要编译的自定义 Java 内容更可取。但是如果框架在所有其他方面都是完美的,我愿意接受一个编译的解决方案(只要它不需要我购买 Visual Studio 或类似的东西——我想构建一个 Windows GUI 前端供个人使用,不要投资成为 Windows 开发人员)。
I'm pretty open and flexible outside of above constraints. Some ActivePerl/Strawberry Perl libraries, MS PowerShell based components - heck, if nothing better shows up I'll just install Apache on my PC and build a web front-end :)
在上述限制之外,我非常开放和灵活。一些 ActivePerl/Strawberry Perl 库,基于 MS PowerShell 的组件 - 哎呀,如果没有更好的显示,我将在我的 PC 上安装 Apache 并构建一个 Web 前端:)
采纳答案by Michael Carman
There are a number of options listed in perlfaq3and some additional ones that aren't. I'm only familiar with the Tk-based ones.
perlfaq3 中列出了许多选项,还有一些没有列出的选项。我只熟悉基于 Tk 的那些。
Perl/Tkhas the most "perlish" interface but it hasn't been updated to take advantage of tile (native/themed widget) support in the current version of Tk (and probably never will be). Tkxuses a different bridge to Tk. It allows access to everything in Tk (and it's faster, too) but the syntax is less perlish. Tkx is designed to be a thin wrapper over Tk; you have to consult the Tk documentation for most things and translate for using it from Perl. The Tcl/Tkmodule uses the same bridge as Tkx but supports a syntax that's mostly the same as Perl/Tk.
Perl/Tk拥有最“perlish”的界面,但尚未更新以利用当前版本的 Tk 中的 tile(本机/主题小部件)支持(并且可能永远不会)。Tkx使用与 Tk 不同的桥接器。它允许访问 Tk 中的所有内容(而且速度更快),但语法不那么简单。Tkx 被设计成 Tk 的薄包装器;大多数事情你必须查阅 Tk 文档并从 Perl 翻译使用它。该的Tcl / Tk模块使用相同的桥为TKX但支持语法这主要是一样的Perl / Tk的。
Whether or not you need to compile anything depends on which version of Perl you use. If you use Strawberry Perl you'll probably have to compile something no matter what toolkit you choose. ActivePerl distributions have included Tkx since sometime in the 5.8.x cycle and stopped bundling Tk as of 5.10, although it's still available via PPM. Tcl/Tk is available from CPAN but I haven't been able to get it to work with the Tk library that comes bundled with ActivePerl; you may need to install Tcl separately to use it.
您是否需要编译任何东西取决于您使用的 Perl 版本。如果您使用 Strawberry Perl,无论您选择什么工具包,您都可能需要编译一些东西。ActivePerl 发行版从 5.8.x 周期的某个时候开始就包含了 Tkx,并且从 5.10 开始停止捆绑 Tk,尽管它仍然可以通过 PPM 获得。Tcl/Tk 可从 CPAN 获得,但我无法让它与 ActivePerl 捆绑的 Tk 库一起工作;您可能需要单独安装 Tcl 才能使用它。
Personally, I used to use Perl/Tk but now use Tkx.
就个人而言,我曾经使用 Perl/Tk,但现在使用 Tkx。
回答by tsee
With respect to "perlishness" of the interface, I'd suggest plain old Tk. Unfortunately, it looks quite antiquated and non-win32-ish.
关于界面的“perlishness”,我建议使用普通的旧Tk。不幸的是,它看起来很陈旧且不符合 win32 标准。
If you want native widgets, I think your best shots are using the native Windows GUI via Win32::GUIor Wx. I have no experience with Win32::GUI, but Wx is quite nice. It does, however, have a rather steep learning curve and the interface isn't very "perlish". The C++ roots show a little bit (for better or worse).
如果您想要本机小部件,我认为您最好的镜头是通过Win32::GUI或Wx使用本机 Windows GUI 。我没有使用 Win32::GUI 的经验,但 Wx 非常好。然而,它确实有一个相当陡峭的学习曲线并且界面不是很“perlish”。C++ 根显示了一点(无论好坏)。
There are a few Tk-replacements that are actually thin wrappers around Tcl/Tk (I think Tcl::Tk and Tkx). They look more modern than Perl/Tk, but I have no hands-on experience with these either. If you're developing for Windows only, have a look at ActivePerl which comes with (I think) Tkx. Their ppm4 package manager is written using it and looks pretty nice!
有一些 Tk 替代品实际上是围绕 Tcl/Tk 的薄包装(我认为 Tcl::Tk 和 Tkx)。它们看起来比 Perl/Tk 更现代,但我也没有这些方面的实践经验。如果您仅针对 Windows 进行开发,请查看(我认为)Tkx 附带的 ActivePerl。他们的 ppm4 包管理器是用它编写的,看起来很不错!
回答by Alex Martelli
While Tk and Qt are also available (more general frameworks originally intended for other languages, on which you can also use Perl), and Tk probably most popular as it's been around longest, Win32::GUIwould seem to meet your requirements best. If you like WISIWYG GUI designers, you could use Lofton top of Win32::GUI, but you don't have to if you'd rather do everything programmatically.
虽然 Tk 和 Qt 也可用(最初用于其他语言的更通用的框架,您也可以在其上使用 Perl),并且 Tk 可能是最受欢迎的,因为它存在的时间最长,但Win32::GUI似乎最能满足您的要求。如果您喜欢 WISIWYG GUI 设计器,您可以在 Win32::GUI 之上使用Loft,但如果您更愿意以编程方式完成所有工作,则不必这样做。
回答by Eric Strom
Shameless plug - I am in the process of writing a pure Perl GUI toolkit, XUL::Guithat renders its GUI using Firefox. It allows you do anything Firefox can (XUL, HTML, JavaScript, Flash, other web tech). Firefox uses the native look and feel of the OS (or any other theme you want), and is available for most platforms.
无耻插件 - 我正在编写一个纯 Perl GUI 工具包,XUL::Gui,它使用 Firefox 呈现其 GUI。它允许你做任何 Firefox 能做的事情(XUL、HTML、JavaScript、Flash、其他网络技术)。Firefox 使用操作系统(或您想要的任何其他主题)的本机外观和感觉,并且可用于大多数平台。
use XUL::Gui;
display Window title=>'My Application',
Button( label=>'click me', oncommand=>sub{ shift->label = 'ouch'} );
It's currently under development, but probably stable enough to start working with. The idea is to be as simple and perlish as possible. Nearly all boilerplate is optional, with sensible defaults. For example, the Window tag is only needed because I wanted to title the window.
它目前正在开发中,但可能足够稳定以开始使用。这个想法是尽可能简单和愚蠢。几乎所有样板都是可选的,具有合理的默认值。例如,仅需要 Window 标记是因为我想为窗口添加标题。
The module is up on CPAN. I'd encourage anyone to take a look, and send me feature requests or bug reports.
该模块在 CPAN 上运行。我鼓励任何人看一看,并向我发送功能请求或错误报告。
回答by Quentin
I'd just stick with Tk myself. It runs on Windowsand you already know it.
我自己会坚持使用 Tk。它在 Windows 上运行,您已经知道了。
回答by xxxxxxx
I would choose GTK because because it has a study guide(at the moment I'm using Wx and there's plenty of available source code in Perl using Wx but no actual official documentation .. apart from some articles, so no book ... no official stuff) , if not Qt is an option also , and it has some proper documentation(but I haven't tried it).
我会选择 GTK,因为它有一个学习指南(目前我正在使用 Wx,并且在 Perl 中有大量使用 Wx 的可用源代码,但没有实际的官方文档......除了一些文章,所以没有书......没有官方的东西),如果不是 Qt 也是一个选项,它有一些适当的文档(但我还没有尝试过)。
Tk has very big problems and I won't use it.
Tk 有很大的问题,我不会使用它。
As for your performance problems ... I'm pretty sure no decent application would be concerned if it's displaying 100000 or 10^100 files , since very few fit on your screen, so you can do some clipping.
至于你的性能问题......我很确定如果它显示 100000 或 10^100 个文件,我很确定没有像样的应用程序会关心,因为很少有适合你的屏幕,所以你可以做一些剪辑。
回答by Peter Mortensen
If it is just to get a simple GUI on top of your scripts then the easiest path is VB.NET (or C#). That is what I do.
如果只是为了在脚本之上获得一个简单的 GUI,那么最简单的途径是 VB.NET(或 C#)。这就是我所做的。
With Visual Studio's designer it is just a matter of designing the form, double click on the button that will that start processing, add code to read off parameters from the GUI elements (e.g. file paths in TextBox'es) and pass the information to the script through environment variables or command line parameters.
使用 Visual Studio 的设计器,只需设计表单,双击开始处理的按钮,添加代码以从 GUI 元素(例如 TextBox 中的文件路径)读取参数并将信息传递给通过环境变量或命令行参数编写脚本。
Example from one of my applications (used by real users):
来自我的应用程序之一的示例(由真实用户使用):
Dim inputFolder As String = txtInputDataMGFfolder.Text
Dim outputFile As String = txtOutputMGFfile.Text
Dim ws As WshShellClass = New WshShellClass
Dim objEnviron2 As IWshRuntimeLibrary.IWshEnvironment = _
ws.Environment("PROCESS")
objEnviron2.Item("INDIR") = inputFolder
objEnviron2.Item("OUTFILE") = outputFile
'It may or may not help for this: the user dialogs for selecting
'files may change the current directory and running the Perl
'script or one of the .pm files would fail.
ws.CurrentDirectory = appPath()
ws.Run("%COMSPEC% /K perl -w MultRawPrepare.pl", 1, False)
Note that use of Windows Script Host for this may not be strictly neccessary, but if it is then this is needed:
请注意,为此使用 Windows Script Host 可能不是绝对必要的,但如果是,则需要这样做:
'Requires adding reference to project:
' menu Project/Add Reference/COM/Windows Script Host Object Model
' Note: "Windows", not "Microsoft".
'
'Note: the DLL may not be registered;
' D:
' cd \WINNT\system32
' regsvr32 wshom.ocx
Imports IWshRuntimeLibrary 'For WshShellClass.
appPath() is defined as follows (and required "Imports System.Reflection" in the beginning of the VB.NET file):
appPath() 定义如下(并且在 VB.NET 文件的开头需要“Imports System.Reflection”):
Public Shared Function appPath() As String
'"[Assembly]" requires System.Reflection
Dim strAppDir As String = _
Path.GetDirectoryName( _
[Assembly].GetExecutingAssembly().GetModules(False)(0).FullyQualifiedName)
Return strAppDir
End Function 'appPath
User selection of files or folders is easy to add, but is helped by HOW-TO instructions and a little bit of boilerplate code.
用户对文件或文件夹的选择很容易添加,但可以通过 HOW-TO 说明和一些样板代码提供帮助。
The Express edition of Visual Studio for VB.NET is free.
Visual Studio for VB.NET Express 版是免费的。