34
Developing with py GTK in EeePC 胡胡胡 [email protected] 胡胡胡 胡胡胡 http://www.openfoundry.org/ 胡胡胡胡胡 胡胡胡胡胡胡胡

Developing with pyGTK in EeePC

Embed Size (px)

DESCRIPTION

speech delivered in EeePC Developer's Day, on May 8, 2008.

Citation preview

Page 1: Developing with pyGTK in EeePC

Developing with pyGTK in EeePC

胡崇偉[email protected]

自由軟體鑄造場http://www.openfoundry.org/

中央研究院 資訊科學研究所

Page 2: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 2

自由軟體鑄造場的服務特色• 提供協同式專案開發知識及工具• 提供法務授權條款專業諮詢• 與學術研究單位及社群團體密切連繫• 培育人才並提供教學訓練材料

Page 3: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 3

OpenFoundry 網站功能簡介

專案管理

Page 4: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 4

OpenFoundry 網站功能簡介

專案管理

版本管理

待辦事項

共同筆記

檔案下載

通信論壇

統計資訊

Page 5: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 5

OpenFoundry 網站功能簡介

專案管理

版本管理

待辦事項

共同筆記

檔案下載

通信論壇

統計資訊

授權條款精靈 電子報

人才資料庫

推廣光碟

資源目錄

研究報告教學文件

Page 6: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 6

Page 7: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 7

Page 8: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 8

Page 9: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 9

Page 10: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 10

Easy Path to Linux Programming

Page 11: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 11

Easy Path to App Programming

• Especially for EeePC Linux Application Development, where requires the ability to quickly prototype and to glue software components.

Page 12: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 12

Benefits Using Python

• Easy to Implement

• Easy to Integrate

• Rich Libraries and Sample Codes

Page 13: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 13

Python Programming Overview

• Builtins

• Data Types

• Functions

• Classes/Objects

• Methods (Member Functions)

• Modules

• Packages

Page 14: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 14

Checking Basic Info

• python -V– Show Version Info

• dir()– Show Namespace Info

Page 15: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 15

Basic Data Types• myString = “Hello World”

• myList = [‘I’, ‘Love’, 7, 11]

• myTuple = (myList, ‘works’, 2)

• myDictionary = {“name”:”marr”,”location”:”taipei”}

Page 16: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 16

Indexing and Slicing

• myString = “I Love Python”

• myString[0] == “I”

• myString[-1] == “n”

• myString[7:-2] == “Pyth”

I L o v e P y t h o n

[0

1

2

7

-6

-2

-1

↓]

Page 17: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 17

Builtin Function Example

range(3)[0, 1, 2]

for a in range(3): print “count down”, a

Page 18: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 18

Indenting Code

• No explicit begin or end

• No curly braces

• Use colon (:) and the indentation

Page 19: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 19

Python Style Guide

• http://www.python.org/doc/essays/styleguide.html

• Lay-out -- how to use tabs, spaces, and newlines.

• Comments -- on proper use of comments (and documentation strings).

• Names -- various naming conventions.

Page 20: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 20

Importing Modules

myString = “250”import mathmath.sqrt(myString)

TypeError: a float is required

from string import atoi

atoi(myString)250

Page 21: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 21

Function Example

def myFunc(score): “”” document strings “”” import math math.sqrt(score) * 10

Page 22: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 22

Libraries and Their Capabilities

• OS Operation– import os– import sys

• File Handling– open()

• Networking– Socket creating and handling– Twisted for high level applications

Page 23: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 23

import os

• os.chdir()

• os.getenv(“HOME”)

• os.listdir(os.getcwd())

Page 24: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 24

import sys

• sys.path

• sys.stdin

• sys.stdout

• sys.stderr

Page 25: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 25

File Handling

fileobj = open(“myfile”, “r”)lines = fileobj.readlines()for line in lines: print line

Page 26: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 26

Socket Connection for Client/Server

• Socket Creation

• Port Binding

• Raw Data I/O (sending and receiving)

• select() and pull() for Nonblocking sockets

Page 27: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 27

Socket Creation

import socket

s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)s.connect( ("www.mysite.com", 80))

Page 28: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 28

Port Binding

import socket

serversocket = socket.socket( socket.AF_INET, socket.SOCK_STREAM)serversocket.bind( (socket.gethostname(), 80))serversocket.listen(5)

Page 29: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 29

FTP lib

from ftplib import FTPftp = FTP(“ftp.cdrom.com”)print ftp.login()ftp.retrlines('LIST‘)filename = “toPut.exe”file = open(filename, ‘wb’)

Page 30: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 30

FTP library example - miniFTP

• FTP Object and Dialog Initialization

• Login to Server and Logout from Server

• File List Generation• File Get/Put/Remove• Event Handling:

BUTTON_PRESS event, error exception

Page 31: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 31

gtkmozembed

• Get ready with these packages– xulrunner– libxul-dev– python-gnome2-extras

• http://www.pygtk.org/pygtkmozembed/class-gtkmozembed.html

Page 32: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 32

Gtkmozembed + flash

• Flash plug-in library placed in specific user folder

• $HOME/.mozilla/plugins

Page 33: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 33

Code Samples

• aspn.activestate.com/ASPN/Cookbook/Python• pyshop• Other Important Issues

– File Format Manipulation

– Exceptions

– Debugging and Testing

– GUI Libraries (Cairo)

– Unicode Howto

Page 34: Developing with pyGTK in EeePC

自由軟體鑄造場 www.openfoundry.org 34

THANK YOU