summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Weller <ianweller@gmail.com>2008-09-29 00:16:37 -0500
committerIan Weller <ianweller@gmail.com>2008-09-29 00:16:37 -0500
commit8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6 (patch)
tree617fa19bc444f083de7361dd61f97777c543a549
parent2d7cffd750006341895d2f20dfa2b4892c421714 (diff)
downloadfedora-business-cards-8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6.zip
fedora-business-cards-8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6.tar.gz
fedora-business-cards-8474b9a4ee0eb8dc51de3b8fe4993272f4d7beb6.tar.xz
Change svg_to_pdf_png, add card editing
-rw-r--r--fedora_business_cards/export.py17
-rw-r--r--fedora_business_cards/frontend.py54
-rw-r--r--fedora_business_cards/information.py1
3 files changed, 66 insertions, 6 deletions
diff --git a/fedora_business_cards/export.py b/fedora_business_cards/export.py
index d4b6c37..5d3d922 100644
--- a/fedora_business_cards/export.py
+++ b/fedora_business_cards/export.py
@@ -25,6 +25,7 @@ Functions to export cards from SVGs.
import rsvg
import cairo
+from StringIO import StringIO
if not cairo.HAS_PDF_SURFACE:
raise SystemExit('cairo was not compiled with PDF support')
@@ -32,21 +33,25 @@ if not cairo.HAS_PNG_FUNCTIONS:
raise SystemExit('cairo was not compiled with PNG support')
-def svg_to_pdf_png(pdfname, pngname, xmlstring, dpi=300):
+def svg_to_pdf_png(xmlstring, filename, format='png', dpi=300):
"""
- Export an SVG to both a PDF and PNG.
- pngname = location of PNG file to export to
- pdfname = location of pdf file to export to
+ Export an SVG to either a PDF or PNG.
xmlstring = the SVG XML to export
+ filename = name of file to save as
+ format = either 'png' or 'pdf'
dpi = DPI to export PNG with (default: 300)
"""
svg = rsvg.Handle(data=xmlstring)
- pdffile = file(pdfname, 'w')
+ if format == "pdf":
+ pdffile = file(filename, 'w')
+ else:
+ pdffile = StringIO()
width = int(svg.props.width/90.*dpi)
height = int(svg.props.height/90.*dpi)
surface = cairo.PDFSurface(pdffile, width, height)
ctx = cairo.Context(surface)
svg.render_cairo(ctx)
- surface.write_to_png(pngname)
+ if format == "png":
+ surface.write_to_png(filename)
surface.finish()
pdffile.close()
diff --git a/fedora_business_cards/frontend.py b/fedora_business_cards/frontend.py
index 59ce189..fe4b809 100644
--- a/fedora_business_cards/frontend.py
+++ b/fedora_business_cards/frontend.py
@@ -31,6 +31,11 @@ from getpass import getpass
import config
import information
+
+def cmdline_card_line(data):
+ return "| %s%s |" % (data, ' '*(59-len(data)))
+
+
def cmdline():
"""
Command-line interface to business card generator. Takes no arguments; uses
@@ -87,3 +92,52 @@ def cmdline():
if options.username == "":
options.username = username
infodict = information.get_information(username, password, options.username)
+ # setup default content
+ name = infodict['name']
+ title = infodict['title']
+ if infodict['gpgid'] == None:
+ gpg = ''
+ else:
+ gpg = "GPG key ID: %s" % infodict['gpgid']
+ if infodict['irc'] == None:
+ lines = [infodict['email'],
+ infodict['phone'],
+ infodict['url'],
+ '',
+ gpg,
+ '']
+ else:
+ lines = [infodict['email'],
+ infodict['phone'],
+ infodict['irc']+" on irc.freenode.net",
+ infodict['url'],
+ '',
+ "GPG key ID: "+infodict['gpgid']]
+ done_editing = False
+ while not done_editing:
+ print "Current business card layout:"
+ print " +"+"-"*61+"+"
+ print " n "+cmdline_card_line(name)
+ print " t "+cmdline_card_line(title)
+ print " "+cmdline_card_line('')
+ for i in range(6):
+ print (" %i " % i)+cmdline_card_line(lines[i])
+ print " "+cmdline_card_line('')
+ print " "+cmdline_card_line('')
+ print " "+cmdline_card_line('fedora'+' '*17+\
+ 'freedom | friends | features | first')
+ print " +"+"-"*61+"+"
+ print "Enter a line number to edit, or [y] to accept:",
+ lineno = raw_input()
+ if lineno == "" or lineno == "y":
+ done_editing = True
+ else:
+ print ("Enter new data for line %s:" % lineno),
+ newdata = raw_input()
+ if lineno == 'n':
+ name = newdata
+ elif lineno == 't':
+ title = newdata
+ elif lineno == '0' or lineno == '1' or lineno == '2' or \
+ lineno == '3' or lineno == '4' or lineno == '5':
+ lines[int(lineno)] = newdata
diff --git a/fedora_business_cards/information.py b/fedora_business_cards/information.py
index 8717c4a..6d260c1 100644
--- a/fedora_business_cards/information.py
+++ b/fedora_business_cards/information.py
@@ -60,4 +60,5 @@ def get_information(loginname, password, username=None):
infodict['phone'] = "(919) 424-0063 x 5%s" % userinfo['id']
infodict['url'] = 'fedoraproject.org'
infodict['gpgid'] = userinfo['gpg_keyid']
+ infodict['irc'] = userinfo['ircnick']
return infodict