顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2013-05-26

[PyConTW 2013]懶人とPythonとAnimation Studio

下面是我在PyConTW 2013給talk的投影片內容:
懶人とPythonとAnimation Studio

本來是想說鍛練自己在大場面的演說能力,剛好看到PyConTW年會又要舉行了,於是就心血來潮,以工作上的經驗報個題目來試試,沒想到還真的得上台給talk XD

基本上相對於Django,AppEngine用很兇或是把Python Parser與VM玩弄於股掌之間的的高手而言,小弟還只是個小咖。如果這次talk有什麼不足之處,歡迎各方高手多給小弟建議 <(_ _)>

2010-11-10

[PyQt] Warning: correctly use openPersistentEditor() and closePersistentEditor() with entered() signal to keep editor opened

Sometimes we may use openPersistentEditor() and closePersistentEditor() to keep editor of delegate opened.
For example, when entered() signal is generated, we close old persistent editor and open new persistent editor to make real editor widget always locates on the cell that mouse is pointing on.

However, the QModelIndex instance from entered() signal will be destroyed after the slot connected to entered() is returned. If we call openPersistentEditor() with the QModelIndex instance from entered() signal, I found that call closePersistentEditor() with QModelIndex:
1. has same instance as what we used to call openPersistentEditor()
2. has another instance that contains same row, column, and parent as what we used to call openPersistentEditor()
will failed, both of them.

If we want to open persistent editor and close it later in slots that entered() signal is connecting, we should create new index with model.index(index.row(), index.column()).
(Caution: directly assign index.parent() to the 3rd argument of model.index() causes the same problem, parent index should be cloned, too.)

2010-08-17

[Tip]escape shell metacharacters

There is an efficient method to make arbitrary string to escape shell metacharacters while using single-quote('). That is, just suspend a string by ('), add(\'), then continue the string by (').

For example, in Python:
def escapeShellArg(string):
    return u"'"+string.replace(u"'",u"'\\''")+u"'"
This is because UNIX shell explain
testcmd 'test'\''string'
as
testcmd "test'string"
Besides, program testcmd will receive argv=["testcmd","test'string"]. Thus, we could efficiently escape shell metacharacters without regular expression library or other complex string processing library.