Next / Previous / Contents / Shipman's homepage

5.7. ScrolledList.__clickHandler(): Event handler for button 1

This method is called when the user clicks mouse button 1 (usually the left button, but left-handers can set it up to be the right-hand button). If the user has provided a callback procedure, we will figure out which line of the listbox the user clicked on, and pass the number of that line to that callback.

scrolledlist.py
    def __clickHandler(self, event):
        """Called when the user clicks on a line in the listbox.
        """

If there is no callback, don't do anything.

scrolledlist.py
        #-- 1
        if  not self.callback:
            return

The event argument holds the screen y-coordinate of the mouse click in its .y attribute. The .nearest() method on the Listbox widget converts this coordinate into a line number.

scrolledlist.py
        #-- 2
        # [ call self.callback(c) where c is the line index
        #   corresponding to event.y ]
        lineNo = self.listbox.nearest(event.y)
        self.callback(lineNo)

So that the listbox will respond to the PageUp and PageDown keys, we move the keyboard focus to the listbox whenever a family is selected.

scrolledlist.py
        #-- 3
        self.listbox.focus_set()