Dinfio Playground

Let's play with Dinfio!




Dictionary

This is the example of English to Indonesian dictionary. The database is stored in a CSV file.
Author: Ahmad Zainal

' English to Indonesian dictionary example v2.0
 
import string
import gui
import fileio
 
global data_file = "dictionary-words.txt"
global words = []
 
start
    load_data()
    create_gui()
stop
 
function load_data()
    path = getfoldername(getcurrentfile()) & "/" & data_file
    var file: f = file(path, file_read)
 
    while !f.eof()
        w = split(f.readln(), ",")
 
        append(words, {
            original: w[0],
            translated: w[1]
        })
    endwhile
stop
 
function create_gui()
    global window = gui_window("English to Indonesian Dictionary", 358, 165)
 
    global label_words = gui_label("Words:", window, 12, 8)
    global label_translated = gui_label("Translated:", window, 182, 8)
    global list_words = gui_listbox(window, [], false, 12, 30)
    global text_translated = gui_textarea("(Click one word in the words list to see the translation)", window, 182, 30)
 
    for i, 0, size(words) - 1
        list_words.add(words[i].original)
    endfor
 
    text_translated.setlocked(true)
    list_words.addevent(event.click, translate())
 
    window.show()
stop
 
function translate()
    text_translated.settext(words[list_words.getindex()].translated)
stop
 

And here is the CSV file:
day,hari
future,masa depan
look,lihat
me,saya
month,bulan
they,mereka
we,kita
year,tahun
you,anda

Screenshots:


← Back to the Dinfio Playground / Download this program