构建Mac和Windows GUI应用程序 [英] Building a Mac and Windows GUI Application

查看:181
本文介绍了构建Mac和Windows GUI应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划为Mac和Windows构建一个GUI应用程序。我一直在做一些关于技术选择的研究,如在语言,库和构建工具中,以便我可以在两个平台之间共享尽可能多的代码。



主要要求是:


  1. 符合Mac App Store的要求。

  2. 需要调用Mac上的Quartz Window Services和Windows上的Windows API。

  3. 使用SQLite存储和读取数据。

我的帖子长度已失去控制,因此我将问题移至



问题




  1. 我倾向于使用Python轻松的编程。这是我的正确选择吗?如果不是为什么C ++会更好?如果是这样,我怎么得到py2app和pyobjc设置编译python和构建一个独立的应用程序加载XIBs的GUI?

  2. 我是不应该使用cross-平台GUI库在Mac上为了一个更原生的接口?

  3. 如果我走错路径和/或有更好的解决方案,我没有考虑,请指出:)
  4. / li>



我的研究和结论到目前为止



GUI libaries



对于Mac,我排除了使用跨平台GUI库(如QT),因为它似乎不像是能够提供一个原生的外观和感觉在Mac(看起来不在和/或难以编写遵循苹果人机接口指南的应用程序)。 wxWidgets说它使用本机库,但是这个帖子提到wxPython可能使用私有的Objective-C调用,并且不太可能被批准为Mac App Store。最后,即使外观是正确的,布局可能仍然需要为两个平台变化。



因此,我计划使用本机Cocoa GUI库为Mac界面,虽然仍然考虑使用wxWidgets的Windows GUI。



语言



这似乎是我最好的选择语言的主要应用程序逻辑是C ++或Python。显然,使用Python编写跨平台代码比C ++容易得多,但总是有折衷。



Python



优点:更快的写作和更容易维护。强大的跨平台库可以大幅缩短开发时间。



缺点:使用Python意味着使用PyObjC,一年(从svn可以看出),我不清楚它是否仍然适用于未来版本的Xcode和OSX。此外,为了使用PyObjc和py2app设置任何完整的构建配置,并在Xcode外使用xibs,是一个噩梦。



C ++



优点:更容易在Mac和Windows上设置构建配置和依赖关系。运行速度比Python快,虽然性能不是我的大问题。



缺点:我不知道C ++。我对C很好,但它不像这样会帮助我写很好的C ++。我有一个普遍的印象是,编写跨平台C ++更困难,但我可能是错误的。有很多关于晦涩的bug的帖子。



构建工具



如果使用C ++作为主要语言,在两个平台上。如果我使用Python,它似乎很容易在Windows上设置,因为我会使用wxWidgets GUI和py2exe部署。



对于Mac和Python,标准选择似乎是pyobjc和py2app。不幸的是,我还没有找到任何使用py2app的构建配置的例子,它使用XIB和Cocoa库,而不是QT或wxWidgets。我不想让Xcode管理构建,因为我更喜欢Python文件和应用程序资源放在
Xcode项目目录之外。



关于QT的编辑:我再看一下QT,花费一个几个小时玩QT设计师。基本UI元素(按钮,文本字段,标签)看起来与Cocoa元素相同。我把一个QWindow和一个QTabView与一些元素容易,它看起来像一个Cocoa应用程序。但是,有一些负面的:




  • 行为有点偏离,像缺乏弹性滚动,QTextEdit没有蓝色阴影

  • QTableView看起来不像它的Cocoa副本。

  • 元素之间的间距,父视图之间的间距,它通常可以通过调整布局,但需要在任何地方做,我会得到它与Xcode免费。

  • 缺少HUD元素,使检查器。这是我可能需要在我的应用程序,至少对于Mac一侧。

  • 可用性支持不佳。



我知道我很挑剔,但需要挑选一个好的UI。总体QT似乎是一个很好的解决方案为Windows,但我想我会坚持可可为Mac。我对现有程序进行了一些额外的研究,发现 VLC Chrome 传输均使用原生GUI对于Mac,而VLC使用QT for Windows,Chrome使用自定义框架,传输使用GTK +和QT for Linux。



我想我决定使用Cocoa GUI对于Mac和Qt或wxWidgets Windows,但仍然分割在C + +和Python之间的共享逻辑。

解决方案

用于共享逻辑。



在Mac上,我使用py2objc作为桥梁,而py2app使用一些自定义配置进行打包。在Windows上,我直接使用Python和wxWidgets。



这允许我在两个平台上都有本地UI,并且对于较低级别的代码非常有用。



然而,我并没有在应用程序上移动到更多令人兴奋的冒险之前。如果任何读者希望使用这个问题/答案作为参考,我强烈建议查看所有列出的技术并得出您自己的结论。


I am planning to build a GUI application for Mac and Windows. I've been doing some research in the technology choices, as in the language, libraries, and build tools, so that I can share as much code as possible between the two platforms.

The main requirements are:

  1. Meets the Mac App Store requirements.
  2. Native look and feel on both Mac and Windows.
  3. Need to call into Quartz Window Services on Mac and the Windows API on Windows.
  4. Store and read data using SQLite.

The length of my post has gotten out of control, so I moved my questions to the top as a summary, while the context is further below.

Questions

  1. I am leaning toward using Python for the ease of programming. Is this the right choice for me? If not why would C++ be better? And if so, how exactly do I get py2app and pyobjc set up to compile the python and build a standalone app that loads XIBs for GUI?
  2. Am I right that I should not use cross-platform GUI libraries on Mac for the sake of a more native interface? Or would I be better off using QT or wxWidgets?
  3. If I am going down the wrong path and/or there are better solutions that I have not considered, please point them out :)

My research and conclusions so far

GUI libaries

For Mac, I ruled out using cross-platform GUI libraries (like QT) since it doesn't seem like they are able to provide a native look and feel on Mac (look out of place and/or difficult to write apps that follow Apple's Human Interface Guidelines). wxWidgets says it uses native libraries, but this post mentions that wxPython may use private Objective-C calls and is unlikely to be approved for the Mac App Store. Finally, even if the look is right, layouts would probably still need to vary for the two platforms.

Therefore I plan to use native Cocoa GUI libraries for the Mac interface, though still considering using wxWidgets for the Windows GUI.

Language

It seems my best choices for language for the main application logic be either C++ or Python. Obviously it's much easier to write cross-platform code with Python than C++, but there are always tradeoffs.

Python

Pros: Much quicker to write and easier maintain. Robust cross-platform libraries that can shorten development time drastically.

Cons: Using Python means using PyObjC, which hasn't been updated in over a year (as seen from svn), and it's unclear to me whether it will still work with future versions of Xcode and OSX. Also, to set up any sane build configuration with PyObjc and py2app and use xibs for GUI, outside of Xcode, is a nightmare.

C++

Pros: Easier to set up the build configuration and dependencies on both Mac and Windows. Runs much faster than Python, though performance isn't a large concern in my case.

Cons: I don't know C++. I'm pretty good with C, but it doesn't look like that will help me much at writing good C++. I have a general impression that it's much harder to write cross-platform C++, but I might be wrong. There are lots of posts about obscure bugs. Boost looks promising though.

Build tools

Setting things up if using C++ as the main language seems simple enough on both platforms. If I use Python, it also seems simple to set up on Windows since I would use wxWidgets for the GUI and py2exe to deploy.

As for Mac and Python, the standard choice seems to be pyobjc and py2app. Unfortunately, I haven't been find any examples of a build configuration with py2app that uses XIBs and Cocoa libraries rather than QT or wxWidgets. I don't want Xcode to manage the build since I would prefer the Python files and application resources be placed outside of the Xcode project directory. This would greatly simplify the setup for Windows and make the file tree cleaner.

Edit regarding QT: I took another look at QT, spending a couple of hours playing with QT designer. The basic UI elements (button, textfield, label) look the same as Cocoa elements. I put together a QWindow and a QTabView with some elements easily, and it looks like a Cocoa app. However, there were a few negatives:

  • Behavior's a little off, like lack of elastic scrolling, QTextEdit doesn't have the blue shadow indicating focus.
  • QTableView doesn't look much like its Cocoa counterpart.
  • Spacing between elements, spacing to parent view, do not follow guidelines. It's mostly fixable by tweaking the layouts, but needs to be done everywhere and I'd get it with Xcode for free.
  • Missing the HUD element for making the inspector. This is something I would very likely need in my app, at least for the Mac side.
  • Poor accessibility support.

I know I'm being picky but need to be picky to make a good UI. Overall QT seems to be a good solution for Windows, but I think I will stick to Cocoa for Mac. I did some additional research into existing programs and found that VLC, Chrome, and Transmission all make native GUIs for Mac, while VLC uses QT for Windows, Chrome uses a custom framework, and Transmission uses GTK+ and QT for Linux.

I think I've decided on using Cocoa GUI for Mac and Qt or wxWidgets for Windows, but still split between C++ and Python for the shared logic.

解决方案

I ended up going with Python for shared logic.

On Mac, I used py2objc as the bridge, and py2app with some custom configuration for packaging. On Windows, I used Python and wxWidgets directly.

This allowed me to have native UIs on both platforms, and worked out quite nicely for lower level code.

However, I didn't actually get very far on the app before moving on to more exciting ventures. If any readers were hoping to use this question/answer as a reference, I strongly suggest looking at all the technologies listed and drawing your own conclusions.

这篇关于构建Mac和Windows GUI应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆