def _instantiate(self): self.gallery = ui.ArtistGallery( self.data, self._current_page_num, self._artist_user_id, ) prompt.gallery_like_prompt(self.gallery)
def leave(self, force=False) -> 'IO': self.event.set() if self.firstmode or force: # Came from view post mode, don't know current page num # Defaults to page 1 mode = ArtistGallery(self.artist_user_id) prompt.gallery_like_prompt(mode)
def go_artist_gallery_num(self, selected_image_num: int) -> 'IO': """Like self.view_image(), but goes to artist mode instead of image""" artist_user_id = self._data.artist_user_id(selected_image_num) mode = ArtistGallery(artist_user_id) prompt.gallery_like_prompt(mode) # Gallery prompt ends, user presses back self._back()
def _go_to_mode(self): """Implements abstractmethod: go to mode 1""" os.system('clear') self.mode = ui.ArtistGallery(self._user_input) prompt.gallery_like_prompt(self.mode) # This is the entry mode, user goes back but there is nothing to catch it main()
def handle_prompt(self, keyseqs): """Implements abstractmethod""" # Display image (using either coords or image number), the show this prompt if keyseqs[0] == 'b': pass # Stop gallery instance, return to previous state elif keyseqs[0] == 'r': self.reload() elif keyseqs[0].lower() == 'a': print('Invalid command! Press h to show help') prompt.gallery_like_prompt(self) # Go back to while loop
def reload(self): ans = input( 'This will delete cached images and redownload them. Proceed?\n') if ans == 'y' or not ans: os.system(f'rm -r {self._main_path}') # shutil.rmtree is better self.data.all_pages_cache = {} # Ensures prefetch after reloading self._back() else: # After reloading, back will return to the same mode again prompt.gallery_like_prompt(self)
def handle_prompt(self, keyseqs): """Implements abstractmethod""" # "b" must be handled first, because keyseqs might be empty if keyseqs[0] == 'b': print('Invalid command! Press h to show help') prompt.gallery_like_prompt(self) # Go back to while loop elif keyseqs[0] == 'r': self.reload() elif keyseqs[0] == 'a': self.go_artist_gallery_coords(*keyseqs[-2:]) elif keyseqs[0] == 'A': self.go_artist_gallery_num(pure.concat_seqs_to_int(keyseqs, 1))
def go_artist_mode(self, selected_user_num: int) -> 'IO': """Concrete method unique for both user modes""" try: artist_user_id = self._data.artist_user_id(selected_user_num) except IndexError: print('Invalid number!') return False mode = ArtistGallery(artist_user_id) prompt.gallery_like_prompt(mode) # After backing from gallery self._show_page() prompt.user_prompt(self)
def handle_prompt(self, keyseqs, gallery_command, selected_image_num, first_num, second_num): # Display image (using either coords or image number), the show this prompt if gallery_command == 'b': pass # Stop gallery instance, return to previous state elif gallery_command == 'r': self.reload() elif keyseqs[0] == 'i': self.view_image(selected_image_num) elif keyseqs[0].lower() == 'a': print('Invalid command! Press h to show help') prompt.gallery_like_prompt(self) # Go back to while loop elif len(keyseqs) == 2: selected_image_num = pure.find_number_map(first_num, second_num) if not selected_image_num: print('Invalid number!') prompt.gallery_like_prompt(self) # Go back to while loop else: self.view_image(selected_image_num)
def handle_prompt(self, keyseqs, gallery_command, selected_image_num, first_num, second_num): # "b" must be handled first, because keyseqs might be empty if gallery_command == 'b': print('Invalid command! Press h to show help') prompt.gallery_like_prompt(self) # Go back to while loop elif gallery_command == 'r': self.reload() elif keyseqs[0] == 'i': self.view_image(selected_image_num) elif keyseqs[0] == 'a': self.go_artist_gallery_coords(first_num, second_num) elif keyseqs[0] == 'A': self.go_artist_gallery_num(selected_image_num) elif len(keyseqs) == 2: selected_image_num = pure.find_number_map(first_num, second_num) if not selected_image_num: print('Invalid number!') prompt.gallery_like_prompt(self) # Go back to while loop else: self.view_image(selected_image_num)
def test_gallery_like_prompt_digits_seq(monkeypatch, patch_cbreak, capsys): class FakeInKey1(FakeInKey): def __call__(self): return Keystroke(ucs='1', code=1, name='1') fake_inkey = iter([FakeInKey1()]) monkeypatch.setattr('koneko.prompt.TERM.inkey', next(fake_inkey)) with pytest.raises(CustomExit): assert prompt.gallery_like_prompt(fakegallery) captured = capsys.readouterr() assert captured.out == 'Enter a gallery view command:\n11'
def test_gallery_like_prompt(monkeypatch, patch_cbreak, letter, capsys): class FakeInKeyNew(FakeInKey): def __call__(self): return Keystroke(ucs=letter, code=1, name=letter) fake_inkey = FakeInKeyNew() monkeypatch.setattr('koneko.prompt.TERM.inkey', fake_inkey) with pytest.raises(CustomExit): assert prompt.gallery_like_prompt(fakegallery) captured = capsys.readouterr() assert captured.out == f'Enter a gallery view command:\n{letter}'
def test_gallery_like_prompt_ask_quit(monkeypatch, patch_cbreak, capsys): class FakeInKeyQuit(FakeInKey): def __call__(self): return Keystroke(ucs='q', code=1, name='quit') fake_inkey = FakeInKeyQuit() monkeypatch.setattr('koneko.prompt.TERM.inkey', fake_inkey) monkeypatch.setattr('koneko.prompt.ask_quit', raises_customexit) with pytest.raises(CustomExit): assert prompt.gallery_like_prompt(fakegallery) captured = capsys.readouterr() assert captured.out == 'Enter a gallery view command:\nq'
def test_gallery_like_prompt_previous(monkeypatch, patch_cbreak, capsys): class FakeInKeyPrev(FakeInKey): def __call__(self): return Keystroke(ucs='p', code=1, name='p') fake_inkey = FakeInKeyPrev() monkeypatch.setattr('koneko.prompt.TERM.inkey', fake_inkey) monkeypatch.setattr('koneko.ui.AbstractGallery.previous_page', raises_customexit) with pytest.raises(CustomExit): assert prompt.gallery_like_prompt(fakegallery) captured = capsys.readouterr() assert captured.out == 'Enter a gallery view command:\np'
def _back(self) -> 'IO': """After user 'back's from image prompt or artist gallery, start mode again""" lscat.show_instant(self._tracker_class, self._data) self._print_page_info() prompt.gallery_like_prompt(self)
def _instantiate(self): self.gallery = ui.IllustFollowGallery(self.data, self._current_page_num) prompt.gallery_like_prompt(self.gallery) # After backing main(start=False)
def illust_recommended_mode() -> 'IO': """Immediately goes to ui.IllustRecommendedGallery()""" mode = ui.IllustRecommendedGallery() prompt.gallery_like_prompt(mode)
def illust_follow_mode() -> 'IO': """Immediately goes to ui.IllustFollowGallery()""" mode = ui.IllustFollowGallery() prompt.gallery_like_prompt(mode)
def illust_follow_mode(): """Immediately goes to ui.IllustFollowGallery()""" mode = ui.IllustFollowGallery() prompt.gallery_like_prompt(mode) # After backing main()
def _back(self) -> 'IO': """After user 'back's from image prompt or artist gallery, start mode again""" self.scroll_or_show() self._report() prompt.gallery_like_prompt(self)
def view_related_images(self): lscat.api.hide(self.image) lscat.api.hide_all(self.preview_images) mode = IllustRelatedGallery(self.image_id, self.download_path.parent) prompt.gallery_like_prompt(mode)
def view_related_images(self): mode = IllustRelatedGallery(self.image_id, self.download_path) prompt.gallery_like_prompt(mode)
def _go_to_mode(self) -> 'IO': """Implements abstractmethod: go to mode 1""" os.system('clear') self.mode = ui.ArtistGallery(self._user_input) prompt.gallery_like_prompt(self.mode)