Commit 3946378c authored by Keegi's avatar Keegi

Implement resetting an option to its default value

parent 94ed9f35
...@@ -152,8 +152,13 @@ class PronterOptionsDialog(wx.Dialog): ...@@ -152,8 +152,13 @@ class PronterOptionsDialog(wx.Dialog):
grid.AddGrowableCol(1) grid.AddGrowableCol(1)
grid.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) grid.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)
for setting in settings: for setting in settings:
grid.Add(setting.get_label(grouppanel), 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.ALIGN_RIGHT) label,widget = setting.get_label(grouppanel),setting.get_widget(grouppanel)
grid.Add(setting.get_widget(grouppanel), 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND) grid.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.ALIGN_RIGHT)
grid.Add(widget, 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND)
if hasattr(label,"set_default"):
label.Bind(wx.EVT_MOUSE_EVENTS, label.set_default)
if hasattr(widget,"Bind"):
widget.Bind(wx.EVT_MOUSE_EVENTS, label.set_default)
grouppanel.SetSizer(grid) grouppanel.SetSizer(grid)
sbox.Add(notebook, 1, wx.EXPAND) sbox.Add(notebook, 1, wx.EXPAND)
panel.SetSizer(sbox) panel.SetSizer(sbox)
......
...@@ -68,10 +68,11 @@ def setting_add_tooltip(func): ...@@ -68,10 +68,11 @@ def setting_add_tooltip(func):
sep = "\n\n" sep = "\n\n"
if self.default is not "": if self.default is not "":
deftxt = _("Default: ") deftxt = _("Default: ")
resethelp = _("(Control-doubleclick to reset to default value)")
if len(repr(self.default)) > 10: if len(repr(self.default)) > 10:
deftxt += "\n " + repr(self.default).strip("'") deftxt += "\n " + repr(self.default).strip("'") + "\n" + resethelp
else: else:
deftxt += repr(self.default) deftxt += repr(self.default) + " " + resethelp
helptxt += sep + deftxt helptxt += sep + deftxt
if len(helptxt): if len(helptxt):
widget.SetToolTipString(helptxt) widget.SetToolTipString(helptxt)
...@@ -98,10 +99,18 @@ class Setting(object): ...@@ -98,10 +99,18 @@ class Setting(object):
raise NotImplementedError raise NotImplementedError
value = property(_get_value, _set_value) value = property(_get_value, _set_value)
def set_default(self, e):
import wx
if e.CmdDown() and e.ButtonDClick() and self.default is not "":
confirmation = wx.MessageDialog(None,_("Are you sure you want to reset the setting to the default value: {0!r} ?").format(self.default),_("Confirm set default"),wx.ICON_EXCLAMATION|wx.YES_NO|wx.NO_DEFAULT)
if confirmation.ShowModal() == wx.ID_YES:
self._set_value(self.default)
@setting_add_tooltip @setting_add_tooltip
def get_label(self, parent): def get_label(self, parent):
import wx import wx
widget = wx.StaticText(parent, -1, self.label or self.name) widget = wx.StaticText(parent, -1, self.label or self.name)
widget.set_default = self.set_default
return widget return widget
@setting_add_tooltip @setting_add_tooltip
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment