Rename folder ibusdaemon to daemon.
[platform/upstream/ibus.git] / daemon / lookuptable.py
1 # vim:set noet ts=4:
2 #
3 # ibus - The Input Bus
4 #
5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA  02111-1307  USA
21
22 import dbus
23
24 class Candidates (list):
25         SIGNATURE = "a(saau)"
26         def to_dbus_value (self):
27                 value = dbus.Array (signature = "(saau)")
28                 for text, attrs in self:
29                         value.append ((text, attrs.to_dbus_value ()), "(s%s)" % attrs.SIGNATURE)
30
31         def from_dbus_value (self):
32                 pass
33
34 class LookupTable:
35         SIGNATURE = "(ibia(saau))"
36
37         def __init__ (self, page_size = 5):
38                 self._page_size = page_size
39                 self._cursor_visible = False
40                 self._cursor_pos = 0
41                 self._candidates = []
42
43         def set_page_size (self, page_size):
44                 self._page_size = page_size
45
46         def get_page_size (self):
47                 return self._page_size
48
49         def show_cursor (self):
50                 self._cursor_visible = True
51
52         def hide_cursor (self):
53                 self._cursor_visible = False
54
55         def is_cursor_visible (self):
56                 return self._cursor_visible
57
58         def get_current_page_start (self):
59                 return (self._cursor_pos / self._page_size) * self._page_size
60
61         def set_cursor_pos (self, pos):
62                 self._current_pos = pos
63
64         def get_cursor_pos (self):
65                 return self._current_pos
66
67         def get_cursor_pos_in_current_page (self):
68                 return self._current_pos % self._page_size
69
70         def page_up (self):
71                 pass
72
73         def page_down (self):
74                 pass
75
76         def cursor_up (self):
77                 pass
78
79         def cursor_down (self):
80                 pass
81
82         def clear (self):
83                 self._candidates = []
84
85         def append_candidate (self, candidate, attrs = None):
86                 self._candidates.append ((candidates, attrs))
87
88         def get_candidate (self, index):
89                 return self._candidates[index]
90
91         def to_dbus_struct (self):
92                 pass
93
94         def from_dbus_struct (self, value):
95                 pass