Python …II N Amanquah Based on EPROM curriculum.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
Table of Contents This document describes about XML application to control, customize, initiate action of phone. Overview of XML Application Each Function.
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
FILE UPLOADS CHAPTER 11. THE BASIC PROCESS 1.The HTML form displays the control to locate and upload a file 2.Upon form submission, the server first stores.
1 Introduction to Human Computer Interaction  Livecode Overview  Based on Livecode User Guide from RunRev Ltd. (2010) 
Python for S60 SmartPhones PostPC Workshop Fall 2006 Amnon Dekel.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Sikuli Ivailo Dinkov QA Engineer PhoneX Team Telerik QA Academy.
MBAC 611.  Click on the My Computer Icon  Open your private network directory  Create a new folder named lab7  Copy your lab6 Access file to the lab7.
Introduction to Python
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Website Development with PHP and MySQL Saving Data.
PC204 Lecture 9 Conrad Huang Genentech Hall, N453A x
Concurrent Programming and Threads Threads Blocking a User Interface.
App Engine Web App Framework Jim Eng
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Pervasive Computing MIT SMA 5508 Spring 2006 Larry Rudolph 1 More Python on Series 60 Larry Rudolph SMA 5508 MIT (Spring 2006) March 10.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
1 UNIT 13 The World Wide Web. Introduction 2 The World Wide Web: ▫ Commonly referred to as WWW or the Web. ▫ Is a service on the Internet. It consists.
How to make an Interactive Voice Response (IVR) using an OzML script This slideshow is intended to be a great explanation on how to develop an Interactive.
Python for Series 60 Platform CTPUG Graeme Glass.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Core ELN Training: Office Web Apps (OWA)
Development Environment
Running a Forms Developer Application
Lecture 11 Networking Part 2.
Working in the Forms Developer Environment
Topics Graphical User Interfaces Using the tkinter Module
Data Virtualization Tutorial: Introduction to SQL Script
PYGAME.
Python Graphics N Amanquah Based on EPROM curriculum.
Python …III N Amanquah Based on EPROM curriculum.
Introduction to Event-Driven Programming
Event-driven programming
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Topics Introduction to Repetition Structures
Intro to Python Programming – Part II
Introduction to Triggers
CS 3305 System Calls Lecture 7.
Functions CIS 40 – Introduction to Programming in Python
PHP / MySQL Introduction
Using Procedures and Exception Handling
Lesson 1: Buttons and Events – 12/18
Engineering Innovation Center
Fundamentals of Python: From First Programs Through Data Structures
Windows Internet Explorer 7-Illustrated Essentials
intro to notifications in iOS 10
CSE 154 Lecture 22: AJAX.
Processor Management Damian Gordon.
User Guide Subversion client TortoiseSVN
Title: MPS500 & Workstation (New System) Keycode Retrieval System (KRS) User Guide Generating and Retrieving Keycode License using URN.
Topics Introduction Hardware and Software How Computers Store Data
Skype for Business Webinar Meeting
Introduction to TouchDevelop
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Topics Graphical User Interfaces Using the tkinter Module
Intro to PHP.
Why Threads Are A Bad Idea (for most purposes)
User Input Keyboard input.
Traditional Internet Applications
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
PHP-II.
Processor Management Damian Gordon.
Presentation transcript:

Python …II N Amanquah Based on EPROM curriculum

Goals for Today Building Applications Title, Screen Size, Tabs, Threads, Body, Menus … GUI Design Customizing Your Own Graphical User Interfaces Creating Our Own Modules Sending Text Messages / Making Phone Calls

Scraping Feedfire.com (still down) Feed43.com Feedyes.com

Get More User Input import appuifw Example from: Larry Rudolph's Intro to Python slides import appuifw planets = [ u'Mars', u'Earth', u'Venus' ] prompt = u'Enter your home planet' index = appuifw.popup_menu(planets, prompt) appuifw.note(u'Hello '+planets[index] , u'info') The ‘menu’ method pops up the list of items in first param It returns with an index into the list of menu items Note that the prompt param must also be a unicode string 4

ashesi.py Our Own Interface Example from: Larry Rudolph's Intro to Python slides ashesi.py There are a bunch of annoyances in the current UI Let’s put wrappers around basic calls 5

Hiding the Unicode # this is file ashesi.py # wrappers to appuifw Example from: Larry Rudolph's Intro to Python slides # this is file ashesi.py # wrappers to appuifw def note( str , type = ‘info’): appuifw.note( unicode(str), type ) def query( str , type = ‘text’ ): return appuifw.query( unicode(str), type ) def menu( list, prompt = ‘select one’ ): ulist = [ unicode(u) for u in list ] return appuifw.popup_menu( ulist , unicode( prompt ) ) 6

Using ashesi.py import ashesi.py planets = [ ’Mars’, ’Earth’, ’Venus’ ] prompt = ’Enter your home planet’ index = ashesi.menu(planets, prompt) ashesi.note(’Hello ’+planets[index] ) Place in a folder called lib in the python folder (on the phone) 7

Sending Text Messages / Making Phone Calls Text / SMS Module: messaging messaging.sms_send(number, txt) Telephone module: telephone telephone.dial(number) hang_up() Play with ex_sms_sendind_descr.py http://www.mobilenin.com/pys60/ex_sms_sending.htm 8

appuifw.app Appuifw contains an instance of the class application, called app 9

The 9-Steps to Application Development 1. import all modules needed 2. set the screen size (normal, large, full) 3. create your application logic ... 4. create an application menu (if necessary) 5. set an exit key handler 6. set the application title 7. deal with active objects if necessary 8. set the application body (text or canvas or listbox or none) 9. create a main loop (e.g. while loop) if suitable 10

1. Importing Modules import appuifw import e32 11

2. Setting Screen Size Example script: app_screen.py # screen has 3 different values: #(a normal screen with title pane and softkeys appuifw.app.screen='normal' #(only softkeys visible) appuifw.app.screen='large' #(a full screen) appuifw.app.screen='full' Example script: app_screen.py 12

3. Application Logic This is where the heart of your application lies. 13

4. Application Menus Example script: app_menu.py An application menu uses the left softkey and can always be accessed while your application is running. An application menu can contain also a submenu # create the callback functions that shall be executed when selecting an item in # the menu: def item1():     print "item one" def subitem1():     print "subitem one" def subitem2():     print "subitem two" # create the menu using appuifw.app.menu[(title, callback1), (title, (subtitle, callback2))] appuifw.app.menu = [(u"item 1", item1), (u"Submenu 1", ((u"sub item 1", subitem1), (u"sub item 2", subitem2)))] Example script: app_menu.py 14

5. The Exit Key Handler The exitkey handler gets activated when you press the right (exit) softkey. By assigning an extra function to the .exit_key_handler you can define what shall happen when it is pressed. def quit():     appuifw.app.set_exit() app.exit_key_handler=quit 15

6. The Application Title appuifw.app.title = u"SMS sending" 16

7.0 UI Threads places objects on screen registers callbacks procedures associated with screen & keyboard events when event occurs, want to pass control to the callback procedure. what if thread is executing something else? Callbacks should execute quickly UI thread should spend most of the time idle 17

7.1 e32 module: Coordination Graphic from: Larry Rudolph's Intro to Python slides Don’t use normal thread locks: import thread lock = thread.allocate_lock() Whole application gets blocked, since no UI actions would be handled Use e32.Ao_lock instead 18

7.2 Active Objects If Symbian written today, AO’s would be called “listeners” Get called by a thread scheduler (have a little bit of state) Run to completion then return to scheduler They preserve the responsiveness of the UI and sockets # You need to import the e32 module import e32 # create an instance of the active object app_lock = e32.Ao_lock() # starts a scheduler -> the script processes #events (e.g. from the UI) until lock.signal() is # callled. app_lock.wait() # stops the scheduler app_lock.signal() For more detail see the python_api.pdf. 19

8. Application Body text or canvas or listbox or none # body as Listbox: appuifw.app.body = appuifw.Listbox(entries,shout) # Example script: app_body_listbox.py # body as Text: appuifw.app.body = appuifw.Text(u'hello') # Example script: app_body_text.py # body as Canvas: appuifw.app.body=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw) # Example script: app_body_canvas.py 20

9. The Main Loop # put in the main loop the things that need to be run through again and again in your script running = 1 while running:     # #e.g. redraw the screen:     handle_redraw(()) 21

Application Skeletons 1. no main loop because the application logic works without Example script: app_skeleton.py   2. with mainloop (if suitable) Example script: app_skeleton_with_mainloop.py 22

Basic Application structure E32 is for low level fxns related to Symbain OS Import appuifw, e32 def quit(): print “Exiting…” app_lock.signal() Appuifw.app.exit_key_handler=quit() #a callback fxn Appuifw.app.title=u”My title” Appuifw.note(u”include other forms/menus here”) App_lock=e32.Ao_lock() App_lock.wait() #wait for user actions till exit key pressed

Redo last assignment as a proper application

File IO import os # drefine the directory and file name to write the file into imagedir=u'c:\\witetest.txt' # create the file file = open(imagedir,'w') # write some text into it file.write('hello, this works') # close the file file.close() print "file stored"

Laboratory #8 ex_graphics_drawing_descr.py Write code that uses keyboard to trigger pop-up notes telling you what key has been pressed. while running: if keyboard.pressed(EScancodeLeftArrow):         appuifw.note(u"Arrow left", "info") Create “Backdoor" Codes in Your Application that trigger events if the user presses the right code… Extra Credit: Modify an application to accept keyboard commands to trigger functions rather than menus. LOOK AT extended_use_of_keys.py! ex_graphics_drawing_descr.py Write a program to conduct a survey. Make your own questions, store them in a file. 27

GPRS… Web Access

GRPS Uploading Why? Automatic Data Collection Mobile Blogging Database Interactions Modules urllib, httplib, ftplib (install) Examples ftp_example.py ex_image_upload_to_database.py 29

Networking with GPRS Downloading Media Content import urllib urllib.urlretrieve(url, tempfile) Handling the Content: Playback content_handler.open(tempfile) rss, images, video, audio, etc… Example: urllib_example.py ex_video_download_descr.py 30

Fetching web content import urllib url = "http://www.google.com/index.htm" tempfile = "c:\\testimg.gif" urllib.urlretrieve(url, tempfile) 31

import urllib params = urllib.urlencode({'data': 'test1', 'eggs': 0, 'bacon': 0}) f=urllib.urlopen("http://127.0.0.1/mywebs/mobilewc/testPython.php?%s" % params) #f=urllib.urlopen("http://127.0.0.1/mywebs/mobilewc/testPython.php?name=namthan&age=4") x=f.read() print x urllib.urlretrieve("http://127.0.0.1/mywebs/mobilewc/testPython.php?%s" % params, "c:\\temp\\fila.txt") f=open( "c:\\temp\\fila.txt") z=f.read() print z

uploading import httplib, urllib, e32 params = urllib.urlencode({'data': test1, 'eggs': 0, 'bacon': 0}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} conn = httplib.HTTPConnection("www.serverIP.com") conn.request("POST", "/file.php", params, headers) conn.close()

<?php // Get the incoming params sent by PyS60 $data = $_POST['data']; $eggs = $_POST['eggs']; $bacon = $_POST['bacon']; //now write to a db or a file if you wish $filename = 'textfile.txt'; $handle = fopen($filename, 'a+'); $text="\n"; fwrite($handle, $data); fwrite($handle, $text); echo 'data received OK'; fclose($handle); ?>

Laboratory Working quickly as a team of 3: Create an application that fetches some information from the user using a series of questions. Save the values in a text file on the phone. Be able to read the text file back and display its contents Create a function for uploading the information to a remote server (by HTTP POST) Create a php file that receives this info and saves in a file Extra credit: Create a little script that allows you to view entries submitted. 35