×
Namespaces

Variants
Actions

Archived:Drawing a Calendar on PySymbian Canvas

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


This article demonstrates how to draw a calendar on a canvas using PySymbian.

Article Metadata
Tested with
Devices(s): N73, N95
Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition
Article
Keywords: Calendar
Created: nirpsis (27 Jul 2009)
Last edited: hamishwillee (08 May 2013)

Contents

Introduction

The application uses the following modules:

  • appuifw module
  • graphics module
  • e32 module

The following functions are used to create the canvas based calendar:

  • draw_screen():draw the black screen on canvas
  • draw_text():write some text on square
  • print_number: print number on square


The following parameters are used when developing this application. They are customizable.

  • number_of_square: Initialize number of column
  • number_of_lines: Initialize number of row
  • Horizontal_Separator: Separate the space between column
  • Vertical_Separator: Separate the space between row

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

Code snippet

The code for the calendar is below.

# import module
import appuifw,graphics,e32
 
# define color code
BLACK= (0,0,0)
RED=(255,0,0)
BLUE= (0,0,255)
GREEN=(0,255,0)
ORANGE= (255,127,0)
WHITE=(255,255,255)
global width,height
width=320
height=320
 
#Global variables
sqrt_x=width/16
sqrt_y=height/4
sqrt_width=30
sqrt_height=25
number_of_square=7
number_of_lines=6
Horizontal_Separator=3
Vertical_Separator=3
 
TextColor=RED
PrintNumber=WHITE
canvas=None
img=None
 
def handle_redraw(rect):
canvas.blit(img)
 
# exit function
def quit():
app_lock.signal()
 
#---------------------------
#draw draw screen
#---------------------------
 
def draw_screen():
 
#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
img = graphics.Image.new(canvas.size)
 
#Clear the image
img.clear(BLACK)
global x1,y1,x2,y2, sqrt_x, sqrt_y, sqrt_width, sqrt_height,number_of_square, Horizontal_Separator,Vertical_Separator,number_of_lines
for j in range(number_of_lines):
#define rectangle coordinate
x1=sqrt_x
y1=sqrt_y+j*(sqrt_height+Vertical_Separator)
x2=x1+sqrt_width
y2=y1+sqrt_height
for i in range(number_of_square):
#draw rectangle
img.rectangle((x1+ i*sqrt_width,y1,x2+ i*sqrt_width-Horizontal_Separator,y2),outline=BLUE)
handle_redraw(None)
Total_x, Total_y = canvas.size
img.text((35,50), u"CALENDER", fill = BLUE,font=(u'Nokia Hindi S60',40,appuifw.STYLE_BOLD))
handle_redraw(None)
 
#define draw_text function
def draw_text():
global sqrt_x,sqrt_y,t1,t2,sqrt_height,y3,x3, number_of_square
t1=5
t2=20
y3=sqrt_y+t2
a=[u'S',u'M',u'T',u'W',u'T',u'F',u'S']
for i in range(1,number_of_square +1):
# draw text on canvas
img.text((sqrt_x+i*t1+(i-1)*sqrt_height,y3), unicode(a[i-1]), fill=TextColor,font=(u'Nokia Hindi S60',20,appuifw.STYLE_BOLD))
handle_redraw(None)
 
 
def draw_number(i, no_of_days_in_month):
global number_of_lines, number_of_square
a=1
for j in range(number_of_lines-1):
if i==number_of_square:
i=0
t1=5
x1=sqrt_x
y1=sqrt_y+(j+1)*sqrt_width+14
while i<number_of_square:
img.text((x1+ i*sqrt_height+(i+1)*t1,y1),unicode(a),fill=PrintNumber)
a+=1
i+=1
if a==no_of_days_in_month+1:
break
handle_redraw(None)
#a+=1
#calling the function
draw_screen()
draw_text()
draw_number(3,31)
app_lock=e32.Ao_lock()
 
#Wait for the user to request the exit
app_lock.wait()

Screenshots

Draw square.JPG Draw text.JPG

Print number.JPG Print number2.JPG

Related links

This page was last modified on 8 May 2013, at 08:12.
115 page views in the last 30 days.
×