This file is indexed.

/usr/share/khmerconverter/modules/converterGUI.py is in khmerconverter 1.4-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#Khmer converter
# (c) 2006 The WordForge Foundation, all rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# See the LICENSE file for more details.
#
# Developed by:
#       Hok Kakada (hokkakada@khmeros.info)
#       Keo Sophon (keosophon@khmeros.info)
#       San Titvirak (titvirak@khmeros.info)
#       Seth Chanratha (sethchanratha@khmeros.info)
#
# This module create a graphical user interface using basically on Tix module

from Tix import *
from mimetypes import MimeTypes
import tkMessageBox
import FontDataXML
import os
import tkFont
import __version__

# Python 2.3 only has sets as a module
try:
    foo = set()
    del(foo)
except:
    from sets import Set as set

# constants
TOUNICODE = 'unicode'
TOLEGACY = 'legacy'
TYPETEXT = 'Plain Text'
TYPEODT = 'OpenOffice.org Writer (*.odt)'
TYPEHTML = 'Web Page, HTML'
CODEISO = 'Plain Text (latin-1/iso-8859-1)'
CODEUTF = 'Unicode (utf-8)'
DEFAULTFONTSIZE = 11

# default value
def setDefault():
    directionVar.set(TOUNICODE)
    cmbDocType.pick(0)
    cmbEncoding.pick(0)
    cmbFontInput.pick(INDEXABCZWSP)
    cmbFontOutput.pick(INDEXKHMEROS)
    
    docTypeVar.set(TYPETEXT)
    fntInput.entry.delete(0, END)
    outputFileVar.set('')
    spnSize['state'] = NORMAL
    fontSizeVar.set(DEFAULTFONTSIZE)
    spnSize['state'] = DISABLED
    chkSize.deselect()
    evUnicodeClick()
    checkStatus()
    
def checkConvertible():
    if (inputFileVar.get() and outputFileVar.get()):
        btnConvert['state'] = NORMAL
    else:
        btnConvert['state'] = DISABLED
       
def checkStatus():
    cmbEncoding['state'] = DISABLED
    cmbEncoding.set_silent(' ')
    
    if (directionVar.get() == TOUNICODE):
        cmbFontInput['state'] = NORMAL
        cmbFontInput.pick(INDEXABCZWSP)
        if (docTypeVar.get() == TYPEODT):
            cmbFontOutput['state'] = NORMAL
            cmbFontOutput.pick(INDEXKHMEROS)
            cmbFontInput['state'] = DISABLED
            cmbFontInput.set_silent(' ')
            chkSize['state'] = NORMAL
        elif (docTypeVar.get() == TYPETEXT):
            cmbEncoding['state'] = NORMAL
            cmbEncoding.pick(0)
            cmbFontOutput['state'] = DISABLED
            cmbFontOutput.set_silent(' ')
            chkSize['state'] = DISABLED
            spnSize['state'] = DISABLED
            chkSize.deselect()
        elif (docTypeVar.get() == TYPEHTML):
            cmbFontOutput['state'] = DISABLED
            cmbFontOutput.set_silent(' ')
            chkSize['state'] = DISABLED
            spnSize['state'] = DISABLED
            chkSize.deselect()

    else:
        cmbFontInput['state'] = DISABLED
        cmbFontInput.set_silent(' ')
        cmbFontOutput['state'] = NORMAL
        if (docTypeVar.get() == TYPEODT):
            chkSize['state'] = NORMAL
        else:            
            chkSize['state'] = DISABLED
            spnSize['state'] = DISABLED
            chkSize.deselect()

# event handler
def evResetClick():
    setDefault()

def evSetInput(val):
    mimeType = mt.guess_type(inputFileVar.get())[0]
    if (mimeType == 'application/vnd.oasis.opendocument.text'):
        docTypeVar.set(TYPEODT)
    elif (mimeType == 'text/html' or mimeType == 'text/xml'):
        docTypeVar.set(TYPEHTML)
    elif (mimeType == None):
        # if mimeType failed to give apropriet value, use file
        # extension instead.
        filename = inputFileVar.get().lower()
        if filename.endswith('.odt'):
            docTypeVar.set(TYPEODT)
        elif filename.endswith('.htm') or filename.endswith('.html'):
            docTypeVar.set(TYPEHTML)
        else:
            docTypeVar.set(TYPETEXT)
    else:
        docTypeVar.set(TYPETEXT)
    cmbDocType.set_silent(docTypeVar.get())

#  set outputFile according to inputFile
    (path, filename) = os.path.split(inputFileVar.get())
    outputFileVar.set(os.path.join(path, 'converted-' + filename))
    checkStatus()
    checkConvertible()

def evSetOutput(val):
    checkConvertible()

def evChkSize():
    if chkSizeVar.get():
        spnSize['state'] = NORMAL
    else:
        spnSize['state'] = DISABLED   

def evDocumentTypeClick(val):
    if (val):
        checkStatus()

def evUnicodeClick():
    cmbFontOutput.slistbox.listbox.delete(0,END)
    for font in unicodeFontList:
        cmbFontOutput.insert(END, font)
    cmbFontOutput.pick(INDEXKHMEROS)
    checkStatus()   

def evLegacyClick():
    cmbFontOutput.slistbox.listbox.delete(0,END)
    for font in legacyFontList:
        cmbFontOutput.insert(END, font)
    cmbFontOutput.pick(INDEXABCZWSP)
    checkStatus()

def evHelp():
    # create the top level window/frame    
    import help    
    helptext = help.HelpText(top)
    btnHelp['state'] = DISABLED
    top.wait_window(helptext.root)
    # use try because the widget might not exist anymore
    try:
        btnHelp['state'] = NORMAL
    except:
        pass
        
def evQuit():
    top.destroy()
    
def evConvert():
    btnConvert.focus_set()
    encoding = encodingVar.get()
    if (encoding == CODEISO):
        encoding = 'iso-8859-1'
    elif (encoding == CODEUTF):
        encoding = 'utf-8'
    else:
        encoding = 'cp1252'
       
    # output font is priority
    if (cmbFontOutput['state'] == NORMAL):
        font = fontOutVar.get().lstrip()
    else:
        font = fontInVar.get().lstrip()

    # set font size to zero if it is disabled
    if (spnSize['state'] == DISABLED):
        fontSize = None
    else:
        fontSize = fontSizeVar.get()
    
    direction = directionVar.get()
    inputFile = inputFileVar.get()
    docType = docTypeVar.get()
    outputFile = outputFileVar.get()

    # check if output file already exist
    if (os.path.exists(outputFile)):
        confirm = tkMessageBox.askquestion('Warning', 'The output file does already exist!\n\nDo you want to overwrite?')
        if (confirm == 'no'):
            return

    try:
        if (direction == TOUNICODE):
            if (docType == TYPEODT):
                import unicodeConvertOdt
                converter = unicodeConvertOdt.unicodeConvertOdt()
                converter.convertOdtFile(inputFile, outputFile, font, fontSize)
            elif (docType == TYPEHTML):
                import unicodeConvertHTML
                unicodeConvertHTML.convertHTMLFile(inputFile, outputFile, font)
            else:
                import unicodeConvertText
                unicodeConvertText.convertTxtFile(inputFile, outputFile, font, encoding)
                
        else:
            if (docType == TYPEODT):
                import legacyConvertOdt
                converter = legacyConvertOdt.legacyConvertOdt()
                converter.convertOdtFile(inputFile, outputFile, font, fontSize)
                
            elif (docType == TYPEHTML):
                import legacyConvertHTML
                legacyConvertHTML.convertHTML(inputFile, outputFile, font)
            else:
                import legacyConvertText
                legacyConvertText.convertTxtFile(inputFile, outputFile, font)
    except Exception, e:
        tkMessageBox.showerror('Error', e)
    else:
        tkMessageBox.showinfo('Information', 'Conversion successful!')
# instance of mime type
mt = MimeTypes()

# create the top level window/frame
top = Tk()
title = 'Khmer Converter' + __version__.ver
top.wm_title(title)
if sys.platform[:4] in "win32":
    top.wm_iconbitmap("converter.ico")
top.protocol("WM_DELETE_WINDOW", top.destroy)
top.geometry("500x550+150+150")
top.minsize(450, 480)
frmTop = Frame(top)

FONTSIZE = tkFont.Font(family="serif", size=DEFAULTFONTSIZE, weight="normal")

#default color
bgcol = "light blue"

# create frame
frmDirection = LabelFrame(frmTop, border=1, borderwidth=1, relief=GROOVE, label ='Conversion direction', labelside=TOP, bg=bgcol)
frmDirection.label.configure(font = FONTSIZE)
frmInput = LabelFrame(frmTop, border=1, borderwidth=1, relief=GROOVE, label='Input', labelside=TOP, bg=bgcol)
frmInput.label.configure(font = FONTSIZE)
frmOutput = LabelFrame(frmTop, border=1, borderwidth=1, relief=GROOVE, label='Output', labelside=TOP, bg=bgcol)
frmOutput.label.configure(font = FONTSIZE)
frmButton = Frame(frmTop, border=1, borderwidth=1)

# create some widgets inside

# widgets for direction
directionVar = StringVar()
radUnicode = Radiobutton(frmDirection.frame, text="Legacy to Unicode", font=FONTSIZE, command=evUnicodeClick, value=TOUNICODE, variable=directionVar)
radLegacy = Radiobutton(frmDirection.frame, text="Unicode to Legacy", font=FONTSIZE, command=evLegacyClick, value=TOLEGACY, variable=directionVar)

# widgets for input
inputFileVar = StringVar()
frmInputSub = Frame(frmInput.frame)
lblInput = Label(frmInputSub, text='File:', font=FONTSIZE)
fntInput = FileEntry(frmInputSub, dialogtype = 'tk_getOpenFile', width = 50, command=evSetInput, variable=inputFileVar)
fntInput.entry.configure(font=FONTSIZE)
docTypeVar = StringVar()
cmbDocType = ComboBox(frmInput.frame, label="Document Type:", dropdown=1, editable=1, variable=docTypeVar, options='listbox.height 3', command=evDocumentTypeClick)
cmbDocType.entry.configure(width=30, font=FONTSIZE)
cmbDocType.label.configure(font = FONTSIZE)
fontInVar = StringVar()
cmbFontInput = ComboBox(frmInput.frame, label="Font:", dropdown=1, editable=1, variable=fontInVar)
cmbFontInput.entry.configure(width=30, font = FONTSIZE)
cmbFontInput.label.configure(font = FONTSIZE)
encodingVar = StringVar()
cmbEncoding = ComboBox(frmInput.frame, label = "Encoding:", dropdown=1, editable=1, variable=encodingVar, options='listbox.height 3' )
cmbEncoding.entry.configure(width=30, font=FONTSIZE)
cmbEncoding.label.configure(font=FONTSIZE)
# widgets for output
outputFileVar = StringVar()
frmOutputSub = Frame(frmOutput.frame)
lblOutput = Label(frmOutputSub, text='File:', font=FONTSIZE)
fntOutput = FileEntry(frmOutputSub, dialogtype='tk_getSaveFile', command=evSetOutput, variable=outputFileVar)
fntOutput.entry.configure(font=FONTSIZE)
fontOutVar = StringVar()
cmbFontOutput = ComboBox(frmOutput.frame, label="Font:", dropdown = 1, editable=1, variable=fontOutVar)
cmbFontOutput.entry.configure(width=30, font=FONTSIZE)
cmbFontOutput.label.configure(font=FONTSIZE)
frmSize = Frame(frmOutput.frame)
chkSizeVar = IntVar()
chkSize = Checkbutton(frmSize, text='Override size', variable=chkSizeVar, command=evChkSize, font=FONTSIZE)
fontSizeVar = IntVar()
spnSize = Control(frmSize, label='Size:', min=1, max=100, variable=fontSizeVar, value=DEFAULTFONTSIZE)
spnSize.tk_focusFollowsMouse()
spnSize.label.configure(font=FONTSIZE)
spnSize.entry.configure(font=FONTSIZE, justify=RIGHT)

#widgets for buttons
btnConvert = Button(frmButton, text='Convert', command=evConvert, width=7, font = FONTSIZE)
btnReset = Button(frmButton, text='Reset', command=evResetClick, width=7, font = FONTSIZE)
btnHelp = Button(frmButton, text='Help', command=evHelp, width=7, font = FONTSIZE)
btnQuit = Button(frmButton, text='Quit', command=evQuit, width=7, font = FONTSIZE)

# pack the widgets
frmTop.pack(fill=BOTH, expand=1)
frmDirection.pack(fill=BOTH, expand=1, padx=10, pady=10)
frmInput.pack(fill=BOTH, expand=1, padx=10)
frmOutput.pack(fill=BOTH, expand=1, padx=10, pady=10)
frmButton.pack(fill=BOTH, expand=1, padx=5)
# direction
radUnicode.pack(anchor=W, padx=10)
radLegacy.pack(anchor=W, padx=10)
# input
frmInputSub.pack(anchor=W, fill=X, expand=1, padx=10, pady=5)
lblInput.pack(side=LEFT, anchor=W)
fntInput.pack(side=LEFT, anchor=W, fill=X, expand=1)
cmbDocType.pack(anchor=E, padx=10, pady=5)
cmbFontInput.pack(anchor=E, padx=10, pady=5)
cmbEncoding.pack(anchor=E, padx=10, pady=5)
# output
frmOutputSub.pack(anchor=W, fill=X, expand=1, padx=10, pady=5)
lblOutput.pack(side=LEFT, anchor=W)
fntOutput.pack(side=LEFT, anchor=W, fill=X, expand=1)
cmbFontOutput.pack(anchor=E, padx=10, pady=5)
frmSize.pack(side=RIGHT, padx=10, pady=5)
chkSize.pack(side=LEFT, anchor=E, padx=10, pady=5)
spnSize.pack(side=LEFT, anchor=E)
# buttons
btnConvert.pack(side=LEFT, padx=5, anchor=NW)
btnReset.pack(side=LEFT, padx=5, anchor=NW)
btnHelp.pack(side=LEFT, padx=5, anchor=NW)
btnQuit.pack(side=LEFT, padx=5, anchor=NW)

# set value for all combo box
fd = FontDataXML.FontData()
legacyFontList = []
for font in fd.listFontTypes():
    legacyFontList.append(font)
    for fontName in fd.listFontNamesForType(font):
        legacyFontList.append("  " + fontName)

unicodeFontList = ['Khmer OS', 'Khmer OS Bokor', 'Khmer OS Battambang', 'Khmer OS Content', 'Khmer OS Fasthand', 'Khmer OS Freehand','Khmer OS Metal Chrieng', 'Khmer OS Muol', 'Khmer OS Muol Light', 'Khmer OS Muol Pali', 'Khmer OS SiemReap', 'Khmer OS System']
encodingList = fd.listEncodingTypes()
documentList = [TYPETEXT, TYPEODT, TYPEHTML]

for font in legacyFontList:
    cmbFontInput.insert(END, font)
for font in unicodeFontList:
    cmbFontOutput.insert(END, font)
for encoding in encodingList:
    cmbEncoding.insert(END, encoding)
for documenttype in documentList:
    cmbDocType.insert(END, documenttype)

# get index for abc-zwsp
INDEXABCZWSP = 0
for i in range(len(legacyFontList)):
    if (legacyFontList[i] == 'abc-zwsp'):
        INDEXABCZWSP = i
        break

# get index for khmer os
INDEXKHMEROS = 0
for i in range(len(unicodeFontList)):
    if (unicodeFontList[i] == 'Khmer OS'):
        INDEXKHMEROS = i
        break

evResetClick()

# set the loop running
top.mainloop()