Below is the file 'JournalInterface.py' from this revision. You can also download the file.

#!/usr/bin/env python

# JournalInterface.py

# Utilities associated with command line UI

import sys
from CLIParser import CLIParser, CLIParserError
from States import *

class JournalInterface:
	def _init_(self):
		self.input = None

	def journal_prompt(self, state, event, params, v, vstatus):
		sys.stdout.write("fourstar-journal> ")
		vstatus.change_state(state, vstatus.counter + 1)

	def command_input(self, state, event, params, v, vstatus):
		self.input = sys.stdin.readline().strip("\n")
		vstatus.change_state(state, vstatus.counter + 1)

	def parse_command(self, state, event, params, v, vstatus):
		#sys.stdout.write(self.input)
		vstatus.change_state(state, 1)

		args = self.input.split()

		if not len(args):
			return

		print "here"

		if len(args) >= 1 and args[0] == "exit":
			vstatus.change_state(STATE_IDLE, 1)
			return

		if args[0] == "details":
			if len(args) == 2:
				vstatus.change_state(STATE_JOURNAL_DETAILS, 1)
			else:
				print "filename not given: %s" % (self.input,)
			return

		if args[0] == "balance":
			if len(args) == 2:
				vstatus.change_state(STATE_JOURNAL_BALANCE, 1)
			else:
				print "filename not given: %s" % (self.input,)
			return

		if len(args) >= 1 and args[0] == "create":
			vstatus.change_state(STATE_JOURNAL_CREATE, 1)
			return

		if len(args) >= 1 and args[0] == "find":
			vstatus.change_state(STATE_JOURNAL_FIND, 1)
			return


		print "1 command not understood: %s" % (self.input,)

	def balance(self, state, event, params, v, vstatus):
		print "status!!!!!"

		vstatus.change_state(STATE_JOURNAL_IDLE, 1)

	def find(self, state, event, params, v, vstatus):
		print "status!!!!!"

		vstatus.change_state(STATE_JOURNAL_IDLE, 1)

	def create(self, state, event, params, v, vstatus):
		print "journal create!!!!!"


		vstatus.change_state(STATE_JOURNAL_CREATE_IDLE, 1)

	def details(self, state, event, params, v, vstatus):
		args = self.input.split()
		print "filename is %s" % (args[1],)


		vstatus.change_state(STATE_JOURNAL_IDLE, 1)


	def create_journal_prompt(self, state, event, params, v, vstatus):
		sys.stdout.write("fourstar-journal-create> ")
		vstatus.change_state(state, vstatus.counter + 1)

	def create_command_input(self, state, event, params, v, vstatus):
		self.input = sys.stdin.readline().strip("\n")
		vstatus.change_state(state, vstatus.counter + 1)

	def create_parse_command(self, state, event, params, v, vstatus):
		#sys.stdout.write(self.input)
		vstatus.change_state(state, 1)

		args = self.input.split()

		if not len(args):
			return

		if len(args) >= 1 and args[0] == "exit":
			vstatus.change_state(STATE_JOURNAL_CREATE_EXIT, 1)
			return

		if len(args) >= 1 and args[0] == "post":
			vstatus.change_state(STATE_JOURNAL_CREATE_POST, 1)
			return

		if len(args) >= 1 and args[0] == "header":
			vstatus.change_state(STATE_JOURNAL_CREATE_HEADER, 1)
			return

		if len(args) >= 1 and args[0] == "line":
			vstatus.change_state(STATE_JOURNAL_CREATE_LINE, 1)
			return

		if len(args) >= 1 and args[0] == "review":
			vstatus.change_state(STATE_JOURNAL_CREATE_REVIEW, 1)
			return

		if len(args) >= 1 and args[0] == "delline":
			vstatus.change_state(STATE_JOURNAL_CREATE_DELLINE, 1)
			return

		print "2 command not understood: %s" % (self.input,)

	def exit(self, state, event, params, v, vstatus):
		print "status!!!!!"

		vstatus.change_state(STATE_JOURNAL_IDLE, 1)

	def post(self, state, event, params, v, vstatus):
		print "postal!!!!!"

		vstatus.change_state(STATE_JOURNAL_IDLE, 1)

	def header(self, state, event, params, v, vstatus):
		print "status!!!!!"

		vstatus.change_state(STATE_JOURNAL_CREATE_IDLE, 1)

	def line(self, state, event, params, v, vstatus):
		print "status!!!!!"

		vstatus.change_state(STATE_JOURNAL_CREATE_IDLE, 1)

	def review(self, state, event, params, v, vstatus):
		print "status!!!!!"

		vstatus.change_state(STATE_JOURNAL_CREATE_IDLE, 1)

	def delline(self, state, event, params, v, vstatus):
		print "status!!!!!"

		vstatus.change_state(STATE_JOURNAL_CREATE_IDLE, 1)
		#
		# need to subclass optionparser

#		op = CLIParser(usage = "foo")
#		try:
#			options, args = op.parse_args(args)
#		except CLIParserError:
##			print "command problem: %s" % (self.input,)
#			return


#		if len(args) != 0:
#			op.error('extra command line arguments: ' + ' '.join(args))
		#print args

		#return options


#	def chart_prompt(self, state, event, params, v, vstatus):
#		sys.stdout.write("fourstar-chart> ")
#		vstatus.change_state(state, vstatus.counter + 1)
#
#	def ledger_prompt(self, state, event, params, v, vstatus):
#		sys.stdout.write("fourstar-ledger> ")
#		vstatus.change_state(state, vstatus.counter + 1)
#
#	def journal_prompt(self, state, event, params, v, vstatus):
#		sys.stdout.write("fourstar-journal> ")
#		vstatus.change_state(state, vstatus.counter + 1)