Forum Archive

How to create more than one UI and interact between them

Kluesi

Hi

I am new in Python especially in Pythonista for iOS. But it looks very interesting. I want to create a little private game for me and my friends. I need to build more then one UI. A Login Screen, a config screen and so on. But which is the right way to create all UIs I need and how can I show these UIs?

Many thanks

Kluesi

Cethric

In this instance it would probably be better to use the scene module and have the 'screens' as seperate layers and then bring each one to the front as required. Have a look at Examples/Games/BrickBreaker.py for a bit more infomation into how this could be achieved.
Otherwise if you would prefer to use the ui module you would need a root view and then apply multiple subviews and only bring them forward as required.

Kluesi

Ok, i tried to use the view element. And I already create a subview but how do I create another subview. Maybe I do not see the right Button to create another subview. Could you help me?
Thanks

ccc

Three screens probably means three ui.Views present()ed one after the other:

import sound, time, ui

def screen(title='title'):
    button = ui.Button(title=title)
    button.action = lambda sender: sender.close()
    button.present(hide_title_bar=True)
    button.wait_modal()

for title in 'login configure play'.split():
    screen(title)

for i in xrange(7):
    sound.play_effect('arcade:Explosion_{}'.format(i+1))
    time.sleep(1)

You are creating your ui in the Pythonista ui Editor? If so, hit the + inside the square at the top left of the screen to add a new subview to the main view. Each .pyui file will be one screen so you will need login.pyui, configure.pyui, and play.pyui to create your three screen game.

Kluesi

Hi

Thanks for your answer. Yes, I create my UIs in the ios Pythonista Editor. If I want to create a new UI I press the "+" Sign in the upper left corner. After that I have to choose one of these options: "Script with UI", "Plain Text File", "Scene with Layers", "Basic Scene" and "Empty Script". So I think I have to create the 3 UIs with "Script with UI". After creating my 3 UIs i have:

configure.py
configure.pyui
login.py
login.pyui
play.py
play.pyui

Now I need a Script to manage these three UIs. So I create an "Empty Script" with the name "MyGame.py". At first I want to show the login UI and (as an example) if I press the Button "Login" I see the play UI.

  1. How can I show the login UI out of MyGame.py?

  2. The Login Button in login.py has its own action in login.py. How can I change from login.py to play.py ?

  3. Do I have to import the three UIs into MyGame.py?

Thanks Kluesi

ccc

My recommendation is that you start with 3. above -- a single MyGame.py file that contains these three lines:

# [ ... ]
ui.load_view('login').present('sheet')
# [ ... ]
ui.load_view('configure').present('sheet')
# [ ... ]
ui.load_view('play').present('fullscreen')
# [ ... ]

This way all of your Python logic is one file which can load UI from three different .pyui files.