×
Namespaces

Variants
Actions
(Redirected from Using graphs in PySymbian)

Archived:Using graphs in PySymbian

From Nokia Developer 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 PySymbian code snippet shows how can to plot graphs for user given inputs.

Article Metadata
Tested with
Devices(s): Nokia N96
Compatibility
Platform(s): S60 2nd Edition, S60 3rd Edition
Article
Keywords: graphics
Created: ck.umraliya (19 Jul 2008)
Last edited: hamishwillee (31 May 2013)


Code

# import modules
import e32, appuifw,graphics
 
# Define quit function
def quit():
app_lock.signal()
 
def draw():
 
# Get number of graphs
t = appuifw.query(u"Enter Number Of Graphs: (Max 9)","number")
 
#title of the application
appuifw.app.title = u"Graphs"
 
# Get range
rrng = appuifw.query(u"Maximum Range Of Graph:","number")
 
# Graph colors
colors = [0x0000ff,0x00ff00,0xff0000,0xffff00,0xc0c0c0,0x808040,0xff00ff,0xf0cb75,0xbe6a0e]
 
# Get graph prameters
y = []
n = []
for j in range(t):
(n1,y1) = appuifw.multi_query(u"Title Of Graph %d:"%(j+1),u"Height Of Graph %d:"%(j+1))
n.append(n1)
y11 = int(y1)
y.append(y11)
 
# Define canvas
canvas=appuifw.Canvas()
appuifw.app.body=canvas
xx,yy = canvas.size
 
# Scaling Graphs according to screen size
arrg = float(yy-50)
mf = arrg/rrng
 
# Draw x,y axis
canvas.line((20,yy-20,xx-32,yy-20), 0)
canvas.line((xx-33,10,xx-33,yy-20),0)
 
# Put indicator points
canvas.text((xx-34,30+(yy-40)*0.75),u"_%d"%(rrng*0.25))
canvas.text((xx-34,30+(yy-40)*0.5),u"_%d"%(rrng/2))
canvas.text((xx-34,30+(yy-40)*0.25),u"_%d"%(rrng*0.75))
canvas.text((xx-34,30),u"_%d"%(rrng))
 
# Draw graphs
h = 30
for i in range(t):
w=(xx-57)/t - 10
s = yy-20-mf*y[i]
canvas.rectangle((h,s,h+w,yy-20), outline=0x000000, fill=colors[i])
x11 = str(y[i])
canvas.text((h,(s-5)),u" %s"%(x11), fill=colors[i])
canvas.text((h,yy), u"%s"%(n[i]), fill=0x4b2192)
h=h+w+10
draw()
 
#the code will allow the user to exit the application when he presses the exit key
appuifw.app.exit_key_handler=quit
app_lock=e32.Ao_lock()
app_lock.wait()

Postconditions

Once the graph is drawn a screenshot function can be used to save the image if user wants. Following images are the outcome of above code.

Number of Graphs
Maximum Range
Graph Parameters
Plotted Graphs

Related Links

Plotting Graphs in Python

This page was last modified on 31 May 2013, at 04:10.
61 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.

×