developing with pygtk in eeepc
Post on 12-May-2015
1.664 Views
Preview:
DESCRIPTION
TRANSCRIPT
Developing with pyGTK in EeePC
胡崇偉marr@iis.sinica.edu.tw
自由軟體鑄造場http://www.openfoundry.org/
中央研究院 資訊科學研究所
自由軟體鑄造場 www.openfoundry.org 2
自由軟體鑄造場的服務特色• 提供協同式專案開發知識及工具• 提供法務授權條款專業諮詢• 與學術研究單位及社群團體密切連繫• 培育人才並提供教學訓練材料
自由軟體鑄造場 www.openfoundry.org 3
OpenFoundry 網站功能簡介
專案管理
自由軟體鑄造場 www.openfoundry.org 4
OpenFoundry 網站功能簡介
專案管理
版本管理
待辦事項
共同筆記
檔案下載
通信論壇
統計資訊
自由軟體鑄造場 www.openfoundry.org 5
OpenFoundry 網站功能簡介
專案管理
版本管理
待辦事項
共同筆記
檔案下載
通信論壇
統計資訊
授權條款精靈 電子報
人才資料庫
推廣光碟
資源目錄
研究報告教學文件
自由軟體鑄造場 www.openfoundry.org 6
自由軟體鑄造場 www.openfoundry.org 7
自由軟體鑄造場 www.openfoundry.org 8
自由軟體鑄造場 www.openfoundry.org 9
自由軟體鑄造場 www.openfoundry.org 10
Easy Path to Linux Programming
自由軟體鑄造場 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.
自由軟體鑄造場 www.openfoundry.org 12
Benefits Using Python
• Easy to Implement
• Easy to Integrate
• Rich Libraries and Sample Codes
自由軟體鑄造場 www.openfoundry.org 13
Python Programming Overview
• Builtins
• Data Types
• Functions
• Classes/Objects
• Methods (Member Functions)
• Modules
• Packages
自由軟體鑄造場 www.openfoundry.org 14
Checking Basic Info
• python -V– Show Version Info
• dir()– Show Namespace Info
自由軟體鑄造場 www.openfoundry.org 15
Basic Data Types• myString = “Hello World”
• myList = [‘I’, ‘Love’, 7, 11]
• myTuple = (myList, ‘works’, 2)
• myDictionary = {“name”:”marr”,”location”:”taipei”}
自由軟體鑄造場 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
↓]
自由軟體鑄造場 www.openfoundry.org 17
Builtin Function Example
range(3)[0, 1, 2]
for a in range(3): print “count down”, a
自由軟體鑄造場 www.openfoundry.org 18
Indenting Code
• No explicit begin or end
• No curly braces
• Use colon (:) and the indentation
自由軟體鑄造場 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.
自由軟體鑄造場 www.openfoundry.org 20
Importing Modules
myString = “250”import mathmath.sqrt(myString)
TypeError: a float is required
from string import atoi
atoi(myString)250
自由軟體鑄造場 www.openfoundry.org 21
Function Example
def myFunc(score): “”” document strings “”” import math math.sqrt(score) * 10
自由軟體鑄造場 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
自由軟體鑄造場 www.openfoundry.org 23
import os
• os.chdir()
• os.getenv(“HOME”)
• os.listdir(os.getcwd())
自由軟體鑄造場 www.openfoundry.org 24
import sys
• sys.path
• sys.stdin
• sys.stdout
• sys.stderr
自由軟體鑄造場 www.openfoundry.org 25
File Handling
fileobj = open(“myfile”, “r”)lines = fileobj.readlines()for line in lines: print line
自由軟體鑄造場 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
自由軟體鑄造場 www.openfoundry.org 27
Socket Creation
import socket
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)s.connect( ("www.mysite.com", 80))
自由軟體鑄造場 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)
自由軟體鑄造場 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’)
自由軟體鑄造場 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
自由軟體鑄造場 www.openfoundry.org 31
gtkmozembed
• Get ready with these packages– xulrunner– libxul-dev– python-gnome2-extras
• http://www.pygtk.org/pygtkmozembed/class-gtkmozembed.html
自由軟體鑄造場 www.openfoundry.org 32
Gtkmozembed + flash
• Flash plug-in library placed in specific user folder
• $HOME/.mozilla/plugins
自由軟體鑄造場 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
自由軟體鑄造場 www.openfoundry.org 34
THANK YOU
top related