Exemplo n.º 1
0
class SuggestRow(QPushButton):
    def __init__(self, parent, suggestion: Suggestion):
        QWidget.__init__(self, parent)
        # defines whether the command has associated options
        self.has_options = True if hasattr(suggestion,
                                           "option_suggestions") else False
        # gets the current theme
        self.active_theme = parent.active_theme
        # gets the font
        self.custom_font = parent.custom_font
        # setting height the row
        width, height = [parent.width(), 57]
        self.resize(width, height)
        # makes command dictionary a class variable
        self.suggestion = suggestion  # Stores information about the command the row will hold
        # widget creation
        self.icon = None  # This can either be an svg or jpg file
        icon_path = self.suggestion.icon_name  # gets the icon path
        if "svg" in icon_path:
            self.icon = QSvgWidget(self)
            self.icon.load(icon_path)
        else:
            pixmap = QPixmap(icon_path)
            icon = QLabel(self)
            icon.setPixmap(pixmap)
            self.icon = icon
        self.title_lbl = QLabel(self.suggestion.title, self)
        self.description_lbl = QLabel(self.suggestion.description, self)
        self.option_icon = QSvgWidget(self)
        self.option_icon.load(f"{ASSETS_DIR}svg{sep}ellipsis.svg")
        self.set_style()

    def set_style(self):
        # TODO: Add support for theming for icon and layout scalability components
        # set style and location of icon
        if "svg" in self.suggestion.icon_name:  # different location and sizes depending on icon type
            self.icon.move(18, 18)
            self.icon.resize(20, 20)
            self.icon.setStyleSheet("background-color: rgba(0,0,0,0%);")
        else:
            self.icon.move(8, 8)
            self.icon.resize(40, 40)
            self.icon.setAlignment(Qt.AlignCenter)
            self.icon.setScaledContents(True)
        # set style for options icon
        self.option_icon.move(490, 16)
        self.option_icon.resize(25, 25)
        self.option_icon.setStyleSheet("background-color: rgba(0,0,0,0%);")
        self.option_icon.hide()
        # set style and location of title
        self.title_lbl.move(56, 9)
        self.title_lbl.setStyleSheet(
            f"font-size: 20px; color: {self.active_theme.foreground}; background-color: rgba(0,0,0,0%);"
        )
        self.title_lbl.setFont(self.custom_font)
        # set style and location of description
        self.description_lbl.resize(479, 15)
        self.description_lbl.move(56, 33)
        self.description_lbl.setStyleSheet(
            f"font-size: 13px; color: {self.active_theme.foreground}; background-color: rgba(0,0,0,0%);"
        )
        self.description_lbl.setFont(self.custom_font)
        # style for widget
        self.setStyleSheet('''
        QPushButton {
            border: none;
        }
        QPushButton:hover {
            background-color: #251e1e;
        }
        QPushButton:hover:focus {
            background-color: #322828;
        }
        QPushButton:focus {
            background-color: #3f3232;
            outline: 0px
        }
        ''')

    def show_option_icon(self):
        if self.has_options:
            self.option_icon.show()

    def hide_option_icon(self):
        if self.has_options:
            self.option_icon.hide()
Exemplo n.º 2
0
class SuggestRow(QPushButton):
    def __init__(self, parent, command_dict):
        QWidget.__init__(self, parent)
        # gets the current theme
        self.active_theme = parent.active_theme
        # gets the font
        self.custom_font = parent.custom_font
        # setting height the row
        height, width = [parent.width(), 114]
        self.resize(height, width)
        # makes command dictionary a class variable
        self.command_dict = command_dict  # Stores information about the command the row will hold
        # widget creation
        self.icon = None  # This can either be an svg or jpg file
        icon_path = command_dict["icon"]  # gets the icon path
        if "svg" in icon_path:
            self.icon = QSvgWidget(self)
            self.icon.load(icon_path)
        else:
            pixmap = QPixmap(icon_path)
            icon = QLabel(self)
            icon.setPixmap(pixmap)
            self.icon = icon
        self.title_lbl = QLabel(command_dict["title"], self)
        self.description_lbl = QLabel(command_dict["description"], self)
        self.set_style()

    def set_style(self):
        # TODO: Add support for theming for icon and layout scalability components
        # set style and location of icon
        if "svg" in self.command_dict[
                "icon"]:  # different location and sizes depending on icon type
            self.icon.move(18, 18)
            self.icon.resize(20, 20)
            self.icon.setStyleSheet("background-color: rgba(0,0,0,0%);")
        else:
            self.icon.move(8, 8)
            self.icon.resize(40, 40)
            self.icon.setAlignment(Qt.AlignCenter)
            self.icon.setScaledContents(True)
        # set style and location of title
        self.title_lbl.move(56, 9)
        self.title_lbl.setStyleSheet(
            f"font-size: 20px; color: {self.active_theme['text']}; background-color: rgba(0,0,0,0%);"
        )
        self.title_lbl.setFont(self.custom_font)
        # set style and location of description
        self.description_lbl.resize(479, 15)
        self.description_lbl.move(56, 33)
        self.description_lbl.setStyleSheet(
            f"font-size: 13px; color: {self.active_theme['text']}; background-color: rgba(0,0,0,0%);"
        )
        self.description_lbl.setFont(self.custom_font)
        # style for widget
        self.setStyleSheet('''
        QPushButton {      
            border: none;
        }
        QPushButton:hover {
            background-color: #251e1e;     
        }
        QPushButton:hover:focus {
            background-color: #322828;
        }
        QPushButton:focus {
            background-color: #3f3232;
            outline: 0px
        }
        ''')