mardi 29 décembre 2020

How to save selected input from a drop-down box with checkboxes? My drop-down box is okay but the checkboxes are not working

Hi, I am trying to run a GUI based on wx. I made checkboxes in a drop-down list. But the checkboxes are not working. I want the checkboxes to work and save the selected input option names somewhere. Here is the code. With these selected input option names (one or more than one) I will filter a big string later. Thank you in advance :)

import wx import wx.stc from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin

class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin): def init(self, parent): wx.ListCtrl.init(self, parent, wx.ID_ANY, style=wx.LC_REPORT | wx.SUNKEN_BORDER) CheckListCtrlMixin.init(self) ListCtrlAutoWidthMixin.init(self) self.SetSize(-1, -1, -1, 50)

def OnCheckItem(self, index, flag):
    item = self.GetItem(index)
    if flag:
        what = "checked"
    else:
        what = "unchecked"

    print(f'{item.GetText()} - {what}')

class ListViewComboPopup(wx.ComboPopup):

def __init__(self):
    wx.ComboPopup.__init__(self)
    self.lc = None

def AddItem(self, txt):
    self.lc.InsertItem(0, txt)


def Init(self):
    self.value = -1
    self.curitem = -1

def Create(self, parent):
    self.lc = CheckListCtrl(parent)
    self.lc.InsertColumn(0, '', width=90)
    return True

def GetControl(self):
    return self.lc

def OnPopup(self):
    wx.ComboPopup.OnPopup(self)

def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
    return wx.ComboPopup.GetAdjustedSize(
        self, minWidth, 110, maxHeight)

class MyForm(wx.Frame):

def __init__(self):
    wx.Frame.__init__(self, None, title="Popup Menu Tutorial")
    panel = wx.Panel(self)
    comboCtrl = wx.ComboCtrl(panel, wx.ID_ANY, "Select filter")    
    popupCtrl = ListViewComboPopup()
    comboCtrl.SetPopupControl(popupCtrl)
    popupCtrl.AddItem("mango")
    popupCtrl.AddItem("cat")
    popupCtrl.AddItem("dog")
    popupCtrl.AddItem("tiger")
    popupCtrl.AddItem("three")
    popupCtrl.AddItem("hat")
    popupCtrl.AddItem("hot")
    popupCtrl.AddItem("sweden")
    popupCtrl.AddItem("kth")



Aucun commentaire:

Enregistrer un commentaire