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;")
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)
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)