|
| 1 | +# Briefcase macOS Xcode Template |
| 2 | + |
| 3 | +A [Cookiecutter](https://github.com/cookiecutter/cookiecutter/) template for |
| 4 | +building Python apps that will run under macOS. |
| 5 | + |
| 6 | +## Using this template |
| 7 | + |
| 8 | +The easiest way to use this project is to not use it at all - at least, not |
| 9 | +directly. [Briefcase](https://github.com/beeware/briefcase/) is a tool that |
| 10 | +uses this template, rolling it out using data extracted from a |
| 11 | +`pyproject.toml` configuration file. |
| 12 | + |
| 13 | +However, if you *do* want use this template directly... |
| 14 | + |
| 15 | +1. Install [cookiecutter](https://github.com/cookiecutter/cookiecutter). |
| 16 | + This is a tool used to bootstrap complex project templates: |
| 17 | + |
| 18 | + ```text |
| 19 | + pip install cookiecutter |
| 20 | + ``` |
| 21 | +
|
| 22 | +2. Run `cookiecutter` on the template: |
| 23 | +
|
| 24 | + ```text |
| 25 | + cookiecutter https://github.com/beeware/briefcase-macOS-Xcode-template |
| 26 | + ``` |
| 27 | +
|
| 28 | + This will ask you for a number of details of your application, including the |
| 29 | + `name` of your application (which should be a valid PyPI identifier), and |
| 30 | + the `Formal Name` of your application (the full name you use to describe |
| 31 | + your app). The remainder of these instructions will assume a `name` of |
| 32 | + `my-project`, and a formal name of `My Project`. |
| 33 | +
|
| 34 | +3. [Obtain a Python Apple support package for macOS](https://github.com/beeware/Python-Apple-support), |
| 35 | + and extract it into the `My Project/Support` directory generated by the template. |
| 36 | +
|
| 37 | +4. Add your code to the template, into the `My Project/My Project/app`. |
| 38 | + directory. At the very minimum, you need to have an |
| 39 | + `app/<app name>/__main__.py` file that will be run on startup. |
| 40 | +
|
| 41 | + If your code has any dependencies, they should be installed into the |
| 42 | + `My Project/My Project/app_packages` directory. |
| 43 | +
|
| 44 | +If you've done this correctly, a project with a formal name of `My Project`, |
| 45 | +with an app name of `my-project` should have a directory structure that |
| 46 | +looks something like: |
| 47 | +
|
| 48 | +```text |
| 49 | +My Project/ |
| 50 | + My Project/ |
| 51 | + app/ |
| 52 | + my_project/ |
| 53 | + __init__.py |
| 54 | + app.py |
| 55 | + app_packages/ |
| 56 | + ... |
| 57 | + ... |
| 58 | + My Project.xcodeproj/ |
| 59 | + ... |
| 60 | + Support/ |
| 61 | + ... |
| 62 | + VERSIONS |
| 63 | + briefcase.toml |
| 64 | +``` |
| 65 | + |
| 66 | +You're now ready to open the XCode project file, build and run your project! |
| 67 | + |
| 68 | +## Next steps |
| 69 | + |
| 70 | +Of course, running Python code isn't very interesting by itself - you'll be |
| 71 | +able to output to the console, and see that output in XCode, but if you tap the |
| 72 | +app icon on your phone, you won't see anything - because there isn't a visible |
| 73 | +console on an iPhone. |
| 74 | + |
| 75 | +To do something interesting, you'll need to work with the native macOS system |
| 76 | +libraries to draw widgets and respond to screen taps. The |
| 77 | +[Rubicon](https://github.com/beeware/rubicon-objc) Objective |
| 78 | +C bridging library can be used to interface with the macOS system libraries. |
| 79 | +Alternatively, you could use a cross-platform widget toolkit that supports macOS |
| 80 | +(such as [Toga](https://beeware.org/project/projects/libraries/toga)) |
| 81 | +to provide a GUI for your application. |
| 82 | + |
| 83 | +Regardless of whether you use Toga, or you write an application natively, the |
| 84 | +template project will try to start a Python module matching the name of the |
| 85 | +`MainModule` property in the `Info.plist` file associated with the project. |
| 86 | +If that module can't be started, any error raised will be logged, and the |
| 87 | +Python interpreter will be shut down. All console output and errors are |
| 88 | +automatically redirected to the macOS system console. |
| 89 | + |
| 90 | +If you have any external library dependencies (like Toga, or anything other |
| 91 | +third-party library), you should install the library code into the |
| 92 | +`app_packages` directory. This directory is the same as a `site_packages` |
| 93 | +directory on a desktop Python install. |
0 commit comments