コード例 #1
0
class TestGroupObjectListView(TestObjectListView):
    def setUp(self):
        super(TestGroupObjectListView, self).setUp()

        panel = wx.Panel(self.frame, -1)
        self.objectListView = GroupListView(panel,
                                            -1,
                                            style=wx.LC_REPORT
                                            | wx.SUNKEN_BORDER)
        sizerPanel = wx.BoxSizer(wx.VERTICAL)
        sizerPanel.Add(self.objectListView, 1, wx.ALL | wx.EXPAND, 4)
        panel.SetSizer(sizerPanel)

        sizerFrame = wx.BoxSizer(wx.VERTICAL)
        sizerFrame.Add(panel, 1, wx.ALL | wx.EXPAND, 4)
        self.frame.SetSizer(sizerFrame)

        loadOLV(self.objectListView)

    #-------------------------------------------------------------------------
    # Override inherited tests

    def testBasicState(self):
        self.assertEqual(self.objectListView.GetColumnCount(),
                         len(personColumns) + 1)
        self.assertEqual(
            self.objectListView.GetItemCount(),
            len(persons) + len(self.objectListView.groups) * 2 - 1)

    def testSorting(self):
        # Sorting within a GroupListView is completely different from an
        # ObjectListView
        pass

    def testSelectAll(self):
        self.objectListView.SelectAll()
        for i in range(0, self.objectListView.GetItemCount()):
            if self.objectListView.GetObjectAt(i):
                self.assertTrue(self.objectListView.IsSelected(i))

    def testAlternateColours(self):
        # Not ever row has alternate colours -- only those for model objects
        self.objectListView.useAlternateBackColors = True
        self.objectListView.RepopulateList()
        for i in range(self.objectListView.GetItemCount()):
            if self.objectListView.GetObjectAt(i):
                if i & 1:
                    self.assertEqual(self.objectListView.oddRowsBackColor,
                                     self.getBackgroundColour(i))
                else:
                    self.assertEqual(self.objectListView.evenRowsBackColor,
                                     self.getBackgroundColour(i))

    def getBackgroundColour(self, i):
        # There is no direct way to get the background colour of an item in a virtual
        # list, so we have to cheat by approximating the process of building a
        # list item
        attr = self.objectListView.OnGetItemAttr(i)
        if attr is None or not attr.HasBackgroundColour():
            # this returns an invalid color
            return self.objectListView.GetItemBackgroundColour(i)
        else:
            return attr.GetBackgroundColour()