Exemple #1
0
    def on_spritebot_import_activate(self, *args):
        dialog = Gtk.FileChooserNative.new(
            _("Import portraits from PNG sheet..."), MainController.window(),
            Gtk.FileChooserAction.OPEN, None, None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            try:
                for subindex, image in SpriteBotSheet.load(
                        fn, self._get_portrait_name):
                    try:
                        self.kao.set_from_img(self.item_id, subindex, image)
                    except Exception as err:
                        name = self._get_portrait_name(subindex)
                        logger.error(f"Failed importing image '{name}'.",
                                     exc_info=err)
                        display_error(
                            sys.exc_info(),
                            f(_('Failed importing image "{name}":\n{err}')),
                            f(_("Error for '{name}'.")))
            except Exception as err:
                logger.error(f"Failed importing portraits sheet: {err}",
                             exc_info=err)
                display_error(sys.exc_info(),
                              f(_('Failed importing portraits sheet:\n{err}')),
                              _("Could not import."))
            self.re_render()
            # Mark as modified
            self.module.mark_as_modified()
            self._mark_as_modified_cb()
Exemple #2
0
 def _import_portrait(self, kaos, config, mdidx, md):
     pokedex_number = md.national_pokedex_number
     form_id = ''
     poke_name = ''
     form_name = ''
     try:
         forms_to_try = ['0000']
         if md.gender == Gender.FEMALE:
             forms_to_try.insert(0, '0000f')
         if mdidx == 279:  # Celebi Shiny
             forms_to_try.insert(0, '0000s')
         if f'{pokedex_number:04}' in config and '0000' in config[
                 f'{pokedex_number:04}']['forms']:
             filename = None
             for form in forms_to_try:
                 if form in config[f'{pokedex_number:04}']['forms']:
                     filename = config[f'{pokedex_number:04}']['forms'][
                         form]['filename']
                     form_id = form
                     break
             if filename is None:
                 return
             poke_name = config[f'{pokedex_number:04}']['name']
             form_name = config[f'{pokedex_number:04}']['forms'][form_id][
                 'name']
             url = f'http://sprites.pmdcollab.org/resources/portraits/{filename}'
             with urllib.request.urlopen(url) as download:
                 for subindex, image in SpriteBotSheet.load(
                         io.BytesIO(download.read()),
                         self._get_portrait_name):
                     kao = kaos.get(mdidx - 1, subindex)
                     if kao:
                         # Replace
                         kao.set(image)
                     else:
                         # New
                         kaos.set(mdidx - 1, subindex, KaoImage.new(image))
             self._debugs.append([
                 f'{pokedex_number:04}', poke_name, form_id, form_name, '✓'
             ])
     except BaseException:
         traceback_str = ''.join(
             traceback.format_exception(*sys.exc_info()))
         self._debugs.append([
             f'{pokedex_number:04}', poke_name, form_id, form_name,
             traceback_str
         ])
Exemple #3
0
    def on_spritebot_import_activate(self, *args):
        dialog = Gtk.FileChooserNative.new(
            "Import portraits from PNG sheet...", MainController.window(),
            Gtk.FileChooserAction.OPEN, None, None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == Gtk.ResponseType.ACCEPT:
            try:
                for subindex, image in SpriteBotSheet.load(
                        fn, self._get_portrait_name):
                    try:
                        kao = self.kao.get(self.item_id, subindex)
                        if kao:
                            # Replace
                            kao.set(image)
                        else:
                            # New
                            self.kao.set(self.item_id, subindex,
                                         KaoImage.new(image))
                    except Exception as err:
                        name = self._get_portrait_name(subindex)
                        logger.error(f"Failed importing image '{name}'.",
                                     exc_info=err)
                        display_error(
                            sys.exc_info(),
                            f'Failed importing image "{name}":\n{err}',
                            f"Error for '{name}'.")
            except Exception as err:
                logger.error(f"Failed importing portraits sheet: {err}",
                             exc_info=err)
                display_error(sys.exc_info(),
                              f'Failed importing portraits sheet:\n{err}',
                              f"Could not import.")
            # Re-render
            self._portrait_provider.reset()
            for draw in self._draws:
                draw.queue_draw()
            # Mark as modified
            self.module.mark_as_modified()
            self._mark_as_modified_cb()