'Reshape the OpenGL viewport based on the size of the window'

def OnReshape(self):

    size = self.GetClientSize()
    (oldwidth, oldheight) = (self.width, self.height)
    (width, height) = (size.width, size.height)
    if ((width < 1) or (height < 1)):
        return
    self.width = max(float(width), 1.0)
    self.height = max(float(height), 1.0)
    self.OnInitGL(call_reshape=False)
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    if self.orthographic:
        glOrtho(((- width) / 2), (width / 2), ((- height) / 2), (height / 2), ((-5) * self.dist), (5 * self.dist))
    else:
        gluPerspective(60.0, (float(width) / height), 10.0, (3 * self.dist))
        glTranslatef(0, 0, (- self.dist))
    glMatrixMode(GL_MODELVIEW)
    if (not self.mview_initialized):
        self.reset_mview(0.9)
        self.mview_initialized = True
    elif ((oldwidth is not None) and (oldheight is not None)):
        wratio = (self.width / oldwidth)
        hratio = (self.height / oldheight)
        factor = min((wratio * self.zoomed_width), (hratio * self.zoomed_height))
        (x, y, _) = self.mouse_to_3d((self.width / 2), (self.height / 2))
        self.zoom(factor, (x, y))
        self.zoomed_width *= (wratio / factor)
        self.zoomed_height *= (hratio / factor)
    if self.GLinitialized:
        self.pygletcontext.set_current()
        self.update_object_resize()
