|
| 1 | +# Briefcase Linux System App Template |
| 2 | + |
| 3 | +A [Cookiecutter](https://github.com/cookiecutter/cookiecutter/) template |
| 4 | +for building Python apps that will run under Linux, packaged as native |
| 5 | +system packages. |
| 6 | + |
| 7 | +## Using this template |
| 8 | + |
| 9 | +The easiest way to use this project is to not use it at all - at least, |
| 10 | +not directly. [Briefcase](https://github.com/beeware/briefcase/) is a |
| 11 | +tool that uses this template, rolling it out using data extracted from a |
| 12 | +`pyproject.toml` configuration file. |
| 13 | + |
| 14 | +However, if you *do* want use this template directly... |
| 15 | + |
| 16 | +1. Install |
| 17 | + [cookiecutter](https://github.com/cookiecutter/cookiecutter). This |
| 18 | + is a tool used to bootstrap complex project templates: |
| 19 | + |
| 20 | + $ pip install cookiecutter |
| 21 | + |
| 22 | +2. Run `cookiecutter` on the template: |
| 23 | + |
| 24 | + $ cookiecutter https://github.com/beeware/briefcase-linux-system-template |
| 25 | + |
| 26 | + This will ask you for a number of details of your application, |
| 27 | + including the <span class="title-ref">name</span> of your |
| 28 | + application (which should be a valid PyPI identifier), and the |
| 29 | + <span class="title-ref">Formal Name</span> of your application (the |
| 30 | + full name you use to describe your app). The remainder of these |
| 31 | + instructions will assume a <span class="title-ref">name</span> of |
| 32 | + `my-project`, and a formal name of `My Project`. |
| 33 | + |
| 34 | +3. Add your code to the template, into the |
| 35 | + `My Project/project/usr/local/share/my_project` directory. At the |
| 36 | + very minimum, you need to have an `app/<app name>/__main__.py` file |
| 37 | + that defines an entry point that will start your application. |
| 38 | + |
| 39 | + If your code has any dependencies, they should be installed into the |
| 40 | + `My Project/project/usr/local/lib/my_project/app_packages` |
| 41 | + directory. |
| 42 | + |
| 43 | +If you've done this correctly, a project with a formal name of |
| 44 | +`My Project`, with an app name of `my-project` should have a directory |
| 45 | +structure that looks something like: |
| 46 | + |
| 47 | + My Project/ |
| 48 | + bootstrap/ |
| 49 | + main.c |
| 50 | + Makefile |
| 51 | + project/ |
| 52 | + usr/ |
| 53 | + lib/ |
| 54 | + my-project/ |
| 55 | + app/ |
| 56 | + my_project/ |
| 57 | + __init__.py |
| 58 | + __main__.py |
| 59 | + app.py |
| 60 | + app_packages/ |
| 61 | + ... |
| 62 | + share/ |
| 63 | + applications/ |
| 64 | + com.example.my-project.desktop |
| 65 | + icons/ |
| 66 | + ... |
| 67 | + Dockerfile |
| 68 | + briefcase.toml |
| 69 | + |
| 70 | +4. Compile and install the bootstrap binary: |
| 71 | + |
| 72 | + $ cd "My Project" |
| 73 | + $ make -C bootstrap install |
| 74 | + |
| 75 | +5. Build the DEB package: |
| 76 | + |
| 77 | + $ dpkg-deb --build --root-owner-group project |
| 78 | + |
| 79 | +This will project a `project.deb` file that you can install with: |
| 80 | + |
| 81 | + $ sudo apt install -f project.deb |
| 82 | + |
| 83 | +## Next steps |
| 84 | + |
| 85 | +Of course, running Python code isn't very interesting by itself. |
| 86 | + |
| 87 | +To do something interesting, you'll need to work with the native system |
| 88 | +libraries to draw widgets and respond to user input. The |
| 89 | +[GTK+](https://python-gtk-3-tutorial.readthedocs.io/) GUI library |
| 90 | +provides Python bindings that you can use to build a user interface. |
| 91 | +Alternatively, you could use a cross-platform widget toolkit that |
| 92 | +supports Windows (such as |
| 93 | +[Toga](https://beeware.org/project/projects/libraries/toga)) to provide |
| 94 | +a GUI for your application. |
| 95 | + |
| 96 | +If you have any external library dependencies (like Toga, or anything |
| 97 | +other third-party library), you should install the library code into the |
| 98 | +`app_packages` directory. This directory is the same as a |
| 99 | +`site_packages` directory on a desktop Python install. |
0 commit comments