Editorial Workflows

Make Questions

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: This workflow has no description.

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Document Text ?
Folded Text
  • Include
  • Replace with:
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import ui
import console
import markdown2

action_in = str(workflow.get_input())

#TODO: Generate the output...

def MakeLineArray(text):
	# This function makes a string into an array of lines
	ReturnArray = []
	
	for line in text.splitlines():
		if line == '':
			print()
			# Do nothing here
		else:
			ReturnArray.append(line)
	print('MakeLineArray is returning ', ReturnArray)
	print()
	return ReturnArray
	
# Assign variables for displaying the questions and answers

CurrentTopic = ''
CurrentQuestion = ''
CurrentAnswer = ''
GlobalTopics = []
GlobalQuestions = [[]]
GlobalAnswers = [[]]
QuestionIterator = 0
TopicIterator = 0
NumQuestionsAnswers = 0

isanswershown = False

def DisplayMarkdown(text):
	view['AnswerView'].load_html(markdown2.markdown(text))
	
# Functions for the buttons
def ToggleAnswer(sender):
	print('Toggling')
	global isanswershown
	global CurrentAnswer
	if isanswershown == True:
		isanswershown = False
		DisplayMarkdown('**Press the toggle**')
	else:
		isanswershown = True
		DisplayMarkdown(CurrentAnswer)
		print(CurrentAnswer)
	
def PreviousButton(sender):
	print('prevoius button')
	global QuestionIterator
	global NumQuestionsAnswers
	global TopicIterator
	global QuestionIterator
	global GlobalAnswers
	global GlobalQuestions
	global GlobalTopics
	global isanswershown
	global CurrentAnswer
	
	if QuestionIterator == 0:
		if TopicIterator != 0:
			TopicIterator += -1
			view['TopicView'].text = GlobalTopics[TopicIterator]
			QuestionIterator = len(GlobalQuestions[TopicIterator]) - 1
			NumQuestionsAnswers = len(GlobalQuestions[TopicIterator])
			view['QuestionLabel'].text = GlobalQuestions[TopicIterator][QuestionIterator]
			CurrentQuestion = GlobalQuestions[TopicIterator][QuestionIterator]
			CurrentAnswer = GlobalAnswers[TopicIterator][QuestionIterator]
			DisplayMarkdown('**Press the toggle**')
			isanswershown = False
		else:
			print()
	else:
		QuestionIterator += -1
		view['QuestionLabel'].text = GlobalQuestions[TopicIterator][QuestionIterator]
		CurrentQuestion = GlobalQuestions[TopicIterator][QuestionIterator]
		CurrentAnswer = GlobalAnswers[TopicIterator][QuestionIterator]
		DisplayMarkdown('**Press the toggle**')
		isanswershown = False
			
	
def NextButton(sender):
	global QuestionIterator
	global NumQuestionsAnswers
	global TopicIterator
	global QuestionIterator
	global GlobalAnswers
	global GlobalQuestions
	global GlobalTopics
	global isanswershown
	global CurrentAnswer
	
	print('this is the next button')
	if QuestionIterator + 1 == NumQuestionsAnswers:
		if TopicIterator == len(GlobalTopics):
			print()
		else:
			TopicIterator += 1
			view['TopicView'].text = GlobalTopics[TopicIterator]
			NumQuestionsAnswers = len(GlobalQuestions[TopicIterator])
			QuestionIterator = 0
			view['QuestionLabel'].text = GlobalQuestions[TopicIterator][QuestionIterator]
			CurrentQuestion = GlobalQuestions[TopicIterator][QuestionIterator]
			CurrentAnswer = GlobalAnswers[TopicIterator][QuestionIterator]
			DisplayMarkdown('**Press the toggle**')
			isanswershown = False
	else:
		
		QuestionIterator += 1
		view['QuestionLabel'].text = GlobalQuestions[TopicIterator][QuestionIterator]
		CurrentQuestion = GlobalQuestions[TopicIterator][QuestionIterator]
		CurrentAnswer = GlobalAnswers[TopicIterator][QuestionIterator]
		DisplayMarkdown('**Press the toggle**')
		isanswershown = False
	
	
# Start the program	
def main():
	# This is where the main habdling of the program happens
	
	# Instantialise the global variables
	global CurrentAnswer
	global CurrentQuestion
	global GlobalTopics
	global GlobalQuestions
	global GlobalAnswers
	global NumQuestionsAnswers
	
	#Get the questions and answers
	QuestionAnswerArray = MakeLineArray(action_in)
	print(QuestionAnswerArray)
	#Now we make the topics and questions/answers
	
	Topics = []
	Questions = [[]]
	Answers = [[]]
	
	# Assign variables for the for loop
	TempAnswerArray = []
	TopicIterator = 0
	LastTopocIterator = 0
	beginning = True
	
	for i in QuestionAnswerArray:
		if '###' in i:
			# Handle a new question
			
			if beginning:
				beginning = False
				Questions[TopicIterator].append(i)
			else:
				if TempAnswerArray == []:
					print()
				else:
					answerstring = ''
					for j in TempAnswerArray:
						answerstring += j
						answerstring += '\n'
					Answers[TopicIterator].append(answerstring)
					TempAnswerArray = []
				Questions[TopicIterator].append(i)
		elif '##' in i:
			# Handle a new topic
			
			Topics.append(i)
			if beginning:
				print()
			else:
				answerstring = ''
				for j in TempAnswerArray:
					answerstring += j
					answerstring += '\n'
				Answers[TopicIterator].append(answerstring)
				TempAnswerArray = []
				answerstring = ''
				
				Questions.append([])
				Answers.append([])
				TopicIterator += 1
		elif '#' in i:
			print()
		else:
			# Append the regular text line to the temporary array
			TempAnswerArray.append(i + '\n')
	
	# Finish off the last answer
	answerstring = ''
	for j in TempAnswerArray:
		answerstring += j
		answerstring += '\n'
	Answers[TopicIterator].append(answerstring)
	
	# Change the values on the ui elements
	view['QuestionLabel'].text = Questions[0][0]
	DisplayMarkdown('**Press the toggle**')
	view['TopicView'].text = Topics[0]
	
	# Assign the initial values for the global variables
	CurrentTopic = Topics[0]
	CurrentQuestion = Questions[0][0]
	CurrentAnswer = Answers[0][0]
	GlobalAnswers = Answers
	GlobalQuestions = Questions
	GlobalTopics = Topics
	NumQuestionsAnswers = len(Questions[0])
	
	# Present the view
	view.present()
	
#do everything with the view	
view = ui.load_view()

# Start the program
main()