예제 #1
0
def SlideOffScreenTLWUpAndLeft(tlw):

    tlw_frame_rect = tlw.frameGeometry()

    tlw_top_left = tlw_frame_rect.topLeft()
    tlw_bottom_right = tlw_frame_rect.bottomRight()

    tlw_right = tlw_bottom_right.x()
    tlw_bottom = tlw_bottom_right.y()

    display_size = ClientGUIFunctions.GetDisplaySize(tlw)
    display_pos = ClientGUIFunctions.GetDisplayPosition(tlw)

    display_right = display_pos.x() + display_size.width(
    ) - CHILD_POSITION_PADDING
    display_bottom = display_pos.y() + display_size.height(
    ) - CHILD_POSITION_PADDING

    move_x = tlw_right > display_right
    move_y = tlw_bottom > display_bottom

    if move_x or move_y:

        delta_x = min(display_right - tlw_right, 0)
        delta_y = min(display_bottom - tlw_bottom, 0)

        delta_point = QC.QPoint(delta_x, delta_y)

        safe_pos = tlw_top_left + delta_point

        tlw.move(safe_pos)
    def SetInitialSize(self, size: QC.QSize):

        display_size = ClientGUIFunctions.GetDisplaySize(self)

        width = min(display_size.width(), size.width())
        height = min(display_size.height(), size.height())

        self.resize(QC.QSize(width, height))

        min_width = min(240, width)
        min_height = min(240, height)

        self.setMinimumSize(QC.QSize(min_width, min_height))
예제 #3
0
def GetSafeSize(tlw: QW.QWidget, min_size: QC.QSize, gravity) -> QC.QSize:

    min_width = min_size.width()
    min_height = min_size.height()

    frame_padding = tlw.frameGeometry().size() - tlw.size()

    parent = tlw.parentWidget()

    if parent is None:

        width = min_width
        height = min_height

    else:

        parent_window = parent.window()

        # when we initialise, we might not have a frame yet because we haven't done show() yet
        # so borrow main gui's
        if frame_padding.isEmpty():

            main_gui = HG.client_controller.gui

            if main_gui is not None and QP.isValid(
                    main_gui) and not main_gui.isFullScreen():

                frame_padding = main_gui.frameGeometry().size(
                ) - main_gui.size()

        if parent_window.isFullScreen():

            parent_available_size = parent_window.size()

        else:

            parent_frame_size = parent_window.frameGeometry().size()

            parent_available_size = parent_frame_size - frame_padding

        parent_available_width = parent_available_size.width()
        parent_available_height = parent_available_size.height()

        (width_gravity, height_gravity) = gravity

        if width_gravity == -1:

            width = min_width

        else:

            max_width = parent_available_width - (2 * CHILD_POSITION_PADDING)

            width = int(width_gravity * max_width)

        if height_gravity == -1:

            height = min_height

        else:

            max_height = parent_available_height - (2 * CHILD_POSITION_PADDING)

            height = int(height_gravity * max_height)

    display_size = ClientGUIFunctions.GetDisplaySize(tlw)

    display_available_size = display_size - frame_padding

    width = min(display_available_size.width() - 2 * CHILD_POSITION_PADDING,
                width)
    height = min(display_available_size.height() - 2 * CHILD_POSITION_PADDING,
                 height)

    return QC.QSize(width, height)