def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.defaultColor = self.GetBackgroundColour()
rows = [("Ford", "Taurus", "1996", "Blue"),
("Nissan", "370Z", "2010", "Green"),
("Porche", "911", "2009", "Red")
]
self.list_ctrl = wx.ListCtrl(self, style=wx.LC_REPORT)
self.list_ctrl.InsertColumn(0, "Make")
self.list_ctrl.InsertColumn(1, "Model")
self.list_ctrl.InsertColumn(2, "Year")
self.list_ctrl.InsertColumn(3, "Color")
index = 0
for row in rows:
self.list_ctrl.InsertStringItem(index, row[0])
self.list_ctrl.SetStringItem(index, 1, row[1])
self.list_ctrl.SetStringItem(index, 2, row[2])
self.list_ctrl.SetStringItem(index, 3, row[3])
if index % 2:
self.list_ctrl.SetItemBackgroundColour(index, "white")
else:
self.list_ctrl.SetItemBackgroundColour(index, "yellow")
index += 1
btn = wx.ToggleButton(self, label="Toggle Dark")
btn.Bind(wx.EVT_TOGGLEBUTTON, self.onToggleDark)
normalBtn = wx.Button(self, label="Test")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
sizer.Add(btn, 0, wx.ALL, 5)
sizer.Add(normalBtn, 0, wx.ALL, 5)
self.SetSizer(sizer)
python类ListCtrl()的实例源码
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None,
title="MvP ListCtrl Dark Mode Demo",
size=(400, 400))
panel = MyPanel(self)
self.Show()
def create_wxwindow(self):
return self.initfn(wx.ListCtrl)(self.parent, self.id, self.pos, self.size, self.style, self.validator, self.name)
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)
TextEditMixin.__init__(self)
CheckListCtrlMixin.__init__(self)
ListCtrlAutoWidthMixin.__init__(self)
ListRowHighlighter.__init__(self, color=MEDIUM_GREY, mode=1)
self.InsertColumn(0, '', width=24)
self.InsertColumn(1, 'MNEM', width=80)
self.InsertColumn(2, 'UNIT', width=80)
self.InsertColumn(3, 'DATA', width=160)
self.InsertColumn(4, 'DESC')
self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.on_begin_label_edit)
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)
TextEditMixin.__init__(self)
CheckListCtrlMixin.__init__(self)
ListCtrlAutoWidthMixin.__init__(self)
ListRowHighlighter.__init__(self, color=MEDIUM_GREY, mode=1)
self.InsertColumn(0, '', width=24)
self.InsertColumn(1, 'MNEM', width=80)
self.InsertColumn(2, 'UNIT', width=80)
self.InsertColumn(3, 'DATA', width=160)
self.InsertColumn(4, 'DESC')
self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.on_begin_label_edit)
def __init__(self):
global myWindow
wx.Frame.__init__(self, None, -1, "MQTT Protocol Trace", size=(600, 400))
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OpenDetails)
self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
self.statusBar = self.CreateStatusBar()
menubar = wx.MenuBar()
menu1 = wx.Menu()
clear = menu1.Append(wx.NewId(), "&Clear")
self.Bind(wx.EVT_MENU, self.OnClear, clear)
saveas = menu1.Append(wx.NewId(), "&Save as")
self.Bind(wx.EVT_MENU, self.OnSaveAs, saveas)
menubar.Append(menu1, "&File")
self.SetMenuBar(menubar)
for index, title in enumerate(cols):
self.list.InsertColumn(index, title)
self.list.SetColumnWidth(index, widths[index])
self.listitem = 0
listmix.ColumnSorterMixin.__init__(self, len(cols))
self.itemDataMap = {}
myWindow = self
self.thread = WorkerThread()
self.thread.start()
def __init__(self, parent):
wx.Dialog.__init__(self, parent, title="Lookup Table", style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
self.SetSizeHints(720,480,-1,-1)
self.parent = parent
self.Bind(wx.EVT_CLOSE, self.OnExit)
self.panelphase = parent.GetParent().GetPage(0)
self.panelvisual = self.GetParent()
self.actor_list3D = ["vtkOpenGLActor", "vtkActor", "vtkMesaActor"]
self.actor_list2D = ["vtkOpenGLImageActor", "vtkImageActor"]
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.hbox = wx.BoxSizer(wx.HORIZONTAL)
self.vbox1 = wx.BoxSizer(wx.VERTICAL)
self.vbox2 = wx.BoxSizer(wx.VERTICAL)
self.font = self.panelvisual.font
self.panels = []
self.listtitles = ["Real Amp","Real Phase", "Fourier Amp","Fourier Phase"]
self.list = wx.ListCtrl(self,wx.ID_ANY,style=wx.LC_REPORT|wx.LC_NO_HEADER|wx.LC_HRULES|wx.SUNKEN_BORDER, size=(200,-1))
self.list.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectListItem)
self.list.InsertColumn(0,'Settings', width = 200)
self.list.SetFont(self.font)
for i in range(len(self.listtitles)):
if IsNotWX4():
self.list.InsertStringItem(i,self.listtitles[i],i)
else:
self.list.InsertItem(i,self.listtitles[i],i)
self.list.SetItemFont(i, self.font)
self.panels.append(ColourDialog(self))
self.panels[-1].Hide()
self.panels[-1].Layout()
self.GetRadioChoice(i)
self.vbox2.Add(self.panels[-1], 1, wx.EXPAND)
self.vbox1.Add(self.list, 1, wx.EXPAND)
self.panel_hld = wx.StaticText(self, label='')
self.vbox2.Add(self.panel_hld, 1, wx.EXPAND)
self.hbox.Add(self.vbox1, 0, wx.EXPAND,2)
self.hbox.Add(self.vbox2, 1, wx.EXPAND,2)
self.sizer.Add(self.hbox, 1, wx.EXPAND,2)
self.button_update = wx.Button(self, label="Update Scale", size=(720, 30))
self.sizer.Add(self.button_update, 0, wx.EXPAND, 2)
self.Bind(wx.EVT_BUTTON, self.OnClickUpdate,self.button_update)
self.SetSizer(self.sizer)
self.Fit()
self.Layout()
self.Show()
def __init__(self, *args, **kwds):
# begin wxGlade: sampoorna_win.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.notebook_1 = wx.Notebook(self, wx.ID_ANY, style=0)
self.login_pane = wx.Panel(self.notebook_1, wx.ID_ANY)
self.panel_login = wx.Panel(self.login_pane, wx.ID_ANY)
self.label_1 = wx.StaticText(self.panel_login, wx.ID_ANY, _("Warning: Always backup your database before you proceed to avoid potential data loss !!!"))
self.label_2 = wx.StaticText(self.panel_login, wx.ID_ANY, _("This software does not save Sampoorna credentials. It is used for one time login"))
self.panel_1 = wx.Panel(self.panel_login, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
self.label_3 = wx.StaticText(self.panel_1, wx.ID_ANY, _("Sampoorna Username"))
self.text_ctrl_user = wx.TextCtrl(self.panel_1, wx.ID_ANY, "", style=wx.TE_PROCESS_ENTER | wx.NO_BORDER)
self.label_4 = wx.StaticText(self.panel_1, wx.ID_ANY, _("Sampoorna Password"))
self.text_ctrl_passw = wx.TextCtrl(self.panel_1, wx.ID_ANY, "", style=wx.TE_PROCESS_ENTER | wx.TE_PASSWORD | wx.NO_BORDER)
self.button_next = wx.Button(self.panel_login, wx.ID_ANY, _("Next >>"))
self.standard_pane = wx.Panel(self.notebook_1, wx.ID_ANY)
self.panel_3 = wx.Panel(self.standard_pane, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.RAISED_BORDER | wx.STATIC_BORDER | wx.TAB_TRAVERSAL)
self.checkbox_8 = wx.CheckBox(self.panel_3, wx.ID_ANY, _("8 Standard"))
self.checkbox_9 = wx.CheckBox(self.panel_3, wx.ID_ANY, _("9 Standard"))
self.checkbox_10 = wx.CheckBox(self.panel_3, wx.ID_ANY, _("10 Standard"))
self.button_previous = wx.Button(self.standard_pane, wx.ID_ANY, _("<<Previous"))
self.button_proceed = wx.Button(self.standard_pane, wx.ID_ANY, _("Proceed >>"))
self.report_pane = wx.Panel(self.notebook_1, wx.ID_ANY)
self.panel_2 = wx.Panel(self.report_pane, wx.ID_ANY)
self.label_7 = wx.StaticText(self.panel_2, wx.ID_ANY, _("Progress"))
self.progresss_total = wx.Gauge(self.panel_2, wx.ID_ANY, range=100)
self.progress_each = wx.Gauge(self.panel_2, wx.ID_ANY, range=100)
self.label_satus = wx.StaticText(self.panel_2, wx.ID_ANY, _("Status"))
self.list_ctrl_1 = wx.ListCtrl(self.panel_2, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_ALIGN_LEFT | wx.SUNKEN_BORDER | wx.NO_BORDER)
self.button_finished = wx.Button(self.panel_2, wx.ID_ANY, _("Finished"))
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_TEXT, self.on_user_pass_text, self.text_ctrl_passw)
self.Bind(wx.EVT_TEXT, self.on_user_pass_text, self.text_ctrl_user)
self.Bind(wx.EVT_BUTTON, self.on_next, self.button_next)
self.Bind(wx.EVT_CHECKBOX, self.on_check, self.checkbox_8)
self.Bind(wx.EVT_CHECKBOX, self.on_check, self.checkbox_9)
self.Bind(wx.EVT_CHECKBOX, self.on_check, self.checkbox_10)
self.Bind(wx.EVT_BUTTON, self.on_previous, self.button_previous)
self.Bind(wx.EVT_BUTTON, self.on_proceed, self.button_proceed)
self.Bind(wx.EVT_BUTTON, self.on_finished, self.button_finished)
# create a pubsub receiver
Publisher().subscribe(self.updateDisplay, "update")
# end wxGlade
def __init__(self, *args, **kwds):
# begin wxGlade: sampoorna_win.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Dialog.__init__(self, *args, **kwds)
self.notebook_1 = wx.Notebook(self, wx.ID_ANY, style=0)
self.login_pane = wx.Panel(self.notebook_1, wx.ID_ANY)
self.panel_login = wx.Panel(self.login_pane, wx.ID_ANY)
self.label_1 = wx.StaticText(self.panel_login, wx.ID_ANY, ("Warning: Always backup your database before you proceed to avoid potential data loss !!!"))
self.label_2 = wx.StaticText(self.panel_login, wx.ID_ANY, ("This software does not save Sampoorna credentials. It is used for one time login"))
self.panel_1 = wx.Panel(self.panel_login, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.RAISED_BORDER | wx.TAB_TRAVERSAL)
self.label_3 = wx.StaticText(self.panel_1, wx.ID_ANY, ("Sampoorna Username"))
self.text_ctrl_user = wx.TextCtrl(self.panel_1, wx.ID_ANY, "", style=wx.TE_PROCESS_ENTER | wx.NO_BORDER)
self.label_4 = wx.StaticText(self.panel_1, wx.ID_ANY, ("Sampoorna Password"))
self.text_ctrl_passw = wx.TextCtrl(self.panel_1, wx.ID_ANY, "", style=wx.TE_PROCESS_ENTER | wx.TE_PASSWORD | wx.NO_BORDER)
self.button_next = wx.Button(self.panel_login, wx.ID_ANY, ("Next >>"))
self.standard_pane = wx.Panel(self.notebook_1, wx.ID_ANY)
self.panel_3 = wx.Panel(self.standard_pane, wx.ID_ANY, style=wx.SUNKEN_BORDER | wx.RAISED_BORDER | wx.STATIC_BORDER | wx.TAB_TRAVERSAL)
self.checkbox_8 = wx.CheckBox(self.panel_3, wx.ID_ANY, ("8 Standard"))
self.checkbox_9 = wx.CheckBox(self.panel_3, wx.ID_ANY, ("9 Standard"))
self.checkbox_10 = wx.CheckBox(self.panel_3, wx.ID_ANY, ("10 Standard"))
self.button_previous = wx.Button(self.standard_pane, wx.ID_ANY, ("<<Previous"))
self.button_proceed = wx.Button(self.standard_pane, wx.ID_ANY, ("Proceed >>"))
self.report_pane = wx.Panel(self.notebook_1, wx.ID_ANY)
self.panel_2 = wx.Panel(self.report_pane, wx.ID_ANY)
self.label_7 = wx.StaticText(self.panel_2, wx.ID_ANY, ("Progress"))
self.progresss_total = wx.Gauge(self.panel_2, wx.ID_ANY, range=100)
self.label_progress_perc = wx.StaticText(self.panel_2, wx.ID_ANY, (""))
self.label_satus = wx.StaticText(self.panel_2, wx.ID_ANY, ("Status"))
#self.list_ctrl_1 = wx.ListCtrl(self.panel_2, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_ALIGN_LEFT | wx.SUNKEN_BORDER | wx.NO_BORDER)
self.text_ctrl_report = wx.TextCtrl(self.panel_2, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL | wx.NO_BORDER)
self.button_finished = wx.Button(self.panel_2, wx.ID_ANY, ("Abort"))
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_TEXT, self.on_user_pass_text, self.text_ctrl_passw)
self.Bind(wx.EVT_TEXT, self.on_user_pass_text, self.text_ctrl_user)
self.Bind(wx.EVT_BUTTON, self.on_next, self.button_next)
self.Bind(wx.EVT_CHECKBOX, self.on_check, self.checkbox_8)
self.Bind(wx.EVT_CHECKBOX, self.on_check, self.checkbox_9)
self.Bind(wx.EVT_CHECKBOX, self.on_check, self.checkbox_10)
self.Bind(wx.EVT_BUTTON, self.on_previous, self.button_previous)
self.Bind(wx.EVT_BUTTON, self.on_proceed, self.button_proceed)
self.Bind(wx.EVT_BUTTON, self.on_finished, self.button_finished)
# create a pubsub receiver
Publisher().subscribe(self.update_display, "update")
Publisher().subscribe(self.final_report, "report")
Publisher().subscribe(self.update_progress_bar, "progress_bar")
Publisher().subscribe(self.update_current_class, "change_class")
# end wxGlade
def __init__(self, parent, id):
wx.ListCtrl.__init__(self, parent, id,
style=wx.LC_REPORT)
files = os.listdir('.')
self.InsertColumn(0, 'Name')
self.InsertColumn(1, 'Ext')
self.InsertColumn(2, 'Size',
wx.LIST_FORMAT_RIGHT)
self.InsertColumn(3, 'Modified')
self.SetColumnWidth(0, 220)
self.SetColumnWidth(1, 70)
self.SetColumnWidth(2, 100)
self.SetColumnWidth(3, 420)
j = 0
for i in files:
(name, ext) = os.path.splitext(i)
size = os.path.getsize(i)
sec = os.path.getmtime(i)
self.InsertStringItem(j, "{}{}".format(name, ext))
self.SetStringItem(j, 1, ext)
self.SetStringItem(j, 2, str(size) + ' B')
self.SetStringItem(
j, 3, time.strftime('%Y-%m-%d %H:%M',
time.localtime(sec)))
if os.path.isdir(i):
self.SetItemImage(j, 1)
elif 'py' in ext:
self.SetItemImage(j, 2)
elif 'jpg' in ext:
self.SetItemImage(j, 3)
elif 'pdf' in ext:
self.SetItemImage(j, 4)
else:
self.SetItemImage(j, 0)
if (j % 2) == 0:
self.SetItemBackgroundColour(j, 'light blue')
j = j + 1