diff --git a/silhouette/ColorSeparation.py b/silhouette/ColorSeparation.py index 23168878..f41ce702 100644 --- a/silhouette/ColorSeparation.py +++ b/silhouette/ColorSeparation.py @@ -16,10 +16,10 @@ def activate_preset(self, preset_name, silent=False): + str(preset), not silent) if not preset: return preset - self.extract_settings_from_preset(preset) + self.extract_settings_from_preset(preset, silent) return preset - def extract_settings_from_preset(self, preset): + def extract_settings_from_preset(self, preset, silent=False): old_colors = self.colors self.colors = [] extra_colors = [] @@ -71,7 +71,7 @@ def extract_settings_from_preset(self, preset): message.append("%d colors from the preset were not used." % len(extra_colors)) if message and not silent: - info_dialog(self, "Colors in the preset and this SVG did not match fully. " + " ".join(message)) + Dialog.info(self, "Colors in the preset and this SVG did not match fully. " + " ".join(message)) def generate_actions(self, default_actions): actions = [] diff --git a/silhouette/Dialog.py b/silhouette/Dialog.py new file mode 100644 index 00000000..50a67cd1 --- /dev/null +++ b/silhouette/Dialog.py @@ -0,0 +1,23 @@ +import wx +from wx.lib.agw import genericmessagedialog as gmd + +class Dialog: + def confirm(parent, question, caption = 'Silhouette Multiple Actions'): + dlg = wx.MessageDialog(parent, question, caption, wx.YES_NO | wx.ICON_QUESTION) + result = dlg.ShowModal() == wx.ID_YES + dlg.Destroy() + return result + + def info(parent, message, extended = '', + caption = 'Silhouette Multiple Actions',): + dlg = gmd.GenericMessageDialog( + parent, message, caption, wrap=1000, + agwStyle=wx.OK | wx.ICON_INFORMATION | gmd.GMD_USE_AQUABUTTONS) + # You might wonder about the choice of "aquabuttons" above. It's the + # only option that led to the buttons being visible on the system + # this was first tested on. + dlg.SetLayoutAdaptationMode(wx.DIALOG_ADAPTATION_MODE_ENABLED) + if extended: + dlg.SetExtendedMessage(extended) + dlg.ShowModal() + dlg.Destroy() diff --git a/silhouette/MultiFrame.py b/silhouette/MultiFrame.py index beb9a9cd..a840f900 100644 --- a/silhouette/MultiFrame.py +++ b/silhouette/MultiFrame.py @@ -9,6 +9,8 @@ from silhouette.ColorSeparation import ColorSeparation +from silhouette.Dialog import Dialog + small_up_arrow = PyEmbeddedImage( "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYA" "AAAf8/9hAAAABHNCSVQICAgIfAhkiAAAADxJ" @@ -23,7 +25,6 @@ "//7+J6SJkYmZEacLkCUJacZqAD5DsInTLhDR" "bcPlKrwugGnCFy6Mo3mBAQChDgRlP4RC7wAAAABJRU5ErkJggg==") - class ParamsNotebook(wx.Notebook): """Handle a notebook of tabs that contain params. @@ -296,7 +297,7 @@ def load_preset(self, event): if not preset_name: return - self._load_preset(preset_name) + return self._load_preset(preset_name) def add_preset(self, event, overwrite=False): preset_name = self.get_preset_name() @@ -304,7 +305,7 @@ def add_preset(self, event, overwrite=False): return if not overwrite and self.load_preset(preset_name): - info_dialog(self, 'Preset "%s" already exists. Please use another name or press "Overwrite"' % preset_name, caption='Preset') + Dialog.info(None, 'Preset "%s" already exists. Please use another name or press "Overwrite"' % preset_name, caption='Preset') self.save_color_settings() self.colsep.save_preset( @@ -334,7 +335,7 @@ def delete_preset(self, event): def check_and_load_preset(self, preset_name): preset = self.load_preset(preset_name) if not preset: - info_dialog(self, 'Preset "%s" not found.' % preset_name, caption='Preset') + Dialog.info(None, 'Preset "%s" not found.' % preset_name, caption='Preset') return preset @@ -343,7 +344,7 @@ def get_preset_name(self): if preset_name: return preset_name else: - info_dialog(self, "Please enter or select a preset name first.", caption='Preset') + Dialog.info(None, "Please enter or select a preset name first.", caption='Preset') return def update_preset_list(self): @@ -359,6 +360,8 @@ def _load_preset(self, preset_name, silent=False): self.actions.Select(self.selected, False) self.refresh_actions() + return preset + def _save_preset(self, preset_name): self.save_color_settings() @@ -370,10 +373,10 @@ def run(self, event): actions = self.colsep.generate_actions(self.notebook.get_defaults) if actions: if not self.options.dry_run: - if not confirm_dialog(self, "About to perform %d actions, continue?" % len(actions)): + if not Dialog.confirm(None, "About to perform %d actions, continue?" % len(actions)): return else: - info_dialog(self, "No colors were enabled, so no actions can be performed.") + Dialog.info(None, "No colors were enabled, so no actions can be performed.") return self._save_preset('__LAST__') diff --git a/silhouette_multi.py b/silhouette_multi.py index 7203b744..eae6c317 100644 --- a/silhouette_multi.py +++ b/silhouette_multi.py @@ -38,36 +38,12 @@ def emit_to_log(msg, whether=True): print(msg, file=multilogfile) multilogfile.flush() - def show_log_as_dialog(parent=None): logname = multilogfile.name multilogfile.close() logtext = Path(logname).read_text().strip() if logtext: - info_dialog(parent, logtext, caption='Silhouette Multi Log') - - -def confirm_dialog(parent, question, caption = 'Silhouette Multiple Actions'): - dlg = wx.MessageDialog(parent, question, caption, wx.YES_NO | wx.ICON_QUESTION) - result = dlg.ShowModal() == wx.ID_YES - dlg.Destroy() - return result - - -def info_dialog(parent, message, extended = '', - caption = 'Silhouette Multiple Actions',): - dlg = gmd.GenericMessageDialog( - parent, message, caption, wrap=1000, - agwStyle=wx.OK | wx.ICON_INFORMATION | gmd.GMD_USE_AQUABUTTONS) - # You might wonder about the choice of "aquabuttons" above. It's the - # only option that led to the buttons being visible on the system - # this was first tested on. - dlg.SetLayoutAdaptationMode(wx.DIALOG_ADAPTATION_MODE_ENABLED) - if extended: - dlg.SetExtendedMessage(extended) - dlg.ShowModal() - dlg.Destroy() - + Dialog.info(parent, logtext, caption='Silhouette Multi Log') class SilhouetteMulti(EffectExtension): def __init__(self, *args, **kwargs): @@ -171,6 +147,7 @@ def effect(self): if self.options.gui: import wx from silhouette.MultiFrame import MultiFrame + from silhouette.Dialog import Dialog app = wx.App() self.frame = MultiFrame( @@ -239,7 +216,7 @@ def run_commands_with_dialog(self, commands): # we just have to go ahead and display it. # But we will use the dialog's extended message to reduce # visual clutter - info_dialog(None, "Action failed.", + Dialog.info(None, "Action failed.", extended = f"Return code: {returncode}\nCommand: '{command}'") sys.exit(1) @@ -273,7 +250,7 @@ def cancel(): dialog.Destroy() wx.Yield() - info_dialog(None, "Action aborted. It may take awhile for the machine to cancel its operation.") + Dialog.info(None, "Action aborted. It may take awhile for the machine to cancel its operation.") sys.exit(1) dialog.Destroy()