Next / Previous / Contents / TCC Help System / NM Tech homepage

14.4. PickList.__init__(): Constructor

First the constructor calls the parent constructor to make it into a Frame. Then it creates and grids the PickList widget.

huey
# - - -   P i c k L i s t . _ _ i n i t _ _

    def __init__ ( self, parent, callback=None ):
        """Constructor for the color name PickList."""
        #-- 1 --
        # [ parent  :=  parent with a new Frame added
        #   self    :=  that Frame ]
        Frame.__init__ ( self, parent )

Next we initialize the internal data structures.

huey
        #-- 2 --
        self.__colorList  =  []
        self.__nameList   =  []
        self.__colorMap   =  {}
        self.__callback   =  None

Now create and grid the sole widget. See Section 4.1, “Imports” for documentation on the ScrolledList widget.

huey
        #-- 3 --
        # [ self  :=  self with a new ScrolledList widget added
        #             and gridded
        #   self.__scrolledList  :=  that widget ]
        self.__scrolledList  =  ScrolledList ( self,
            width=self.NAME_WIDTH, height=self.NAME_LINES,
            callback=self.__pickHandler )
        self.__scrolledList.listbox["font"]  =  BUTTON_FONT
        self.__scrolledList.grid ( row=0, column=0 )

The logic that populates the widget with color names, and sets up the corresponding internal tables, is Section 14.5, “PickList.__addColors(): Populate the color list”.

huey
        #-- 4 --
        # [ self.__scrolledList  :=  self.__scrolledList populated
        #       with non-redundant color names from the standard
        #       file if found, defaulting to an internal color list
        #   self.__colorMap   +:=  as invariant
        #   self.__colorList  +:=  as invariant
        #   self.__nameList   +:=  as invariant ]
        self.__addColors()

Now that everything is set up, enable the callback mechanism.

huey
        #-- 5 --
        self.__callback   =  callback