2016-09-22 7 views
0

Я создал раскрывающийся список, используя wxcomboctrl.wxWidgets - как добавить полосы прокрутки в ListBox, созданные с помощью виджета comboctrl в wxpython

self.Worker = wx.combo.ComboCtrl(self, -1, size=(250, -1), style=wx.CB_DROPDOWN) 
self.testWorkloadComboCtrl = self.ListCtrlComboPopup() 
self.worker.SetPopupControl(self.workerComboCtrl) 


class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup): 

    def __init__(self): 
     self.PostCreate(wx.PreListCtrl()) 

     # Also init the ComboPopup base class. 
     wx.combo.ComboPopup.__init__(self) 


    def AddItem(self, txt): 
     for t in txt: 
      self.InsertStringItem(self.GetItemCount(), t) 


    def OnMotion(self, evt): 

     item, flags = self.HitTest(evt.GetPosition()) 
     if item >= 0: 
      self.Select(item) 
      self.curitem = item 


    def OnLeftDown(self, evt): 

     self.value = self.curitem 
     self.Dismiss() 


    # The following methods are those that are overridable from the 
    # ComboPopup base class. 

    def Init(self): 
     """ This is called immediately after construction finishes. You can 
     use self.GetCombo if needed to get to the ComboCtrl instance. """ 

     self.value = -1 
     self.curitem = -1 


    def Create(self, parent): 
     """ Create the popup child control. Return True for success. """ 

     wx.ListCtrl.Create(self, parent, 
         style=wx.LC_LIST|wx.LC_SINGLE_SEL|wx.SIMPLE_BORDER) 
     self.Bind(wx.EVT_MOTION, self.OnMotion) 
     self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) 

     return True 


    def GetControl(self): 
     """ Return the widget that is to be used for the popup. """ 

     return self 

    def SetStringValue(self, val): 
     """ Called just prior to displaying the popup, you can use it to 
    'select' the current item. """ 

     idx = self.FindItem(-1, val) 

     if idx != wx.NOT_FOUND: 
      self.Select(idx) 


    def GetStringValue(self): 
     """ Return a string representation of the current item. """ 

     if self.value >= 0: 
      return self.GetItemText(self.value) 

     return "" 


    def OnPopup(self): 
     """ Called immediately after the popup is shown. """ 

     wx.combo.ComboPopup.OnPopup(self) 


    def OnDismiss(self): 
     " Called when popup is dismissed. """ 

     wx.combo.ComboPopup.OnDismiss(self) 

Выпадающий список, отображающий элементы, такие как 2 или 3 столбца с горизонтальной полосой прокрутки.

Но я хочу отобразить один список элементов с горизонтальными и вертикальными полосами прокрутки.

Я искал свойства comboctrl, но до сих пор не понял о comboctrl.

Может ли кто-нибудь предложить мне об этом.

+0

Вы пробовали использовать wxFormBuilder https://sourceforge.net/projects/wxformbuilder/ – macroland

ответ

0

Попробуйте использовать стиль wx.LC_REPORT вместо wx.LC_LIST. Вам также понадобится создать столбец (колонки), как и любое другое использование wx.LC_REPORT в стиле wx.ListCtrls.

+0

спасибо за ответ. Я понятия не имею, как создать столбец с списком comboctrl pop up..Can вы скажите мне пример для одного список. – Nithya

+0

Когда вы создаете listctrl, вам нужно использовать 'AddColumn', как и вы, если бы вы использовали' wx.ListCtrl' самостоятельно без comboctrl. – RobinDunn