Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-action dialogs #217

Merged
merged 4 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions silhouette/ColorSeparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 = []
Expand Down
23 changes: 23 additions & 0 deletions silhouette/Dialog.py
Original file line number Diff line number Diff line change
@@ -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()
17 changes: 10 additions & 7 deletions silhouette/MultiFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from silhouette.ColorSeparation import ColorSeparation

from silhouette.Dialog import Dialog

small_up_arrow = PyEmbeddedImage(
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYA"
"AAAf8/9hAAAABHNCSVQICAgIfAhkiAAAADxJ"
Expand All @@ -23,7 +25,6 @@
"//7+J6SJkYmZEacLkCUJacZqAD5DsInTLhDR"
"bcPlKrwugGnCFy6Mo3mBAQChDgRlP4RC7wAAAABJRU5ErkJggg==")


class ParamsNotebook(wx.Notebook):
"""Handle a notebook of tabs that contain params.

Expand Down Expand Up @@ -296,15 +297,15 @@ 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()
if not preset_name:
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(
Expand Down Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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()

Expand All @@ -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__')
Expand Down
31 changes: 4 additions & 27 deletions silhouette_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down