Skip to content

Commit

Permalink
Some adjustments, new IPython version
Browse files Browse the repository at this point in the history
  • Loading branch information
c-holtermann authored and gjanssens committed Jun 9, 2014
1 parent 2c910ed commit 2c955a4
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/optional/python-bindings/example_scripts/latex_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
import getopt
import gnucash
import str_methods
from IPython.Shell import IPShellEmbed
from IPython import version_info as IPython_version_info
if IPython_version_info[0]>=1:
from IPython.terminal.ipapp import TerminalIPythonApp
else:
from IPython.frontend.terminal.ipapp import TerminalIPythonApp
from gnucash.gnucash_business import Customer, Employee, Vendor, Job, \
Address, Invoice, Entry, TaxTable, TaxTableEntry, GNC_AMT_TYPE_PERCENT, \
GNC_DISC_PRETAX
Expand Down Expand Up @@ -120,7 +124,7 @@ def write_variable(ukey, uvalue, replace_linebreak=True):
add_str=u""
owner = invoice.GetOwner()
if owner.GetName() != "":
add_str += owner.GetName()+"\n"
add_str += owner.GetName().decode("UTF-8")+"\n"

addr = owner.GetAddr()
if addr.GetName() != "":
Expand Down Expand Up @@ -191,9 +195,10 @@ def main(argv=None):
prog_name = argv[0]
with_ipshell = False
ignore_lock = False
no_latex_output = False
no_latex_output = True
list_invoices = False
output_file_name = "data.lco"
invoice_number = None

try:
opts, args = getopt.getopt(argv[1:], "fhiln:po:", ["help"])
Expand All @@ -215,12 +220,10 @@ def main(argv=None):
if opt[0] in ["-n"]:
invoice_number = int(opt[1])
print "using invoice number", invoice_number
no_latex_output = False
if opt[0] in ["-o"]:
output_file_name = opt[1]
print "using outpu file", output_file_name
if opt[0] in ["-p"]:
print "no latex output"
no_latex_output=True
print "using output file", output_file_name
if len(args)>1:
print "opts:",opts,"args:",args
raise Usage("Only one input can be accepted !")
Expand Down Expand Up @@ -249,9 +252,8 @@ def main(argv=None):
print "-h or --help for this help"
print "-i for ipython shell"
print "-l list all invoices"
print "-n number use invoice number (no. from previous run -l)"
print "-n number use invoice number (no. from previous run with -l)"
print "-o name use name as outputfile. default: data.lco"
print "-p pretend (=no) latex output"

return retcode

Expand Down Expand Up @@ -294,8 +296,9 @@ def main(argv=None):
f.close()

if with_ipshell:
ipshell= IPShellEmbed()
ipshell()
app = TerminalIPythonApp.instance()
app.initialize(argv=[]) # argv=[] instructs IPython to ignore sys.argv
app.start()

#session.save()
session.end()
Expand Down

0 comments on commit 2c955a4

Please sign in to comment.