2008/11/02

装来ibus输入法,感觉不错

不论输入的效率拟或是外观都很能让我满意。

整句输入的时候如果句子过长,会感到有一点点lag

但是这是所有输入法都无法避免的通病吧?

据说在qt程序中可能会有些问题,但我想总要比scim在qt程序中的表现好吧?

至少在qt4.0的smplayer中输入中文还是没有什么问题的。

再用段时间看看到底是fitx还是ibus更好用吧

当然,如果fitx转用ibus作为基础的话那就更好了。

2008/08/25

解决windows下,py2exe打包的程序在用subprocess时弹出cmd窗口

在subprocess加入
creationflags = 0x8000000
也就是CREATE_NO_WINDOW

在win下给gtk程序指定主题

把主题包里,gtkrc那级的文件以及子目录copy到gtk目录的/etc/gtk-2.0就可以了

2008/08/13

subprocess.Popen的僵死

最近在作python的 mencoder前端。

解决了两个Popen僵死的问题。

第一个是,由于mencoder显示的进度信息只有\r,不换行,默认的时候readline会等到所有的进度显示完毕

解决方法是,在popen时,加入universal_newlines=True

第二个是,由于我分别制定了stdout和stderr,由于stderr是程序运行完后读取的,结果stderr的buff满了,mencoder也卡住了。

参照:http://bugs.python.org/issue1256

解决方式是,不指定stderr或者指定stderr为subproess.STDOUT和stdout一起读取。

2008/08/08

在pygtk中使用thread

必须在gtk_main()之前gtk.gdk.threads_init()

不然的话,线程会随着调用它的函数死亡

在做进度条之类的时候必须要注意这点

2008/07/27

好用的录像软件:recordMydesktop

keywork:ubuntu 804
recoredMydesktop  是一款很不错的录像软件

它可以录桌面特效,3D游戏,对系统要求不高,有十分好用的gui界面,可以设定录制指定的区域

当然,任何软件也有缺点。他的缺点是只生成ogg格式的输出文件,以及没法设置录像的分辨率。

但总的来说,它还是款十分好用的录像软件

安装方法:

源里安装 gtk-recoredMydesktop

这里有我用这个软件做得录像

http://www.mrxu.net/2008/07/blog-post_976.html

2008/07/03

python得到汉字拼音首字母

#!/usr/bin/env python
#coding=utf-8

def get_cn_first_letter(str,codec="UTF8"):
    if codec!="GBK":
        if codec!="unicode":
            str=str.decode(codec)
        str=str.encode("GBK")
   
    if str<"\xb0\xa1" or str>"\xd7\xf9":
        return ""
    if str<"\xb0\xc4":
        return "a"
    if str<"\xb2\xc0":
        return "b"
    if str<"\xb4\xed":
        return "c"
    if str<"\xb6\xe9":
        return "d"
    if str<"\xb7\xa1":
        return "e"
    if str<"\xb8\xc0":
        return "f"
    if str<"\xb9\xfd":
        return "g"
    if str<"\xbb\xf6":
        return "h"
    if str<"\xbf\xa5":
        return "j"
    if str<"\xc0\xab":
        return "k"
    if str<"\xc2\xe7":
        return "l"
    if str<"\xc4\xc2":
        return "m"
    if str<"\xc5\xb5":
        return "n"
    if str<"\xc5\xbd":
        return "o"
    if str<"\xc6\xd9":
        return "p"
    if str<"\xc8\xba":
        return "q"
    if str<"\xc8\xf5":
        return "r"
    if str<"\xcb\xf9":
        return "s"
    if str<"\xcd\xd9":
        return "t"
    if str<"\xce\xf3":
        return "w"
    if str<"\xd1\x88":
        return "x"
    if str<"\xd4\xd0":
        return "y"
    if str<"\xd7\xf9":
        return "z"
   

2008/07/01

python 中实现了entry的多单词自动完成



#!/usr/bin/env python
#coding=utf-8
# a class of completion
import pygtk
import gobject
import gtk
class Completion():
    def __init__(self,Entry,model):
        self.comp= gtk.EntryCompletion()
        Entry.set_completion(self.comp)
        self.comp.set_match_func(self.match_func)
        self.comp.connect("match-selected",self.on_completion_match)
        self.model=model
        self.comp.set_model(model)
        self.comp.set_text_column(0)
        self.Entry=Entry
        Entry.set_completion(self.comp)
        self.comp.set_inline_completion(False)
        self.comp.set_inline_selection(False)
#        self.comp.set_popup_single_match(True)
    def get_comp_point(self):
        str=self.Entry.get_text()
        pos=self.Entry.get_position()
        pos1=str.rfind(" ",0,pos)
        pos2=[str.rfind(" \"",0,pos),str.rfind(" "",0,pos),str.rfind(" "",0,pos),str.rfind(" '",0,pos),str.rfind(" '",0,pos),str.rfind(" '",0,pos)]
        pos3=[str.rfind("\" ",0,pos),str.rfind("" ",0,pos),str.rfind("" ",0,pos),str.rfind("' ",0,pos),str.rfind("' ",0,pos),str.rfind("' ",0,pos)]
        for item in pos2:
            if item>pos2[0]:
                pos2[0]=item
        for item in pos3:
            if item>pos3[0]:
                pos3[0]=item
        if pos2[0]<pos3[0]:
            return pos3[0]
        else:
            return pos1+1
    def match_func(self, completion, key, iter):
        self.pos=self.get_comp_point()
        model = completion.get_model()
        return model[iter][0].startswith(self.Entry.get_text()[self.pos:self.Entry.get_position()])
    def on_completion_match(self, completion, model, iter):
        str=self.Entry.get_text()
        self.Entry.set_text(str[:self.pos]+model[iter][0]+str[self.Entry.get_position():])
        self.Entry.set_position(-1)
        return True
    def add_words(self, words):
        model = self.comp.get_model()
        for word in words:
            model.append([word])