5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
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.
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.
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
24 class Candidates (list):
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
)
31 def from_dbus_value (self
):
35 SIGNATURE
= "(ibia(saau))"
37 def __init__ (self
, page_size
= 5):
38 self
._page
_size
= page_size
39 self
._cursor
_visible
= False
43 def set_page_size (self
, page_size
):
44 self
._page
_size
= page_size
46 def get_page_size (self
):
47 return self
._page
_size
49 def show_cursor (self
):
50 self
._cursor
_visible
= True
52 def hide_cursor (self
):
53 self
._cursor
_visible
= False
55 def is_cursor_visible (self
):
56 return self
._cursor
_visible
58 def get_current_page_start (self
):
59 return (self
._cursor
_pos
/ self
._page
_size
) * self
._page
_size
61 def set_cursor_pos (self
, pos
):
62 self
._current
_pos
= pos
64 def get_cursor_pos (self
):
65 return self
._current
_pos
67 def get_cursor_pos_in_current_page (self
):
68 return self
._current
_pos
% self
._page
_size
79 def cursor_down (self
):
85 def append_candidate (self
, candidate
, attrs
= None):
86 self
._candidates
.append ((candidates
, attrs
))
88 def get_candidate (self
, index
):
89 return self
._candidates
[index
]
91 def to_dbus_struct (self
):
94 def from_dbus_struct (self
, value
)