Search code examples
c++pythoncross-platformwxpythonpy2app

Building a Mac and Windows GUI Application


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.


Solution

  • 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.