Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:PyPhotoFrame

From Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

This code snippet shows a PySymbian app which can overlay a photo frame pattern over user-selected photos.

Article Metadata
Tested with
Devices(s): Nokia N73
Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition
Article
Keywords: PhotoFrame
Created: nirpsis (21 Aug 2009)
Last edited: hamishwillee (08 May 2013)

Overview

The application uses the following modules:

  • appuifw module
  • graphics module
  • e32 module
  • time module

The following functions are used:

  • draw_screen():draw the black screen on canvas
  • save_image(): save the image with its selected frame
  • gold_frame():draw the gold frame on selected image
  • sliver_frame(): draw the sliver frame on selected image
  • wooden_frame(): draw the wooden frame on selected image
  • red_frame(): draw the red frame on selected image
  • blue_frame(): draw the blue frame on selected image
  • RingsnChain(): draw the Rings and Chain frame on selected image
  • DottedLine(): draw the Dotted line frame on selected image
  • DottedLine(): draw the Big Dotted line frame on selected image
  • BigDottedFrame(): draw the fancy4 frame on selected image
  • ArrowFrame(): draw the arrow frame on selected image

All the functions and parameters are defined in source code in detail.

Code snippet

The code for the example is below.

VERSION = "1.00"
# importing the necessary modules
import e32
import appuifw
import graphics
import math
 
# defining color codes
 
BLACK=(0,0,0)
RED=(176,23,31)
BLUE=(0,178,238)
WHITE=(255,255,255)
DEEP_BLUE=(0,0,255)
VIOLET=(255,62,150)
GOLD=(205,133,0)
SLIVER=(139,137,137)
ORANGE=(139,90,0)
GRAY=(205,201,201)
WOOD= (139,87,66)
MEGENTA=(139,0,139)
CRIMSON=(220,20,60)
BLUE2=(0,0,238)
 
running=1
 
#global variables
global x,y
x=240
y=320
x1=25
Separator=10
outer_line=14
inner_line=5
x_Separator=10
y_Separator=20
 
def quit():
'''the exit function'''
global running
running=0
app_lock.signal()
 
def menu_about():
'''the about function'''
appuifw.note(u"PhotoFrame version 1.00" + "\n Developed by Nirpsis")
 
def handle_redraw(rect):
'''function that will be called when the canvas needs to be redrawn'''
canvas.blit(img)
 
def draw_screen():
'''define the draw
function - loads new image'''

#Global variable for application UI
global canvas
#Create an instance of Canvas and set it as the application's body
canvas = appuifw.Canvas(redraw_callback = handle_redraw,event_callback = None)
appuifw.app.body=canvas
#Set the screen to full
appuifw.app.screen = 'full'
appuifw.app.exit_key_handler=quit
#Global variable for application UI
global img
#We open the image
img=graphics.Image.open("C:\\image.jpg")
img=img.resize((240,320), keepaspect=0)
handle_redraw(img)
 
def save_image():
'''save image'''
img.save("C:\\saved.jpg", quality=100)
appuifw.note(u"Image saved at C:\\saved.jpg")
 
def gold_frame():
'''function to draw golden frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=GOLD,width=20)
for j in range(1,inner_line):
img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=ORANGE)
handle_redraw(None)
 
def sliver_frame():
'''function to draw silver frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=GRAY,width=20)
for j in range(1,inner_line):
img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-20)+(j*2)),((y-20)+(j*2))),fill=None,outline=SLIVER)
handle_redraw(None)
 
def wooden_frame():
'''function to draw wooden frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=WOOD,width=20)
for j in range(1,inner_line):
img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=WOOD)
handle_redraw(None)
 
def red_frame():
'''function to draw red frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=RED,width=20)
for j in range(1,inner_line):
img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=RED)
handle_redraw(None)
 
def blue_frame():
'''function to draw blue frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=BLUE,width=20)
for j in range(1,inner_line):
img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=WHITE)
handle_redraw(None)
 
def RingsnChain():
'''function to draw rings and chain frame '''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=BLUE,width=5)
img.rectangle((20,20,220,300),fill=None,outline=BLUE,width=4)
for a in range(1,23):
img.point(((Separator*a),Separator),fill=None,outline=DEEP_BLUE,width=8)
for b in range(1,23):
global x,y,Separator
img.point(((Separator*b),(y-Separator)),fill=None,outline=DEEP_BLUE,width=8)
for c in range(1,31):
img.point((Separator,(Separator*c)),fill=None,outline=DEEP_BLUE,width=8)
for d in range(1,31):
global x,y,Separator
img.point(((x-Separator),(Separator*d)),fill=None,outline=DEEP_BLUE,width=8)
handle_redraw(None)
 
def DottedLine():
'''function to draw dotted line frame '''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=MEGENTA,width=5)
img.rectangle((20,20,220,300),fill=None,outline=MEGENTA,width=4)
for a in range(2,y_Separator+2):
global x,y,x1,x_Separator,y_Separator
img.ellipse(((x_Separator*a),(x_Separator/2),((x_Separator*a)+5),x1),fill=None,outline=MEGENTA)
for b in range(2,y_Separator+2):
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator*b),(y-x1),((x_Separator*b)+(x_Separator/2)),(y-(x_Separator/2))),fill=None,outline=MEGENTA)
for c in range(1,y_Separator-1):
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator/2),(x_Separator+(c*15)),y_Separator,(x1+(c*15))),fill=None,outline=MEGENTA)
for d in range(1,y_Separator-1):
global x,y,x_Separator,x1
img.ellipse(((x-y_Separator),(x_Separator+(d*15)),(x-(x_Separator/2)),(x1+(d*15))),fill=None,outline=MEGENTA)
handle_redraw(None)
 
def DottedLine():
'''function to draw dotted line frame '''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=CRIMSON,width=5)
img.rectangle((20,20,220,300),fill=None,outline=CRIMSON,width=4)
for a in range(0,x_Separator+1):
global x,y,x1,x_Separator,y_Separator
img.ellipse(((x_Separator+(a*y_Separator)),x_Separator,(x1+(a*y_Separator)),(y_Separator-(x_Separator/2))),fill=CRIMSON,outline=GRAY)
for b in range(0,x_Separator+1):
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator+(b*y_Separator)),(y-(x1-x_Separator)),(x1+(b*y_Separator)),(y-x_Separator)),fill=CRIMSON,outline=GRAY)
for c in range(0,x_Separator+5):
global x,y,x_Separator,y_Separator,x1
img.ellipse((x_Separator,(x_Separator+(c*y_Separator)),(x1-x_Separator),(x1+(c*y_Separator))),fill=CRIMSON,outline=GRAY)
for d in range(0,x_Separator+5):
global x,y,x_Separator,x1
img.ellipse(((x-15),(x_Separator+(d*y_Separator)),(x-x_Separator),(x1+(d*y_Separator))),fill=CRIMSON,outline=GRAY)
handle_redraw(None)
 
def BigDottedFrame():
'''function to draw big dotted frame '''
draw_screen()
x1=25
img.rectangle((0,0,x,y),fill=None,outline=VIOLET,width=4)
img.rectangle((20,20,220,300),fill=None,outline=VIOLET,width=2)
for a in range(0,y_Separator+2):
global x,y,x1,x_Separator,y_Separator
img.ellipse(((x_Separator+(a*x_Separator)),(x_Separator/2),(x1+(a*x_Separator)),(x1-x_Separator)),fill=VIOLET,outline=GRAY)
for b in range(0,y_Separator+2):
img.ellipse(((x_Separator+(b*x_Separator)),(y-(x1-x_Separator)),(x1+(b*x_Separator)),(y-5)),fill=VIOLET,outline=GRAY)
for c in range(0,y_Separator+x_Separator):
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator/2),(x_Separator+(c*x_Separator)),(x1-x_Separator),(x1+(c*x_Separator))),fill=VIOLET,outline=GRAY)
for d in range(0,y_Separator+x_Separator):
global x,y,x_Separator,x1
img.ellipse(((x-(x1-x_Separator)),(x_Separator+(d*x_Separator)),(x-5),(x1+(d*x_Separator))),fill=VIOLET,outline=GRAY)
handle_redraw(None)
 
def ArrowFrame():
'''function to draw arrow frame '''
draw_screen()
x1=25
img.rectangle((0,0,x,y),fill=None,outline=BLUE2,width=4)
img.rectangle((20,20,220,300),fill=None,outline=BLUE2,width=2)
for a in range(0,x_Separator+3):
global x,y,x1,x_Separator,y_Separator
img.ellipse(((x_Separator+(a*(y_Separator-3))),(x_Separator/2),(x1+(a*(y_Separator-3))),y_Separator),fill=BLUE2,outline=WHITE)
for b in range(0,x_Separator+3):
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator+(b*(y_Separator-3))),(y-(x1-x_Separator)),(x1+(b*(y_Separator-3))),y),fill=BLUE2,outline=WHITE)
for c in range(0,y_Separator-2):
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator/2),(x_Separator+(c*(y_Separator-3))),y_Separator,(x1+(c*(y_Separator-3)))),fill=BLUE2,outline=WHITE)
for d in range(0,y_Separator-2):
global x,y,x_Separator,x1
img.ellipse(((x-y_Separator),(x_Separator+(d*(y_Separator-3))),(x-5),(x1+(d*(y_Separator-3)))),fill=BLUE2,outline=WHITE)
handle_redraw(None)
 
# Create options menu
appuifw.app.menu = [(u"Load Image", draw_screen),(u"Simple",((u"Golden",gold_frame),(u"Sliver",sliver_frame),(u"Wooden",wooden_frame),(u"Red",red_frame),(u"Blue",blue_frame))),(u"Fancy",((u"Rings n Chain",RingsnChain),(u"Dotted line",DottedLine),(u"Dotted Line",DottedLine),(u"Big Dotted",BigDottedFrame),(u"Arrow",ArrowFrame))),(u"Save Image",save_image),(u"About",menu_about),(u"Exit",quit)]
 
draw_screen()
 
app_lock = e32.Ao_lock()
#Wait for the user to request the exit
 
app_lock.wait()


Screenshots

Option.JPG SimpleOptions.JPG Fancyoption.JPG

DottedLine.JPG Ring and Chain.JPG Fancy1.jpg

This page was last modified on 8 May 2013, at 06:18.
43 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×