Sunday, September 12, 2010

My third Python book


Rapid GUI Programming with Python and QT: The Definitive Guide to PyQt Programming 

which is differed to prior two books that I bought, this book is brought to you that building GUI prototypes or full-fledged cross-platform GUI applications with native look-and-feel, PyQt 4 is your fastest, easiest, most powerful solution. So that's what I want. 

The examples are here.

Let's see Phil Thompson Talks About PyQt and PyQt in Wikipedia. 

Gotcha's: developing commercial software with PyQT vrs PySide

 

Tuesday, September 7, 2010

謝謝


人生的方向, 這問題太深奧; 很遙遠, 不好玩!
現在的生活, 很滿足; 但不要太奢求, 卻值得玩味一番.

小學可以有心儀欣賞的玩伴; 國中可以有愛慕的對象; 高中可以有真實發展的角色; 大學可以過得精彩繽紛的生活, 碩博士要得又是啥玩意? 還好這些我都不是!

這似乎早已不重要, 可不是!?

四十不惑之齡, 顯得格外分明! 不知何時開始, 生活不再祇是一個人的事, 往前努力活在當下的愉悅, 必須有妳才行!

努力往前邁向一個未知的領域, 並非催眠自己, 盲目追隨; 重在絕對相信自己的眼光!
開心可以有現在愉悅從容自在的生活態度, 環繞四周, 一片放牛班景象; 生處其中, 自當出淤泥而不染; 前人早已逝, 後人續重生.

相互扶持, 謹記莫貪瞋癡癲, 才能減少阻礙, 通往未來.

Monday, September 6, 2010

IndentationError: unindent does not match any outer indentation level


I got this err:
File "ru16.py", line 23
self.relay = Serial(port = port)
^
IndentationError: unindent does not match any outer indentation level

after I edited my python codes as following:

def __init__(self, port = '/dev/ttyUSB0', bps = 9600, timeout = 0.1):
"""Open serial port, set baud rate, timeout,
switch all relays off immediately"""
self.relay = Serial(port = port)
self.relay.xonxoff = False
self.relay.rtscts = False
self.relay.baudrate = bps
self.relay.timeout = timeout
self.relay.open()
self.allOff()

Later I found that it's because I've somehow mixed up tabs and spaces in my gedit editor. So if you met with this same err as mine. There might be spaces mixed in with your tabs. Try doing a search&replace to replace all tabs with a few spaces.

You could use:

python -m tabnanny yourfile.py

to check or instead you just set up your editor correctly.

Friday, September 3, 2010

Install eric4 IDE


For some reasons, I'd like to install eric4 IDE to have fun. After I downloaded install package, there's README.txt file shows that the following steps of installation must get them and install them in the following order (order is important). You'd better to follow installation guide from official site, here's just my references to recall while I was installing and learning. So you should always install them depends on your demands.
My environment is Ubuntu 10.04 LTS - the Lucid Lynx

1. Install Qt 4.6.2
1-1. Download http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.6.3.tar.gz, If you want to install this package, pls follow Qt on X11 Platforms
   After configure, it will show:

   Qt is now configured for building. Just run 'make'.
   Once everything is built, you must run 'make install'.
   Qt will be installed into /usr/local/Trolltech/Qt-4.6.3

   To reconfigure, run 'make confclean' and 'configure'.

 1-2. Download Qt 4.6.2
   The above 4.6.3 version didn't install successfully, so I used "Synaptic Package Manager" to install Qt 4.6.2.

2. Build and install SIP 4.11.1, to see installation
    
   ~/python configure.py

   This is SIP 4.11.1 for Python 2.6.5 on linux2.
   The SIP code generator will be installed in /usr/bin.
   The SIP module will be installed in /usr/lib/python2.6/dist-packages.
   The SIP header file will be installed in /usr/include/python2.6.
   The default directory to install .sip files in is /usr/share/sip.
   The platform/compiler configuration is linux-g++.
   Creating sipconfig.py...
   Creating top level Makefile...
   Creating sip code generator Makefile...
   Creating sip module Makefile...

   ~/make
   ~/sudo make install 

   make[1]: Entering directory `/home/adam/packages/sip-4.11.1/sipgen'
   cp -f sip /usr/bin/sip
   make[1]: Leaving directory `/home/adam/packages/sip-4.11.1/sipgen'
   make[1]: Entering directory `/home/adam/packages/sip-4.11.1/siplib'
   cp -f sip.so /usr/lib/python2.6/dist-packages/sip.so
   strip /usr/lib/python2.6/dist-packages/sip.so
   cp -f /home/adam/packages/sip-4.11.1/siplib/sip.h /usr/include/python2.6/sip.h
   make[1]: Leaving directory `/home/adam/packages/sip-4.11.1/siplib'
   cp -f sipconfig.py /usr/lib/python2.6/dist-packages/sipconfig.py
   cp -f /home/adam/packages/sip-4.11.1/sipdistutils.py /usr/lib/python2.6/dist-
   packages/sipdistutils.py


3. Build and install QScintilla2.4.5, see installation
    To build and install QScintilla, run:
   ~/cd Qt4
   ~/qmake qscintilla.pro
   ~/make
   ~/make install
4. Build and install PyQt4 PyQt-x11-gpl-4.7.6.tar.gz

    ~/python configure.py

    Determining the layout of your Qt installation...
    This is the GPL version of PyQt 4.7.6 (licensed under the GNU General Public
    License) for Python 2.6.5 on linux2.

    Type '2' to view the GPL v2 license.
    Type '3' to view the GPL v3 license.
    Type 'yes' to accept the terms of the license.
    Type 'no' to decline the terms of the license.

    Do you accept the terms of the license? yes
    Checking to see if the QtGui module should be built...
    Checking to see if the QtHelp module should be built...
    Checking to see if the QtMultimedia module should be built...
    Checking to see if the QtNetwork module should be built...
    Checking to see if the QtOpenGL module should be built...
    Checking to see if the QtScript module should be built...
    Checking to see if the QtScriptTools module should be built...
    Checking to see if the QtSql module should be built...
    Checking to see if the QtSvg module should be built...
    Checking to see if the QtTest module should be built...
    Checking to see if the QtWebKit module should be built...
    Checking to see if the QtXml module should be built...
    Checking to see if the QtXmlPatterns module should be built...
    Checking to see if the phonon module should be built...
    Checking to see if the QtAssistant module should be built...
    Checking to see if the QtDesigner module should be built...
    Checking to see if the dbus support module should be built...
    DBus v1 does not seem to be installed.
    Qt v4.6.2 free edition is being used.
    SIP 4.11.1 is being used.
    The Qt header files are in /usr/include/qt4.
    The shared Qt libraries are in /usr/lib.
    The Qt binaries are in /usr/bin.
    The Qt mkspecs directory is in /usr/share/qt4.
    These PyQt modules will be built: QtCore, QtGui, QtHelp, QtMultimedia,
    QtNetwork, QtOpenGL, QtScript, QtScriptTools, QtSql, QtSvg, QtTest, QtWebKit,
    QtXml, QtXmlPatterns, QtAssistant, QtDesigner.
    The PyQt Python package will be installed in /usr/lib/python2.6/dist-packages.
    PyQt is being built with generated docstrings.
    PyQt is being built with 'protected' redefined as 'public'.
    The Designer plugin will be installed in /usr/lib/qt4/plugins/designer.
    The QScintilla API file will be installed in /usr/share/qt4/qsci/api/python.
    The PyQt .sip files will be installed in /usr/share/sip/PyQt4.
    pyuic4, pyrcc4 and pylupdate4 will be installed in /usr/bin.
    Generating the C++ source for the QtCore module...
    Creating the Makefile for the QtCore module...
    Generating the C++ source for the QtGui module...
    Creating the Makefile for the QtGui module...
    Generating the C++ source for the QtHelp module...
    Creating the Makefile for the QtHelp module...
    Generating the C++ source for the QtMultimedia module...
    Creating the Makefile for the QtMultimedia module...
    Generating the C++ source for the QtNetwork module...
    Creating the Makefile for the QtNetwork module...
    Determining the OpenGL data types...
    Generating the C++ source for the QtOpenGL module...
    Creating the Makefile for the QtOpenGL module...
    Generating the C++ source for the QtScript module...
    Creating the Makefile for the QtScript module...
    Generating the C++ source for the QtScriptTools module...
    Creating the Makefile for the QtScriptTools module...
    Generating the C++ source for the QtSql module...
    Creating the Makefile for the QtSql module...
    Generating the C++ source for the QtSvg module...
    Creating the Makefile for the QtSvg module...
    Generating the C++ source for the QtTest module...
    Creating the Makefile for the QtTest module...
    Generating the C++ source for the QtWebKit module...
    Creating the Makefile for the QtWebKit module...
    Generating the C++ source for the QtXml module...
    Creating the Makefile for the QtXml module...
    Generating the C++ source for the QtXmlPatterns module...
    Creating the Makefile for the QtXmlPatterns module...
    Generating the C++ source for the QtAssistant module...
    Creating the Makefile for the QtAssistant module...
    Generating the C++ source for the QtDesigner module...
    Creating the Makefile for the QtDesigner module...
    Generating the C++ source for the Qt module...
    Creating the Makefile for the Qt module...
    Creating QScintilla API file...
    Creating top level Makefile...
    Creating QPy support library for QtCore Makefile...
    Creating QPy support library for QtGui Makefile...
    Creating QPy support library for QtDesigner Makefile...
    Creating QPy support libraries Makefile...
    Creating pyuic4 wrapper...
    Creating pyuic4 Makefile...
    Creating pylupdate4 Makefile...
    Creating pyrcc4 Makefile...
    Creating Qt Designer plugin Makefile...
    Creating pyqtconfig.py...
    ~/make
    ~/make install

 5. Build and install QScintilla2 Python bindings

    To build and install the Python bindings, run:
    ~/ cd Python
    ~/python configure.py
    QScintilla 2.4.5 is being used.
    PyQt 4.7.6 is being used.
    Qt v4.6.2 free edition is being used.
    SIP 4.11.1 is being used.
    The QScintilla module will be installed in
    /usr/lib/python2.6/dist-packages/PyQt4.
    The QScintilla API file will be installed in /usr/share/qt4/qsci/api/python.
    The QScintilla .sip files will be installed in /usr/share/sip/PyQt4.
    The QScintilla module is being built with generated docstrings.
    Generating the C++ source for the Qsci module...
    Creating the Makefile for the Qsci module... 
    ~/make
  ~/make install 

6. Download eric4-4.4.8.tar.gz and Install eric4
    but I've not installed successfully and got err below:

    ~/python install.py
    Checking dependencies
    Python Version: 2.6.5
    An internal error occured.  Please report all the output of the program,
    including the following traceback, to eric4-bugs@eric-ide.python-projects.org.

    Traceback (most recent call last):
    File "install.py", line 831, in 
    main(sys.argv)
    File "install.py", line 744, in main
    doDependancyChecks()
    File "install.py", line 516, in doDependancyChecks
    from PyQt4.QtCore import qVersion, PYQT_VERSION
    RuntimeError: the sip module implements API v8.0 but the PyQt4.QtCore       

    module  requires API v7.1

    so I sent an email to eric4-bugs@eric-ide.python-projects.org, then replies as below:

"You probably updated sip to a newer version. Once you do this, you must either
update PyQt4 as well or build it from your sources using the newer sip. After
you've done this, don't forget to rebuild the QScintilla Python bindings. The
issue is not related to eric in any way."


    I got this err since my PyQt version is 4.7.2, so I removed all my PyQt by "Synaptic Package Manager" and download a version 4.7.6 from PyQt4 PyQt-x11-gpl-4.7.6.tar.gz

    ~/sudo python install.py

    [sudo] password for adam:
    Checking dependencies
    Python Version: 2.6.5
    Found PyQt
    Found QScintilla2
    Qt Version: 4.6.2
    PyQt Version:  4.7.6
    QScintilla Version:  2.4.5
    All dependencies ok.

    Compiling user interface files...

    Compiling source files...

    Installing eric4 ...

    Installation complete.

ref.: 1, http://nxforce.blogspot.com/2010/07/pyqt.html
     2, http://lianix.blogspot.com/2009/12/pyqt-eric-windows.html
     3, http://fire01312.javaeye.com/blog/703339

Wednesday, September 1, 2010

Moonlight

I tried to install Moonlight in my Ubuntu 9.04, but it still can not work. Hopefully I can fix this later.

[轉載]博士是甚麼?


意外看到了這一標題, 它很清楚的表達了所謂的博士; 簡單明白, 有教育意涵; 但它卻最後提醒了各位別忘了你的來時路.

----------------------------------------------------

这篇来自美国犹他大学的助理教授Matt Might,原址在这里。汉化:阮一峰

译者注解:
美国犹他大学的助理教授Matt Might,用这组图解释,博士学位到底是什么意思。他说,每年都有新生的入学教育,但是有些观点语言说不清楚,不如画图。
我觉得,这组图真的很好懂,而且一点没错,博士就应该是图中的意思。老子说”大道至简”,可是真的要很简单地表达出来,却是非常难的一件事。