Exemple #1
0
 def _instantiate(self):
     self.gallery = ui.ArtistGallery(
         self.data,
         self._current_page_num,
         self._artist_user_id,
     )
     prompt.gallery_like_prompt(self.gallery)
Exemple #2
0
 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)
Exemple #3
0
 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()
Exemple #4
0
 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()
Exemple #5
0
 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
Exemple #6
0
 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)
Exemple #7
0
 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))
Exemple #8
0
    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)
Exemple #9
0
 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)
Exemple #10
0
 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)
Exemple #11
0
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'
Exemple #12
0
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}'
Exemple #13
0
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'
Exemple #14
0
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'
Exemple #15
0
 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)
Exemple #16
0
 def _instantiate(self):
     self.gallery = ui.IllustFollowGallery(self.data,
                                           self._current_page_num)
     prompt.gallery_like_prompt(self.gallery)
     # After backing
     main(start=False)
Exemple #17
0
def illust_recommended_mode() -> 'IO':
    """Immediately goes to ui.IllustRecommendedGallery()"""
    mode = ui.IllustRecommendedGallery()
    prompt.gallery_like_prompt(mode)
Exemple #18
0
def illust_follow_mode() -> 'IO':
    """Immediately goes to ui.IllustFollowGallery()"""
    mode = ui.IllustFollowGallery()
    prompt.gallery_like_prompt(mode)
Exemple #19
0
def illust_follow_mode():
    """Immediately goes to ui.IllustFollowGallery()"""
    mode = ui.IllustFollowGallery()
    prompt.gallery_like_prompt(mode)
    # After backing
    main()
Exemple #20
0
 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)
Exemple #21
0
 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)
Exemple #22
0
 def view_related_images(self):
     mode = IllustRelatedGallery(self.image_id, self.download_path)
     prompt.gallery_like_prompt(mode)
Exemple #23
0
 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)