Exemplo n.º 1
0
 def set_image(self, image):
     raw_picture = data.QPixmap(
         os.path.join(
             data.resources_directory, image
         )
     )
     picture = raw_picture.scaled(16, 16, data.Qt.KeepAspectRatio)
     self.setPixmap(picture)
Exemplo n.º 2
0
    def _init_background(self):
        sgm_picture = data.QPixmap(
            SettingsGuiManipulator.create_background_image(self.scale_factor))
        self.picture = data.QLabel(self)
        self.picture.setPixmap(sgm_picture)
        self.picture.setScaledContents(True)
        self.layout = data.QGridLayout()
        self.layout.setSpacing(0)
        self.layout.setContentsMargins(data.QMargins(10, 10, 10, 10))
        self.layout.addWidget(self.picture)
        self.setLayout(self.layout)

        self.setStyleSheet("background-color:transparent;")
        self.setStyleSheet("border:0;")
Exemplo n.º 3
0
 def __init__(self, parent, image, text, return_code, scale=1.0):
     # Initialize superclass
     super().__init__(parent)
     # Set the on/off images
     self.pixmap = data.QPixmap(image)
     self.scale = scale
     if scale != 1.0:
         self.pixmap = self.pixmap.scaled(
             self.pixmap.size() * scale,
             transformMode=data.Qt.SmoothTransformation)
     # Set the text and return code
     self.text = text
     self.return_code = return_code
     # Enable mouse move events
     self.setMouseTracking(True)
     self.setScaledContents(True)
     # Disable the button on startup
     self.off()
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def __init__(self, 
                 parent, 
                 main_form,
                 input_pixmap, 
                 input_function=None, 
                 input_function_text="", 
                 input_font=data.QFont(
                 'Courier', 14, weight=data.QFont.Bold
                 ), 
                 input_focus_last_widget=data.HexButtonFocus.NONE, 
                 input_no_tab_focus_disable=False, 
                 input_no_document_focus_disable=True, 
                 input_check_last_tab_type=False, 
                 input_check_text_differ=False, 
                 input_tool_tip=None,
                 input_scale=(1, 1)):
        #Initialize superclass
        super().__init__(parent)
        #Store the reference to the parent
        self._parent = parent
        #Store the reference to the main form
        self.main_form = main_form
        #Store the reference to the group box that holds the parent
        #(the parent of the parent)
        self.group_box_parent = parent.parent
        #Store the main function image
        self.stored_pixmap = input_pixmap
        #Store the hex edge image
        self.stored_hex = data.QPixmap(
            os.path.join(
                data.resources_directory, 
                "various/hex-button-edge.png"
            )
        )
        #Store the function that will be executed on the click event
        self.function = input_function
        #Store the function text
        self.function_text = input_function_text
        #Set the attribute that will be check if focus update is needed
        #when the custom button executes its function
        self.focus_last_widget = input_focus_last_widget
        #Set the attribute that checks if any tab is focused
        self.no_tab_focus_disable = input_no_tab_focus_disable
        #Set the attribute that will be check if button will be disabled
        #if there is no focused document tab
        self.no_document_focus_disable = input_no_document_focus_disable
        #Set checking the save state stored in the main form
        self.check_last_tab_type = input_check_last_tab_type
        #Set checking for if the focused tab is a text differer
        self.check_text_differ = input_check_text_differ
        #Set the font that will be used with the button
        self.stored_font = input_font
        #Enable mouse move events
        self.setMouseTracking(True)
        #Set the image for displaying
#        self.setPixmap(input_pixmap)
#        #Image should scale to the button size
#        self.setScaledContents(True)
#        # Set the button mask, which sets the button area to the shape of
#        # the button image instead of a rectangle
#        self.setMask(self.stored_hex.mask())
#        #Set the initial opacity to low
#        self._set_opacity_with_hex_edge(self.OPACITY_LOW)
        #Set the tooltip if it was set
        if input_tool_tip != None:
            self.setToolTip(input_tool_tip)
        # Set the scaling
        self.scale = input_scale
Exemplo n.º 7
0
        def __init__(self,
                     name,
                     picture,
                     scale_factor=1.0,
                     function=None,
                     key_combination=None,
                     starting_position=None,
                     end_position=None,
                     parent=None):
            super().__init__(parent)

            self.name = name
            self.scale_factor = scale_factor
            self.key_combination = key_combination
            self.animating = False
            self.starting_position = starting_position
            self.end_position = end_position
            self.disable()
            self.properties = {}
            # Set default font
            self.setFont(data.get_current_font())
            # Button image
            self.button_image = data.QPixmap(
                os.path.join(data.resources_directory, picture))
            adjusted_size = self.DEFAULT_SIZE * self.scale_factor
            self.button_image = self.button_image.scaled(
                functions.create_size(
                    math.ceil(adjusted_size),
                    math.ceil(adjusted_size),
                ),
                transformMode=data.Qt.SmoothTransformation)

            width, height = components.HexBuilder.get_single_hex_size(
                adjusted_size, 2)

            def create_base_image():
                hex_image = data.QImage(
                    functions.create_size(width, height),
                    data.QImage.Format_ARGB32_Premultiplied)
                hex_image.fill(data.Qt.transparent)
                qpainter = data.QPainter(hex_image)
                qpainter.setRenderHints(data.QPainter.Antialiasing
                                        | data.QPainter.TextAntialiasing
                                        | data.QPainter.SmoothPixmapTransform)
                hb = components.HexBuilder(
                    qpainter,
                    (width / 2, height / 2),
                    self.DEFAULT_SIZE,
                    self.scale_factor,
                    fill_color=data.theme.Settings_Hex_Background,
                    line_width=2,
                    line_color=data.QColor(64, 64, 64),
                )
                hb.create_grid(False)
                qpainter.end()
                return data.QPixmap.fromImage(hex_image)

            self.hex_image = create_base_image()
            self.hex_image = self.hex_image.scaled(
                functions.create_size(
                    math.ceil(self.hex_image.size().width() *
                              self.scale_factor),
                    math.ceil(self.hex_image.size().height() *
                              self.scale_factor),
                ),
                transformMode=data.Qt.SmoothTransformation)

            # Green hex background
            def create_color_image(color):
                hex_image = data.QImage(
                    functions.create_size(width, height),
                    data.QImage.Format_ARGB32_Premultiplied)
                hex_image.fill(data.Qt.transparent)
                qpainter = data.QPainter(hex_image)
                qpainter.setRenderHints(data.QPainter.Antialiasing
                                        | data.QPainter.TextAntialiasing
                                        | data.QPainter.SmoothPixmapTransform)
                hb = components.HexBuilder(
                    qpainter,
                    (width / 2, height / 2),
                    self.DEFAULT_SIZE,
                    self.scale_factor,
                    fill_color=color,
                    line_width=0,
                    line_color=data.QColor(0, 0, 0),
                )
                hb.create_grid(False)
                qpainter.end()
                return data.QPixmap.fromImage(hex_image)

            self.hex_image_green = create_color_image(data.QColor(
                138, 226, 52))
            self.hex_image_green = self.hex_image_green.scaled(
                functions.create_size(
                    math.ceil(self.hex_image_green.size().width() *
                              self.scale_factor) - 1,
                    math.ceil(self.hex_image_green.size().height() *
                              self.scale_factor) - 1,
                ),
                transformMode=data.Qt.SmoothTransformation)
            # Red hex background
            self.hex_image_red = create_color_image(data.QColor(239, 41, 41))
            self.hex_image_red = self.hex_image_red.scaled(
                functions.create_size(
                    math.ceil(self.hex_image_red.size().width() *
                              self.scale_factor) - 1,
                    math.ceil(self.hex_image_red.size().height() *
                              self.scale_factor) - 1,
                ),
                transformMode=data.Qt.SmoothTransformation)

            scaled_size = functions.create_size(
                self.hex_image.size().width(),
                self.hex_image.size().height(),
            )
            image = data.QImage(
                scaled_size,
                data.QImage.Format_ARGB32_Premultiplied,
            )
            image.fill(data.Qt.transparent)
            button_painter = data.QPainter(image)
            button_painter.setCompositionMode(
                data.QPainter.CompositionMode_SourceOver)
            button_painter.setOpacity(1.0)
            # Adjust inner button positioning according to the scale
            x = (self.hex_image.width() - self.button_image.width()) / 2
            y = (self.hex_image.height() - self.button_image.height()) / 2
            button_painter.drawPixmap(0, 0, self.hex_image)

            button_painter.drawPixmap(x, y, self.button_image)
            button_painter.end()

            # Set properites
            self.setParent(parent)
            self.setPixmap(data.QPixmap.fromImage(image))
            self.setGeometry(0, 0, int(image.width() * self.scale_factor),
                             int(image.height() * self.scale_factor))
            self.setMask(self.hex_image.mask())
            self.setScaledContents(True)
            # Set the non-enlarged dimensions
            self.original_size = (self.geometry().width(),
                                  self.geometry().height())

            # Set the initial color state
            self.current_color = "default"