'Layout the buttons to fit inside size.'

def __layout(self, size):

    mygeom = self.geometry()
    mygeom.setSize(size)
    (dx, dy, dw, dh) = self.getContentsMargins()
    mygeom.adjust(dx, dy, (- dw), (- dh))
    (dx, dy, dw, dh) = self.layout().getContentsMargins()
    mygeom.adjust(dx, dy, (- dw), (- dh))
    actions = self.actions()
    widgets = list(map(self.widgetForAction, actions))
    orientation = self.orientation()
    if (orientation == Qt.Horizontal):
        widgets = sorted(widgets, key=(lambda w: w.pos().x()))
    else:
        widgets = sorted(widgets, key=(lambda w: w.pos().y()))
    spacing = self.layout().spacing()
    uniform_layout_helper(widgets, mygeom, orientation, spacing=spacing)
