Ejemplo n.º 1
0
    def __init__(self, parent: Window):
        super().__init__(title='Warning - Anki is open', transient_for=parent)

        self.set_default_size(width=250, height=100)
        self.set_modal(True)
        self.set_keep_above(True)
        self.set_decorated(False)
        self.set_urgency_hint(True)

        lbl: Label = Label(
            label=
            'Warning: your anki is probably opened, please close it before trying again.'
        )

        box: Box = self.get_content_area()

        setMargin(box, 20)

        # box.pack_(child, expand, fill, padding)
        box.pack_start(lbl, False, True, 0)

        img_path: Filepath = path.abspath('asts/Icons/alert.png')

        try:
            warn_pixbuf: Pixbuf = Pixbuf().new_from_file_at_scale(
                img_path, 50, 50, True)

            warn_img: Image = Image().new_from_pixbuf(warn_pixbuf)

            box.pack_start(warn_img, False, True, 0)

            setMargin(warn_img, 20)

        except GLib_Error:
            exit(f'{img_path} file not found. Failed to create pixbuf.')

        self.add_buttons(STOCK_OK, ResponseType.OK)
Ejemplo n.º 2
0
    def _setButtonsSignals(self) -> None:
        """
        Set up the buttons and their respective signals for both grids.

        :param win: A window.
        :param fst_grid: The first grid container where the buttons goes in.
        :param box: The box container where the first grid goes in.
        :param fc_s: A list with file choosers.
        :return:
        """

        del_img: Optional[Pixbuf]

        img_path: str = path.abspath('asts/Icons/delete.png')

        try:
            del_img = Pixbuf().new_from_file_at_scale(img_path, 20, 20, False)
        except GLib_Error:
            exit(f'{img_path} file not found. Failed to create pixbuf.')

        icons: List[Optional[Image]] = [
            Image().new_from_pixbuf(del_img) for _ in range(4)
        ]

        btns: List[Button] = [Button() for _ in range(4)]

        for (idx, btn) in enumerate(btns):
            btn.set_image(icons[idx])
            setMargin(btn, 0, 5, 0, 5)
            btn.set_halign(Align.END)

            self._fst_grid.attach(btn, 2, idx, 1, 1)

        btns[FileType.ANKI2_COLLECTION].connect(
            'clicked',
            lambda _: self._fc_s[FileType.ANKI2_COLLECTION].unselect_all())

        btns[FileType.VIDEO].connect(
            'clicked', lambda _: self._fc_s[FileType.VIDEO].unselect_all())

        btns[FileType.SUBTITLE].connect(
            'clicked', lambda _: self._fc_s[FileType.SUBTITLE].unselect_all())

        btns[FileType.O_SUBTITLE].connect(
            'clicked',
            lambda _: self._fc_s[FileType.O_SUBTITLE].unselect_all())

        box: Box = Box()

        self._box.pack_end(box, False, True, 0)

        box.set_orientation(Orientation.HORIZONTAL)
        box.set_halign(Align.CENTER)

        cancel_btn: Button = Button(label='Cancel')

        box.pack_start(cancel_btn, False, True, 0)

        cancel_btn.set_margin_bottom(10)
        cancel_btn.connect('clicked', lambda _: self.close())

        self._next_btn = Button(label='Next')

        box.pack_end(self._next_btn, False, True, 0)

        setMargin(self._next_btn, 200, 10, 0, 0)
        self._next_btn.connect('clicked', self._onNextBtnClicked)

        timeout_add(300, self._setSensitiveNextBtn)
        timeout_add(300, self._checkInvalidSelection)