1 ##############################################################################
3 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
34 class selection(wid_int
.wid_int
):
35 def __init__(self
, name
, parent
, attrs
={}):
36 wid_int
.wid_int
.__init
__(self
, name
, parent
, attrs
)
38 self
.widget
= gtk
.combo_box_entry_new_text()
39 self
.widget
.child
.set_editable(True)
40 self
.widget
.child
.connect('key_press_event', self
.sig_key_press
)
42 if 'selection' in attrs
:
43 self
.set_popdown(attrs
.get('selection',[]))
45 def set_popdown(self
, selection
):
46 self
.model
= self
.widget
.get_model()
50 for (i
,j
) in selection
:
55 self
._selection
[name
]=i
56 self
.widget
.append_text('')
58 self
.widget
.append_text(l
)
61 def sig_key_press(self
, widget
, event
):
62 completion
=gtk
.EntryCompletion()
63 completion
.set_inline_selection(True)
64 if (event
.type == gtk
.gdk
.KEY_PRESS
) \
65 and ((event
.state
& gtk
.gdk
.CONTROL_MASK
) != 0) \
66 and (event
.keyval
== gtk
.keysyms
.space
):
68 elif not (event
.keyval
==65362 or event
.keyval
==65364):
69 completion
.set_model(self
.model
)
70 widget
.set_completion(completion
)
71 completion
.set_text_column(0)
74 model
= self
.widget
.get_model()
75 index
= self
.widget
.get_active()
77 res
= self
._selection
.get(model
[index
][0], False)
79 return [(self
.name
,'=',res
)]
82 def _value_set(self
, value
):
85 for s
in self
._selection
:
86 if self
._selection
[s
]==value
:
87 self
.widget
.child
.set_text(s
)
90 self
.widget
.child
.set_text('')
92 value
= property(_value_get
, _value_set
, None,
93 'The content of the widget or ValueError if not valid')
95 def _readonly_set(self
, value
):
96 self
.widget
.set_sensitive(not value
)