Second, even though it’s read only, I still want to allow the user to copy the value to the clipboard.

]]>You need to jump through another hoop and turn it into a gist, so that you can just share the link.

]]>I tried, but when I tried to post, it was flagged as spam

]]>I’m not sure how to provide the pyui file

An easy and quick way is

- rename the .pyui into .txt
- edit it
- select all
- copy
- paste in forum post, like you do for the .py
- rename it back to .pyui

```

The trailing ``` must be **on a line all by itself** or it will appear at the the end of your script.

I ended up “cheating” in a sense. I made the calculation result a button instead of a TextField or label. It made things easier for me because I’m not experienced enough yet with Pythonista. I attached my current code in case you’re interested. I still have to add input validation. Feel free to offer criticism, if you wish. I’m not sure how to provide the pyui file. I wish scipy was included with Pythonista.

```
import ui
import math
import clipboard
def derivative(f):
def compute(x, dx):
return (f(x + dx) - f(x)) / dx
return compute
def newtons_method(f, x, dx = 0.00000001, tolerance = 0.000000001):
df = derivative(f)
while True:
x1 = x - f(x) / df(x, dx)
t = abs(x1 - x)
if t < tolerance:
break
x = x1
return x
def f(x):
try:
ret = -2 * math.log10((rr / 3.7) + (2.51 / (re * math.sqrt(x)))) - (1 / math.sqrt(x))
except(SyntaxError, ZeroDivisionError):
ret = 2 * math.log10((rr / 3.7) + (2.51 / (re * math.sqrt(.000001)))) - (1 / math.sqrt(.000001))
return ret
def button_tapped(sender):
'@type sender: ui.Button'
# Get the button's title for the following logic:
t = sender.name
global re
global rr
if t == 'calc':
# Get the labels:
re = eval(sender.superview['reyNum'].text)
e = eval(sender.superview['pipeRough'].text)
dia = eval(sender.superview['pipeDia'].text) / 12
rr = e / dia
if re <= 2300 and re > 0:
ff = 64 / re
elif re >= 4000:
x_approx = 0.00001
ff = newtons_method(f, x_approx)
elif re == 0:
ff = 0
else:
ff = -1
frictFactorObj = sender.superview['frictFactor']
if ff > 0:
frictFactorObj.title = '{0:.5f}'.format(ff)
elif ff == 0:
frictFactorObj.title = "No Flow"
else:
frictFactorObj.title = "Transition Flow"
elif t == 'frictFactor':
sender.superview['copyButton'].hidden = False
elif t == 'copyButton':
clipboard.set(sender.superview['frictFactor'].title)
sender.superview['copyButton'].hidden = True
v = ui.load_view("Moody")
v['reyNum'].keyboard_type = ui.KEYBOARD_DECIMAL_PAD
v['pipeRough'].keyboard_type = ui.KEYBOARD_DECIMAL_PAD
v['pipeDia'].keyboard_type = ui.KEYBOARD_DECIMAL_PAD
v['copyButton'].hidden = True
v.present('sheet')
```

]]>Now I just need to implement copy to clipboard. Don’t tell me. I want to try to figure it out first. 😀

]]>```
import ui
tf = ui.TextField()
tf.text = '123'
tf.enabled = False
tf.present('sheet')
```

]]>