2007年12月28日 星期五
对字符集和编码的一些错误认识
- ISO-8859-1 .. ISO-8859-16 这些都是西欧各国用的字符集,主要的差别在与128-255之间各自代表的字符不同;
- 仍然不明白为啥GB2312, Big5这些就算MBCS,而同样采用多字节编码的Unicode却不算
- GBK应该是GB2312的超集,向下兼容GB2312的,记得以前谁跟我说不是,我迷惑了好一阵;
- 很 多编辑器说可以支持"Unicode编码",并且一些软件说"Unicode"就是两字节编码,这都是基于Unicode 4.0之前的认识。在那之前,Unicode跟GB2312这样的名称一样,即是字符集(charset)名称又是编码(encoding)名称, Unicode字符均是两个字节。但从Unicode 4.0开始,它已经不只65536个字符了,Unicode只是一个字符集名称,而UCS-2, UCS-4,UTF-8, UTF-16, UTF-32这些才是编码名称(当然,历史包袱总是存在的);
- UCS-2与UTF-16是不一样的,UCS-2固定采用两个字节,它不能表达Unicode 4.0之后增补的字符(当然,那些字符很生僻),而UTF-16里面每个字符可能是2或4个字符组成;
- UTF-8
- 从新的理论上而言,UTF-8应该是1-6个字符不等,但目前应该是1-3个字符就可以表达已有的字符了;
- UTF-8的优点
- 如果原有数据大都采用ASCII表达,那么这些数据不用转换
- 如果系统采用ASCII可以表达大多数数据,那么相对UCS-2,UTF-16这些节省空间;
- 编码中字符边界很容易找到:以0开头的字节肯定是ASCII字符,最高位以11开头的字节肯定是字符的开头字节,以10开头的字节肯定是字符的后续字节;
- 容错性强一些,偶尔一两个错误不会影响后面,原因同上(想咱们都碰到过GB2312/Big5的半个汉字问题带来的乱码问题吧)
- 按字节流读取,不用考虑大端(big endian)/小端(little endian)问题
- 字符串中不会出现0x00这样的字节(而UCS-2这些会),这样char *这样的方式表达缓冲区时不太容易导致错误
- UTF-8的缺点
- 对于非ASCII字符,相对以前存储空间增加了,比如非英语的西欧字符集现在都需要两个字节了,而中文等很多都需要三个字节了;
- 计算字符串长度比较麻烦,只能逐个统计;
- 综上,现在很多系统内部处理采用UCS-2,只在存储和数据交换中采用UTF-8
- Java以前内部全部采用Unicode(其实是UCS-2)来处理字符串,但Unicode 4.0以上的那些字符它不能处理。在Java 5.0中加入了一些奇怪的机制来解决这个问题;
- Python也不能同时支持UCS-2和UCS-4,只是可以在编译时挑选(--enable-unicode=ucs2和--enable-unicode=ucs4),看sys.maxunicode是否大于65535就知道是否是UCS-4了。我看Windows上的预编译版本是UCS-2(python2.5)的,而Linux上是UCS-4(Debian testing, python 2.4)。注意这两种版本在二进制上是不兼容的。
- Joel Spolsky: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
- 每一个软件开发人员绝对必须掌握的关于 Unicode 和字符集的最基础的知识(上文的简体翻译,居然木野狐翻译的,好久不见他了)
- 对字符编码与Unicode,ISO 10646,UCS,UTF8,UTF16,GBK,GB2312的理解
2007年12月20日 星期四
找不到python24_d.lib怎么办(VC上编译wxPython)
---------------------------------------
(下面是详细说明——我现在是越来越罗嗦了)
这几日在琢磨能不能直接采用wxPython搭建我们的下一版本的界面,各方面看都是我们要找的东西,除了一条: 如何将旧系统兼容进去(旧系统采用MFC+COM+Active Scripting技术搭建)。
于是我想先看看用MFC写的程序能不能集成wxPython,但google了半天没有任何信息,只好退而求其次查找wxWidgets上嵌入wxPython,倒是找到一个例子:
http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/samples/embedded/
它本来的Makefile是编译debug版的,这就需要python, wxWidgets和wxPython的debug版本动态库,好像网上对于Windows上都没有提供(不象Linux上还有python2.4-dbg, libwxgtk2.6-dbg可供安装),这就意味着必须完全自己来编译,编译时还有unicode,universal一大堆的选项,编译完了还有安装/配置的问题。
我烦了,就编译release版本吧,自己修改Makefile.vc,去掉了调试选项,编译出来了。但将embeded.exe放到wxPython的目录运行,它跟我报怨说版本不匹配,wxPython的是"debug,unicode,Visual C++....",而embeded.exe是"no debug,unicode,Visual C++..."。奇怪,怎么预编译的wxPython居然还是debug版本?
没办法,又回头来编译debug版本,但折腾了半天,最后碰到一个python24_d.lib过不去。看来非得自己编译python不可了。我不死心,又在网上搜了一阵,找到一个办法: 修改Python\include里面的python.h,把静态库都改成同一个,其它.h文件也搜索Py_DEBUG,将两种模式下的处理搞成一致(比如不采用不同的引用计数函数),然后就OK了。
2007年3月27日 星期二
我的学习方法,呵呵
16:25:00 菠萝油王子 says: 跑牛?
16:25:31 (F)深南大道走到黑 ~ .. says: 你稍微想想难道还不懂么
16:25:53 菠萝油王子 says: 没有,在翻以前泡妞的消息日志
16:26:04 (F)深南大道走到黑 ~ .. says: ....
16:26:20 菠萝油王子 says: 是MSN的 xml格式
16:26:34 菠萝油王子 says: 打算写个小脚本转换成html格式
16:26:46 (F)深南大道走到黑 ~ .. says: 你打算给我看么
16:27:04 菠萝油王子 says: 然后学习了一下python的xml.dom.minidom库的用法
16:27:34 (F)深南大道走到黑 ~ .. says: 你别逗我笑了
16:27:53 菠萝油王子 says: 发现整个库用起来相当麻烦,又到python网站上看哪些xml库比较有名/好用
16:28:11 菠萝油王子 says: 初步选定了elementtree/lxml
2006年9月11日 星期一
Python 2.4终于进入testing了
2006年2月11日 星期六
GUI程序的RAD和脚本化: 答案就是boa-constuctor?
还不太稳定 pythonwin debugger menu
于是拿出reshacker, 打开win32gui.pyd,将菜单资源修改了一下。
11128 MENU
POPUP "&Run"
{
MENUITEM "&Run...\tCtrl+R", 36864
}11130 MENU
POPUP "&Run"
{
MENUITEM "Chec&k\tCtrl+Shift+C", 36881
MENUITEM "&Run...\tCtrl+R", 36864
MENUITEM "&Import..\tCtrl+I", 36867
MENUITEM SEPARATOR
MENUITEM "&Go\tF5", 15022
MENUITEM "Step &in\tF11", 16013
MENUITEM "Step &out\tF10", 15020
MENUITEM "&Stop\tShift+F5", 16010
MENUITEM "Toggle Breakpoint\tF9", 16004
MENUITEM "Stop Debugging", 16010
MENUITEM SEPARATOR
MENUITEM "Watch List", 40002
MENUITEM "Stack View", 36888
MENUITEM "Breakpoint List", 36889
}
2006年1月31日 星期二
GUI程序的RAD和脚本化?
但UI怎么办呢? 当然是要求有一些常用控件的,而且有事件响应能力,脚本中也要求能够操纵这些UI元素。基于俺个人多年的爱好,最好是能够同时编辑UI和事件处理代码(我认为没有这个功能就不能叫RAD:-)。
比较理想的是像Excel/Word那样用VBA(该项目是在Windows上用MFC开发的),但似乎这方面的例子和文档都比较少,也拿不到VBA的试用版来评估一下。
从目前看到的一些东西来看,Windows下比较接近我们的需求的是Script Builder, 它是基于Delphi的,可以直接使用ActiveX或者Delphi编写的package,支持ActiveScript(也就是说可以使用 VBScript, JScript, Python和Perl了)和DelphiScript。如果我们自己的项目是用Delphi开发的,把这个集成进去应该是件很酷的事情。(这个东西实际 是基于以前见过的Dream Scripter,只是UI表现上做得更加接近了我们“用脚本写程序”的想法而已。)
再看一些其他的GUI toolkit吧:
- gtk有一个glade来编辑界面,然后我们可以在pygtk/python-glade或者gtk-perl/glade-perl来写响应代码,没法直接编辑界面代码(毕竟glade不是针对具体哪种语言的) P.S 刚刚在Planet Debian TW上看见yungyuc介绍一个新东东Gazpacho,说是"看起來是 Python+GTK 的 IDE",我还高兴了一阵,拉下来试试却发现只是一个改为完全用python写的一个glade而已。当然,我们可以以此为基础再来扩展。
- wxWidgets有个wxGlade, 是模仿Glade的,不用多说。
- Qt有Qt-Designer来编辑UI, 但这个东西也是跟glade差不多;同时它还有个Qt Script for Application,使得可以通过Qt Script(基于JavaScript)来操纵UI,不知道这两个东西是否可以接合,不过这已经很不错了。
- SpecTcl是一个tk的界面设计器,不过它可以直接生成脚本(tcl甚至perl, python, ruby)
- Java方面我用过JBuilder, 对于Borland的这种方式,用最近最红火的郭德纲的话说:“ 这个杭子,我做兴!”,简直" 要了亲命了"。只是因为java的烦琐,一个用JBuilder编写的略微复杂的界面,其创建UI部分的代码,基本上是不可手工维护的。至于Eclipse上UI设计器,还没玩过,不瞎说了。
说了这么些,有朋友会问,到底你们用的哪种?呵呵,记住我们的程序是用MFC写的,也没有买Qt这样的界面套件。最后我们用了用友华表的 Cell控件做模板来模拟UI,上面也可以放些按钮、下拉框什么的,虽然显得很不专业,但总算能对付过去。
想 想也知道为什么这种东西没有基于MFC的: 要在脚本中操纵UI控件(当然是说比较自然的方式,比如MainForm.Statubar1.SimpleText = "hello, world", 不是我见一些高手在tcl里面用c代码封装SendMessage来操纵的那种),这显然要求界面库有良好的RTTI,以便宿主程序能够很方便地将界面控 件对象加到脚本解释器当中去,否则脚本中怎么操纵它们。MFC有这些个嘛? ──除非完全自己手工来折腾。
补充:
1. 忘了gambas了,这个接近于Visual Basic,UI是用Qt写的。
2. mozilla的XUL应该是一个很不错的选择,而且传言很快将加入python支持,只是比较耗内存(似乎也没界面编辑器)。
标签: delphi, programming, python, script, ui
2005年11月8日 星期二
Python and XUL
在Daily Python-URL上看见的:
Sidnei da Silva: Python and XUL: The Screenshot [«Mark Hammond just shown me a screenshot of Python and XUL. That's right, Python used as scripting language on our most beloved browser to create XUL interfaces.»]
比较完整的说明在这里。上面说估计在Mozilla 1.9上可以看到这个东西。
2005年10月25日 星期二
gnochm: show me the icons
去年我把Inside the X网站上提供的所有The X Files的对白都弄了下来,然后打包成了一个CHM文件。
最近在重看《X档案》的主线部分,就是有关黑油、外星殖民、超级战士的,在Inside the X主页上有星号标记的。为了方便,当初我做CHM时也将目录树中的节点用了特殊的图标。
现在的问题是我在Debian上一边看碟,一边用gnochm看剧本,gnochm的目录树没有图标,从目录里面却根本看不出来哪些是阴谋论部分的。
毛主席说:自己动手,丰衣足食。于是又来改gnochm。本以为要加个图标会比较麻烦,没想到非常简单。效果如下,补丁已经提交给upstream.
2005年8月30日 星期二
XML module for Jython 2.2
Although I know that after Jim Hugunin left, the development of jython became very stagnant, I still checked Jython's homepage and found that Jython 2.2alpha1 were out quietly in last month.
But after upgrading, I found that the XML modules now even totally removed in this release!
Fortunately enough on the jython-user mailing list , someone had just asked the same question, and David Hume said that he had written an implementation of the xml.dom API which acts as a thin wrapper for the Java libraries, which could be downloaded from here. It works very, even with Chinese characters (even CPython < 2.4 doesn't handle this well).
2005年8月10日 星期三
Perl这种语言...
在/.cn上看见一则<全球编程语言流行程度列表>,让我没有想到的是Perl居然排第四,只居于Java, C和C++之后。
恰好两周以前公司里面我原来所在的部门跟BT(Britian Telecom, 可不是BitTorrent)有个项目是用Perl开发的,偌大一个部门居然没有人会,我以前的主管打电话给我让我过去支援两周。
对 于Perl 4我倒是比较熟悉,但对Perl 5以后的包、引用等的了解就少一点。考虑到很久没怎么用了(后来投身到Python去了),于是赶紧找了两本电子书(一本Advanced Perl Programming, 一本Perl Cookbook)来翻。由于我还是更喜欢纸做的书,周末还打算去书店淘两本,谁知道跑了两家大书店,两家小书店,都没有几本Perl的书(仅看见 O'Reilly的Learning Perl, 还有一本Perl for C++ Programmer, 好像还有一本CGI Programming with Perl)。china-pub和当当也没什么好的。记得以前还常常看到一些的啊,怎么...也怪不得他们没多少人会了。
回头说说Perl这门语言,这个东西约定的东西太多了,到处都是约定、特殊变量、特殊语法。举个例子,Advanced Perl Programming第一章讲引用(reference):
$s = \('a', 'b', 'c'); # WARNING: probably not what you think$s指向什么?指向('a', 'b', 'c')这样一个list么?嘿嘿,可不是:
As it happens, this is identical to
$s = ('a', 'b', 'c'); # List of references to scalarsAn enumerated list always yields the last element in a scalar context (as in C), which means that $s contains a reference to the constant string c.
用Perl写东西,有些时候写起来还挺顺,但调起来就够费劲的,而且先不多写点注释的话回头就看不懂了。至少后来很多小玩意儿改用Python来做就易写易读了。
--------BTW: 看见Delphi/Pascal的流行程度不断下降,很有些难过。前两日看见Bob Swart(Dr. Bob)在他的网站上打出了Forever Loyal to Delphi的标语,觉得都到了这个地步了,更是黯然。
2005年8月2日 星期二
gnochm问题的定位
索引的排序问题很好解决,只要将index那个TreeView的model换成一个可以排序的就可以了。补丁如后面所示。
索引不全的问题其实并不能怪gnochm,而是有些关键字当中有非法字符导致了HTML解析失败
chm文件中的topic和index都是sitemap格式,以HTML格式为载体的
gnochm 采用python编写,很自然地用了HTMLParser这个类来解析这个文件,但碰到上面的非法标识(The "link-selected" signal,注意这里引号是不合法的),后面的就都无法读取出来了,所以会丢掉很多关键字。而xchm就会忽略这个继续往下分析。
不能跳到archor的问题明天再来琢磨,也不知道是不是gtkhtml2的问题。
--------- 8< ---------------------
[bamanzi@saynomdk ~]$ diff -Nurp /usr/bin/gnochm gnochm
--- /usr/bin/gnochm 2005-03-18 09:27:00.000000000 +0800
+++ gnochm 2005-08-02 23:23:35.000000000 +0800
@@ -811,11 +811,13 @@ class MainApp:
# Index
self.imodel = gtk.TreeStore(gobject.TYPE_STRING,
gobject.TYPE_STRING)
+ self.isortmodel = gtk.TreeModelSort(self.imodel)
self.indexview = self.xml.get_widget('IndexTView')
- self.indexview.set_model(self.imodel)
+ self.indexview.set_model(self.isortmodel)
cell2 = gtk.CellRendererText()
column2 = gtk.TreeViewColumn('Index', cell2, text=0)
self.indexview.append_column(column2)
+ self.isortmodel.set_sort_column_id(0, gtk.SORT_ASCENDING)
# Search
self.smodel = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING)
Comments for post
HTMLParser
nick | 03/08/2005, 13:54
Use SGMLParser then. More fault tolerant.
test with sgml
nick | 03/08/2005, 13:59
$ python /usr/lib/python2.3/sgmllib.py sitemap.html
Shows that no big deal for sgml.
sorted list
nick | 03/08/2005, 14:02
For sorted list, I'd rather sort the list before feeding to the treemodel. Should be faster for big list. Treeview is already slow in itself.
But let the treemodel do the sorting is simpler.
Re: SGMLParser
bamanzi | 03/08/2005, 17:41
Really, SGMLParser works!
Thanks!
2005年8月1日 星期一
还是xchm强 (was Re: CHM viewers总结)
2005年7月30日 星期六
glib2,gtk2,pygtk2 reference in CHM format
I modified devhelp2chm a little, to workaround a problem I found when using gnochm to read the CHM files generated by it.
And updated two CHM files generated by it:
glib2/gtk2 gtk-2.6.8, glib-2.6.5, including FAQ and tutorial
(source: package libgtk2.0-doc, libglib2.0-doc)
pygtk2 reference pygtk2ref 2.6.0, and GtkSourceView, GtkSpell, GnomePrint, GnomePrintUI, GtkMozembed
(source: pygtk2 website)
----------------
How to build:
gtk2.chm:
apt-get install libglib2.0-doc libgtk2.0-doc
cd /usr/share/gtk-doc/html/
DIRS="gtk/ gdk/ gdk-pixbuf/ gtk-faq/ gtk-tutorial/ glib/ gobject/"
find $DIRS -name '*.devhelp.gz' | xargs gunzip
for d in $DIRS; do
(cd $d;
echo $d
for f in *.html; do
sed 's#/usr/share/gtk-doc/html/#../#' $f > $f.tmp
mv $f.tmp $f
done)
done
find $DIRS -name '*.devhelp | xargs ~/bin/devhelp2chm-v2.sh
-p gtk2 -T "GTK+ Reference Manual" -t gtk/index.html
...Then use HtmlHelp Workshop to build it.
pygtk2ref.chm
wget http://www.pygtk.org/dist/pygtk2reference.tbz2tar jxf pygtk2reference.tbz2
find . -name '*.devhelp' | xargs ~/bin/devhelp2chm-v2.sh
-p pygtk2ref -T "PyGTK2 Reference" -t pygtk2reference/index.html
2005年4月30日 星期六
Friends剧本CHM版本
不一定能够长期保留,要下载趁早。

是用脚本转的(见前面的帖子I, II, III),当初学习Dive Into Python里面HTML Processing一章练手写的,(原来的Word文档)
p.s Part II的脚本有点问题,因为后来发现后面有些episode不是<hr>分隔的,改用"End"和"The End"划分准确性大一点,但还是有几个需要手工分割。脚本已经更新到下载区friends-split2.py。
2005年4月8日 星期五
Convert CHM contents to normal HTML contents
I have some eBooks (CHM format or SRM format). Now I want to copy them to my cellphone. As CHM or SRM format could not be supported, thus I choose PalmDoc (.pdb) format.
Yes,I can convert a pack of HTML files into one PDB file. But:
1) Some CHM books don't have a content page. They use the CHM contents. With a content page, browsing the result PDB file would be not a happy experience.
2) SRM books could be exported as CHM files. All of them
don't have a content page either.
Then came this simple recipe.
I remember two or three years ago, I used to do these things in Perl. Perl's regex feature is so powerful. The only problem is that after a few days, the script seems to be unreadable. :-(
Python is differenent than Perl. This recipe is so simple, isn't it?
#!env python
from sgmllib import SGMLParser
import htmlentitydefs
from chmmaker import HHCWriter
import os
class SiteMapParser(SGMLParser):
def reset(self):
SGMLParser.reset(self)
# some temp variables
self.level = 0
self.link_url = ""
self.link_title = ""
def start_ul(self, attrs):
self.on_section_starts()
def end_ul(self):
self.on_section_ends()
def start_param(self, attrs):
if len(attrs)>1:
if attrs[0][0]=='name':
if attrs[0][1]=='Name':
self.link_title=attrs[1][1]
elif attrs[0][1]=="Local":
self.link_url=attrs[1][1]
def start_object(self, attrs):
self.link_title = ""
self.link_url = ""
def end_object(self):
self.on_link_found(self.link_title, self.link_url)
def on_section_starts(self):
self.level = self.level + 1
def on_section_ends(self):
self.level = self.level - 1
def on_link_found(self, title, url):
# you can override this
if title and url:
print " " * self.level + "%s [%s]" % (title, url)
class ContentParser(SiteMapParser):
""" A simple class to convert CHM contents (foo.hhc) to a normal HTML contents """
def reset(self):
print "<HTML><HEAD></HEAD><BODY>"
SiteMapParser.reset(self)
def on_section_starts(self):
print "<ul>"
def on_section_ends(self):
print "</ul>"
def on_link_found(self, title, url):
print '<li><a href="%s">%s</a></li>' % (url, title)
if __name__=='__main__':
import sys
if len(sys.argv)<2:
print "Usage: %s foo.hhc" % sys.argv[0]
sys.exit()
trans=ContentParser()
fh=open(sys.argv[1], "r")
try:
trans.feed(fh.read())
except:
pass
trans.close()
fh.close()
# vim:expandtab softtabstop=4
Powered by ScribeFire.
2005年4月5日 星期二
总算将python.cn邮件列表设成了digest模式
的邮件列表(python-chinese@lists.python.cn)水贴(可能说垃圾邮件更贴切)真是多得要命,每天有好几十封邮件,有价值的
估计只有三分之一。偏偏又离不开它,它的人气在所有python社区里面算是比较旺的,很多问题在这里有人能解答。我原来退订过,但后来还是想没事翻翻,
又订阅了。
偏偏网站上提供的mailman设置页面又缺少“提交"(submit)按钮(也不知道管理员哪里去了,这事反映过但总没有消
息),没法将其设置为文摘模式。不过这个困扰我大半年的问题总算解决了:发送一封邮件到python-chinese-
request@lists.python.cn,主题空白,内容如下:
set authenticate password <address=xxxx> set digest mime
address项在用其他邮件帐号发邮件更改设置时有用。
应该mailman管理的邮件列表都有这个功能。如果不清楚具体用法,发送主题为help的邮件给foo-bar-request@some.where就可以了。
Usage:
set help
Show this detailed help.
set show [address=]
View your current option settings. If you're posting from an address
other than your membership address, specify your membership address
with `address=' (no brackets around the email address, and no
quotes!).
set authenticate
To set any of your options, you must include this command first, along
with your membership password. If you're posting from an address
other than your membership address, specify your membership address
with `address=' (no brackets around the email address, and no
quotes!).
set ack on
set ack off
When the `ack' option is turned on, you will receive an
acknowledgement message whenever you post a message to the list.
set digest plain
set digest mime
set digest off
When the `digest' option is turned off, you will receive postings
immediately when they are posted. Use `set digest plain' if instead
you want to receive postings bundled into a plain text digest
(i.e. RFC 1153 digest). Use `set digest mime' if instead you want to
receive postings bundled together into a MIME digest.
set delivery on
set delivery off
Turn delivery on or off. This does not unsubscribe you, but instead
tells Mailman not to deliver messages to you for now. This is useful
if you're going on vacation. Be sure to use `set delivery on' when
you return from vacation!
set myposts on
set myposts off
Use `set myposts off' to not receive copies of messages you post to
the list. This has no effect if you're receiving digests.
set hide on
set hide off
Use `set hide on' to conceal your email address when people request
the membership list.
set duplicates on
set duplicates off
Use `set duplicates off' if you want Mailman to not send you messages
if your address is explicitly mentioned in the To: or Cc: fields of
the message. This can reduce the number of duplicate postings you
will receive.
set reminders on
set reminders off
Use `set reminders off' if you want to disable the monthly password
reminder for this mailing list.
2005年1月1日 星期六
Nokia S60上的Python
相关网址:
Slashdot上的新闻
http://developers.slashdot.org/article.pl?sid=04/12/22/1533241&from=rss CSDN上的新闻
http://www.csdn.net/news/newstopic/19/19130.shtml
Python-chinese邮件列表上的讨论(我最开始看见信息的地方)
http://python.cn/pipermail/python-chinese/2004-December/007200.html
Nokia网站
http://www.forum.nokia.com/main/0,,034-821,00.html
Nokia 6600还是Dopod 565?
翻 了移动"存话费, 送手机"活动的宣传材料,nokia的手机有一款6600,查了一下,倒也是s60系列之一,可以支持python。问题是这款手机样 子我不太喜欢,胖胖的样子(同事蒋亮说它绰号"胖六" :-) 。而且nokia网站上的资料显示,它是一年半以前推出的。
但我对 python的喜爱是显然的。所以问题就来了,到底是买dopod 565呢还是nokia 6600呢?dopod采用windows modile, 在上面扩充python是否容易呢?如果现在没有,以后会出现么?毕竟这个windows mobile跟自己熟悉的操作系统windows是比较熟悉 的(相对于那个symbian而言),而词霸什么的我也很喜欢,可能还有那个total commander(也不知道windows ce与 windows mobile是不是一回事或者兼容).
不知道哪些支持java的能不能跑Jython――尽管Java的运行速度和块头总是问题
2004年11月18日 星期四
How to convert Friends.doc into a CHM file (1)
1. Open Friends.doc with MS Word and save it into a html file (friends.html). I used Office XP,
and due the garbage info added by M Word, the output file is about 28M!
2. Write a simple script (friends-diet.html) to get rid of the garbage attributes
generated by evil M word, include 'class', 'style' and 'lang' etc.
This would cut the size 75% off!
#!/bin/python
from sgmllib import SGMLParser
import htmlentitydefs
import os, sys
class FriendsDiet(SGMLParser):
def reset(self):
self.output=open("friends-thin.html", "w"[img]/images/wink.gif[/img]
SGMLParser.reset(self)
def unknown_starttag(self, tag, attrs):
if tag=='p':
self.output.write("
n"[img]/images/wink.gif[/img]
elif tag=='span' or tag=='o':
pass
elif tag=='o:SmartTagType' or tag=='SmartTagType':
print "Ignore",tag
pass
else:
strattrs=""
for key, value in attrs:
if (key!='class' and key!='style' and key!='lang' and key[0:5]!='xmlns'):
strattrs = strattrs + ' %s="%s"' % (key, value)
self.output.write("<%s%s>" % (tag, strattrs))
if tag=='body':
self.output.write('n')
def unknown_endtag(self, tag):
if tag!='span' and tag!='p' and tag[0:2]!='o:':
self.output.write("%s>n" % tag)
def handle_data(self, text):
if text.strip()!='':
self.output.write(text+"n"[img]/images/wink.gif[/img]
def handle_charref(self, ref):
self.output.write("&#%s;" % ref)
def handle_entityref(self, ref):
semicolon=""
if htmlentitydefs.entitydefs.has_key(ref):
semicolon=";"
self.output.write("&%s%s" % (ref, semicolon))
if __name__=='__main__':
import sys
parser=FriendsDiet()
#fh=open(sys.argv[1], "r"[img]/images/wink.gif[/img]
fh=open("friends.htm", "r"[img]/images/wink.gif[/img]
content=fh.read()
parser.feed(content)
fh.close()
parser.close()
2004年11月16日 星期二
gwhereviewer.py: 用PyGTK2写的gwhere数据文件查看工具
gwhere是一个disk catalog工具,类似于gtktalog以及windows上的WhereIsIt。
我的远期目标是写一个完整的disk catalog工具,数据格式上兼容gwhere,但脚本的方式可以让我轻松地扩展description提取器。
下载脚本: gwhereviewer.py
在Cygwin上测试通过,但用纯win32版本的gtk+/pygtk时会崩溃,不知道为什么
2004年11月5日 星期五
Create a CHM file for PyGTK2 Tutorial
[1] http://www.pygtk.org/dist/pygtk2tutorial.tgz
The main problem is to parse the contents from index.html write then into a HHC file for MS HtmlHelp Workshop.
You can use this simple script to do this (see below)
pygtk-index2hhc.py pygtk2tut.hhc index.html
P.S:
As to the PyGTK2 Reference[2], you can download the devhelp index file[3], and then use my devhelp2chm.sh[4]to get the .HHP, .HHC and .HHK.
[2] http://www.pygtk.org/dist/pygtk2reference.tbz2
[3] http://www.moeraki.com/pygtkreference/pygtk2reference.devhelp.gz
[4] http://www.linuxeden.com/forum/blog/resserver.php?blogId=110848&resource=devhelp2chm.sh
#!env python from sgmllib import SGMLParser import htmlentitydefs from chmmaker import HHCWriter import os class ContentParser(SGMLParser): def __init__(self, outputfile): self.hhcwriter = HHCWriter(outputfile) self.hhcwriter.print_header() SGMLParser.__init__(self) def __del__(self): self.hhcwriter.print_footer() def reset(self): SGMLParser.reset(self) # some temp variables self.level=0 self.title = self.url = "" self.in_href = False def start_dd(self, attrs):
self.hhcwriter.hhcfile.write("<UL>")
def end_dd(self):
self.hhcwriter.hhcfile.write("</UL>")
def start_a(self, attrs): for attr in attrs: if attr[0].lower()=='href': self.in_href = True self.title = "" self.url = attr[1] break def end_a(self): if self.in_href and self.title and self.url: self.on_href(self.title.replace('"', ""), self.url) self.in_href = False self.title = self.url = "" def handle_data(self, text): self.title += text def handle_charref(self, ref): if self.in_href: self.title += "&#%(ref)s;" % locals() def handle_entityref(self, ref): if self.in_href: self.title += "&%(ref)s" % locals() if htmlentitydefs.entitydefs.has_key(ref): self.title += ";" def on_href(self, title, url): target=url if url[-3:]=='fig': target= "" if title and target: self.hhcwriter.add_topic(title, target) if __name__=='__main__': import sys if len(sys.argv)<3: print "Usage: %s hhcfilename index.html" % sys.argv[0] sys.exit() trans=ContentParser(sys.argv[1]) fh=open(sys.argv[2], "r"[img]/images/wink.gif[/img] try: trans.feed(fh.read()) except: pass trans.close() fh.close()
# vim:expandtab softtabstop=4
Powered by ScribeFire.
订阅 帖子 [Atom]
