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
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments #MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------
#Copyright (C) #Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin #2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156 #BP 156
#6, rue Jules Horowitz #6, rue Jules Horowitz
#38042 Grenoble Cedex 9 #38042 Grenoble Cedex 9
#France #France
#pellegrini[at]ill.fr #pellegrini[at]ill.fr
#goret[at]ill.fr #goret[at]ill.fr
#aoun[at]ill.fr #aoun[at]ill.fr
# #
#This library is free software; you can redistribute it and/or #This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public #modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either #License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version. #version 2.1 of the License, or (at your option) any later version.
# #
#This library is distributed in the hope that it will be useful, #This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of #but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details. #Lesser General Public License for more details.
# #
#You should have received a copy of the GNU Lesser General Public #You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software #License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
''' '''
Created on Apr 14, 2015 Created on Apr 14, 2015
:author: Eric C. Pellegrini :author: Eric C. Pellegrini
''' '''
import wx import abc
class UserDefinitionsPanel(wx.Panel): import wx
def __init__(self, parent, *args, **kwargs): from MDANSE import LOGGER
from MDANSE.Externals.pubsub import pub
wx.Panel.__init__(self, parent, wx.ID_ANY, *args, **kwargs) from MDANSE.Framework.UserDefinitionsStore import UD_STORE
self._parent = parent class UserDefinitionsDialog(wx.Dialog):
sb = wx.StaticBox(self, wx.ID_ANY) __metaclass__ = abc.ABCMeta
actionsSizer = wx.StaticBoxSizer(sb, wx.HORIZONTAL)
def __init__(self, parent, target, section, *args, **kwargs):
self._cancelButton = wx.Button(self, wx.ID_ANY, label="Cancel")
self._udName = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_PROCESS_ENTER) wx.Dialog.__init__(self, parent, *args, **kwargs)
self._saveButton = wx.Button(self, wx.ID_ANY, label="Save")
self._parent = parent
actionsSizer.Add(self._cancelButton, 0, wx.ALL, 5)
actionsSizer.Add(self._udName, 1, wx.ALL|wx.EXPAND, 5) self._target = target
actionsSizer.Add(self._saveButton, 0, wx.ALL, 5)
self._section = section
self.SetSizer(actionsSizer)
self._ud = {}
self.Layout()
self._mainSizer = wx.BoxSizer(wx.VERTICAL)
self.Bind(wx.EVT_BUTTON, self.on_close, self._cancelButton)
self.Bind(wx.EVT_BUTTON, self.on_save, self._saveButton) self.build_dialog()
def get_selection_name(self): udPanel = wx.Panel(self,wx.ID_ANY)
return self._udName.GetValue() sb = wx.StaticBox(udPanel, wx.ID_ANY)
actionsSizer = wx.StaticBoxSizer(sb, wx.HORIZONTAL)
def on_close(self, event):
cancelButton = wx.Button(udPanel, wx.ID_ANY, label="Cancel")
self._parent.Parent.on_close() self._udName = wx.TextCtrl(udPanel, wx.ID_ANY, style = wx.TE_PROCESS_ENTER)
saveButton = wx.Button(udPanel, wx.ID_ANY, label="Save")
def on_save(self, event):
actionsSizer.Add(cancelButton, 0, wx.ALL, 5)
self._parent.Parent.on_save() actionsSizer.Add(self._udName, 1, wx.ALL|wx.EXPAND, 5)
\ No newline at end of file actionsSizer.Add(saveButton, 0, wx.ALL, 5)
udPanel.SetSizer(actionsSizer)
self._mainSizer.Add(udPanel,0,wx.EXPAND|wx.ALL,5)
self.SetSizer(self._mainSizer)
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)
@abc.abstractmethod
def build_dialog(self):
pass
@abc.abstractmethod
def validate(self):
pass
def getUserDefinitionName(self):
return str(self._udName.GetValue())
def on_save(self, event):
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