Example #1
0
class TabButton(fsui.Panel):
    activated = fsui.Signal()

    TYPE_TAB = 0
    TYPE_BUTTON = 1

    STATE_NORMAL = 0
    STATE_SELECTED = 1

    def __init__(
        self,
        parent,
        icon,
        button_type=TYPE_TAB,
        left_padding=0,
        right_padding=0,
    ):
        fsui.Panel.__init__(self, parent, paintable=True)
        Skin.set_background_color(self)
        self.layout = fsui.VerticalLayout()
        # self.set_background_color((0xdd, 0xdd, 0xdd))
        self.set_min_width(Constants.TAB_WIDTH + left_padding + right_padding)
        self.set_min_height(Constants.TAB_HEIGHT)
        self.group_id = 0
        self.icon = icon
        self.type = button_type
        self.state = self.STATE_NORMAL
        self.hover = False
        self.left_padding = left_padding
        self.right_padding = right_padding

    def select(self):
        self.get_parent().set_selected_tab(self)
        self.on_select()

    def on_paint(self):
        dc = self.create_dc()
        selected = self.state == self.STATE_SELECTED
        TabPanel.draw_background(
            self,
            dc,
            selected=selected,
            hover=self.hover,
            button_style=(self.type == self.TYPE_BUTTON),
        )
        # TabPanel.draw_border(self, dc)
        size = self.size()
        x = (self.left_padding + (size[0] - self.left_padding -
                                  self.right_padding - self.icon.size[0]) // 2)
        # subtracting two because of bottom border
        y = (size[1] - 2 - self.icon.size[1]) // 2
        dc.draw_image(self.icon, x, y)

    def check_hover(self):
        # FIXME: check if mouse is hovering, used for example after having
        # dismissed a popup menu
        self.hover = False
        self.refresh()

    def on_mouse_enter(self):
        self.hover = True
        self.refresh()

    def on_mouse_leave(self):
        self.hover = False
        self.refresh()

    def on_select(self):
        pass

    def on_left_down(self):
        if self.type == self.TYPE_TAB:
            self.select()

    def on_left_up(self):
        if self.type == self.TYPE_BUTTON:
            # FIXME: hack to avoid sticky hover due to mouse leave not
            # being sent if on_activate opens modal dialog
            # self.hover = False
            # self.refresh()
            self.on_activate()

    def on_activate(self):
        self.activated.emit()
Example #2
0
class PagedDialog(fsui.Window):
    page_changed = fsui.Signal()

    def __init__(self, parent, title):
        super().__init__(parent, title, minimizable=False, maximizable=False)
        self.theme = LauncherTheme.get()
        self.layout = fsui.VerticalLayout()

        # self.layout.set_padding(20)
        layout = self.layout

        h_layout = fsui.HorizontalLayout()
        layout.add(h_layout, fill=True, expand=True)

        layout_2 = fsui.VerticalLayout()
        # layout_2.padding_top = 20
        # layout_2.padding_bottom = 20
        # layout_2.padding_left = 20

        self.list_view = fsui.ListView(self, border=False)
        self.list_view.set_min_width(240)
        self.list_view.item_selected.connect(self.on_select_item)

        self.list_view.set_row_height(
            self.window.theme.sidebar_list_row_height)
        self.list_view.setStyleSheet("""
        QListView {{
            padding-top: 20px;
            background-color: {base};
            outline: none;
        }}
        QListView::item {{
            padding-left: 20px;
            border: 0px;
        }}
        QListView::item:selected {{
            background-color: {row_bg};
            color: {row_fg};
        }}
        """.format(
            row_fg=self.window.theme.sidebar_list_row_text.to_hex(),
            row_bg=self.window.theme.sidebar_list_row_background.to_hex(),
            base=self.window.theme.sidebar_list_background.to_hex()))
        layout_2.add(self.list_view, fill=True, expand=True)
        h_layout.add(layout_2, fill=True)

        # h_layout.add_spacer(20)

        v_layout = fsui.VerticalLayout()
        h_layout.add(v_layout, fill=True, expand=True)

        use_scrolling = False
        if use_scrolling:
            # FIXME: Problems with page height
            scroll_area = fsui.VerticalScrollArea(self)
            self.page_container = fsui.Panel(scroll_area)
            self.page_container.layout = fsui.VerticalLayout()
            scroll_area.set_widget(self.page_container)
            v_layout.add(scroll_area, fill=True, expand=True)
        else:
            self.page_container = fsui.Panel(self)
            self.page_container.layout = fsui.VerticalLayout()
            v_layout.add(self.page_container, fill=True, expand=True)

        # self.layout.add_spacer(20)

        # h_layout = fsui.HorizontalLayout()
        # layout.add(h_layout, fill=True)

        self.page_titles = []
        self.pages = []

        # self.add_page(_("Hardware"), HardwarePage)
        # self.add_page(_("Hard Drives"), HardDrivesPage)
        # elf.add_page(_("Custom Options"), CustomOptionsPage)

        self.button_layout = fsui.HorizontalLayout()
        v_layout.add(self.button_layout, fill=True, margin=20, margin_top=0)
        if self.window.theme.has_close_buttons:
            self.button_layout.add_spacer(expand=True)
            self.close_button = CloseButton(self)
            self.button_layout.add(
                self.close_button, fill=True, margin_left=10)

        self.current_page = None

        # self.page_container.set_min_width(600)
        # self.page_container.set_min_height(640)
        # self.set_size_from_layout()
        self.set_size((840, 640))
        self.center_on_parent()

    # def on_close_button(self):
    #     self.end_modal(0)

    def on_select_item(self, index):
        self.set_page(index)

    @property
    def index(self):
        return self.list_view.get_index()

    @property
    def page(self):
        return self.current_page

    def get_index(self):
        return self.list_view.get_index()

    def get_page_title(self, index):
        # return self.page_titles[index][0]
        return self.page_titles[index]["label"]

    def get_page_index_by_title(self, title):
        # for index, t in enumerate(self.page_titles):
        #     if t[0] == title:
        for i, item in enumerate(self.page_titles):
            if item["label"] == title:
                return i
        return None

    def add_page(self, title, function, icon=None, bold=False):
        self.page_titles.append({"label": title, "icon": icon, "bold": bold})
        self.pages.append(function)
        self.list_view.set_items(self.page_titles)

    def set_page(self, index):
        if self.current_page:
            self.current_page.hide()
            self.page_container.layout.remove(self.current_page)
        if callable(self.pages[index]):
            page = self.pages[index](self.page_container)
            self.pages[index] = page
        else:
            page = self.pages[index]
        self.page_container.layout.add(page, fill=True, expand=True)
        self.current_page = page
        page.show()
        # print("calling self.layout.update")
        self.page_container.layout.update()
        self.layout.update()

        self.page_changed.emit()

    def set_page_by_title(self, title):
        index = self.get_page_index_by_title(title)
        if index is not None:
            # self.set_page(index)
            self.list_view.set_index(index)
        return index