Commit 38c70846 authored by eric pellegrini's avatar eric pellegrini

Removed unused modules

Bug fixes with user definition related widgets
parent 45eff477
......@@ -2,6 +2,8 @@ import wx
from MDANSE import REGISTRY
from MDANSE.Framework.Configurators.IConfigurator import ConfiguratorError
class ConfigurationPanel(wx.Panel):
def __init__(self, parent, configurable):
......@@ -44,21 +46,21 @@ class ConfigurationPanel(wx.Panel):
return dict([(k,v.get_value()) for k,v in self._widgets.items()])
# def validate(self):
#
# for w in self._widgets.values():
# w.SetBackgroundColour(wx.NullColour)
# w.Refresh()
#
# try:
# self._configurable.parameters = self.get_value()
# except ConfiguratorError as e:
# d = wx.MessageDialog(self, str(e), style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTRE)
# d.ShowModal()
# w = self._widgets[e.configurator.name]
# w.SetBackgroundColour("Pink")
# w.Refresh()
# w.SetFocus()
# return False
# else:
# return True
def validate(self):
for w in self._widgets.values():
w.SetBackgroundColour(wx.NullColour)
w.Refresh()
parameters = {}
try:
parameters.update(self.get_value())
except ConfiguratorError as e:
d = wx.MessageDialog(self, str(e), style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTRE)
d.ShowModal()
w = self._widgets[e.configurator.name]
w.SetBackgroundColour("Pink")
w.Refresh()
w.SetFocus()
finally:
return parameters
......@@ -100,7 +100,10 @@ class JobPlugin(ComponentPlugin):
def on_run(self, event=None):
parameters = self._parametersPanel.get_value()
parameters = self._parametersPanel.validate()
if not parameters:
return
name = self._jobClass.set_name()
......@@ -123,10 +126,10 @@ class JobPlugin(ComponentPlugin):
def on_save(self, event=None):
if not self._parametersPanel.validate():
parameters = self._parametersPanel.validate()
if not parameters:
return
parameters = self._parametersPanel.get_value()
d = wx.FileDialog(self, "Save MDANSE python script", style = wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT, wildcard = "Python files (*.py)|*.py")
......
......@@ -151,6 +151,8 @@ class Query(object):
class AtomSelectionDialog(UserDefinitionsDialog):
type = 'atom_selection'
def __init__(self, parent, trajectory, *args, **kwargs):
self._query = Query()
......@@ -167,7 +169,7 @@ class AtomSelectionDialog(UserDefinitionsDialog):
target = os.path.basename(self._trajectory.filename)
UserDefinitionsDialog.__init__(self, parent, target, 'atom_selection', wx.ID_ANY, title="Atom selection dialog",style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
UserDefinitionsDialog.__init__(self, parent, target, wx.ID_ANY, title="Atom selection dialog",style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
pub.subscribe(self.on_select_atoms_from_viewer, ('select_atoms_from_viewer'))
......@@ -367,16 +369,18 @@ class AtomSelectionDialog(UserDefinitionsDialog):
def set_selection(self):
_, selection = self._query.parse()
_, self._selection = self._query.parse()
pub.sendMessage("set_selection", message = (self,selection))
pub.sendMessage("set_selection", message = (self,self._selection))
def validate(self):
if not self._ud:
if not self._selection:
LOGGER("The current selection is empty", "error", ["dialog"])
return None
self._ud['indexes'] = self._selection
return self._ud
class AtomSelectionWidget(UserDefinitionWidget):
......
......@@ -39,6 +39,8 @@ from MDANSE.App.GUI.Framework.Widgets.AtomSelectionWidget import AtomSelectionDi
class AtomTransmutationDialog(AtomSelectionDialog):
type = 'atom_transmutation'
def build_dialog(self):
AtomSelectionDialog.build_dialog(self)
......@@ -54,12 +56,15 @@ class AtomTransmutationDialog(AtomSelectionDialog):
def validate(self):
if not self._selection:
LOGGER("No atoms selected.", "error", ["dialog"])
LOGGER("The current selection is empty", "error", ["dialog"])
return None
element = self._elements.GetStringSelection()
return {'transmutation' : {'element' : element, 'selection' : self._selection}}
self._ud['element'] = element
self._ud['indexes'] = self._selection
return self._ud
class AtomTransmutationWidget(UserDefinitionWidget):
......
......@@ -39,7 +39,7 @@ from MDANSE.App.GUI.Framework.Widgets.UserDefinitionWidget import UserDefinition
from MDANSE.MolecularDynamics.Trajectory import find_atoms_in_molecule, get_chemical_objects_dict
class AtomsListDialog(UserDefinitionsDialog):
def __init__(self, parent, trajectory, nAtoms):
self._parent = parent
......@@ -53,10 +53,10 @@ class AtomsListDialog(UserDefinitionsDialog):
self._selection = []
target = os.path.basename(self._trajectory.filename)
section = "%d_atoms_list" % self._nAtoms
UserDefinitionsDialog.__init__(self, parent, target, section, wx.ID_ANY, title="%d Atoms selection dialog" % nAtoms,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
self.type = "%d_atoms_list" % self._nAtoms
UserDefinitionsDialog.__init__(self, parent, target, wx.ID_ANY, title="%d Atoms selection dialog" % nAtoms,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
def build_dialog(self):
......@@ -154,23 +154,26 @@ class AtomsListDialog(UserDefinitionsDialog):
def validate(self):
if not self._selection:
LOGGER("The current selection is empty", "error", ["dialog"])
return None
self._ud['indexes'] = self._selection
return {'selection' : self._selection}
return self._ud
class AtomListWidget(UserDefinitionWidget):
type = "atoms_list"
type = 'atoms_list'
def initialize(self):
self.type = "%d_atoms_list" % self._configurator._nAtoms
UserDefinitionWidget.initialize(self)
self.type = "%d_atoms_list" % self._configurator.nAtoms
def on_new_user_definition(self,event):
atomsListDlg = AtomsListDialog(self,self._trajectory,self.configuration[self._name].nAtoms)
atomsListDlg = AtomsListDialog(self,self._trajectory,self._configurator._nAtoms)
atomsListDlg.ShowModal()
......
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#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,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on Mar 30, 2015
:author: Eric C. Pellegrini
'''
from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.Configurable import ConfigurationError
from MDANSE.App.GUI.Framework.Widgets.UserDefinitionWidget import UserDefinitionWidget
class AxisSelectionWidget(UserDefinitionWidget):
type = "axis_selection"
def __init__(self, parent, name, configuration, *args, **kwargs):
UserDefinitionWidget.__init__(self,parent, name, configuration, *args, **kwargs)
pub.subscribe(self.msg_set_trajectory, ("set_trajectory"))
pub.subscribe(self.msg_new_definition, ("new_axis",))
def get_widget_value(self):
names = self._selections.GetControl().GetCheckedStrings()
if len(names) != 1:
raise ConfigurationError("Invalid number of axis definitions selected")
return names[0]
\ No newline at end of file
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#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,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''
Created on Mar 30, 2015
:author: Eric C. Pellegrini
'''
from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.Configurable import ConfigurationError
from MDANSE.App.GUI.Framework.Widgets.UserDefinitionWidget import UserDefinitionWidget
class BasisSelectionWidget(UserDefinitionWidget):
type = "basis_selection"
def __init__(self, parent, name, configuration, *args, **kwargs):
UserDefinitionWidget.__init__(self,parent, name, configuration, *args, **kwargs)
pub.subscribe(self.msg_set_trajectory, ("set_trajectory"))
pub.subscribe(self.msg_new_definition, ("new_basis",))
def get_widget_value(self):
names = self._selections.GetControl().GetCheckedStrings()
if len(names) != 1:
raise ConfigurationError("Invalid number of basis definitions selected")
return names[0]
\ No newline at end of file
......@@ -154,20 +154,20 @@ class QVectorsPanel(wx.Panel):
return self._progress
class QVectorsDialog(UserDefinitionsDialog):
type = 'q_vectors'
def __init__(self, parent, trajectory):
self._currentGenerator = None
self._value = None
self._qVectors = {}
self._trajectory = trajectory
target = os.path.basename(self._trajectory.filename)
UserDefinitionsDialog.__init__(self, parent, target, 'q_vectors', wx.ID_ANY, title="Q vectors generator dialog",style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
UserDefinitionsDialog.__init__(self, parent, target, wx.ID_ANY, title="Q vectors generator dialog",style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
self.SetSize((800,700))
......@@ -223,10 +223,9 @@ class QVectorsDialog(UserDefinitionsDialog):
LOGGER("No data is the selected Q vectors tab", "error")
return
self._qVectors.clear()
self._qVectors['parameters'] = (qPanel.generator.type,qPanel.parameters)
self._qVectors['q_vectors'] = qPanel.grid.GetTable().data
self._qVectors['is_lattice'] = qPanel.generator.is_lattice
self._ud['parameters'] = (qPanel.generator.type,qPanel.parameters)
self._ud['q_vectors'] = qPanel.grid.GetTable().data
self._ud['is_lattice'] = qPanel.generator.is_lattice
def on_close(self, event):
......@@ -280,10 +279,11 @@ class QVectorsDialog(UserDefinitionsDialog):
self.set_user_definition()
if not self._qVectors:
if not self._ud['q_vectors']:
LOGGER("No Q vectors generated.", "error", ["dialog"])
return None
return self._qVectors
return self._ud
def select_generator(self, generatorName):
......
......@@ -46,7 +46,7 @@ class UserDefinitionsDialog(wx.Dialog):
__metaclass__ = abc.ABCMeta
def __init__(self, parent, target, section, *args, **kwargs):
def __init__(self, parent, target, *args, **kwargs):
wx.Dialog.__init__(self, parent, *args, **kwargs)
......@@ -54,9 +54,9 @@ class UserDefinitionsDialog(wx.Dialog):
self._target = target
self._section = section
self._mainSizer = wx.BoxSizer(wx.VERTICAL)
self._ud = {}
self.build_dialog()
......@@ -107,15 +107,15 @@ class UserDefinitionsDialog(wx.Dialog):
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'])
if UD_STORE.has_definition(self._target,self.type,name):
LOGGER('There is already a user-definition that matches %s,%s,%s' % (self._target,self.type,name),'error',['dialog'])
self.EndModal(wx.ID_CANCEL)
return
UD_STORE.set_definition(self._target,self._section,name,value)
UD_STORE.set_definition(self._target,self.type,name,value)
UD_STORE.save()
pub.sendMessage("save_definition", message = (self._target, name))
pub.sendMessage("save_definition", message = (self._target, self.type, name))
self.EndModal(wx.ID_OK)
......@@ -177,9 +177,12 @@ class UserDefinitionWidget(IWidget):
def on_save_definition(self, message):
filename, name = message
filename, section, name = message
if section is not self.type:
return
if filename != self._basename:
return
self._availableUDs.Append(name)
......@@ -92,16 +92,14 @@ class AtomTransmutationConfigurator(IConfigurator):
indexes = parser.parse(element,expression)
self.transmutate(configuration, indexes, element)
# Otherwise, it must be a list of strings that will be found as user-definition keys
elif isinstance(value,(list,tuple)):
for definition in value:
if UD_STORE.has_definition(trajConfig["basename"],"atom_transmutation",value):
ud = UD_STORE.get_definition(trajConfig["basename"],"atom_transmutation",definition)
self.transmutate(configuration, ud["indexes"], ud["element"])
else:
raise ConfiguratorError("wrong parameters type: must be either a dictionary whose keys are an atom selection string and values are the target element \
or a list of string that match an user definition",self)
# Otherwise, it must be a string that will be found as a user-definition keys
elif isinstance(value,basestring):
if UD_STORE.has_definition(trajConfig["basename"],"atom_transmutation",value):
ud = UD_STORE.get_definition(trajConfig["basename"],"atom_transmutation",value)
self.transmutate(configuration, ud["indexes"], ud["element"])
else:
raise ConfiguratorError("wrong parameters type: must be either a dictionary whose keys are an atom selection string and values are the target element \
or a list of string that match an user definition",self)
else:
raise ConfiguratorError("wrong parameters type: must be either a dictionary whose keys are an atom selection string and values are the target element \
or a list of string that match an user definition",self)
......
......@@ -120,8 +120,6 @@ class MeanSquareDisplacement(IJob):
series = self.configuration['projection']["projector"](series)
1/0
msd = mean_square_displacement(series)
return index, msd
......
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