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

19.4. ParamSlider.__init__(): Constructor

For internal widgets and their placement, see Section 19, “class ParamSlider: Scale widget for a color model parameter”.

huey
# - - -   P a r a m S l i d e r . _ _ i n i t _ _

    def __init__ ( self, parent, model, color, paramx, callback=None ):
        """Constructor for ParamSlider.
        """

First we call the parent constructor and store all the constructor's arguments.

huey
        #-- 1 --
        # [ parent  :=  parent with a new Frame widget added but
        #               not gridded
        #   self  :=  that Frame widget ]
        Frame.__init__ ( self, parent )

        #-- 2 --
        self.__model     =  model
        self.__color     =  color
        self.__paramx    =  paramx
        self.__callback  =  None

Create the two control variables. self.__scaleVar is for the Scale widget, so its values vary in the range [0,MAX_BYTE].

The second control variable, self.__topLabelVar, is for the Label widget that displays the parameter name. We can't create this Label using the normal text= parameter, because it can change any time the model is changed.

For example, if this is the third parameter of the RGB model, this Label would display “B”. The paramx value in that case would be 2 (since indices count from 0).

huey
        #-- 3 --
        # [ self.__topLabelVar  :=  a new StringVar control variable
        #       set to the (paramxth) parameter name of self.__model
        #   self.__scaleVar  :=  a new IntVar control variable ]
        paramLabel  =  self.__model.labelList[self.__paramx]
        self.__topLabelVar  =  StringVar()
        self.__topLabelVar.set ( paramLabel )
        self.__scaleVar  =  IntVar()

Now we're ready to create the widgets; see Section 19.5, “ParamSlider.__createWidgets().

huey
        #-- 4 --
        # [ self  :=  self with all internal widgets created and
        #             gridded ]
        self.__createWidgets()

        #-- 5 --
        self.__callback  =  callback