# -*- coding: utf-8 -*- # vim: set ts=4: # # Name: FitxUtil # # Copyright: Copyright (c) 2008 Loya Liu # # $Id$ # # Author: loya.liu@gmail.com (Loya Liu) # try: import sqlite3 except: pass import os import codecs __author__ = "loya.liu@gmail.com (Loya Liu)" from gettext import dgettext _ = lambda a : dgettext("fitx", a) N_ = lambda a : a def prop_punct_full(prop): prop.icon="/usr/share/scim/icons/full-punct.png" prop.tip = _("Switch to half punctuation mode") def prop_punct_half(prop): prop.icon="/usr/share/scim/icons/half-punct.png" prop.tip = _("Switch to full punctuation mode") #support use define punctutations def prop_punct(prop,mode): if mode==0: prop.icon="/usr/share/fit/full-punct.png" prop.tip = _("Switch to half punctuation mode") elif mode==1: prop.icon="/usr/share/fit/half-punct.png" prop.tip = _("Switch to user defined punctuation mode") elif mode==2: prop.icon="/usr/share/fit/cust-punct.png" prop.tip = _("Switch to full punctuation mode") def prop_full_letter(prop,full_letter): if full_letter: prop.icon="/usr/share/scim/icons/full-letter.png" prop.tip = _("Switch to half letter mode") else: prop.icon="/usr/share/scim/icons/half-letter.png" prop.tip = _("Switch to full letter mode") def export_single(mode,path,tofile): conn=sqlite3.connect(path) cur=conn.cursor() cur.execute('select * from words') tofile.write("--%s--\n" % mode) for w in cur: word_str=str(w[0])+","+w[1]+","+w[2]+","+str(w[3])+","+str(w[4])+","+str(w[5])+","+str(w[6])+","+str(w[7]) tofile.write(word_str+"\n") cur.close() conn.close() def export_db_txt(tofile): f=codecs.open(tofile,"w",'utf-8') export_single('py',os.path.expanduser('~/.fit/py.sqlite'),f) export_single('bh',os.path.expanduser('~/.fit/bh.sqlite'),f) export_single('wbx',os.path.expanduser('~/.fit/wbx.sqlite'),f) f.close() def import_single_word(cur,w): w=w.strip().split(',') cur.execute('select hit from words where code=? and string=?',(w[1],w[2])) row=cur.fetchone() if row: w_hit=row[0] if w_hit6: if l[0:6]=='--py--': curdb=cur_py elif l[0:6]=='--bh--': curdb=cur_bh elif l[0:7]=='--wbx--': curdb=cur_wbx else: import_single_word(curdb,l) conn_py.commit() cur_py.close() conn_py.close() conn_bh.commit() cur_bh.close() conn_bh.close() conn_wbx.commit() cur_wbx.close() conn_wbx.close() f.close() def clear_user_db(): clear_user_db_single(os.path.expanduser('~/.fit/py.sqlite')) clear_user_db_single(os.path.expanduser('~/.fit/bh.sqlite')) clear_user_db_single(os.path.expanduser('~/.fit/wbx.sqlite')) def clear_user_db_single(path): conn=sqlite3.connect(path) cur=conn.cursor() cur.execute('delete from words') conn.commit() cur.close() conn.close()