summaryrefslogtreecommitdiffstats
path: root/input-methods/ibus-sulekha/engine/keymap.py
blob: 8f049ca4c8077afcd8cd3a9d29cf095ea8e4977e (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
# -*- coding: utf-8 -*-
#
# Sulekha
#
# Copyright (c) 2009 Santhosh Thottingal <santhosh.thiotttingal@gmail.com>
#
#
# This library 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 of the License, or (at your option) any later version.
#
# This library 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA
import os
class Keymap:
	def __init__(self, map="inscript_ml_IN"):
		self. keymap_dict = self.load_key_map(map)

	def get_candidates(self,key):
		if self. keymap_dict == None :
			return None
		if self. keymap_dict.has_key(key) :
			value = self.keymap_dict[key]
			candidate_list=value.split(":")
			for candidate in candidate_list:
				candidate = candidate.replace("\"","");
				candidate_list[candidate_list.index(candidate)] = candidate
			return 	candidate_list
		else :
			return None
	def load_key_map(self, map):
		keymap_dict=dict()
		try:
			keymap_file = open("/usr/share/ibus-sulekha/engine/keymaps/"+map, 'r')
		except:
			print "Could not find keymaps/"+map + " file."
			return None
		while True:
			line =	 keymap_file .readline()
			if line == "":
				break
			line=line.strip()
			try:
				key = line.split("=")[0].strip()
				value = line.split("=")[1].strip()
				key = key.replace("\"","")
				value = value.replace("\"","")
				keymap_dict[key]=value
			except:
				continue
		return keymap_dict
if __name__ == '__main__':
	keymap=	Keymap("swanalekha_ml_IN")
	candidate_list= keymap.get_candidates("k")	
	for candidate in candidate_list:
		print candidate