What is icon mode

A list control looks like the display panel of a file tree system like MS Windows Explorer. The control displays a list of information in one of four different modes. The default is icon mode, where each element in the list is displayed as an icon with the text for the item below. Figure 13.1 displays a sample list in icon mode.

The code for figure 13.1 is displayed in listing 13.1. Note that listing 13.1 depends on some .png files being in the directory with this module. These files are available at the book's website for you to run this example.

Listing 13.1 Creating a sample list in icon mode import wx import sys, glob class DemoFrame(wx.Frame):

"wx.ListCtrl in wx.LC_ICON mode", size=(600,400))

il = wx.imageList(32,32, True) <— Creating an image list for name in glob.glob("icon??.png"):

bmp = wx.Bitmap(name, wx.BITMAP_TYPE_PNG)

tct-^ t , Creating the list widget self.list = wx.ListCtrl(self, -1 <1—1 6 6

style=wx.LC_ICON | wx.LC_AUTOARRANGE) self.list.AssignImageList(il, wx.IMAGE_LIST_NORMAL)

for x in range(25): ^ ^ Populating the list img = x % (il_max+1) 1 r °

self.list.InsertImageStringItem(x,

app = wx.PySimpleApp() frame = DemoFrame() frame.Show() app.MainLoop()

Figure 13.1

A sample list in icon mode

Figure 13.1

A sample list in icon mode

In listing 13.1, the demo frame creates an image list to hold references to the images to be displayed, then it builds and populates the list control. We'll discuss image lists later in this chapter.

Was this article helpful?

0 0

Post a comment