0

Hello!
I am trying to set up a masked combobox using wx.lib.masked.combobox.BaseMaskedComboBox with autocompletion. However, I've found a couple of problems. On one hand, if I run the code as I provide it (code at the end of the post), I get an error caused by the 'Antigua and Bermuda' option on the Country combobox. This is the traceback:

Traceback (most recent call last):
  File "test.py", line 56, in <module>
    Query(None, -1)
  File "test.py", line 27, in __init__
    self.Country = wx.lib.masked.combobox.BaseMaskedComboBox(panel, -1,size=(200, -1), choices=countries)
  File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/lib/masked/combobox.py", line 97, in __init__
    MaskedEditMixin.__init__( self, name, **kwargs )
  File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/lib/masked/maskededit.py", line 1857, in __init__
    self.SetCtrlParameters(**kwargs)
  File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/lib/masked/maskededit.py", line 2012, in SetCtrlParameters
    self._validateChoices()
  File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/lib/masked/maskededit.py", line 2661, in _validateChoices
    raise ve
ValueError: "Antigua and Bermuda" could not be entered into field -1 of control "maskedComboBox"

Then, if I remove this choice, I can run the code. However, it doesn't autocomplete when I start typing the name in the country combobox. Can anyone help?
Cheers!

Dani

#! /usr/bin/env python
# TestDialogs.py
 
import wx, MySQLdb, wx.lib.intctrl, wx.grid, time, datetime, wx.lib.masked.maskededit
ID_SPECIES=1
 
class Query(wx.Frame):
	def __init__(self, parent, id, title = 'Query'):
		wx.Frame.__init__(self, parent, id, title, size=(900,650))
#Define main panel
		panel = wx.Panel(self, -1)
		vbox = wx.BoxSizer(wx.VERTICAL)
	#Define sizers
		#Horizontal sizers
		hbox1 = wx.BoxSizer(wx.HORIZONTAL)
		hbox2 = wx.BoxSizer(wx.HORIZONTAL)
		hbox3 = wx.BoxSizer(wx.HORIZONTAL)
		hbox2 = wx.BoxSizer(wx.HORIZONTAL)
		btnSizer = wx.BoxSizer(wx.HORIZONTAL)
		DateTXT = 	wx.StaticText(panel, -1, 'Select range of dates to filter:', size=(200, -1))
		self.dpc1 = wx.DatePickerCtrl(panel, -1, size=(110, -1), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
		self.dpc2 = wx.DatePickerCtrl(panel, -1, size=(110, -1), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
		CountriesTXT = wx.StaticText(panel, -1, 'Country:', size=(55, -1))
		countries = ['Spain', 'France', 'Italy', 'Great Britain', 'Antigua and Bermuda']
		regions = ['1', '2', '3']
		places = ['1', '2', '3']
		self.Country = wx.lib.masked.combobox.BaseMaskedComboBox(panel, -1,size=(200, -1), choices=countries)
		RegionTXT = wx.StaticText(panel, -1,size=(55, -1),label='Region: ')
		self.Region = wx.lib.masked.combobox.BaseMaskedComboBox(panel, -1,size=(200, -1), choices=regions)
		PlaceTXT = wx.StaticText(panel, -1,size=(55, -1),label='Place: ')
		self.Place = wx.lib.masked.combobox.BaseMaskedComboBox(panel, -1,size=(200, -1), choices=places)
		SubmitQueryBtn = wx.Button(panel, id=wx.ID_OK,label='Submit')
		hbox1.Add(DateTXT, 0, wx.ALL, 5)
		hbox2.Add(self.dpc1, 0, wx.ALL, 5)
		hbox2.Add(self.dpc2, 0, wx.ALL, 5)
		hbox3.Add(CountriesTXT, 0, wx.ALL, 5)
		hbox3.Add(self.Country, 0, wx.ALL, 5)
		hbox3.Add(RegionTXT, 0, wx.ALL, 5)
		hbox3.Add(self.Region, 0, wx.ALL, 5)
		hbox3.Add(PlaceTXT, 0, wx.ALL, 5)
		hbox3.Add(self.Place, 0, wx.ALL, 5)
		btnSizer.Add(SubmitQueryBtn, 0, wx.ALL, 5)
		vbox.Add(hbox1, 0, wx.ALIGN_LEFT | wx.ALL, 5)
		vbox.Add(hbox2, 0, wx.ALIGN_LEFT | wx.ALL, 5)
		vbox.Add(hbox3, 0, wx.ALIGN_LEFT | wx.ALL, 5)
		vbox.Add(btnSizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
		panel.SetSizer(vbox)
		self.Centre()
		self.Show(True)

app = wx.App()
Query(None, -1)
app.MainLoop()

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by acrocephalus
0

I solved the auto-complete issue by passing the autoSelect = True argument to the control. However, I haven't been able to solve the error given when keeping a long string in the choices ("Antigua and Bermuda" in the provided example). I have tried using wx.lib.masked.ComboBox instead of wx.lib.masked.combobox.BaseMaskedComboBox without luck. Can anyone help?
Cheers!

Dani

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.