Skip to content

Commit

Permalink
Merge pull request #16 from marcmolla/master
Browse files Browse the repository at this point in the history
Briefcase basic tutorial
  • Loading branch information
freakboy3742 authored Sep 16, 2016
2 parents 98c3beb + 495bac9 commit 0bff506
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ specific settings can be specified using a platform key::
},
'macos': {
'app_requires': [
'toga[macos]'
'toga-cocoa'
],
'icon': 'icons/macos.icns',
},
'ios': {
'app_requires': [
'toga[ios]'
'toga-ios'
],
'icon': 'images/ios_icon',
'splash': 'images/ios_splash'
},
'android': {
'app_requires': [
'toga[android]'
'toga-android'
],
'icon': 'images/android_icon',
},
'tvos': {
'app_requires': [
'toga[tvos]'
'toga-ios'
]
},
}
Expand Down
Binary file added docs/tutorials/screenshots/tutorial-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions docs/tutorials/tutorial-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,63 @@ Lets start by creating a ``iostutorial`` directory:
$ mkdir iostutorial
$ cd iostutorial
Now, we create our simple "Hello, world!" application:

.. code-block:: bash
$ mkdir HelloWorld
$ touch HelloWorld/__init__.py
$ echo 'print("Hello, World!")' > HelloWorld/app.py
.. note:: In ``ios`` the application entry point is always ``ApplicationName/app.py``

Finally, we have to add the setuptools ``setup.py`` script:

.. code-block:: python
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='HelloWorld',
version = '0.1',
packages = find_packages(),
options = {
'app': {
'formal_name': 'Hello World',
'bundle': 'org.example'
},
'ios': {
'app_requires': [
]
}
}
)
In the setup script we included the basic information of our application (``name``, ``version`` and ``packages``) needed by setuptools for deploying our application. Additionally, we added in the ``options`` the required configuration for ``briefcase``.

Create an iOS project
---------------------

It is all ready for using ``briefcase``. You can invoke it, using:

.. code-block:: bash
$ python setup.py ios
to create the iOS app.

Open the iOS project with Xcode
-------------------------------

There is a new folder in your project called 'iOS', which contains the Xcode project (``Hello World.xcodeproj``). Open it with Xcode and check that your application is the ``app``folder.
You can test the app by running it in Xcode. As our application only shows a message, the ios application will show only a blank screen. You can check if it is working in the console logs, which should contain something like this:
.. code-block:: bash
Hello World.app/Library/Application Support/org.example.HelloWorld/app/HelloWorld/app.py
Hello World!
2016-09-16 10:49:14.564094 Hello World[6791:4292188] subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 1, privacy_setting: 2, enable_private_data: 0
And that is all, you created your first ios python app!
76 changes: 76 additions & 0 deletions docs/tutorials/tutorial-1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Tutorial 1- Toga Hello, World
=============================

In this tutorial you will create a simple ios application using toga framework.

Update your ios project
-----------------------

In this step we assume that you followed the previous tutorial :doc:`/intro/tutorial-0.rst`.
First at all, you can clean your previous app in your ``iostutorial`` folder:

.. code-block:: bash
rm -rf iOS/
We are going to use the Toga framework, so we have to include the ``toga-ios`` requirement in the ``ios`` section
of ``setup.py`` script:

.. code-block:: python
setup(name='HelloWorld',
...
options = {
...
'ios': {
'app_requires': [
'toga-ios'
]
}
}
)
And now you can update the application, using for example the Toga Hello World,
found at <https://toga.readthedocs.io/en/latest/tutorial/tutorial-0.html>:

.. code-block:: python
import toga
def button_handler(widget):
print("hello")
def build(app):
container = toga.Container()
button = toga.Button('Hello world', on_press=button_handler)
button.style.set(margin=50)
container.add(button)
return container
if __name__ == '__main__':
app = toga.App('First App', 'org.pybee.helloworld', startup=build)
app.main_loop()
Create the iOS app
------------------

Now you can invoke setuptools again:

.. code-block:: bash
$ python setup.py ios
Notice that the ``app_packages`` is not empty after the update, and it contains toga packages and their requirements.

Open the iOS project with Xcode
-------------------------------

If you the ios project in Xcode you will see a Toga application:

.. image:: screenshots/tutorial-1.png

If you click on the button, you should see messages appear in the console.

0 comments on commit 0bff506

Please sign in to comment.