Editorial Workflows


public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: A simple, Python-based calculator UI.

Shared by: Rekenmachine

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# -*- coding: utf-8 -*-
from __future__ import division
import ui
import clipboard
from console import hud_alert
shows_result = False

def button_tapped(sender):
	t = sender.title
	operators = '+-÷×'
	global shows_result
	label = sender.superview['label1']
	label2 = sender.superview['label2']
	if t in '0123456789':
		if shows_result or label.text == '0':
			label.text = t
			label.text += t
	elif t == '.' and label.text[-1] != '.':
		label.text += t
	elif t in operators:
		if label.text[-1] in operators:
			label.text = label.text[:-1] + t
			label.text += t
	elif t == 'AC':
		label.text = '0'
	elif t == 'C':
		label.text = label.text[:-1]
		if len(label.text) == 0:
			label.text = '0'
	elif t == '=':
			label2.text = label.text + ' ='
			term = label.text.replace('×', '*').replace('÷', '/')
			label.text = str(eval(term))
		except SyntaxError:
			label.text = 'ERROR'
		except ZeroDivisionError:
			label.text = 'DIVISION BY ZERO'
			shows_result = True
	if t != '=':
		shows_result = False
		label2.text = ''

v = ui.load_view()
for button in v.subviews:
	if isinstance(button, ui.Button):
		button.font = ('SourceSansPro-Regular', 27)
v.present('popover', title_bar_color='white', title_color=0.3)