三月 24, 2010
» onlinedict線上版小改進

PB124666
lac d'Anncey.France

在這邊看到,透過點小設定,可以讓Chrome的網址列充當搜尋引擎,自訂想要的搜尋。之前用Google App Enginen包裝出來的OnlineDict,只有吃由form餵入的資料,也就是只支援post的方式。為了要讓它也可以做為Chrome搜尋用的引擎,就得要為它做點小改變,讓它也支援get方式的查詢才可以。

所以,我改了一下程式碼。有多簡單呢?就copy paste一行程式碼而已。
原本def get(self)底下是直接呼叫OutputHtml(),現在改成呼叫post(self),就可以跟post做一模一樣的處理了。

#/usr/bin/env python

import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import os
from google.appengine.ext.webapp import template

import Dict

class OnlineDic(webapp.RequestHandler):
def __init__(self):
self.fren_dic = Dict.collins_fren_dict()
self.ench_dic = Dict.yahoo_dict()
self.eijiro_dic = Dict.eijiro_dict()

def get(self):
self.post()

def post(self):
word = self.request.get('word')
dic = self.request.get('dic')
if dic == 'Fr-En':
content = self.fren_dic.doSearch(word)
content = content // handling
elif dic == 'Ja-En':
content = self.eijiro_dic.doSearch(word)
else:
content = self.ench_dic.doSearch(word)
self.OutputHtml(content,dic)


def OutputHtml(self, content="", dic=""):
template_values = { 'content': content,
'dic': dic,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))

application = webapp.WSGIApplication(
[('/', OnlineDic)],
debug=True)

def main():
run_wsgi_app(application)

if __name__ == "__main__":
main()

# vim:set nu et ts=4 sw=4 cino=>4:

網站在此:http://onlinedict.appspot.com/
目前支援法翻英,範例如下:
http://onlinedict.appspot.com/?dic=Fr-En&word=%s
英翻中
http://onlinedict.appspot.com/?dic=En-Ch&word=%s
日翻英
http://onlinedict.appspot.com/?dic=Ja-En&word=%s

為了貼上面的程式碼,特別去找了一個透過javascript的syntax highlighter,路徑如下:
http://alexgorbatchev.com/wiki/SyntaxHighlighter
使用方式可以參考下面這個網址:
http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html

三月 6, 2010
» onlinedict by google app engine

PB173371
Central Station.NYC.US

I posted an article about using Google App Engine in last June, and the experiment target is the onlinedict. Everything goes well and since onlinedict is originally written in python, the porting task is without any efforts.

However, there's one limitation of using Google App Engine: You can get your codes back from the server. You have to keep your codes somewhere. That's quite strange as a policy. I know it may be easier to control the whole system on google side, but as a user, it's troublesome ofr me because I am too lazy to my stuff in another source control website.

As a consequence, I lost my codes after re-installing OS on my nb for several times. Although my original work still runs well, it looks bad on all mobile devices. The words are too small to read. However, I don't have original codes anymore! no way to improve it at all!

Finally, I decided to rewrite it again,since this website should help me most on mobile devices. If the outlook on devices are bad, then it is somehow useless to me. Well, the first thing to do is study again how to apply the google app engine framework into my dictionaries. With the help of the tutorial, I quickly achieved what I have done last time: a working fr-en, ch-en dictionary, and, plus eijiro dictionary!

The most difficult part (not really difficult at all, I just don't know how to do) is to adopt some css style to make it look great on mobile devices. Well, I found a good refernce site: http://building-iphone-apps.labs.oreilly.com/. And, it's free!

Okay, after several hours of work, I am happy with my new dictionary now. The font size is good, the input control is at the right position, with some hints in the box. Three online dictionaries are available. It's time to go to sleep again~~

二月 23, 2010
» Development on android

PB124730
Annecy.France

看了點文件,想說就來寫寫東西吧,從最簡單的開始。

之前在國外時,為了學法文,幫onlinedic寫了個Vocabulary Review的小程式在Windows Mobile上。讓自己可以用當時帶出去的dopod818加減看一下查過的單字。現在,當時的code已經都不見了,所以想說在android上也寫一個好了。反正onlinedic的export機制都還是okay的。

在寫程式時,也可以順便練習到android上的一些基本觀念,比方說:如何透過intent來叫起另一個activity;如果在叫起別的activity時,帶想要的參數給它;透過xml的UI建置方式,畫面橫轉正轉的處理;UI元件的動作指派;目錄結構的讀取,文字檔的讀取;簡單的webview應用;activity暫存狀態的記錄;功能權限的開啟;androidManifest.xml的基本設定;eclipse開發環境的熟悉等。

真的寫下去了,明明是個很簡單的程式,但也弄了一天多才寫好,花了許多時間在小細節上。如果不把除錯、追臭蟲方式弄熟,接下來的日子應該會很痛苦吧。

= = =
如果有空的話,乾脆一不做二不休,把onlinedict也搬到android,這樣子就不用每次都要裝一堆字典了。在網路上找到open source,可以讀取stardict字典檔的程式,有空再研究吧。先記下link:
http://code.google.com/p/toolkits/wiki/YAStarDict

另外,沒想到有人替eblib包了個python wrapper!!
當初在onlinedict裡亂寫的鄨腳command line程式,應該可以用這個wrapper把它換掉吧,省下暫存文字檔輸入輸出的廢工。
也是…改天有空再試吧。
Link: http://code.google.com/p/pyeb/

十月 25, 2009
» Resurrect, my onlinedict

R8076411 (by plateaukao)
Taidon.Taiwan

Oh, I will survive too, even under this kind of tremendous pressure.
Just....don't bite me. It hurts.

====

I don't like to use stardict in Ubuntu, bacause of its UI. So, I decided to resurrect my onlinedict. Actually, it already works well in ubuntu after getting the latest codes from sourceforge website, although some libs are depreciated. I replaced the depreciated lib, and modifed a bit the parser of collins online dictionary, which is one of my favorite dics.

六月 21, 2009
» Google App engine

p7135683.jpg (by plateaukao)
Biei.Japan

I forgot how I bumped into this site Google App engine. I saw there's a small youtube video at the right-hand side. Out of curiosity, I clicked on the video and gave it a gimplse. Wow, it's written in Python. That made me more interested in how it works. Within hours, I wrote my first google app based on its simple sample provided in the Google App Engine SDK. Hey, but it's already good enough to compete with my onlinedic!! The speed is amazing comparing to my desktop client. Instead of completing my first workable (and useful) android app, I ported my onlinedic to google apps. Well, I just changed the I/O part of my original python scripts. As for the html post-processing part, I did not change them at all.

Now, I have French-English dictionary, Yahoo Chinese-English dictionary, and French Conjugator ready on the internet! I can always have these basic function set as long as I have internet access.

Here are some notes about what obstacles I encountered while writing this small app.

1. use python 2.5 instead of python 2.6
If you are using python version other than 2.5, it'd better that you install python2.5 too.
It will prevent you from bumping into a out-of-nowhere debugging error.
(I spent some time on finding this out on my ubuntu 9.0)

2. There's new_project_temple folder in the SDK root directory. That's where you can start with.

3. Do not use urllib from python library. Use urlfetch from google.appengine.api instead.

4. You can only upload/update your files to google app server, but you CANNOT download these files from the server!!
So, remeber to back up your files and use version control systems by yourself.


LINK:
http://onlinedict.appspot.com


REF:
http://code.google.com/intl/zh-TW/appengine/

六月 23, 2008
» how to do merging in tortoisesvn

R8071976 (by plateaukao)
Ricoh GRD
Annecy, France
2008.06.22
la Fete de la Musique

很難在午夜時分,還能在安納西看到這麼多遊客。

****

onlinedic的word list目前使用上還算穩定,
所以今天把這個branch merge到主要的trunk上。
久沒用tortoisesvn了,只好再查一下它的用法。
下面是官方網頁的解釋:
Merging


五月 26, 2008
» Details for comiplation of ebmodule-2.0 under ubuntu

RIMG0368
(Ricoh GRD Semnoz, Annecy, France)

滑雪滑到一半遇上大雪,多少會讓人覺得很掃興。
買的是一日券,少溜愈多虧愈多。
看著屋外一字排開的滑雪用具和空蕩蕩的桌椅,
還是快進到餐廳裡取暖吧。

****

I need to write it down here to prevent that some day my no-so-working brains forget how I did it. Actually it's not so complicated. Here's the steps:

1. download eb-3.1.tar.gz and compile it. You will find dynamic libraries under eb/.libs and zlib/.libs.
2. download ebmodule-2.0. Modify setup.py and ebmodule.c
2.1 change library path and include path to where you put eb libraries and eb headers.
2.2 modify ebmodule.c. The "static char" is not well written. So gcc will complain about it. You have to modify all the "static char".
2.3 compile! Voila. If everything goes fine, you can test your eblib.py or test.py.

I uploaded a modified version of ebmodule-2.0 (compiled python lib included) to my googlepage. You can find everything you need in the file to start programming with ebmodule. Have fun!


REF:
EB Library

DOWNLOAD:
compiled ebmodule-2.0 module and modified source codes

五月 17, 2008
» 一不做二不休 modification of stardict dictionary file

p7135667 (by plateaukao)
(Biie, Hokkaide)

一直很討厭在查單字時還要輸入法語的音符,雖然之前找到的輸入方式已經很簡單了,但是如果能夠只輸入一般英文字母就能查詢的話,不是很輕鬆嗎?

要在某些地方偷懶,就要在其他地方付出。

於是,我把Larousse的字典export出來,重新生出了新的字典,裡頭包含了單純字母組成的單字,然後在解釋部分,利用=>來指到原始的單字。另外在stardict.py裡頭,加上識別=>的程式碼。這麼一來,以後就可以只輸入字母查詢啦!

原本Babylon格式的字典檔,也可以支援syncronym,不過我怎麼樣也試不成功,所以只好用自己爛爛的workaround。Anyways, it works now~~

五月 16, 2008
» OnlineDic supports word list now!

onlinedic_word_list (by plateaukao)

it's awkwardly implemented yesterday. The word list support was not considered in the original design of Dict module so it's hard to find a place to fit it in.

Finally, I decided to add a default function for Dict base class: get_word_list(). Currently, this new feature is only supported for dictionary files with stardict format .

After calling match() from FileDB in stardict module, it will not only return the word explanation, but also provide a list of words that are before and after current word.

When the MainWindow receives SearchDone event, it will upate the left side panel if word list is available. If not, the word list panel won't be displayed.

五月 12, 2008
» Psyco

R8070920 (by plateaukao)
(Ricoh GRD Cannes, France. 坎城小火車)

南部每個鎮都會有逛市區的小火車,帶著你穿街過巷,在較短的時間內一覽當地名勝和景點。價錢大都落在5歐到10歐之間。車上一般會提供英文和法文的解說,可以帶上耳機或是由司機直接口頭介紹景點。行程則大概是二十分鐘到三十分鐘之間。

我只有在馬賽突然心血來潮坐了一次,登上了馬賽著名的教堂,俯看整個馬賽港。一路上車子緩縱上坡,和兩旁的行人擦肩而過,吹著微風。

****
Psyco,一個號稱可以加速python程式執行速度的module。只要加個兩行code就可以見效。雖然我看不大出來效果,不過還是在onlinedic中加入了這個功能。Psyco需要從其官網另外下載套件才行,目前支援linux和Windows。

REF:
IBM網站上的介紹
Psyco官網

五月 7, 2008
» Add Global Hotkeys for OnlineDic on Windows platform

R8070831 (by plateaukao)
(Ricoh GRD Marseille, France. ile d'if)

到馬賽沒上伊芙島,大概算不上是到過馬賽吧。不過伊芙島卻一點兒也不吸引我。來回的船票要十歐,上了島,還得一定要再交五歐參觀Chateau d'if才行。(如果有買馬賽一日周遊券的話,會比較划算,因為20歐裡面便包含了來回船票,城堡門票,還可以參觀很多市區內的博物館,一日的交通票,Tram,地鐵,巴士坐到爽,還可以坐上山的市區觀光小火車)。可惜我發現有一日券的時間太晚了,所以沒來得及買。

從伊芙島往陸上看去,海的顏色是漸層的,很夢幻。很多家庭拿著食物,就在城堡四周野餐起來,完全不介意這曾經是個關犯人的地方。小時候看過的"基度山恩仇記"早就忘光了,所以不大體會得到被關在這兒的痛苦。

****

from long time ago, I've kept trying to add supports of global hotkeys for onlinedic; however, it's always in vain. Tonight, I finally found a way to achieve it!!! (though it only works for Windows platform) Why didn't I find the API earlier, I keep wondering....

This feature is supported by wxWidgets. As consequences, it's been ported to wxPython too. Actually it's quite easy. All I need to do is to invoke RegisterHotKey provided by Frame.

self.RegisterHotKey(
self.hotKeyIdToggleScan, #a unique ID for this hotkey
MOD_WIN, #the modifier key
VK_F3) #the key to watch for

The usage of the parameters are rather obvious. The last two parameters should be filled in by definitions from win32con. If you don't have installed win32 extension, you can just find out the right definitions you want to used by the second following references.

Once you want to quit the program, you have to unregister the hotkey:

self.UnregisterHotKey(self.hotKeyIdToggleScan)

REF:
Sample of RegisterHotKey for wxpython
Virtual Key Definition in win32con

四月 30, 2008
» PC version of VocabReview

VocReview with explication

Though VocabReview ( a small program that I wrote for Windows Mobile system to display vocabularies that have been exported to a text file) works well on my dopod818, I found out that actually I spend more time on my PC than on my PDA. Well... I am kind of otaku, I do not go out often. So, I think it's probably a good idea to create a similar program on my PC too. In this way, I can review the words while I am surfing on the internet.

Since it'll be used on PC, that means I can still use python as I did for onlinedic. It turns out using python is a right choice. I just spent one night to finish this little program, comparing to several day's work I've done for VocabReview on Windows Mobile. Now, it is well integrated into onlinedic too, though it can be used separately.

After updating files on svn server, you can trigger it by using hotkey Ctrl-R, or click it from menu > File. By default, it will open the export file defined by onlinedic and display the vocabularies. You can click "Toggle" button to change the display as the following screenshot.

In the near future, I may change the layout to make it smaller with alpha blending, so that I can put it on the top of the screen. And...the feature manage words (add/remove words) too.

VocReview with only Vocabulary

四月 24, 2008
» 法語動詞變位查詢

fr_conjugate_table
( French Verbs Conjugation)

在很早期,onlinedic就已經加入了法文動詞變位查詢的支援。
當時是直接把別人寫好現成的library拿來用,
因為原本的library就已經有我想要的API,所以沒有特別改什麼。

用了好一陣子之後,覺得它在呈現HTML格式時,有點不大人性化。
從上表可以看出,主要的動詞變化有十一種。
原本的呈現方式是一長條的。
也就是說,以目前的視窗大小,只能看到前三到四種變化。
後面的變化得要透過一旁的捲動列來向下拉才看得到。
對於這點我一直不是很滿意(我實在是太懶了…)

所以今天看了一下Conjugator部分的code,
在convertToHTML的部分加了點code,
讓輸出HTML格式時,能夠以table的方式表示。
這麼一來,我想要有幾欄,有幾列,都變成是件很容易的事。
瞧上面的表格,多麼一目瞭然啊!

Open source就是有這種好處。
只要會一點點程式,遇到使用上不順手的情況,或是看不順眼的地方,
就可以自己動手DIY一下,讓程式符合自己的需要。

四月 2, 2008
» new francais-anglais dictionary for onlinedic

PA273853 (by plateaukao)
(Olympus E300 France.Chamonix)

週日有到夏慕尼滑雪的活動,光是車錢就要18歐。
如果再加上一整天的forfait的話,大概總共要50歐。
還在考慮中…

****
今天在網上找資料時,看到有人說wordreference的解釋比較精確。
我去找了幾個最近在學的les mots familiers,它裡頭大都有明確的英文解釋。
所以,早上花了點時間把它也加到onlinedic裡頭。

跟其他網站不一樣的地方是,wordreference會檢查request的header,
看user-agent是不是一般常用的browser,如果不是的話會擋掉該request。
這麼一來,python提供的最基本的

urllib.urlopen

就派不上用場了。

上網看了一下,要改掉預設的user-agent,得要改用urllib2才行。
大致上的code如下:

import urllib2
req=urllib2.Request(url=url_line,headers={'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113'})
f = urllib2.urlopen(req)
source = f.read()


嗯~又多了一個好字典 :)

相關連結:
WordReference

三月 16, 2008
» onlinedic update again!!

Screenshot-onlineDic-0.9.3

When I read Harry Potter III, I used three instances of onlinedic: one in Chambers Francais Anglais; one with XMLittre, Francais-Francais Dictionnaire; one in woaifayu-fc 我愛法語法漢字庫.

Most of the time I used the third one, because I can quickly grab the idea of the word, and move on to the following details of the plots.

However, the content of woaifayu-fc (a dictionary file from stardict website) is not well orgnized. All the explanations are crammed together. It's hard to find the meannings that I want.

So, I did a little modifications for the display of woaifayu-fc. As you can see in the screenshot, explanations are separated out with green colored font.

It'll work better when I export them out to text file and read by my ReviewVocab on PocketPC.

:-)

十月 15, 2007
» little improvement for onlinedic

R8060518
(Ricoh GRD Annecy. Yellow Leaf)

I use my onlinedic a lot recently both in Windows and Ubuntu, for looking up tens or hundreds of french vocabularies coming from notes of classes or from the Harry Potter novel. Under such heavy utilization, I found it quite intolerable for two things:

  1. I need to check the verb deconjugation first, to see wheter the transformation from, and then, look up for the meaning of the word. If I want to export the vocab in a file, that will be two times of the effort: one for deconjugation, and one for the vocab meaning.
  2. After exporting explanations to a text file, I can review it in my PocketPC simply by a text reader. However, it's hard to move to the next word or the previous word due to the long explanations for some common used words.
The first one is just a design problem of onlinedic. I should have implemented the French conjugation/deconjugation feature into the dictionary search part instead of making it a separate feature that user can toggle on/off with. Fortunately, it's not so difficult to tackle it at this stage. Though a little bit awkard, I made a small fix for it and it works great now. If Auto deconjugation feature is turned on, the conjugation type will be shown first and then following the word explanation. Easy for reading and exporting.

As for the second problem, it will take me longer for coming out a feasible solution. I may need to write a specific application on PockePC to read the exported text file. It will parse the content and make movements between words easily by just clicking on navigation keypad.

I hope I can finish it as a small programming practice sooner or later this week.

八月 24, 2007
» another improvement to onlineDic

R8059725 (by plateaukao)
(Ricoh GRD 颱風來臨前)

When using onlineDic under Windows platform, I will hide the main window if I am doing other things rather than looking up words in the dictionary. When I want to activate onlineDic again, I will click on the Taskbar icon. But most of the time, although the main window reappears on the task list, it won't move the top layer. As a consequence, I have to manually click on the task list to bring it to the front.

Today, I found the solution.

After calling frame.Show(true), I should also call frame.Raise() to get the effect I want. : ) This feature is not included in 0.9.3. If you want to have this, you can update your svn source, or just add the line in wxGUI.py.

八月 15, 2007
» onlinedic update

R8059719 20070814
(Ricoh GRD CompanyView 20070814)

雖然已經買了Babylons的字典,但是常常還是會使用自己寫的onlineDic;尤其是在linux底下,Babylons不行用,非得用onlineDic不可。目前光是menu item上列的字典分類,就多達八種,更別說每種分類下,一大串的字典項目。

在主要的視窗上,因為可以把字典依據不同語言,分到不同的選單下,所以不至於造成選單過長;但是,在工具列上的選單,就沒那麼順利了。原本的作法是把所有的字典一字排開,外加Scan, Restore, Quit等選項。遇到螢幕小一點的情況,就會發生整個選單無法一次把所有選項列出的窘況,得要scroll好久才能回到Scan的選項。

這兩天,花了十幾分鐘把它做了修正,讓它可以跟主視窗一樣,依照不同的語言來分類。這麼一來,就不會列一大排了。

onlinedic_taskbar_menu

****

另外一點是,在用firefox時,雖然可以利用AutoCopy來選擇要查詢的字串,讓onlineDic可以做查詢的動作,但是,遇到單字是在長長的連結裡時,就沒輒了。因為連結一點下去,就連出去了。目前看到有一些firefox的extension可以做出mouseover就查詢的效果,所以我去google了一下。之前有在用的rikaichan,還有昨天找到的cndict都可以做到這種效果。

我把cndict extension的.js檔研究了一番,把它原本線上查詢英漢的地方,換成了呼叫onlineDic。透過這種方式,我的onlineDic在Linux下,也可以用類似mouse over lookup的功能。

biggo.com.tw

A Django site.