Commit 59c7b4e8 authored by eric pellegrini's avatar eric pellegrini
Browse files

Implemented a generic dialog for setting user definitions

Removed the old unused UserDefinitionsPanel
parent 2a25af75
......@@ -30,42 +30,93 @@ Created on Apr 14, 2015
:author: Eric C. Pellegrini
'''
import abc
import wx
class UserDefinitionsPanel(wx.Panel):
from MDANSE import LOGGER
from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.UserDefinitionsStore import UD_STORE
class UserDefinitionsDialog(wx.Dialog):
__metaclass__ = abc.ABCMeta
def __init__(self, parent, *args, **kwargs):
def __init__(self, parent, target, section, *args, **kwargs):
wx.Panel.__init__(self, parent, wx.ID_ANY, *args, **kwargs)
wx.Dialog.__init__(self, parent, *args, **kwargs)
self._parent = parent
sb = wx.StaticBox(self, wx.ID_ANY)
self._target = target
self._section = section
self._ud = {}
self._mainSizer = wx.BoxSizer(wx.VERTICAL)
self.build_dialog()
udPanel = wx.Panel(self,wx.ID_ANY)
sb = wx.StaticBox(udPanel, wx.ID_ANY)
actionsSizer = wx.StaticBoxSizer(sb, wx.HORIZONTAL)
self._cancelButton = wx.Button(self, wx.ID_ANY, label="Cancel")
self._udName = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_PROCESS_ENTER)
self._saveButton = wx.Button(self, wx.ID_ANY, label="Save")
cancelButton = wx.Button(udPanel, wx.ID_ANY, label="Cancel")
self._udName = wx.TextCtrl(udPanel, wx.ID_ANY, style = wx.TE_PROCESS_ENTER)
saveButton = wx.Button(udPanel, wx.ID_ANY, label="Save")
actionsSizer.Add(self._cancelButton, 0, wx.ALL, 5)
actionsSizer.Add(cancelButton, 0, wx.ALL, 5)
actionsSizer.Add(self._udName, 1, wx.ALL|wx.EXPAND, 5)
actionsSizer.Add(self._saveButton, 0, wx.ALL, 5)
actionsSizer.Add(saveButton, 0, wx.ALL, 5)
self.SetSizer(actionsSizer)
udPanel.SetSizer(actionsSizer)
self.Layout()
self._mainSizer.Add(udPanel,0,wx.EXPAND|wx.ALL,5)
self.Bind(wx.EVT_BUTTON, self.on_close, self._cancelButton)
self.Bind(wx.EVT_BUTTON, self.on_save, self._saveButton)
self.SetSizer(self._mainSizer)
def get_selection_name(self):
self.Bind(wx.EVT_CLOSE, self.on_close)
self.Bind(wx.EVT_BUTTON, self.on_close, cancelButton)
self.Bind(wx.EVT_BUTTON, self.on_save, saveButton)
return self._udName.GetValue()
@abc.abstractmethod
def build_dialog(self):
pass
def on_close(self, event):
@abc.abstractmethod
def validate(self):
pass
self._parent.Parent.on_close()
def getUserDefinitionName(self):
return str(self._udName.GetValue())
def on_save(self, event):
self._parent.Parent.on_save()
\ No newline at end of file
name = str(self._udName.GetValue().strip())
if not name:
LOGGER('Empty user definition name.','error',['dialog'])
return
value = self.validate()
if value is None:
return
if UD_STORE.has_definition(self._target,self._section,name):
LOGGER('There is already a user-definition that matches %s,%s,%s' % (self._target,self._section,name),'error',['dialog'])
self.EndModal(wx.ID_CANCEL)
return
UD_STORE.set_definition(self._target,self._section,name,value)
UD_STORE.save()
pub.sendMessage("save_definition", message = (self._target, name))
self.EndModal(wx.ID_OK)
def on_close(self, event):
self.EndModal(wx.ID_CANCEL)
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