Next / Previous / Contents / Shipman's homepage

8. PageTurner.__createWidgets(): Place internal widgets

This method creates and grids all the widgets inside a PageTurner. Its steps mirror the three major components: the controls (self.__buttonFrame), the heading frame (self.headFrame), and the body frame (self.bodyFrame).

pageturner.py
# - - -   P a g e T u r n e r . _ _ c r e a t e W i d g e t s   - - -

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

          [ self.__size is as invariant ->
              self  :=  self with all widgets created ]
        """

The .__buttonFrame is gridded with sticky=E+W so that it will be stretched across the full width of the PageTurner. This will allow us to place the Next page button at the top right corner.

pageturner.py
        #-- 1 --
        # [ self  :=  self with a new Frame added and gridded
        #             containing self's control widgets ]
        self.__buttonFrame  =  self.__createButtons()
        rowx  =  0
        self.__buttonFrame.grid ( row=rowx, column=0,
            columnspan=99, sticky=E+W )

Next we add empty frames for the heading and for the content page display area.

pageturner.py
        #-- 2 --
        # [ self            :=  self with a new, empty Frame added
        #                       and gridded
        #   self.headFrame  :=  that Frame ]
        self.headFrame  =  Frame ( self )
        rowx  +=  1
        self.headFrame.grid ( row=rowx, sticky=W )

        #-- 3 --
        # [ self            :=  self with a new, empty Frame added
        #                       and gridded
        #   self.bodyFrame  :=  that Frame ]
        self.bodyFrame  =  Frame ( self, relief=SUNKEN,
                                   borderwidth=2 )
        rowx  +=  1
        self.bodyFrame.grid ( row=rowx, sticky=W )

One obscure operation remains. In general, the .grid() geometry manager allows all widgets to resize dynamically to fit their contents. However, if the user has provided a size argument to the constructor, they want the self.bodyFrame to be fixed in size. To do this, it is necessary to disable “propagation” of internal dimensions to the containing widget. This is done by calling the .grid_propagate() method.

pageturner.py
        #-- 4 --
        # [ if self.__size is not None ->
        #     self.bodyFrame  :=  self.bodyFrame fixed as size
        #                         self.__size
        #   else -> I ]
        if  self.__size:
            self.bodyFrame['width']   =  self.__size[0]
            self.bodyFrame['height']  =  self.__size[1]
            self.bodyFrame.grid_propagate(0)