#! /usr/bin/perl ## 學藉系統備份程式perl版 by 二林國小 村仔 2009.07;2010.07修正 ## 功用:備份、FTP備份檔到遠方主機、更新學籍系統、更新系統 ## 適用環境 ubuntu 主機。 $conf{'chktime'}='Y';##要不要進行校時 $conf{'bakup'}='Y';##要不要備份某些目錄, 設定值 Y/N $conf{'ftp'}='Y';##要不要透過ftp將資料送到遠方主機 設定值 Y/N $conf{'upsfs'}='Y';##要不要更新學藉系統, 設定值 Y/N $conf{'upSYS'}='Y';##要不要更新系統, 設定值 Y/N #每類型備份檔案最多數量 $lim=12; ## 學藉系統路徑,保留最後斜線 $conf{'sfspath'}='/home/webadmin/html/sfs3/'; ## 欲備份目錄及備份檔的前置字元,注意不要破壞格式,可以自行增添多組 ## $BB{前置字元}='備份目錄';不須有後面的斜線 $BB{'SFS_DB'}="/var/lib/mysql/sfs3"; $BB{'SFS_data'}="/home/webadmin/html/sfs3/data"; $ftp{'host'}='192.168.11.6';##遠方主機 $ftp{'path'}='BB/';##登入後檔案放置目錄 $ftp{'user'}='edu';##遠方主機帳號 $ftp{'pass'}='123';##遠方主機密碼 ## 學藉系統下載網址 $conf{'url'}='http://sfscvs.tcc.edu.tw/sfs_stable.tar.gz'; #備份檔放置目錄 $BAK="/home/webadmin/baksfs/"; ##----------以下不用修改----------------### ##關閉防火牆 #`/etc/init.d/firewall stop`; ###----0.校時----### if ($conf{'chktime'} eq 'Y'){ `/usr/sbin/ntpdate time.stdtime.gov.tw > /dev/null `; `/usr/sbin/ntpdate time.stdtime.gov.tw > /dev/null `; `/usr/sbin/ntpdate time.stdtime.gov.tw > /dev/null `; } ###----1.檢查備份目錄存在否----### if (!-e $BAK) { `/bin/mkdir -p $BAK`; `/bin/sync `; `/bin/sync `; } ###----2.關閉apache及MySQL----### `/etc/init.d/apache2 stop `; `/etc/init.d/mysql stop `; ###----3.設定作業時間字串----### $TT=`date "+%Y%m%d_%H%M%S"`; ## perl用chomp函數去掉結尾的CR/LF chomp $TT; ##-----4.備份檔案作業、刪除多餘備份檔-----------##### if ($conf{'bakup'} eq 'Y'){ while (($key, $value)=each %BB) { $fi=$BAK.$key."_".$TT.".tgz"; @total = split('/',$value); $data=pop @total; $path = join '/' , @total; `cd $path ;/bin/tar -zcf $fi $data `; `/bin/sync `; `/bin/sync `; } ##刪除多餘備份檔作業 while (($key, $value)=each %BB) { $num=`/bin/ls $BAK$key* | /usr/bin/wc -l`; ## perl用chomp函數去掉結尾的CR/LF chomp $num; if ($num > $lim) { $delnum=$num-$lim; @dfiles=`/bin/ls $BAK$key* `; $i=0; while ($i < $delnum) { chomp $dfiles[$i]; unlink $dfiles[$i] if -e $dfiles[$i]; $i++; } } } } ##-----5.送檔案到ftp主機(只送本次)-----------##### if (($conf{'ftp'} eq 'Y') && ($conf{'bakup'} eq 'Y' ) ){ while (($key, $value)=each %BB) { $fi=$BAK.$key."_".$TT.".tgz"; `/usr/bin/ncftpput -u $ftp{user} -p $ftp{pass} $ftp{host} $ftp{path} $fi `; } } ##-----6.更新學籍系統-----------##### if ($conf{'upsfs'} eq 'Y'){ `cd /tmp;/usr/bin/wget -q $conf{'url'} `; `/bin/sync `; `/bin/sync `; # 判斷檔案是否存在 if (-e '/tmp/sfs_stable.tar.gz' ) { `cd /tmp;/bin/tar zxf sfs_stable.tar.gz`; `/bin/rm /tmp/setup.sh`; `/bin/rm /tmp/sfs3_stable/install.php`; `/bin/cp -a /tmp/sfs3_stable/* $conf{'sfspath'} `; `/bin/rm /tmp/sfs_stable.tar.gz`; `/bin/rm -rf /tmp/sfs3_stable`; `/bin/sync `; `/bin/sync `; } } ##-----7.更新系統檔案-----------##### if ($conf{'upSYS'} eq 'Y'){ `/usr/bin/apt-get update > /dev/null `; `/usr/bin/apt-get -y upgrade > /dev/null `; ## `/usr/bin/apt-get -y dist-upgrade > /dev/null `; `/usr/bin/apt-get autoclean > /dev/null `; `/bin/sync `; `/bin/sync `; } ##-----8.啟動apache及 MySQL-----------##### `/etc/init.d/apache2 start `; `/etc/init.d/mysql start `; # `/etc/init.d/firewall start`;
2010年12月30日 星期四
縣內備份程式
手動備份學籍資料
------------------------------------
/etc/init.d/firewall stop
/etc/init.d/apache2 stop
/etc/init.d/mysql stop
cd /home/webadmin/html/sfs3
tar zcvf /home/webadmin/html.tgz data
cd /var/lib/mysql/
tar zcvf /home/webadmin/mysql.tgz sfs3
---------------------
cd /usr/bin/
ncftp -u 使用者 -p 密碼 163.23.115.
put /home/webadmin/html.tgz
put /home/webadmin/mysql.tgz
cd /home/webadmin/
rm html.tgz
rm mysql.tgz
/etc/init.d/apache2 start
/etc/init.d/mysql start
/etc/init.d/firewall start
--------------------------------------
/etc/init.d/firewall stop
/etc/init.d/apache2 stop
/etc/init.d/mysql stop
cd /home/webadmin/html/sfs3
tar zcvf /home/webadmin/html.tgz data
cd /var/lib/mysql/
tar zcvf /home/webadmin/mysql.tgz sfs3
---------------------
cd /usr/bin/
ncftp -u 使用者 -p 密碼 163.23.115.
put /home/webadmin/html.tgz
put /home/webadmin/mysql.tgz
cd /home/webadmin/
rm html.tgz
rm mysql.tgz
/etc/init.d/apache2 start
/etc/init.d/mysql start
/etc/init.d/firewall start
--------------------------------------
2010年12月29日 星期三
Could not reliably determine the server's fully qualified domain name
Could not reliably determine the server's fully qualified domain name 問題
vi /etc/apache2/apache2.conf
ServerName 127.0.0.1
sudo /etc/init.d/apache2 restart
第一次手動
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo dpkg-reconfigure -a
vi /etc/apache2/apache2.conf
ServerName 127.0.0.1
sudo /etc/init.d/apache2 restart
第一次手動
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo dpkg-reconfigure -a
2010年12月28日 星期二
備份學籍
cd /bin/
./ACFSsfsBK.txt
./upsfs
./upSYS
□將另一部電腦的資料填入
$ftp{'host'}='192.168.1.4';##遠方主機
$ftp{'path'}='BB/';##登入後檔案放置目錄
$ftp{'user'}='edu';##遠方主機帳號
$ftp{'pass'}='stu123';##遠方主機密碼
將要定時服務功能的參數改為Y,並設定備份檔最大數量
$conf{'chktime'}='Y';##要不要進行校時
$conf{'bakup'}='Y';##要不要備份某些目錄, 設定值 Y/N
$conf{'ftp'}='Y';##要不要透過ftp將資料送到遠方主機 設定值 Y/N
$conf{'upsfs'}='Y';##要不要更新學藉系統, 設定值 Y/N
$conf{'upSYS'}='Y';##要不要更新系統, 設定值 Y/N
./ACFSsfsBK.txt
./upsfs
./upSYS
□將另一部電腦的資料填入
$ftp{'host'}='192.168.1.4';##遠方主機
$ftp{'path'}='BB/';##登入後檔案放置目錄
$ftp{'user'}='edu';##遠方主機帳號
$ftp{'pass'}='stu123';##遠方主機密碼
將要定時服務功能的參數改為Y,並設定備份檔最大數量
$conf{'chktime'}='Y';##要不要進行校時
$conf{'bakup'}='Y';##要不要備份某些目錄, 設定值 Y/N
$conf{'ftp'}='Y';##要不要透過ftp將資料送到遠方主機 設定值 Y/N
$conf{'upsfs'}='Y';##要不要更新學藉系統, 設定值 Y/N
$conf{'upSYS'}='Y';##要不要更新系統, 設定值 Y/N
學籍設定檔
sfs3/include/config.php
檢查密碼與mysql是否一致
/var/www/html/sfs3 要改為=>/var/www/sfs3
/var/www/html/sfs3/data/==>/var/www/sfs3/data/
Debain/Ubuntu 網頁根目錄在/var/www/
Redhat/MDK/CentOS 網頁根目錄在/var/www/html
檢查密碼與mysql是否一致
/var/www/html/sfs3 要改為=>/var/www/sfs3
/var/www/html/sfs3/data/==>/var/www/sfs3/data/
Debain/Ubuntu 網頁根目錄在/var/www/
Redhat/MDK/CentOS 網頁根目錄在/var/www/html
2010年12月23日 星期四
能量倍增(抬腳)
一、在抬腳時前、後需各喝300西西溫開水,心平氣和保持輕鬆,自然呼吸、不可憋氣,靠腰力及丹田氣力來支撐身體下半部所受之酸。使身體與大腿成九十度、大腿與小腿成九十度。支撐至少十五分鐘以上。
二、在抬腳時血液會迅速流回肝、腎,給予重新解毒排毒,此時新陳代謝增加,腰部以下會有強烈極酸的反應,為了排解瞬間增加毒素,人體腦下垂體自會分泌激素,激發潛能,加強排毒,最後在流汗中,將毒素予以排出。
三、在抬腳時可引濁氣下行排出,升清降濁正氣倍增,體內正常細胞大曾活躍,癌細胞自然死亡。
四、在抬腳時神闕(肚臍)及命門同運氣,打通任督氣血暢行無阻,毛細孔擴張,增加皮膚呼吸及代謝作用,因丹田訓練呼吸,減少肺部負擔胸腔之濁氣自可順利排出,解決心胸之鬱悶、心胸開朗氣沉丹田、心臟恢復正常功能,心理壓大降低、血壓隨之穩定。
五、在抬腳時因流汗,自可將體內酸性毒素排出,血脂肪自然燃燒。脾主四肢,所以血糖可以穩定,改善脾的功能,人的性情自然溫順和譪可親。
六、在抬腳時,大小腸自然會蠕動,膀胱更有力,男女生理功能更是增強奏效,何來秘便、月事不順、攝護腺腫大等失調症。胃腸消化、排便正常,何來肥瘦不均,胃口不開呢?
七、在抬腳時,脊椎保持水平,全身肌肉富有彈性,氣血順暢,各關節自會增生骨髓,脊椎兩旁神經恢復平常傳導作用,何來關節退化,或長骨刺的名稱,壓迫神經的病痛呢?
八、在抬腳時,因內臟全身運作,腦內革命,心理生理調適正常,何來睡眠障礙症。頭腦清醒、智慧、記憶力當然會增加,這是真善美的表現。激發意志力及吃苦耐力,方能突破酸的痛楚、障礙,達到流汗的過程,發揮抬腳的最終目:抬的愈久,活的愈久。
二、在抬腳時血液會迅速流回肝、腎,給予重新解毒排毒,此時新陳代謝增加,腰部以下會有強烈極酸的反應,為了排解瞬間增加毒素,人體腦下垂體自會分泌激素,激發潛能,加強排毒,最後在流汗中,將毒素予以排出。
三、在抬腳時可引濁氣下行排出,升清降濁正氣倍增,體內正常細胞大曾活躍,癌細胞自然死亡。
四、在抬腳時神闕(肚臍)及命門同運氣,打通任督氣血暢行無阻,毛細孔擴張,增加皮膚呼吸及代謝作用,因丹田訓練呼吸,減少肺部負擔胸腔之濁氣自可順利排出,解決心胸之鬱悶、心胸開朗氣沉丹田、心臟恢復正常功能,心理壓大降低、血壓隨之穩定。
五、在抬腳時因流汗,自可將體內酸性毒素排出,血脂肪自然燃燒。脾主四肢,所以血糖可以穩定,改善脾的功能,人的性情自然溫順和譪可親。
六、在抬腳時,大小腸自然會蠕動,膀胱更有力,男女生理功能更是增強奏效,何來秘便、月事不順、攝護腺腫大等失調症。胃腸消化、排便正常,何來肥瘦不均,胃口不開呢?
七、在抬腳時,脊椎保持水平,全身肌肉富有彈性,氣血順暢,各關節自會增生骨髓,脊椎兩旁神經恢復平常傳導作用,何來關節退化,或長骨刺的名稱,壓迫神經的病痛呢?
八、在抬腳時,因內臟全身運作,腦內革命,心理生理調適正常,何來睡眠障礙症。頭腦清醒、智慧、記憶力當然會增加,這是真善美的表現。激發意志力及吃苦耐力,方能突破酸的痛楚、障礙,達到流汗的過程,發揮抬腳的最終目:抬的愈久,活的愈久。
2010年12月21日 星期二
freebasic顯示中文
#ifdef __FB_WIN32__
# define unicode
# include once "windows.bi"
#endif
const LANG = "Chinese"
dim helloworld as wstring * 20 => "你好,世界!"
print """Hello World!"" in "; LANG; ": "; helloworld
#ifdef __FB_WIN32__
messagebox( 0, helloworld, """Hello World!"" in " & LANG & ":", MB_OK )
#endif
# define unicode
# include once "windows.bi"
#endif
const LANG = "Chinese"
dim helloworld as wstring * 20 => "你好,世界!"
print """Hello World!"" in "; LANG; ": "; helloworld
#ifdef __FB_WIN32__
messagebox( 0, helloworld, """Hello World!"" in " & LANG & ":", MB_OK )
#endif
freebasic秀一張圖
事先準備一張p1.bmp圖檔
Screen 18, 32
Cls
BLoad "p1.bmp"
Sleep
秀一張48x48的圖
ScreenRes 320, 200, 32
Dim myImage As Any Ptr = ImageCreate( 48, 48 )
BLoad "48.bmp", myImage
Put (10,10), myImage
ImageDestroy( myImage )
Sleep
Screen 18, 32
Cls
BLoad "p1.bmp"
Sleep
秀一張48x48的圖
ScreenRes 320, 200, 32
Dim myImage As Any Ptr = ImageCreate( 48, 48 )
BLoad "48.bmp", myImage
Put (10,10), myImage
ImageDestroy( myImage )
Sleep
畫圓
' 設定 640x480 顯示模式, 256 colors
Screen 18
' 畫圓
Circle (320, 240), 200, 15
' 畫橢圓並填色
Circle (320, 240), 200, 2, , , 0.2, F
' 畫一個弧
Circle (320, 240), 200, 4, 0.83, 1.67, 3
Sleep
Screen 18
' 畫圓
Circle (320, 240), 200, 15
' 畫橢圓並填色
Circle (320, 240), 200, 2, , , 0.2, F
' 畫一個弧
Circle (320, 240), 200, 4, 0.83, 1.67, 3
Sleep
slax6.12-freebasic
slax 6 需要套件
glibc-solibs-2.9-i486-3.lzm
libfreebasic-0.18.2b-1-i386.lzm
freebasic-0.21.0-linux.lzm
glibc-solibs-2.9-i486-3.lzm
libfreebasic-0.18.2b-1-i386.lzm
freebasic-0.21.0-linux.lzm
2010年12月20日 星期一
pyinstaller
http://www.pyinstaller.org/
需要套件
build-essential
python-dev
終端機下指令
apt-get install build-essential python-dev
cd /usr/bin
mkdir pyinstaller
cd pyinstaller
cp /home/使用者/pyinstaller-1.4.tar.bz2 /usr/bin/pyinstaller
tar xvf pyinstaller-1.4.tar.bz2
cd pyinstaller-1.4
cd source/linux
python Make.py #[-n|-e]
make
成功的話會看到
support/load/run
support/load/run_d
cd /usr/bin/pyinstaller/pyinstaller-1.4/
./Configure.py
成功建立 config.dat
mkdir test
cd test
vi test.py
print"cat3"
存檔
cd ..
python Makespec.py test/test.py
產生出一個 test.spec 的檔案
python Build.py test/test.spec
就可以建立出一個執行檔
位置在/build/pyi.linux2/test/
測試一下
./test
需要套件
build-essential
python-dev
終端機下指令
apt-get install build-essential python-dev
cd /usr/bin
mkdir pyinstaller
cd pyinstaller
cp /home/使用者/pyinstaller-1.4.tar.bz2 /usr/bin/pyinstaller
tar xvf pyinstaller-1.4.tar.bz2
cd pyinstaller-1.4
cd source/linux
python Make.py #[-n|-e]
make
成功的話會看到
support/load/run
support/load/run_d
cd /usr/bin/pyinstaller/pyinstaller-1.4/
./Configure.py
成功建立 config.dat
mkdir test
cd test
vi test.py
print"cat3"
存檔
cd ..
python Makespec.py test/test.py
產生出一個 test.spec 的檔案
python Build.py test/test.spec
就可以建立出一個執行檔
位置在/build/pyi.linux2/test/
測試一下
./test
2010年12月19日 星期日
現在時間
import Tkinter
import time
curtime = ''
clock = Tkinter.Label()
clock.pack()
def tick():
global curtime
newtime = time.strftime('%H:%M:%S')
if newtime != curtime:
curtime = newtime
clock.config(text=curtime)
clock.after(200, tick)
tick()
clock.mainloop()
import time
curtime = ''
clock = Tkinter.Label()
clock.pack()
def tick():
global curtime
newtime = time.strftime('%H:%M:%S')
if newtime != curtime:
curtime = newtime
clock.config(text=curtime)
clock.after(200, tick)
tick()
clock.mainloop()
滑鼠畫圓2
from Tkinter import *
class PaintBox( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "A simple paint program" )
self.master.geometry( "300x150" )
self.message = Label( self, text = "Drag the mouse to draw" )
self.message.pack( side = BOTTOM )
# create Canvas component
self.myCanvas = Canvas( self )
self.myCanvas.pack( expand = YES, fill = BOTH )
# bind mouse dragging event to Canvas
self.myCanvas.bind( "<B1-Motion>", self.paint )
def paint( self, event ):
x1, y1 = ( event.x - 4 ), ( event.y - 4 )
x2, y2 = ( event.x + 4 ), ( event.y + 4 )
self.myCanvas.create_oval( x1, y1, x2, y2, fill = "red" )
def main():
PaintBox().mainloop()
if __name__ == "__main__":
main()
class PaintBox( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "A simple paint program" )
self.master.geometry( "300x150" )
self.message = Label( self, text = "Drag the mouse to draw" )
self.message.pack( side = BOTTOM )
# create Canvas component
self.myCanvas = Canvas( self )
self.myCanvas.pack( expand = YES, fill = BOTH )
# bind mouse dragging event to Canvas
self.myCanvas.bind( "<B1-Motion>", self.paint )
def paint( self, event ):
x1, y1 = ( event.x - 4 ), ( event.y - 4 )
x2, y2 = ( event.x + 4 ), ( event.y + 4 )
self.myCanvas.create_oval( x1, y1, x2, y2, fill = "red" )
def main():
PaintBox().mainloop()
if __name__ == "__main__":
main()
滑鼠畫圓
from Tkinter import *
trace = 0
class CanvasEventsDemo:
def __init__(self, parent=None):
canvas = Canvas(width=300, height=300, bg='beige')
canvas.pack()
canvas.bind('<ButtonPress-1>', self.onStart)
canvas.bind('<B1-Motion>', self.onGrow)
canvas.bind('<Double-1>', self.onClear)
canvas.bind('<ButtonPress-3>', self.onMove)
self.canvas = canvas
self.drawn = None
self.kinds = [canvas.create_oval, canvas.create_rectangle]
def onStart(self, event):
self.shape = self.kinds[0]
self.kinds = self.kinds[1:] + self.kinds[:1]
self.start = event
self.drawn = None
def onGrow(self, event):
canvas = event.widget
if self.drawn: canvas.delete(self.drawn)
objectId = self.shape(self.start.x, self.start.y, event.x, event.y)
if trace: print objectId
self.drawn = objectId
def onClear(self, event):
event.widget.delete('all')
def onMove(self, event):
if self.drawn:
if trace: print self.drawn
canvas = event.widget
diffX, diffY = (event.x - self.start.x), (event.y - self.start.y)
canvas.move(self.drawn, diffX, diffY)
self.start = event
if __name__ == '__main__':
CanvasEventsDemo()
mainloop()
trace = 0
class CanvasEventsDemo:
def __init__(self, parent=None):
canvas = Canvas(width=300, height=300, bg='beige')
canvas.pack()
canvas.bind('<ButtonPress-1>', self.onStart)
canvas.bind('<B1-Motion>', self.onGrow)
canvas.bind('<Double-1>', self.onClear)
canvas.bind('<ButtonPress-3>', self.onMove)
self.canvas = canvas
self.drawn = None
self.kinds = [canvas.create_oval, canvas.create_rectangle]
def onStart(self, event):
self.shape = self.kinds[0]
self.kinds = self.kinds[1:] + self.kinds[:1]
self.start = event
self.drawn = None
def onGrow(self, event):
canvas = event.widget
if self.drawn: canvas.delete(self.drawn)
objectId = self.shape(self.start.x, self.start.y, event.x, event.y)
if trace: print objectId
self.drawn = objectId
def onClear(self, event):
event.widget.delete('all')
def onMove(self, event):
if self.drawn:
if trace: print self.drawn
canvas = event.widget
diffX, diffY = (event.x - self.start.x), (event.y - self.start.y)
canvas.move(self.drawn, diffX, diffY)
self.start = event
if __name__ == '__main__':
CanvasEventsDemo()
mainloop()
功能鍵
from Tkinter import *
def displayHelp(event):
print 'hlp', event.keysym
def sayKey(event):
print 'say',event.keysym, event.char
def printWindow(event):
print 'prt', event.keysym
def cursor(*args):
print 'cursor'
def unbindThem(*args):
print 'Gone...'
root.unbind_all('<F1>')
root.unbind_class('Entry', '<KeyPress>')
root.unbind('<Alt_L>')
root.unbind('<Control-Shift-Down>')
root = Tk()
frame = Frame(root, takefocus=1, highlightthickness=2)
text = Entry(frame, width=10, takefocus=1, highlightthickness=2)
root.bind_all('<F1>', displayHelp)
text.bind_class('Entry', '<KeyPress>', lambda e: sayKey(e))
root.bind('<Alt_L>', printWindow)
frame.bind('<Control-Shift-Down>' , cursor)
text.bind('<Control-Shift-Up>', unbindThem)
text.pack()
frame.pack()
text.focus_set()
root.mainloop()
def displayHelp(event):
print 'hlp', event.keysym
def sayKey(event):
print 'say',event.keysym, event.char
def printWindow(event):
print 'prt', event.keysym
def cursor(*args):
print 'cursor'
def unbindThem(*args):
print 'Gone...'
root.unbind_all('<F1>')
root.unbind_class('Entry', '<KeyPress>')
root.unbind('<Alt_L>')
root.unbind('<Control-Shift-Down>')
root = Tk()
frame = Frame(root, takefocus=1, highlightthickness=2)
text = Entry(frame, width=10, takefocus=1, highlightthickness=2)
root.bind_all('<F1>', displayHelp)
text.bind_class('Entry', '<KeyPress>', lambda e: sayKey(e))
root.bind('<Alt_L>', printWindow)
frame.bind('<Control-Shift-Down>' , cursor)
text.bind('<Control-Shift-Up>', unbindThem)
text.pack()
frame.pack()
text.focus_set()
root.mainloop()
文字輸入 Entry
import Tkinter
root = Tkinter.Tk()
tv = Tkinter.StringVar()
Tkinter.Label(textvariable=tv).pack()
Tkinter.Entry(textvariable=tv).pack()
tv.set('')
Tkinter.Button(text="Exit", command=root.quit).pack()
Tkinter.mainloop()
print tv.get()
root = Tkinter.Tk()
tv = Tkinter.StringVar()
Tkinter.Label(textvariable=tv).pack()
Tkinter.Entry(textvariable=tv).pack()
tv.set('')
Tkinter.Button(text="Exit", command=root.quit).pack()
Tkinter.mainloop()
print tv.get()
key released
from Tkinter import *
class KeyDemo( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Keystroke Events" )
self.master.geometry( "350x50" )
self.message1 = StringVar()
self.line1 = Label( self, textvariable = self.message1 )
self.message1.set( "Type any key or shift" )
self.line1.pack()
self.message2 = StringVar()
self.line2 = Label( self, textvariable = self.message2 )
self.message2.set( "" )
self.line2.pack()
self.master.bind( "<KeyRelease>", self.keyReleased )
def keyReleased( self, event ):
self.message1.set( "Key released: " + event.char )
self.message2.set( "This key is not left shift" )
def main():
KeyDemo().mainloop()
if __name__ == "__main__":
main()
class KeyDemo( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Keystroke Events" )
self.master.geometry( "350x50" )
self.message1 = StringVar()
self.line1 = Label( self, textvariable = self.message1 )
self.message1.set( "Type any key or shift" )
self.line1.pack()
self.message2 = StringVar()
self.line2 = Label( self, textvariable = self.message2 )
self.message2.set( "" )
self.line2.pack()
self.master.bind( "<KeyRelease>", self.keyReleased )
def keyReleased( self, event ):
self.message1.set( "Key released: " + event.char )
self.message2.set( "This key is not left shift" )
def main():
KeyDemo().mainloop()
if __name__ == "__main__":
main()
key pressed
from Tkinter import *
class KeyDemo( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Keystroke Events" )
self.master.geometry( "350x50" )
self.message1 = StringVar()
self.line1 = Label( self, textvariable = self.message1 )
self.message1.set( "Type any key or shift" )
self.line1.pack()
self.message2 = StringVar()
self.line2 = Label( self, textvariable = self.message2 )
self.message2.set( "" )
self.line2.pack()
self.master.bind( "<KeyPress>", self.keyPressed )
def keyPressed( self, event ):
self.message1.set( "Key pressed: " + event.char )
self.message2.set( "This key is not left shift" )
def main():
KeyDemo().mainloop()
if __name__ == "__main__":
main()
class KeyDemo( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Keystroke Events" )
self.master.geometry( "350x50" )
self.message1 = StringVar()
self.line1 = Label( self, textvariable = self.message1 )
self.message1.set( "Type any key or shift" )
self.line1.pack()
self.message2 = StringVar()
self.line2 = Label( self, textvariable = self.message2 )
self.message2.set( "" )
self.line2.pack()
self.master.bind( "<KeyPress>", self.keyPressed )
def keyPressed( self, event ):
self.message1.set( "Key pressed: " + event.char )
self.message2.set( "This key is not left shift" )
def main():
KeyDemo().mainloop()
if __name__ == "__main__":
main()
秀Gif 圖
from Tkinter import *
root = Tk()
root.title('Canvas')
canvas = Canvas(root, width =400, height=400)
img = PhotoImage(file='1.gif')
canvas.create_image(150,120, image=img, anchor=CENTER)
canvas.pack()
root.mainloop()
root = Tk()
root.title('Canvas')
canvas = Canvas(root, width =400, height=400)
img = PhotoImage(file='1.gif')
canvas.create_image(150,120, image=img, anchor=CENTER)
canvas.pack()
root.mainloop()
test1
import pygame, sys,os
from pygame.locals import *
pygame.init()
window = pygame.display.set_mode((468, 60))
pygame.display.set_caption('Monkey Fever')
screen = pygame.display.get_surface()
monkey_head_file_name = os.path.join("data","chimp.bmp")
monkey_surface = pygame.image.load(monkey_head_file_name)
screen.blit(monkey_surface, (0,0))
pygame.display.flip()
def input(events):
for event in events:
if event.type == QUIT:
sys.exit(0)
else:
print event
while True:
input(pygame.event.get())
from pygame.locals import *
pygame.init()
window = pygame.display.set_mode((468, 60))
pygame.display.set_caption('Monkey Fever')
screen = pygame.display.get_surface()
monkey_head_file_name = os.path.join("data","chimp.bmp")
monkey_surface = pygame.image.load(monkey_head_file_name)
screen.blit(monkey_surface, (0,0))
pygame.display.flip()
def input(events):
for event in events:
if event.type == QUIT:
sys.exit(0)
else:
print event
while True:
input(pygame.event.get())
陣列
b[4:] 第四個陣列值到最後
b[:4] 第四個之前的陣列值
b[4:6] 第4個到第6個
b[-1] 最後一個
b[1:-1] 去除首尾
(1,2)+(3,4)
>>(1,2,3,4)
(1,2)*2
>>(1,2,1,2)
b[:4] 第四個之前的陣列值
b[4:6] 第4個到第6個
b[-1] 最後一個
b[1:-1] 去除首尾
(1,2)+(3,4)
>>(1,2,3,4)
(1,2)*2
>>(1,2,1,2)
pil秀圖
會以內建的秀圖軟體秀出圖片
import Image
im = Image.open("1.jpg")
im.show()
#im.rotate(45).show() #旋轉45度
----------------------------
開啟模式
‧1 (1-bit pixels, black and white, stored with one pixel per byte)
‧L (8-bit pixels, black and white)
‧P (8-bit pixels, mapped to any other mode using a colour palette)
‧RGB (3x8-bit pixels, true colour)
‧RGBA (4x8-bit pixels, true colour with transparency mask)
‧CMYK (4x8-bit pixels, colour separation)
‧YCbCr (3x8-bit pixels, colour video format)
‧I (32-bit signed integer pixels)
‧F (32-bit floating point pixels)
---------------------------------
import Image
im = Image.open("1.jpg")
im.show()
#im.rotate(45).show() #旋轉45度
----------------------------
開啟模式
‧1 (1-bit pixels, black and white, stored with one pixel per byte)
‧L (8-bit pixels, black and white)
‧P (8-bit pixels, mapped to any other mode using a colour palette)
‧RGB (3x8-bit pixels, true colour)
‧RGBA (4x8-bit pixels, true colour with transparency mask)
‧CMYK (4x8-bit pixels, colour separation)
‧YCbCr (3x8-bit pixels, colour video format)
‧I (32-bit signed integer pixels)
‧F (32-bit floating point pixels)
---------------------------------
重要套件
*PIL - Python Imaging Library,圖形處理專用函式
* Numpy - 多元陣列、基本線性代數、基本傅立葉轉換等函式
*PyOpenGL - 在Python使用OpenGL的API來繪圖
* PyInstaller - 把你的程式碼針對Windows、Linux、Mac OS X,包裝為一個獨立執行檔
* cz_Freeze - 把你的程式碼針對Windows、Linux,包裝為一個獨立執行檔
*py2exe - 把你的程式碼打包為一個win32的執行檔
* Numpy - 多元陣列、基本線性代數、基本傅立葉轉換等函式
*PyOpenGL - 在Python使用OpenGL的API來繪圖
* PyInstaller - 把你的程式碼針對Windows、Linux、Mac OS X,包裝為一個獨立執行檔
* cz_Freeze - 把你的程式碼針對Windows、Linux,包裝為一個獨立執行檔
*py2exe - 把你的程式碼打包為一個win32的執行檔
Python Image Library
Python Image Library
好用的圖形函式庫
# 支援格式 JPEG, PNG, BMP, GIF, TIFF。
# 基本的影像處理:裁切、平移、旋轉、改變尺寸、調置 (transpose)、剪下與貼上。
# 強化圖形:亮度、色調、對比、銳利度。
# 色彩處理。
# 濾鏡 (filter):濾鏡可以用在 Python 程式裡面,提供批次化處理的能力。
# PIL 可以在影像中繪圖製點、線、面、幾何形狀、填滿、文字。
-------------------------------------------
轉檔練習 jpg轉png
from glob import glob
from os.path import splitext
import Image
jpglist = glob( "python_imaging_pix/*.[jJ][pP][gG]" )
for jpg in jpglist:
im = Image.open(jpg)
png = splitext(jpg)[0]+".png"
im.save(png)
print png
好用的圖形函式庫
# 支援格式 JPEG, PNG, BMP, GIF, TIFF。
# 基本的影像處理:裁切、平移、旋轉、改變尺寸、調置 (transpose)、剪下與貼上。
# 強化圖形:亮度、色調、對比、銳利度。
# 色彩處理。
# 濾鏡 (filter):濾鏡可以用在 Python 程式裡面,提供批次化處理的能力。
# PIL 可以在影像中繪圖製點、線、面、幾何形狀、填滿、文字。
-------------------------------------------
轉檔練習 jpg轉png
from glob import glob
from os.path import splitext
import Image
jpglist = glob( "python_imaging_pix/*.[jJ][pP][gG]" )
for jpg in jpglist:
im = Image.open(jpg)
png = splitext(jpg)[0]+".png"
im.save(png)
print png
2010年12月18日 星期六
wxpython框架
frame.Show(False) # 使框架隱藏
frame.Show(True) # True是默認值,使框架可見.
frame.Hide() # 等同於frame.Show(False)
frame.Show(True) # True是默認值,使框架可見.
frame.Hide() # 等同於frame.Show(False)
中文顯示
chinese = u"中文!"
print chinese
--------------------------------------------------------
加入 wxpython 的練習,建立一個中文標題視窗
-------------------------------------------------------
mytitle = u"練習"
import wx # 導入wxPython
class App(wx.App):#子類化wxPython
def OnInit(self): #定義一個應用程序的初始化方法
frame = wx.Frame(parent=None, title=mytitle)
frame.Show()
return True
app = App() #創建一個應用程序類的實例
app.MainLoop() #進入這個應用程序的主事件循環
-------------------------------------
讀取utf8檔案
------------------------------------------
import codecs
fileObj = codecs.open( "someFile", "r", "utf-8" )
u = fileObj.read() # Returns a Unicode string from the UTF-8 bytes in the file
-------------------------------------------------------------
以萬用碼Unicode編寫python
special comment in the first or second lines of your script:
print chinese
--------------------------------------------------------
加入 wxpython 的練習,建立一個中文標題視窗
-------------------------------------------------------
mytitle = u"練習"
import wx # 導入wxPython
class App(wx.App):#子類化wxPython
def OnInit(self): #定義一個應用程序的初始化方法
frame = wx.Frame(parent=None, title=mytitle)
frame.Show()
return True
app = App() #創建一個應用程序類的實例
app.MainLoop() #進入這個應用程序的主事件循環
-------------------------------------
讀取utf8檔案
------------------------------------------
import codecs
fileObj = codecs.open( "someFile", "r", "utf-8" )
u = fileObj.read() # Returns a Unicode string from the UTF-8 bytes in the file
-------------------------------------------------------------
以萬用碼Unicode編寫python
special comment in the first or second lines of your script:
# -*- coding: utf-8 -*-
2010年12月16日 星期四
helloworld.py
import sys from PyQt4.QtGui import * app = QApplication(sys.argv) button = QPushButton("Hello World", None) button.show() app.exec_() 執行 python helloworld.py
test1
#include
#include
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton hello("Hello world!");
hello.show();
return app.exec();
}
然後依序執行以下指令,Makefile會自動產生
$ qmake -project
$ qmake
$ make
編譯完成
#include
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton hello("Hello world!");
hello.show();
return app.exec();
}
然後依序執行以下指令,Makefile會自動產生
$ qmake -project
$ qmake
$ make
編譯完成
PyQt4
Ubuntu 10.04
安裝Qt4
$ sudo apt-get install libqt4-dev libqt4-dbg libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig
安裝PyQt4
$ sudo apt-get install "python-qt4-*"
PyQt4範例
/usr/share/doc/python-qt4-doc/examples
安裝Qt4
$ sudo apt-get install libqt4-dev libqt4-dbg libqt4-gui libqt4-sql qt4-dev-tools qt4-doc qt4-designer qt4-qtconfig
安裝PyQt4
$ sudo apt-get install "python-qt4-*"
PyQt4範例
/usr/share/doc/python-qt4-doc/examples
Qt+KDevelop
http://www.kdevelop.org/
KDevelop採用用GPL,支援許多語言如:C/C++,
Ada, Java, Pascal, Fortran, PHP, Perl, Shell, Python, Ruby,
SQL等
Qt Designer是一個強大GUI界面開發工具
安裝
# tar zvxf qt-x11-opensource-src-4.1.0.tar.gz
# cd qt-x11-opensource-src-4.1.0
# ./configure
# make
# make install
設置KDEDIR和QTDIR兩個環境變數,
以及PATH變數
KDE的頭文件在/usr/include/kde
Qt的頭文件和API在/usr/lib/qt-3.3
設置環境變數
# export KDEDIR=/usr/include/kde
# export QTDIR=/usr/lib/qt-3.3
# export PATH=$QTDIR/bin:$KDEDIR/bin:$PATH
# export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
也可將上述指令寫入.bashrc 文件中
KDevelop採用用GPL,支援許多語言如:C/C++,
Ada, Java, Pascal, Fortran, PHP, Perl, Shell, Python, Ruby,
SQL等
Qt Designer是一個強大GUI界面開發工具
安裝
# tar zvxf qt-x11-opensource-src-4.1.0.tar.gz
# cd qt-x11-opensource-src-4.1.0
# ./configure
# make
# make install
設置KDEDIR和QTDIR兩個環境變數,
以及PATH變數
KDE的頭文件在/usr/include/kde
Qt的頭文件和API在/usr/lib/qt-3.3
設置環境變數
# export KDEDIR=/usr/include/kde
# export QTDIR=/usr/lib/qt-3.3
# export PATH=$QTDIR/bin:$KDEDIR/bin:$PATH
# export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
也可將上述指令寫入.bashrc 文件中
Ubuntu 10.04
Based on a clean Ubuntu 10.04, I could get FreeBASIC 0.21 to work with these packages:
32bit Ubuntu:
Quote:
libncurses5-dev
libx11-dev
libxext-dev
libxpm-dev
libxrandr-dev
libxrender-dev
libstdc++6-4.4-dev (only needed with the normal non-standalone FreeBASIC)
32bit Ubuntu:
Quote:
libncurses5-dev
libx11-dev
libxext-dev
libxpm-dev
libxrandr-dev
libxrender-dev
libstdc++6-4.4-dev (only needed with the normal non-standalone FreeBASIC)
訂閱:
文章 (Atom)