summaryrefslogtreecommitdiffstats
path: root/pychathans/chathans.py
blob: eab4c8d60926fb15eeb76dafd8e1d00611d2065f (plain)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# chathans.py
#       
# Copyright (c) 2009 Rajeesh K Nambiar <rajeeshknambiar@gmail.com>
# http://smc.org.in/
#       
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#       
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

import os
import sys
import string

try:
	import gtk
except ImportError:
	''' ചാത്തന്‍സിന് കള്‍സില്ലെന്നോ? '''
	print "Chathans requires PyGTK"
	raise SystemExit
	
try:
	from payyans import Payyans
except ImportError:
	''' ഹൈയ്, പയ്യന്റെ ദുര്‍ജ്ജനസംസര്‍ഗ്ഗമില്ലാതെ നോം സാധനം തൊടാറില്ല! '''
	print "Chathans require Payyans"
	raise SystemExit

name = "Chathans"
version = "0.2"
title = name + " " + version

class Chathans (gtk.Window):
	''' ചാത്തന്‍സ് അഥവാ സര്‍ ചാത്തു. വിക്ടോറിയാ രാജ്ഞിയില്‍ നിന്നും നേരിട്ട് പ്രഭുത്വം ! '''
	def __init__(self):
		self.AsciiFile 	 = None
		self.MappingFile = None
		self.UnicodeFile = None
		self.PdfFile	 = None
		self.__init_gui()
		
	def __init_gui(self):
		''' പൂമുഖം തുറന്ന്, ദര്‍ശനം നല്‍കാം... '''
		gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
		self.set_title(title)
		self.set_default_size(340, 160)
                self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
		self.connect("destroy", self.__quit)
		
		# ലേബലടിക്ക്.
		ascii_lbl   = gtk.Label("ASCII File : ")
		mapping_lbl = gtk.Label("Mapping File : ")
		unicode_lbl = gtk.Label("Unicode File : ")
		
		# പ്രമാണോം പത്രോം ആധാരോം എടുക്ക്വാ..
		ascii_btn   = gtk.FileChooserButton("Select the ASCII File (.txt,.pdf)")
		mapping_btn = gtk.FileChooserButton("Select the ASCII-Unicode Mapping File")
		unicode_btn = gtk.FileChooserButton("Select Output Unicode File")
		
		# മാപ്പ്, സാധാരണ എവിടെ കിട്ടും? അല്ല, എവിടെ കിട്ടും?
		mapping_dir = sys.prefix + "/share/payyans/maps/"
		mapping_btn.set_current_folder(mapping_dir)
		
		# Define the Actions. Lets get some action, baby!
		convert_btn = gtk.Button("Convert", gtk.STOCK_CONVERT)
		convert_btn.connect("clicked", self.__convert_file)
		cancel_btn = gtk.Button("Quit", gtk.STOCK_QUIT)
		cancel_btn.connect("clicked", self.__quit)
		about_btn = gtk.Button("About", gtk.STOCK_ABOUT)
		about_btn.connect("clicked", self.__show_about)
		
		# Add File Filter for ASCII input file. അരിപ്പ!
		ascii_filter = gtk.FileFilter()
		ascii_filter.set_name("*.txt,*.pdf")
		ascii_filter.add_pattern("*.[Tt][Xx][Tt]")
		ascii_filter.add_pattern("*.[Pp][Dd][Ff]")
		ascii_btn.add_filter(ascii_filter)
		
		self.ascii_btn   = ascii_btn
		self.mapping_btn = mapping_btn
		self.unicode_btn = unicode_btn
		
		# Pack the widgets. പാക്കു ചെയ്യ്, പാക്കു വെട്ട്.
		hbox1 = gtk.HBox()
		hbox1.set_border_width(4)
		hbox1.pack_start(ascii_lbl)
		hbox1.pack_end(ascii_btn)
		
		hbox2 = gtk.HBox()
		hbox2.set_border_width(4)
		hbox2.pack_start(mapping_lbl)
		hbox2.pack_end(mapping_btn)
		
		hbox3 = gtk.HBox()
		hbox3.set_border_width(4)
		hbox3.pack_start(unicode_lbl)
		hbox3.pack_end(unicode_btn)
					
		btn_box = gtk.HButtonBox()
		btn_box.set_border_width(4)
		btn_box.pack_start(convert_btn)
		btn_box.pack_start(about_btn)
		btn_box.pack_start(cancel_btn)
		
		vbox1 = gtk.VBox()
		vbox1.set_border_width(4)
		vbox1.pack_start(hbox1)
		vbox1.pack_start(hbox2)
		vbox1.pack_start(hbox3)
		vbox1.pack_end(btn_box)
		
		frame = gtk.Frame()
		frame.set_border_width(5)
		frame.add(vbox1)	
		self.add(frame)
		
		self.show_all()
		
	def __convert_file(self, event):
		''' പയ്യനെ വിളിക്ക്യാ, ഇനി നോം ഗ്യാലറിയിലിരുന്ന് കളി കാണട്ടെ. '''
		self.AsciiFile   = self.ascii_btn.get_filename()
		self.MappingFile = self.mapping_btn.get_filename()
		self.UnicodeFile = self.unicode_btn.get_filename()
		
		if (   self.AsciiFile 	== None
		   or  self.MappingFile == None ):
			   dlg = gtk.MessageDialog(self.get_toplevel(),
					gtk.DIALOG_MODAL,
					gtk.MESSAGE_INFO,
					gtk.BUTTONS_OK,
					"Please select both ASCII file and Mapping file")
			   dlg.run()
			   dlg.destroy()
			   return
			   
		if self.UnicodeFile == None:
			(inp_file, inp_ext) = os.path.splitext(self.AsciiFile)
			self.UnicodeFile = inp_file + "-unicode" + ".txt"
			   
		# ഓഹ്, പയ്യന്‍! നീ വ്യാഘ്രമാകുന്നു.
		payyan = Payyans(self.AsciiFile, self.UnicodeFile, self.MappingFile)
		payyan.ascii2unicode()
		# കത്തിച്ചു കഴിഞ്ഞു.
		msg = "Coversion Done - Unicode file :" + self.UnicodeFile
		dlg = gtk.MessageDialog(self.get_toplevel(),
					gtk.DIALOG_MODAL,
					gtk.MESSAGE_INFO,
					gtk.BUTTONS_OK,
					msg)
		dlg.run()
		dlg.destroy()
				
		return
		
	def __show_about(self, event):
		''' അധികപ്രസംഗം !!! '''
		dlg = gtk.AboutDialog()
		dlg.set_name(name)
		dlg.set_version(version)
		autxt1 = "Chathans frontend : Rajeesh K Nambiar <rajeeshknambiar@gmail.com>"
		autxt2 = "Payyans : Santhosh Thottingal, Nishan Naseer, Manu S Madhav"
		authors = ["\n" + autxt1 + "\n" + autxt2]
		dlg.set_authors(authors)
		dlg.set_copyright("Copyright (c) Rajeesh K Nambiar")
		dlg.set_license("Licensed under GNU GPL version 3")
		dlg.set_website("http://smc.org.in/Payyans")
		
		dlg.run()
		dlg.destroy()
		
	def __quit(self, event):
		''' ന്നാ, കട്ടേം പടോം മടക്കാം ! '''
		dlg = gtk.MessageDialog(self.get_toplevel(),
					gtk.DIALOG_MODAL,
					gtk.MESSAGE_QUESTION,
					gtk.BUTTONS_YES_NO,
					"Do you really want to Quit?")
		if ( dlg.run() == gtk.RESPONSE_YES ):
			dlg.destroy()
			gtk.main_quit()
		dlg.destroy()
		return
	

if __name__ == '__main__':
	chathans = Chathans()
	gtk.main()