comboentry in toolbar determines optimal width automatically
svn: r15840
This commit is contained in:
parent
e24b184508
commit
5d4246b0a7
@ -82,11 +82,19 @@ class ShortlistComboEntry(ValidatedComboEntry):
|
|||||||
|
|
||||||
# create the model and insert the items
|
# create the model and insert the items
|
||||||
model = gtk.ListStore(gtype, gobject.TYPE_BOOLEAN)
|
model = gtk.ListStore(gtype, gobject.TYPE_BOOLEAN)
|
||||||
|
maxlen = -1
|
||||||
for item in items:
|
for item in items:
|
||||||
|
if len(str(item)) > maxlen:
|
||||||
|
maxlen = len(str(item))
|
||||||
model.append((item, False))
|
model.append((item, False))
|
||||||
|
|
||||||
|
width = -1 #default width
|
||||||
|
if 1 < maxlen < 4:
|
||||||
|
width = 4
|
||||||
|
elif 1 < maxlen < 10:
|
||||||
|
width = maxlen + 1
|
||||||
ValidatedComboEntry.__init__(self, data_type, model,
|
ValidatedComboEntry.__init__(self, data_type, model,
|
||||||
COLUMN_ITEM, validator)
|
COLUMN_ITEM, validator, width=width)
|
||||||
if shortlist:
|
if shortlist:
|
||||||
self._shortlist = []
|
self._shortlist = []
|
||||||
self.connect("changed", self._on_combobox_changed)
|
self.connect("changed", self._on_combobox_changed)
|
||||||
|
@ -65,10 +65,11 @@ class ValidatedComboEntry(gtk.ComboBox, gtk.CellLayout):
|
|||||||
"""
|
"""
|
||||||
__gtype_name__ = "ValidatedComboEntry"
|
__gtype_name__ = "ValidatedComboEntry"
|
||||||
|
|
||||||
def __init__(self, datatype, model=None, column=-1, validator=None):
|
def __init__(self, datatype, model=None, column=-1, validator=None, width=-1):
|
||||||
gtk.ComboBox.__init__(self, model)
|
gtk.ComboBox.__init__(self, model)
|
||||||
|
|
||||||
self._entry = gtk.Entry()
|
self._entry = gtk.Entry()
|
||||||
|
self._entry.set_width_chars(width)
|
||||||
# <hack description="set the GTK_ENTRY(self._entry)->is_cell_renderer
|
# <hack description="set the GTK_ENTRY(self._entry)->is_cell_renderer
|
||||||
# flag to TRUE in order to tell the entry to fill its allocation.">
|
# flag to TRUE in order to tell the entry to fill its allocation.">
|
||||||
dummy_event = gtk.gdk.Event(gtk.gdk.NOTHING)
|
dummy_event = gtk.gdk.Event(gtk.gdk.NOTHING)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user