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

17.4. ModelSelector.__createWidgets()

For the list of internal widgets and the grid plan, see Section 17, “class ModelSelector: Widgets to select a color model”.

huey
# - - -   M o d e l S e l e c t o r . _ _ c r e a t e W i d g e t s

    def __createWidgets ( self ):
        """Create and grid all internal widgets.
        """

        #-- 1 --
        # [ self.__topLabel  :=  a Label labeling the radiobuttons ]
        self.__topLabel  =  Label ( self,
            font=BUTTON_FONT,
            text="Select a color model:" )
        rowx  =  0
        self.__topLabel.grid ( row=rowx, column=0, columnspan=3,
            sticky=W )

The radiobuttons can be arranged either horizontally or vertically. We chose horizontal under the assumption that space may be at a premium, and also because the labels for the color models are short (all are three letters). First we create the associated control variable, then we populate self.__radioList with Radiobutton widgets, each displaying the name from the corresponding model as its label.

huey
        #-- 2 --
        # [ self.__modelList is a list of ColorModel instances ->
        #     self  :=  self with one Radiobutton added and gridded for
        #         each element of self.__modelList, labeled with the
        #         model name of that element, and setting self.__radioVar
        #         to the position of that element in self.__modelList
        #     self.__radioList  +:=  those Radiobuttons in the
        #         same order ]
        rowx  +=  1
        colx  =   0
        for  radiox in range(len(self.__modelList)):
            #-- 2 body --
            # [ radiox is an index in self.__modelList ->
            #     self  :=  self with a new Radiobutton added and
            #         gridded, labeled with the model name from
            #         self.__modelList[radiox], and setting
            #         self.__radioVar to radiox ]
            model  =  self.__modelList[radiox]
            radio  =  Radiobutton ( self, font=BUTTON_FONT,
                command=self.__radioHandler,
                value=radiox, variable=self.__radioVar,
                text=model.modelName )
            radio.grid ( row=rowx, column=colx, sticky=W, padx=6 )
            colx  +=  1
            self.__radioList.append ( radio )