Пример #1
0
        def _start_animation(self, state, start_position_x, start_position_y,
                             start_width, start_height, end_position_x,
                             end_position_y, end_width, end_height):
            self.clearMask()
            animation = data.QPropertyAnimation(self, b"geometry")
            animation.setEasingCurve(data.QEasingCurve.Linear)
            animation.setDuration(self.animation_duration)

            animation.setStartValue(
                functions.create_rect(
                    int(start_position_x),
                    int(start_position_y),
                    int(start_width),
                    int(start_height),
                ))
            animation.setEndValue(
                functions.create_rect(
                    int(end_position_x),
                    int(end_position_y),
                    int(end_width),
                    int(end_height),
                ))
            animation.setDirection(data.QAbstractAnimation.Forward)
            self.state = state
            animation.start()
            self.add_animation(animation)
            animation.stateChanged.connect(self.sig_animation_ended)
Пример #2
0
 def init_extra_button(self,
                       parent,
                       main_form,
                       input_extra_pixmap,
                       input_extra_function=None,
                       input_extra_function_text=""):
     #Store the parent and main form references
     self._parent = parent
     self.main_form = main_form
     #Initialize the extra button
     self.extra_button = data.QLabel(self)
     width = int(self.geometry().width() * self.extra_button_size_factor)
     height = int(self.geometry().height() * self.extra_button_size_factor)
     self.extra_button_position = functions.create_point(
         int(self.geometry().width() * 2 / 3 - width),
         int(self.geometry().height() * 1 / 4))
     rectangle = functions.create_rect(self.extra_button_position,
                                       functions.create_size(width, height))
     self.extra_button.setGeometry(rectangle)
     self.extra_button_stored_pixmap = input_extra_pixmap
     self.extra_button.setPixmap(input_extra_pixmap)
     self.extra_button.setScaledContents(True)
     #Store the function options
     self.extra_button_function = input_extra_function
     self.extra_button_function_text = input_extra_function_text
     #Set the extra button opacity to low
     self._set_extra_button_opacity(self.OPACITY_LOW)
     #Overridden the extra buttons events
     self.extra_button.mousePressEvent = self.extra_button_click
     self.extra_button.enterEvent = self.extra_button_enter_event
     self.extra_button.leaveEvent = self.extra_button_leave_event
Пример #3
0
 def resizeEvent(self, event):
     """Overridden resize event"""
     #Execute the superclass resize function
     super().resizeEvent(event)
     #Update the extra button geometry
     width = int(self.geometry().width() * self.extra_button_size_factor)
     height = int(self.geometry().height() * self.extra_button_size_factor)
     rectangle = functions.create_rect(self.extra_button_position,
                                       functions.create_size(width, height))
     self.extra_button.setGeometry(rectangle)
Пример #4
0
    def animate(self):
        def end(new_state, old_state, button):
            button.set_start_position()
            if new_state == data.QPropertyAnimation.Stopped:
                #                button.set_green()
                button.enable()
                button.add_to_queue("leave")
                if button.animating == False:
                    button.animate()

        animation_time = 300
        animation_delay = 20

        def _animate(animation):
            animation.start()

        for i, b in enumerate(self.buttons):
            b.raise_()
            animation = data.QPropertyAnimation(b, b"geometry")
            animation.setStartValue(
                functions.create_rect(int(b.starting_position[0]),
                                      int(b.starting_position[1]),
                                      int(b.geometry().width()),
                                      int(b.geometry().height())))
            animation.setEndValue(
                functions.create_rect(int(b.end_position[0]),
                                      int(b.end_position[1]),
                                      int(b.geometry().width()),
                                      int(b.geometry().height())))
            animation.stateChanged.connect(functools.partial(end, button=b))
            animation.setDuration(animation_time)
            animation_time += 5
            #            animation.setEasingCurve(data.QEasingCurve.InQuad)

            #            animation_timer = data.QTimer(self)
            #            animation_timer.setInterval(animation_delay)
            #            animation_delay += 5
            #            animation_timer.setSingleShot(True)
            #            animation_timer.timeout.connect(functools.partial(_animate, animation))
            #            animation_timer.start()

            animation.start()
            self.animations.append(animation)
Пример #5
0
 def center(self, size):
     """
     Center the settings GUI manipulator to the main form,
     according to the size parameter
     """
     x_offset = int((self.main_form.size().width() - size.width()) / 2)
     y_offset = int(
         (self.main_form.size().height() * 93 / 100 - size.height()) / 2)
     rectangle_top_left = functions.create_point(x_offset, y_offset)
     rectangle_size = size
     rectangle = functions.create_rect(rectangle_top_left, rectangle_size)
     self.setGeometry(rectangle)
Пример #6
0
 def scale(self, width_scale_factor=1, height_scale_factor=1):
     """Scale the size of the function wheel and all of its child widgets"""
     #Scale the function wheel form
     geo = self.geometry()
     new_width = int(geo.width() * width_scale_factor)
     new_height = int(geo.height() * height_scale_factor)
     rectangle = functions.create_rect(
         geo.topLeft(), functions.create_size(new_width, new_height))
     self.setGeometry(rectangle)
     #Scale all of the function wheel child widgets
     for button in self.children():
         geo = button.geometry()
         new_topLeft = functions.create_point(
             int(geo.topLeft().x() * width_scale_factor),
             int(geo.topLeft().y() * height_scale_factor))
         new_width = int(geo.width() * width_scale_factor)
         new_height = int(geo.height() * height_scale_factor)
         new_size = functions.create_size(new_width, new_height)
         rectangle = functions.create_rect(new_topLeft, new_size)
         button.setGeometry(rectangle)
     #Center to main form
     self.center(self.size())
Пример #7
0
 def __init__(self, parent=None, main_form=None, offset=(0, 0)):
     # Initialize the superclass
     super().__init__(parent)
     # Store the reference to the parent
     self.setParent(parent)
     # Store the reference to the main form
     self.main_form = main_form
     # Set default font
     self.setFont(data.get_current_font())
     # Store the painting offset
     self.offset = offset
     # Set the background color
     style_sheet = "background-color: transparent;"
     style_sheet += "border: 0 px;"
     self.setStyleSheet(style_sheet)
     # Set the groupbox size
     screen_resolution = data.application.desktop().screenGeometry()
     width, height = screen_resolution.width(), screen_resolution.height()
     self.setGeometry(functions.create_rect(0, 0, width, height))
Пример #8
0
 def __init__(self, parent, app_dir=""):
     """Initialization routine"""
     #Initialize superclass, from which the current class is inherited,
     #THIS MUST BE DONE SO THAT THE SUPERCLASS EXECUTES ITS __init__ !!!!!!
     super().__init__()
     #Setup the window
     self.setWindowTitle("About Ex.Co.")
     self.setWindowFlags(data.Qt.WindowStaysOnTopHint)
     #Setup the picture
     exco_picture = data.QPixmap(data.about_image)
     self.picture = data.QLabel(self)
     self.picture.setPixmap(exco_picture)
     self.picture.setGeometry(self.frameGeometry())
     self.picture.setScaledContents(True)
     #Assign events
     self.picture.mousePressEvent = self._close
     self.picture.mouseDoubleClickEvent = self._close
     #Initialize layout
     self.layout = data.QGridLayout()
     self.layout.addWidget(self.picture)
     self.layout.setSpacing(0)
     self.layout.setContentsMargins(data.QMargins(0, 0, 0, 0))
     self.setLayout(self.layout)
     #Set the log window icon
     if os.path.isfile(data.application_icon) == True:
         self.setWindowIcon(data.QIcon(data.application_icon))
     #Save the info window geometry, the values were gotten by showing a dialog with the label containing
     #the ExCo info image with the size set to (50, 50), so it would automatically resize to the label image size
     my_width = 610
     my_height = 620
     #Set the info window position
     parent_left = parent.geometry().left()
     parent_top = parent.geometry().top()
     parent_width = parent.geometry().width()
     parent_height = parent.geometry().height()
     my_left = parent_left + (parent_width / 2) - (my_width / 2)
     my_top = parent_top + (parent_height / 2) - (my_height / 2)
     self.setGeometry(
         functions.create_rect(my_left, my_top, my_width, my_height))
     self.setFixedSize(my_width, my_height)
Пример #9
0
    def init_layout(self, text, dialog_type):
        # Setup the image
        # First create the background image using the hex builder
        back_image = data.QImage(functions.create_size(246, 211),
                                 data.QImage.Format_ARGB32_Premultiplied)
        back_image.fill(data.Qt.transparent)
        painter = data.QPainter(back_image)
        painter.setRenderHints(data.QPainter.Antialiasing
                               | data.QPainter.TextAntialiasing
                               | data.QPainter.SmoothPixmapTransform)
        hex_builder = components.HexBuilder(
            painter,
            (123, 28),
            30,
            1.0,
            fill_color=data.theme.YesNoDialog_Background,
            line_width=3,
            line_color=data.theme.YesNoDialog_Edge,
        )
        hex_builder.create_grid(
            False,
            2,
            2,
            3,
            4,
            0,
            5,
            3,
            (3, True),
            5,
            0,
            0,
            4,
            3  # OkDialog
        )
        painter.end()
        original_dialog_image = data.QPixmap.fromImage(back_image)

        # Now add the images according to the type of dialog
        dialog_image = original_dialog_image.scaled(
            original_dialog_image.size() * self.scale,
            transformMode=data.Qt.SmoothTransformation)
        self.image = data.QLabel(self)
        self.image.setPixmap(dialog_image)
        self.image.setGeometry(
            0,
            0,
            int(dialog_image.rect().width() * self.scale),
            int(dialog_image.rect().height() * self.scale),
        )
        self.image.setScaledContents(True)
        # Set the dialog mask to match the image mask
        self.setMask(dialog_image.mask())
        # Setup the image behind the label
        if dialog_type != None:
            if dialog_type == "question":
                type_pixmap = data.QPixmap(
                    os.path.join(data.resources_directory,
                                 "various/dialog-question.png"))
            elif dialog_type == "warning":
                type_pixmap = data.QPixmap(
                    os.path.join(data.resources_directory,
                                 "various/dialog-warning.png"))
            elif dialog_type == "error":
                type_pixmap = data.QPixmap(
                    os.path.join(data.resources_directory,
                                 "various/dialog-error.png"))
            else:
                raise Exception("Wrong dialog type!")
            image = data.QImage(type_pixmap.size(),
                                data.QImage.Format_ARGB32_Premultiplied)
            image.fill(data.Qt.transparent)
            painter = data.QPainter(image)
            painter.setOpacity(0.2)
            painter.drawPixmap(0, 0, type_pixmap)
            painter.end()
            type_pixmap = data.QPixmap.fromImage(image)
            type_pixmap = type_pixmap.scaled(
                type_pixmap.size() * 2.0 * self.scale,
                transformMode=data.Qt.SmoothTransformation)
            self.type_label = data.QLabel(self)
            self.type_label.setPixmap(type_pixmap)
            type_label_rect = functions.create_rect(
                (self.image.rect().width() - type_pixmap.rect().width()) / 2 *
                self.scale,
                (self.image.rect().height() - type_pixmap.rect().height()) /
                2 * self.scale,
                type_pixmap.rect().width() * self.scale,
                type_pixmap.rect().height() * self.scale,
            )
            self.type_label.setGeometry(type_label_rect)
        # Setup the text label
        self.text = text
        self.label = data.QLabel(self)
        self.label.setFont(
            data.QFont('Segoe UI', int(12 * self.scale), data.QFont.Bold))
        self.label.setWordWrap(True)
        self.label.setAlignment(data.Qt.AlignCenter)
        self.label.setStyleSheet('color: rgb({}, {}, {})'.format(
            data.theme.Font.Default.red(),
            data.theme.Font.Default.green(),
            data.theme.Font.Default.blue(),
        ))
        self.label.setText(text)
        width_diff = self.image.rect().width() - original_dialog_image.width()
        height_diff = self.image.rect().height(
        ) - original_dialog_image.height()
        x_offset = 20 * (self.scale - 1.0)
        y_offset = 60 * (self.scale - 1.0)
        label_rect = functions.create_rect(
            dialog_image.rect().x() + 20 + x_offset,
            dialog_image.rect().y() + 60 + y_offset,
            dialog_image.rect().width() - (40 * self.scale),
            dialog_image.rect().height() - (120 * self.scale),
        )
        self.label.setGeometry(label_rect)
        # Shrink text if needed
        for i in range(10):
            label_width = label_rect.width()
            label_height = label_rect.height()
            font_metrics = data.QFontMetrics(self.label.font())
            bounding_rectangle = font_metrics.boundingRect(
                functions.create_rect(0, 0, label_width, label_height),
                self.label.alignment() | data.Qt.TextWordWrap, text)
            if (bounding_rectangle.width() > label_width
                    or bounding_rectangle.height() > label_height):
                self.label.setFont(
                    data.QFont('Segoe UI', int((12 - i) * self.scale),
                               data.QFont.Bold))
            else:
                break
        # Setup the buttons
        self.button_no = self.Button(
            self, os.path.join(data.resources_directory,
                               "various/hex-red.png"), "OK",
            data.QMessageBox.No, self.scale)
        x_offset = 93 * (self.scale - 1.0)
        y_offset = 158 * (self.scale - 1.0)
        self.button_no.setGeometry(int(93 + x_offset), int(158 + y_offset),
                                   int(59 * self.scale), int(50 * self.scale))
        self.button_no.on_signal.connect(self.update_state_off)
        self.button_no.off_signal.connect(self.update_state_reset)
        # Setup the layout
        self.layout = data.QGridLayout()
        self.layout.setSpacing(0)
        self.layout.setContentsMargins(data.QMargins(0, 0, 0, 0))
        self.layout.addWidget(self.image)
        self.setLayout(self.layout)
        # Setup tranparency and borders
        if data.on_rpi == True:
            self.image.setStyleSheet("border:0;" + "background-color:white;")
        else:
            self.image.setAttribute(data.Qt.WA_TranslucentBackground)
            self.image.setStyleSheet("border:0;" +
                                     "background-color:transparent;")
        self.setAttribute(data.Qt.WA_TranslucentBackground)
        self.setStyleSheet("border:0;" + "background-color:transparent;")

        self.setGeometry(dialog_image.rect())
        self.center()
        self.setWindowFlags(data.Qt.FramelessWindowHint)
Пример #10
0
 def check_hit(self, p):
     r = create_rect(self.x, self.y, self.width, self.height)
     if check_point_rectangle(p[0], p[1], r):
         self.click()
Пример #11
0
 def set_position(self, x, y):
     self.setGeometry(
         functions.create_rect(int(x), int(y),
                               self.geometry().width(),
                               self.geometry().height()))