Business Card

Description:

This application creates a business card and saves it as a jpg file on the phone.
The "Add Info" got a submenu
consisting of "From contact" and "Enter manually". The first queries for a
name and performs a search in the phonebook. If nothing is found, an error
is shown. If one record is found, the "title, mobile_number/phone_number
and email is added as text to the picture. If two or more records was
found in the phonebook, a listbox is displayed  allowing
you to select which one to use.
"Enter manually" is a simple query and it adds a line to the card. You can
see this in the "Oizo.jpg" picture - the line "Mr paaarty" is a manually
added line. The two other lines was added by using the "Oizo" contact.
The application shows the businesscard as you work on it (this isnt
visible in the screenshots).

### By Dennis Møllegaard Pedersen <dennis@moellegaard.dk>

### Modules
import appuifw
import camera
import e32
import contacts
import graphics

class Bizcard:
def __init__(self):
self.script_lock = e32.Ao_lock()
self.list=[]
self.contacts=[]
self.contact=None
self.texts=[]
self.pic=None
self.finished=0

def menu_save(self):
old_screen = appuifw.app.screen
old_menu = appuifw.app.menu
appuifw.app.screen="full"
appuifw.app.menu=[]
self.render()
sc=graphics.screenshot()
appuifw.app.screen = old_screen
appuifw.app.menu = old_menu
name = name = appuifw.query(u"Save as", "text", "bizard.jpg")
if name:
sc.save(u"c:\\Nokia\\Images\\" + name )
appuifw.app.body=appuifw.Text(u"Stored as " + name)
self.script_lock.signal()

def menu_manually(self):
t = appuifw.query(u"Add text", "text")
self.texts.append(t)
self.script_lock.signal()

def observe_contacts(self):
self.selected_contact(self.contacts[self.listbox.current()])
self.script_lock.signal()


def selected_contact(self,contact):
self.contact=contact
self.list = []
text = contact.title;
# mobile or phonenumber
n = contact.find('mobile_number')
if n:
text = text + ": " + n[0].value;
else:
n = contact.find('phone_number')
if n:
text = text + ": " + n[0].value;
self.texts.append(text)
# Email if exists
n = contact.find('email_address')
if n:
self.texts.append("email: " + n[0].value)
self.script_lock.signal()

def menu_from_contacts(self):
name = appuifw.query(u"Search for..", "text")
entries = contacts.open().find(name)
self.contacts=entries
self.list=[]
if len(entries) == 0:
appuifw.note(u"No contacts found", "error")
elif len(entries) == 1:
self.selected_contact(entries[0])
else:
for e in entries:
self.list.append(e.title)
appuifw.app.body = self.listbox = appuifw.Listbox(self.list, self.observe_contacts)

def menu_take_picture(self):
if appuifw.query(u"Press OK to take photo", "query"):
self.pic=camera.take_photo()
self.script_lock.signal()


def exit_key_handler(self):
self.finished=1
self.script_lock.signal()

def render(self):
f=appuifw.Text()
f.font = u"albi17p"
f.color = 0xaaaaaa
f.style = (appuifw.STYLE_BOLD | appuifw.HIGHLIGHT_SHADOW)

appuifw.app.body=canvas=appuifw.Canvas()
if self.pic:
canvas.blit(self.pic,scale=1)

y=10
for t in self.texts:
canvas.text((2,y),t, 0x000000)
canvas.text((2+1,y+1),t,0xffffff)
y=y+13

def main(self):
self.old_exit_handler=appuifw.app.exit_key_handler
appuifw.app.exit_key_handler=self.exit_key_handler
old_title = appuifw.app.title
appuifw.app.screen="large"
appuifw.app.title=u"BizCard"
appuifw.app.body = None
appuifw.app.menu = [
(u"Take picture", self.menu_take_picture ),
(u"Add Info", ( (u"From Contacts", self.menu_from_contacts),
(u"Enter Manually", self.menu_manually ) )),
(u"Save Card", self.menu_save ),
(u"Close", self.exit_key_handler )
]
while not self.finished:
self.render()
self.script_lock.wait()

appuifw.app.exit_key_handler=self.old_exit_handler
appuifw.app.title = old_title


if __name__ == '__main__':
Bizcard().main()

Download:

BusinessCard.py

Output:

The following screenshots are the outcome. Just click on the icons to enlarge them for a better view.

Output

Department of Electronic Systems | Aalborg University | Niels Jernes Vej 12 | DK-9220 Aalborg | Denmark
Phone: (+45) 9635 8695 | Fax (+45) 9815 1583 | E-mail ies(at)ies.aau.dk
Copyright © 2006 Department of Electronic Systems

Last update:06-10-2006