I just started on Pythonista a few days ago (and so far I love it), in order to learn a bit more of Python (I have no professional programming experience).
So after having stolen and modified the code by @cvp here and modified it a bit I ended up with the following little snippet, to convert a temperature from Fahrenheit to Celcius (just to have it do something more than print hello world):
from dialogs import _FormDialogController
from console import set_color
c = _FormDialogController('Input Box', [('', [{'title':'Fahrenheit:','type':'text','value':''}])], done_button_title='Done')
c.container_view.frame = (0, 0, 400,130)
c.container_view.present('sheet')
c.container_view.wait_modal()
c.container_view = None
if c.was_canceled:
set_color(1,0,0)
print('! ', end='')
set_color()
print('Cancelled')
else:
try:
float(c.values['Fahrenheit:'])
set_color(1,1,1)
print(round((int(c.values['Fahrenheit:'])-32)*5/9,2), end='')
set_color()
print('˚C')
except:
set_color(1,0,0)
print('! ', end='')
set_color()
I went the way with the custom box, in order to generate a simple single-line input form, which the dialogs in the dialogs-module does not seem to have, so this seemed like the appropriate way.
I am missing a way to to press enter after having entered the Fahrenheit value, rather than having pto press Done. Is this doable?
On a side-note: The documentation for console.set_color doesn't actually mention this, unlike for console.set_font, but set_color() (without parameters) does actually set the color back to default color.