def _setTextEntry(self) -> None: """ Sets the text entry for deck name. :return: """ self._entry = Entry(placeholder_text='Deck name...') setMargin(self._entry, 10, 5, 10, 5) self._fst_grid.attach(self._entry, 1, 4, 1, 1)
def _setProgressBar(self) -> None: """ Sets up the progress bar. :return: """ self._cur_progress = 0 self._progress_bar = ProgressBar() setMargin(self._progress_bar, 5) self._main_box.pack_start(self._progress_bar, False, True, 0)
def _setSearchEntry(self) -> None: """ Connect the changed event for the search_entry object. :return: """ search_entry: SearchEntry = SearchEntry() search_entry.set_halign(Align.END) setMargin(search_entry, 0, 5, 0, 5) self._subtitles_grid.attach(search_entry, 0, 0, 1, 1) search_entry.connect('changed', self.searchIt)
def __init__(self, app: Application): super().__init__(title='Asts', application=app) self._app: Application = app self.set_default_size(1000, 700) self.set_keep_above(True) self.set_resizable(False) self._box: Box = Box() self._box.set_orientation(Orientation.VERTICAL) setBgColor(widget=self, alpha=0.93) setMargin(self._box, 10) self._fst_grid: Grid = Grid() # labels self._setLabels() # file choosers button # _fc_s[0] = anki2.collection file # _fc_s[1] = video file # _fc_s[2] = subtitle file # _fc_s[3] = optional subtitle file self._fc_s: List[FileChooser] = self._setFileChoosers() # text entry self._entry: Entry self._setTextEntry() self._fillCachedFile() # filters self._setFilters() # buttons self._next_btn: Button self._setButtonsSignals() # box.pack_(child, expand, fill, padding) self._box.pack_start(self._fst_grid, False, True, 0) self.add(self._box)
def _setFileChoosers(self) -> List[FileChooser]: """ Set up the file choosers for the grid. :return: The file choosers created. """ f_cs: List[FileChooser] = [FileChooserButton() for _ in range(4)] for (idx, f_c) in enumerate(f_cs): f_c.set_hexpand(True) setMargin(f_c, 10, 5, 10, 5) f_c.set_halign(Align.FILL) self._fst_grid.attach(f_c, 1, idx, 1, 1) return f_cs
def _setButtons(self) -> None: """ Sets up the cancel and generate buttons. :return: """ box: Box = Box() self._main_box.pack_end(box, False, True, 0) box.set_halign(Align.CENTER) box.set_orientation(Orientation.HORIZONTAL) setMargin(box, 5) self._cancel_btn = Button(label='Cancel') box.pack_start(self._cancel_btn, False, True, 0) setMargin(self._cancel_btn, 5, 5, 100, 5) self._cancel_btn.connect('clicked', self._onCancelBtnClicked) self._generate_btn = Button(label='Generate') box.pack_end(self._generate_btn, False, True, 0) setMargin(self._generate_btn, 100, 5, 5, 5) self._generate_btn.connect('clicked', self._onGenerateBtnClicked) timeout_add(300, self._setSensitiveGenerateBtn)
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)
def _setSentenceRelated(self) -> None: """ Sets up the sentence editing widgets related. Also initialize both text buffers. :return: """ box: Box = Box() self._main_box.pack_start(box, False, True, 0) box.set_orientation(Orientation.VERTICAL) setMargin(box, 5) toolbar: Toolbar = Toolbar() box.pack_start(toolbar, False, True, 0) toolbar.set_halign(Align.END) setMargin(toolbar, 5) lbl: Label = Label() lbl.set_markup('<i><b>Front</b></i>') box.pack_start(lbl, False, True, 0) lbl.set_halign(Align.START) setMargin(lbl, 5) scrl_wnd: ScrolledWindow = ScrolledWindow() scrl_wnd.set_hexpand(True) scrl_wnd.set_vexpand(True) textview: TextView = TextView() scrl_wnd.add(textview) box.pack_start(scrl_wnd, False, True, 0) self._textbuffer_front = textview.get_buffer() lbl2: Label = Label() lbl2.set_halign(Align.START) lbl2.set_markup('<i><b>Back</b></i>') box.pack_start(lbl2, False, True, 0) setMargin(lbl2, 5) scrl_wnd2: ScrolledWindow = ScrolledWindow() scrl_wnd2.set_hexpand(True) scrl_wnd2.set_vexpand(True) textview2: TextView = TextView() scrl_wnd2.add(textview2) box.pack_end(scrl_wnd2, False, True, 0) self._textbuffer_back = textview2.get_buffer() # this depends on the text buffer to be initialized self._setToolbarColorButton(toolbar) toolbar.insert(SeparatorToolItem(), 3) self._setToolbarUnderlineButton(toolbar) self._setToolbarBoldButton(toolbar) self._setToolbarItalicButton(toolbar) toolbar.insert(SeparatorToolItem(), 7) self._setToolbarTagRemoverButton(toolbar)
def __init__(self, parent: Window, app: Application, col_filename: Filename, vid_filename: Filename, sub_filename: Filename, opt_sub_filename: OptFilename, deck_name: str): super().__init__(title='Asts - Anki Card Generator', application=app, transient_for=parent) self.set_default_size(width=1000, height=700) self.set_keep_above(True) self.set_modal(True) self.set_resizable(False) setBgColor(widget=self, alpha=0.93) self._main_box: Box = Box() self._main_box.set_orientation(Orientation.VERTICAL) setMargin(self._main_box, 10) self.add(self._main_box) self._subtitles_grid: Grid = Grid() setMargin(self._subtitles_grid, 5) # box.pack_(expand, fill, padding) self._main_box.pack_start(self._subtitles_grid, False, True, 0) self._collection_filename: Filename = col_filename self._video_filename: Filename = vid_filename self._subtitles_filename: Filename = sub_filename self._opt_subtitles_filename: OptFilename = opt_sub_filename self._deck_name: str = deck_name self._any_media_toggled: bool = False self._dict_any_media: Dict[str, bool] self._dict_any_change_front: Dict[str, bytes] self._dict_any_change_back: Dict[str, bytes] self._textview_front: TextView self._textview_back: TextView self._textbuffer_front: TextBuffer self._textbuffer_back: TextBuffer self._subtitles_liststore: ListStore self._subtitles_liststore_back: ListStore self._subtitles_treeview: TreeView self._selected_row: TreeSelection self._progress_bar: ProgressBar self._cancel_btn: Button self._generate_btn: Button self._cur_progress: int self._max_tasks: int self._cancel_task: bool self._list_of_sentences: ListSentences self._list_info_medias: List[List[Info]] self._color_tag_names: List[str] # TheadingHandler will utilize these # updating the status for each task tasks # also the sensitive and progress of the progress bar # depends on these. self._futures_list: List[Future]
def _setSelectAll(self) -> None: """ Sets up widgets to select all sentences. :return: """ grid: Grid = Grid() grid.set_halign(Align.END) self._subtitles_grid.attach(grid, 0, 2, 1, 1) lbl: Label = Label(label='Select all') setMargin(lbl, 5) grid.attach(lbl, 0, 0, 1, 1) all_vid_toggle: CheckButton = CheckButton() all_vid_toggle.set_halign(Align.CENTER) all_vid_toggle.connect('toggled', self._onAllVideosToggled) setMargin(all_vid_toggle, 5) grid.attach(all_vid_toggle, 1, 0, 1, 1) lbl2: Label = Label(label='Videos') setMargin(lbl2, 5) grid.attach(lbl2, 1, 1, 1, 1) all_audio_toggle: CheckButton = CheckButton() all_audio_toggle.set_halign(Align.CENTER) all_audio_toggle.connect('toggled', self._onAllAudiosToggled, all_vid_toggle) setMargin(all_audio_toggle, 5) grid.attach(all_audio_toggle, 2, 0, 1, 1) lbl3: Label = Label(label='Audios') setMargin(lbl3, 5) grid.attach(lbl3, 2, 1, 1, 1) all_img_toggle: CheckButton = CheckButton() all_img_toggle.set_halign(Align.CENTER) all_img_toggle.connect('toggled', self._onAllImagesToggled) setMargin(all_img_toggle, 5) grid.attach(all_img_toggle, 3, 0, 1, 1) lbl4: Label = Label(label='Snapshot') setMargin(lbl4, 5) grid.attach(lbl4, 3, 1, 1, 1)
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)