def __init__(self, initial_layer_tree, settings): super(_ExportLayersGui, self).__init__() self._initial_layer_tree = initial_layer_tree self._image = self._initial_layer_tree.image self._settings = settings self._is_exporting = False self._suppress_gimp_progress() self._layer_exporter_for_previews = exportlayers.LayerExporter( gimpenums.RUN_NONINTERACTIVE, self._image, self._settings['main'], overwrite_chooser=overwrite.NoninteractiveOverwriteChooser( self._settings['main/overwrite_mode'].items['replace']), layer_tree=self._initial_layer_tree) self._init_settings() self._hpaned_previous_position = self._settings['gui/chooser_and_previews_hpane_position'].value self._vpaned_previous_position = self._settings['gui/previews_vpane_position'].value self._init_gui() pggui.set_gui_excepthook_parent(self._dialog) gtk.main()
def _run_plugin_noninteractive(run_mode, layer_tree): layer_exporter = exportlayers.LayerExporter(run_mode, layer_tree.image, SETTINGS["main"]) try: layer_exporter.export(layer_tree=layer_tree) except exportlayers.ExportLayersCancelError: pass
def _run_plugin_noninteractive(run_mode, layer_tree): layer_exporter = exportlayers.LayerExporter(run_mode, layer_tree.image, settings['main']) try: layer_exporter.export_layers(layer_tree=layer_tree) except exportlayers.ExportLayersCancelError: pass
def _on_button_export_clicked(self, widget): self._setup_gui_before_export() self._install_gimp_progress(self._progress_set_value, self._progress_reset_value) overwrite_chooser = pggui.GtkDialogOverwriteChooser( # Don't insert the Cancel item as a button. zip( self._settings['main/overwrite_mode'].items.values()[:-1], self._settings['main/overwrite_mode'].items_display_names.values()[:-1]), default_value=self._settings['main/overwrite_mode'].items['replace'], default_response=self._settings['main/overwrite_mode'].items['cancel'], title=pygimplib.config.PLUGIN_TITLE, parent=self._dialog) progress_updater = pggui.GtkProgressUpdater(self._progress_bar) self._layer_exporter = exportlayers.LayerExporter( gimpenums.RUN_INTERACTIVE, self._image, self._settings['main'], overwrite_chooser, progress_updater, export_context_manager=_handle_gui_in_export, export_context_manager_args=[self._dialog]) should_quit = True self._is_exporting = True try: self._layer_exporter.export_layers() except exportlayers.ExportLayersCancelError as e: should_quit = False except exportlayers.ExportLayersError as e: display_export_failure_message(e, parent=self._dialog) should_quit = False except Exception as e: if pdb.gimp_image_is_valid(self._image): raise else: display_export_failure_invalid_image_message(traceback.format_exc(), parent=self._dialog) else: self._settings['special/first_plugin_run'].set_value(False) self._settings['special/first_plugin_run'].save() if not self._layer_exporter.exported_layers: display_message(_("No layers were exported."), gtk.MESSAGE_INFO, parent=self._dialog) should_quit = False finally: self._uninstall_gimp_progress() self._layer_exporter = None self._is_exporting = False self._settings['main/overwrite_mode'].set_value(overwrite_chooser.overwrite_mode) pgsettingpersistor.SettingPersistor.save( [self._settings['main'], self._settings['gui'], self._settings['gui_session']], [pygimplib.config.SOURCE_SESSION]) if should_quit: gtk.main_quit() else: self._restore_gui_after_export() progress_updater.reset()
def on_export_click(self, widget): try: self.setting_presenters.assign_element_values_to_settings() except pgsetting.SettingValueError as e: self.display_message_label(e.message, message_type=self.ERROR) return self.setup_gui_before_export() pdb.gimp_progress_init("", None) overwrite_chooser = pggui.GtkDialogOverwriteChooser( # Don't insert the Cancel option as a button. zip(self.main_settings['overwrite_mode'].options.values()[:-1], self.main_settings['overwrite_mode'].options_display_names.values()[:-1]), default_value=self.main_settings['overwrite_mode'].options['replace'], default_response=self.main_settings['overwrite_mode'].options['cancel'], title=_(constants.PLUGIN_TITLE)) progress_updater = pggui.GtkProgressUpdater(self.progress_bar) # Make the enabled GUI components more responsive(-ish) by periodically checking # whether the GUI has something to do. refresh_event_id = gobject.timeout_add(self._GUI_REFRESH_INTERVAL_MILLISECONDS, self.refresh_ui) self.layer_exporter = exportlayers.LayerExporter(gimpenums.RUN_INTERACTIVE, self.image, self.main_settings, overwrite_chooser, progress_updater) should_quit = True try: self.layer_exporter.export_layers() except exportlayers.ExportLayersCancelError as e: should_quit = False except exportlayers.ExportLayersError as e: self.display_message_label(e.message, message_type=self.ERROR) should_quit = False except Exception as e: display_exception_message(traceback.format_exc(), parent=self.dialog) else: self.special_settings['first_run'].value = False self.setting_persistor.save([self.special_settings['first_run']]) if not self.layer_exporter.exported_layers: display_message(_("No layers were exported."), gtk.MESSAGE_INFO, parent=self.dialog) should_quit = False finally: gobject.source_remove(refresh_event_id) pdb.gimp_progress_end() self.main_settings['overwrite_mode'].value = overwrite_chooser.overwrite_mode self.setting_persistor.save(self.main_settings, self.gui_settings, self.session_only_gui_settings) if should_quit: gtk.main_quit() else: progress_updater.reset() self.restore_gui_after_export()
def export_layers(self): overwrite_chooser = overwrite.NoninteractiveOverwriteChooser(self.settings['main']['overwrite_mode'].value) progress_updater = pggui.GtkProgressUpdater(self.export_dialog.progress_bar) pdb.gimp_progress_init("", None) refresh_event_id = gobject.timeout_add(self._GUI_REFRESH_INTERVAL_MILLISECONDS, self.refresh_ui) try: self.layer_exporter = exportlayers.LayerExporter( gimpenums.RUN_WITH_LAST_VALS, self.image, self.settings['main'], overwrite_chooser, progress_updater) self.layer_exporter.export_layers() except exportlayers.ExportLayersCancelError: pass except exportlayers.ExportLayersError: pass except Exception: display_exception_message(traceback.format_exc(), parent=self.export_dialog.dialog) else: if not self.layer_exporter.exported_layers: display_message(_("No layers were exported."), gtk.MESSAGE_INFO, parent=self.export_dialog.dialog) finally: gobject.source_remove(refresh_event_id) pdb.gimp_progress_end()
def _run_plugin_noninteractive(self, run_mode, image): layer_exporter = exportlayers.LayerExporter( run_mode, image, self.settings['main'], overwrite_chooser=overwrite.NoninteractiveOverwriteChooser( self.settings['main']['overwrite_mode'].value), progress_updater=None) try: layer_exporter.export_layers() except exportlayers.ExportLayersCancelError as e: print(e.message) except exportlayers.ExportLayersError as e: print(e.message) raise self.settings['special']['first_plugin_run'].set_value(False) pgsettingpersistor.SettingPersistor.save([ self.settings['main'], self.settings['special']['first_plugin_run'] ], [self.session_source])
def _run_plugin_noninteractive(self, run_mode, image): self.main_settings.streamline(force=True) layer_exporter = exportlayers.LayerExporter( run_mode, image, self.main_settings, overwrite_chooser=overwrite.NoninteractiveOverwriteChooser( self.main_settings['overwrite_mode'].value), progress_updater=None) try: layer_exporter.export_layers() except exportlayers.ExportLayersCancelError as e: print(e.message) except exportlayers.ExportLayersError as e: print(e.message) raise self.special_settings['first_run'].value = False self.setting_persistor.save(self.main_settings, [self.special_settings['first_run']])
def export_layers(self): self._install_gimp_progress(self._progress_set_value, self._progress_reset_value) self._layer_exporter = exportlayers.LayerExporter( gimpenums.RUN_WITH_LAST_VALS, self._image, self._settings['main'], overwrite.NoninteractiveOverwriteChooser(self._settings['main/overwrite_mode'].value), pggui.GtkProgressUpdater(self._progress_bar), export_context_manager=_handle_gui_in_export, export_context_manager_args=[self._dialog]) try: self._layer_exporter.export_layers(layer_tree=self._layer_tree) except exportlayers.ExportLayersCancelError: pass except exportlayers.ExportLayersError as e: display_export_failure_message(e, parent=self._dialog) except Exception as e: if pdb.gimp_image_is_valid(self._image): raise else: display_export_failure_invalid_image_message(traceback.format_exc(), parent=self._dialog) else: if not self._layer_exporter.exported_layers: display_message(_("No layers were exported."), gtk.MESSAGE_INFO, parent=self._dialog) finally: self._uninstall_gimp_progress()