Hello,
I have made a special class that consists of a wxTextCtrl and a wxComboBox.
When Enter is pressed in the wxTextCtrl, the entries pf the wxComboBox which
do not match the text in the wxTextCtrl are removed. That works on windows.
I recently started to explore Suse linux 9.1 and have installed the RPM for
Redhat 9, wxPython version 2.5.3. The GTK libraries are those provided by
Suse. Unfortunately, the wx.EVT_TEXT_ENTER event that updates the wxComboBox
doesn´t seem to be processed correctly. Is this assumption correct, and if
so, is there a solution to this problem?
Thanks in advance, Piet
Here is a sample program:
#-*- coding: UTF-8 -*-
import wx
ID_BTN_ADDENTRY = 100
···
#__________________________________________________________
class TextFilterComboControl:
def __init__(self,parent):
self.parent = parent
self.COMBOBOX_ID = wx.NewId()
TEXTBOX_ID = wx.NewId()
self.TextCtrl = wx.TextCtrl(parent,TEXTBOX_ID,style=wx.TE_LINEWRAP)
self.TextCtrl.Bind(wx.EVT_TEXT_ENTER,self.OnTextChange,id=TEXTBOX_ID)
def OnTextChange(self,event):
self.ComboBox.Clear()
for item in self._list:
if item[0].lower().find(self.TextCtrl.GetValue().lower()) <> -1:
self.ComboBox.Append(item[0],item[1])
if self.ComboBox.__class__ == wx.ComboBox:
self.ComboBox.SetValue(item[0])
if self.ComboBox.__class__ == wx.ListBox:
self.ComboBox.SetStringSelection(item[0])
def SetList(self,liste):
self.ComboBox.Clear()
self._list = liste
for item in self._list:
self.ComboBox.Append(item[0],item[1])
def GetList(self):
return self._list
def SetComboBox(self,ComboBox,style):
self.ComboBox = ComboBox(self.parent,self.COMBOBOX_ID,style=style)
def GetComboBox(self):
return self.ComboBox
def GetTextCtrl(self):
return self.TextCtrl
#__________________________________________________________
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,id,title)
self.SetSize(wx.Size(400,400))
self.Panel = wx.Panel(self,-1)
self.Sizer = wx.BoxSizer(wx.HORIZONTAL)
self.SelectListe = [("Eins",1),("Zwei",2),("Drei",3)]
self.SelectControl = TextFilterComboControl(self.Panel)
self.SelectControl.SetComboBox(wx.ComboBox,style=wx.CB_READONLY|wx.CB_SORT)
self.SelectText = self.SelectControl.GetTextCtrl()
self.SelectComboBox = self.SelectControl.GetComboBox()
self.SelectControl.SetList(self.SelectListe)
self.addButton = wx.Button(self.Panel,ID_BTN_ADDENTRY,"Add Entry")
wx.EVT_BUTTON(self,ID_BTN_ADDENTRY,self.OnAddEntry)
self.Sizer.Add(self.SelectComboBox)
self.Sizer.Add(self.SelectText)
self.Sizer.Add(self.addButton)
self.Panel.SetSizer(self.Sizer)
self.Sizer.Fit(self.Panel)
def OnAddEntry(self,e):
self.AddEntry(self.SelectListe)
def AddEntry(self,listToAdd):
listToAdd.append(("Vier",4))
print str(listToAdd)
print str(self.SelectControl.GetList())
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "ComboTest")
frame.Show(True)
app.MainLoop()
--
DSL Komplett von GMX +++ Supergünstig und stressfrei einsteigen!
AKTION "Kein Einrichtungspreis" nutzen: http://www.gmx.net/de/go/dsl