How do I get arrows in a wxPython Ultimate List Control to scroll correctly?

45 Views Asked by At

I've got an Ultimate List Control with two columns. If I select an item and the use the arrow keys, focus changes appropriately. If I use an arrow key to select an item that is above or below the area currently visible, the control does not scroll up or down as I would expect. Instead it throws the following error:

TypeError: _ScrolledWindowBase.Scroll(): arguments did not match any overloaded call:
  overload 1: argument 2 has unexpected type 'float'
  overload 2: argument 1 has unexpected type 'int'

(While we're here, if there's a way to get a column to accept ints and sort numerically, I'd be interested in knowing about it.)

I've looked at the documentation, and I have failed to find something I can apply. I don't have a good understanding (any understanding?) of how _ScrolledWindowBase.Scroll() is called. I'm entirely lost.

Here's the code for the Panel. Thanks!

###called from MainFrame parent
###displays monsters and CRs
###features View button to call MonsterDialog
class MainPanel(wx.Panel, listmix.ColumnSorterMixin):
    def __init__(self, parent):
        super().__init__(parent)
            ###create main and top sizers
            mainSizer = wx.BoxSizer(wx.VERTICAL)
            topSizer = wx.BoxSizer(wx.HORIZONTAL)
    
            ###create list control and add to sizer
            self.listCtrl = ULC.UltimateListCtrl(self, -1, agwStyle = ULC.ULC_REPORT )
            self.listCtrl.InsertColumn(0, "Monster")
            self.listCtrl.InsertColumn(1, "CR", width = 30)
            topSizer.Add(self.listCtrl, 1, wx.ALL | wx.EXPAND, 5)
    
            #self.listCtrl.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
    
            ###get monster data, populate list control, create monster dictionary
            self.monsterDict = {}
            index = 0
            self.monsterPath = os.getcwd()+'/monsters'
            self.refSheet = self.monsterPath + "/refSheet.txt"
            f = open(self.refSheet, "r")
            self.itemDataMap = {}
            for line in f.readlines():
                #(display, CR, monster)
                (d, c, m) = line.split(":")
                self.monsterDict[index] = [m.strip(), d]
                self.listCtrl.InsertStringItem(index, d)
                if len(c) == 1:
                    c = '0'+c
                    self.listCtrl.SetStringItem(index, 1, c)
                    self.itemDataMap[(d,c)] = [d,c]
                    self.listCtrl.SetItemData(index, (d,c))
                    index+=1
            f.close()
    
            ###set width of clumns and control
            self.listCtrl.SetColumnWidth(0, -1)
            self.listCtrl.SetColumnWidth(1, 50)
            _s = self.listCtrl
            _size = (sum([_s.GetColumnWidth(i) for i in range(_s.GetColumnCount())]), -1)
            self.listCtrl.SetMaxSize(_size)
            self.listCtrl.SetMinSize(_size)
            self.listCtrl.PostSizeEventToParent()
    
            ###make columns sortable
            listmix.ColumnSorterMixin.__init__(self, 2)
            self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.listCtrl)
            
            ###this is an empty widget for space to be replaced later
            empty = wx.TextCtrl(self, -1, size = _size)
            empty.SetMinSize(_size)
            empty.SetMaxSize(_size)
            topSizer.Add(empty, 1, wx.ALL | wx.EXPAND, 5)

            mainSizer.Add(topSizer, 1, wx.ALL | wx.CENTER, 0)

            ###create button to open dialog relevant to selected monster
            viewButton = wx.Button(self, label = 'View')
            viewButton.Bind(wx.EVT_BUTTON, self.onView)
            mainSizer.Add(viewButton, 0, wx.ALL | wx.CENTER, 5)
            self.SetSizer(mainSizer)

            ###window width = size of widgets + 10 per widget + 10 per sizer + 6 for window border
            winWidth = 36+_size[0]*2
            self.Parent.SetSize(-1, -1, winWidth, 250)
            self.Parent.SetMinSize((winWidth, -1))

    def onView(self, event):
        selection = self.listCtrl.GetFocusedItem()
        fileName = self.monsterDict[selection][0]
        filePath = self.monsterPath + '/' + fileName
        dlg = MonsterDialog(fileName, filePath)
        dlg.ShowModal()
        dlg.Destroy()

    def onViewTest(self, event):
        selection = self.listCtrl.GetFocusedItem()
        fileName = self.monsterDict[selection][0]
        filePath = self.monsterPath + '/' + fileName

    #def OnSetFocus(self, event):
    #   pass
    #   #print (self.listCtrl.GetFocusedItem())


    def GetListCtrl(self):
        return self.listCtrl

    def OnColClick(self, event):
        pass
1

There are 1 best solutions below

0
Joseph_the_Levi On

Including ULC.ULC_HAS_VARIABLE_ROW_HEIGHT in the agwStyle variable has resolved the issue. That line now reads:

self.listCtrl = ULC.UltimateListCtrl(self, -1, agwStyle = ULC.ULC_REPORT | ULC.ULC_HAS_VARIABLE_ROW_HEIGHT )