View page as slide show

Environment

Python crash course

  • Two types of programming languages
  • Compiled

  • Interpreted

  • Both options in your tasks/projects

Python ...

  • Code in two manners
    • Command line
    • .py file
  • Output to terminal
    • print 1 + 1
    • print “hello world”
  • Variables
    • int, str, float
    • »type(4.2) vs »type('4.2')
    • variable names begin with characters i.e. not numbers
      • 2010wse = “wireless service engineering”

Python ...

Keywords

  • and, def, exec, if, not, return, assert, del, finally, …
  • “#” or “”“blah blah”“” - comments out code

Statments

  • » x = 2
  • » print x
  • » 2

Operators

  • Standard operators (*, /, -) and then some (/ /, … )

Python ...

Functions() importing & composition

  • type()
  • » str(-273.15) absolute zero
  • » import math
    • »math.sqrt(2) / 2.0
    • »0.707106781187

composition

  • »def hello():
  • » print “hello world”
  • » print “wse2010”
  • hello()
  • Alway recall the flow of execution – indentation

Python ...

Conditions & recursions

  • Boolean & logical expressions
    • » 26 == 26
    • » True
    • !=, >, <; >=, ⇐, %, and, …
  • Alternative executions
    • if, else, elif,
    • Nested layers
  • return, continue

Python ...

Iterations/loops

  • while n > 20:
  • for i in range(0, 20):
  • for char in fruit:

Strings - length, slicing

  • » fruit = “banana”
  • » letter = fruit[1]
  • » print letter
  • len(fruit), fruit[0:3], fruit[0:-1], fruit[:]?
  • String are immutable i.e. fruit[0]='K' vs 'K'+fruit[1:]

Python ...

Lists

  • » numbers = [10, 20, 30, 40], words = [“spam”, “bungee”, “swallow”]
  • » numbers[3], len(words), for word in words:, …
  • Lists are immutable

Objects & values

  • » a=“banana”, b=“banana”
  • » id(a) vs id(b)
  • » a = [1, 2, 3], b=[1, 2, 3]
  • » id(a) vs id(b)

More usefull stuff

  • tuples - similar to lists but immutable
  • random numbers
    • » import random
    • » random.random()
  • dictionary
    • » fruits = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
    • » print fruits, » del fruits['apples'], » fruits.keys(). fruits.values()

Python ...

Classes

  • Class Area:
    • def square_area(w, h):
    • area = w*h
    • return area
  • » import Area()
  • » ar = Area.Area()
  • » print ar.squre_area(20, 20)

Much more

  • Inheritance
  • Special libraries e.g. bluetooth, xml, etc

Development environment

  • Scratchbox
  • Esbox
  • Run apps in emulator

Scratchbox introduction

  • Cross compilation environment for ARM development
  • Virtual file system view for user & target (ARM & x86) - good amount of symbolic links
  • pyMaemo development - no need for cross compilling
    • Rather scratchbox runtimes needed

Using scratchbox

  • 2 ways to use scratchbox
    1. Processor emulation - qemu
    2. Remote execution on actual device - sbrsh (USB enabled)
  • Login
    • > /scratchbox/login
    • [sbox:]>
  • Usefull
    • [sbox:]> fakeroot - give root access to install packages etc
    • Similar to debian or ubuntu environment

Target selection

  • 2 ways
    • From scratchbox
      • > /scratchbox/login
      • [sbox:]>sb-menu
      • select target
  • From Eclipse (esbox)
    • window → preferences → esbox → target

The Xephyr X Server

  • Xephyr is a kdrive based X Server which targets a window on a host X Server as its framebuffer
  • Support mordern X extensions - even if host does not - advantage over Xnest
  • Uses SHM Images and shadow framebuffer updates to provide good performance.
  • Has a visual debugging mode for observing screen updates.
  • Two ways to start Xephyr
    1. host> Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -extension Composite
    2. From esbox

Maemo in Xephyr

  • 2 ways
    1. Scratchbox
    2. Esbox
  • Starting
    • [sbox] > af-sb-init.sh start
  • Stopping
    • [sbox-SDK_ARMEL:] > af-sb-init.sh stop
Last modified: 2013/07/01 14:41