Commit 1ac79dbf authored by eric pellegrini's avatar eric pellegrini
Browse files

Modified configurators widget according to the change in Configurable

class
parent 7831fa64
import wx import wx
from MDANSE import REGISTRY from MDANSE import REGISTRY
from MDANSE.Framework.Configurators.IConfigurator import ConfiguratorError
class ConfigurationPanel(wx.Panel): class ConfigurationPanel(wx.Panel):
...@@ -19,11 +18,15 @@ class ConfigurationPanel(wx.Panel): ...@@ -19,11 +18,15 @@ class ConfigurationPanel(wx.Panel):
self.panelSizer = wx.BoxSizer(wx.VERTICAL) self.panelSizer = wx.BoxSizer(wx.VERTICAL)
for cfgName, cfg in self._configurable.settings.items(): configuration = self._configurable.build_configuration()
widgetClass = REGISTRY["widget"][cfg[1].get('widget',cfg[0])] for cfgName in self._configurable.settings.keys():
widget = configuration[cfgName].widget
widgetClass = REGISTRY["widget"][widget]
self._widgets[cfgName] = widgetClass(self, cfgName, self._configurable) self._widgets[cfgName] = widgetClass(self, cfgName, configuration[cfgName])
self.panelSizer.Add(self._widgets[cfgName], 0, wx.ALL|wx.EXPAND, 5) self.panelSizer.Add(self._widgets[cfgName], 0, wx.ALL|wx.EXPAND, 5)
...@@ -41,21 +44,21 @@ class ConfigurationPanel(wx.Panel): ...@@ -41,21 +44,21 @@ class ConfigurationPanel(wx.Panel):
return dict([(k,v.get_value()) for k,v in self._widgets.items()]) return dict([(k,v.get_value()) for k,v in self._widgets.items()])
def validate(self): # def validate(self):
#
for w in self._widgets.values(): # for w in self._widgets.values():
w.SetBackgroundColour(wx.NullColour) # w.SetBackgroundColour(wx.NullColour)
w.Refresh() # w.Refresh()
#
try: # try:
self._configurable.parameters = self.get_value() # self._configurable.parameters = self.get_value()
except ConfiguratorError as e: # except ConfiguratorError as e:
d = wx.MessageDialog(self, str(e), style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTRE) # d = wx.MessageDialog(self, str(e), style=wx.ICON_ERROR|wx.STAY_ON_TOP|wx.CENTRE)
d.ShowModal() # d.ShowModal()
w = self._widgets[e.configurator.name] # w = self._widgets[e.configurator.name]
w.SetBackgroundColour("Pink") # w.SetBackgroundColour("Pink")
w.Refresh() # w.Refresh()
w.SetFocus() # w.SetFocus()
return False # return False
else: # else:
return True # return True
...@@ -38,7 +38,6 @@ import wx ...@@ -38,7 +38,6 @@ import wx
from MDANSE import LOGGER, REGISTRY from MDANSE import LOGGER, REGISTRY
from MDANSE.Externals.pubsub import pub from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.AtomSelectionParser import AtomSelectionParser, AtomSelectionParserError from MDANSE.Framework.AtomSelectionParser import AtomSelectionParser, AtomSelectionParserError
from MDANSE.Framework.Configurable import ConfigurationError
from MDANSE.MolecularDynamics.Trajectory import sorted_atoms from MDANSE.MolecularDynamics.Trajectory import sorted_atoms
from MDANSE.App.GUI.Framework.Widgets.UserDefinitionWidget import UserDefinitionsDialog, UserDefinitionWidget from MDANSE.App.GUI.Framework.Widgets.UserDefinitionWidget import UserDefinitionsDialog, UserDefinitionWidget
...@@ -389,6 +388,15 @@ class AtomSelectionWidget(UserDefinitionWidget): ...@@ -389,6 +388,15 @@ class AtomSelectionWidget(UserDefinitionWidget):
dlg = AtomSelectionDialog(self,self._trajectory) dlg = AtomSelectionDialog(self,self._trajectory)
dlg.Show() dlg.Show()
def get_widget_value(self):
ud = self._availableUDs.GetStringSelection()
if not ud:
return 'all'
else:
return str(ud)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -34,7 +34,8 @@ import wx ...@@ -34,7 +34,8 @@ import wx
from MDANSE import ELEMENTS, LOGGER from MDANSE import ELEMENTS, LOGGER
from MDANSE.App.GUI.Framework.Widgets.AtomSelectionWidget import AtomSelectionDialog, AtomSelectionWidget from MDANSE.App.GUI.Framework.Widgets.UserDefinitionWidget import UserDefinitionWidget
from MDANSE.App.GUI.Framework.Widgets.AtomSelectionWidget import AtomSelectionDialog
class AtomTransmutationDialog(AtomSelectionDialog): class AtomTransmutationDialog(AtomSelectionDialog):
...@@ -60,7 +61,7 @@ class AtomTransmutationDialog(AtomSelectionDialog): ...@@ -60,7 +61,7 @@ class AtomTransmutationDialog(AtomSelectionDialog):
return {'transmutation' : {'element' : element, 'selection' : self._selection}} return {'transmutation' : {'element' : element, 'selection' : self._selection}}
class AtomTransmutationWidget(AtomSelectionWidget): class AtomTransmutationWidget(UserDefinitionWidget):
type = "atom_transmutation" type = "atom_transmutation"
...@@ -69,6 +70,15 @@ class AtomTransmutationWidget(AtomSelectionWidget): ...@@ -69,6 +70,15 @@ class AtomTransmutationWidget(AtomSelectionWidget):
dlg = AtomTransmutationDialog(self,self._trajectory) dlg = AtomTransmutationDialog(self,self._trajectory)
dlg.Show() dlg.Show()
def get_widget_value(self):
ud = self._availableUDs.GetStringSelection()
if not ud:
return None
else:
return str(ud)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -166,11 +166,11 @@ class AtomListWidget(UserDefinitionWidget): ...@@ -166,11 +166,11 @@ class AtomListWidget(UserDefinitionWidget):
UserDefinitionWidget.initialize(self) UserDefinitionWidget.initialize(self)
self.type = "%d_atoms_list" % self.configurator.nAtoms self.type = "%d_atoms_list" % self._configurator.nAtoms
def on_new_user_definition(self,event): def on_new_user_definition(self,event):
atomsListDlg = AtomsListDialog(self,self._trajectory,self.configurator.nAtoms) atomsListDlg = AtomsListDialog(self,self._trajectory,self.configuration[self._name].nAtoms)
atomsListDlg.ShowModal() atomsListDlg.ShowModal()
......
...@@ -42,10 +42,8 @@ class BooleanWidget(IWidget): ...@@ -42,10 +42,8 @@ class BooleanWidget(IWidget):
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
default = self.configurator.default
self._boolean = wx.CheckBox(self._widgetPanel, wx.ID_ANY, label="Yes") self._boolean = wx.CheckBox(self._widgetPanel, wx.ID_ANY, label="Yes")
self._boolean.SetValue(default) self._boolean.SetValue(self._configurator.default)
sizer.Add(self._boolean, 1, wx.ALL|wx.EXPAND, 5) sizer.Add(self._boolean, 1, wx.ALL|wx.EXPAND, 5)
......
...@@ -44,7 +44,7 @@ class FloatWidget(StringWidget): ...@@ -44,7 +44,7 @@ class FloatWidget(StringWidget):
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
self._float = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=str(self.configurator.default)) self._float = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=str(self._configurator.default))
sizer.Add(self._float, 0, wx.ALL, 5) sizer.Add(self._float, 0, wx.ALL, 5)
...@@ -53,9 +53,8 @@ class FloatWidget(StringWidget): ...@@ -53,9 +53,8 @@ class FloatWidget(StringWidget):
def get_widget_value(self): def get_widget_value(self):
try: try:
_ = float(self._float.GetValue()) val = float(self._float.GetValue())
except ValueError: except ValueError:
raise ConfigurationError("Invalid value for %r entry" % self.configurator.name) raise ConfigurationError("Invalid value for %r entry" % self.name)
val = self._float.GetValue() else:
return val
return val
...@@ -42,28 +42,22 @@ class IWidget(wx.Panel): ...@@ -42,28 +42,22 @@ class IWidget(wx.Panel):
type = "widget" type = "widget"
def __init__(self, parent, name, configurable, *args, **kwargs): def __init__(self, parent, name, configurator, *args, **kwargs):
wx.Panel.__init__(self, parent, wx.ID_ANY, *args, **kwargs) wx.Panel.__init__(self, parent, wx.ID_ANY, *args, **kwargs)
self._parent = parent self._parent = parent
self._name = name self._name = name
self._configurable = configurable self._configurator = configurator
self._configurator = self._configurable.configurators[name] self._label = name
self._label = self._configurator.label
self.initialize() self.initialize()
self.build_panel() self.build_panel()
@property
def configurator(self):
return self._configurator
@property @property
def label(self): def label(self):
return self._label return self._label
......
...@@ -41,12 +41,12 @@ class InputDirectoryWidget(IWidget): ...@@ -41,12 +41,12 @@ class InputDirectoryWidget(IWidget):
def add_widgets(self): def add_widgets(self):
cfg = self.configurator default = self._configurator.default
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
self._dirname = wxfile.DirBrowseButton(self._widgetPanel, wx.ID_ANY, startDirectory=cfg.default, newDirectory=True) self._dirname = wxfile.DirBrowseButton(self._widgetPanel, wx.ID_ANY, startDirectory=default, newDirectory=True)
self._dirname.SetValue(cfg.default) self._dirname.SetValue(default)
sizer.Add(self._dirname, 1, wx.ALL|wx.EXPAND, 0) sizer.Add(self._dirname, 1, wx.ALL|wx.EXPAND, 0)
......
...@@ -43,11 +43,12 @@ class InputFileWidget(IWidget): ...@@ -43,11 +43,12 @@ class InputFileWidget(IWidget):
def add_widgets(self): def add_widgets(self):
cfg = self.configurator default = self._configurator.default
wildcard = self._configurator.wildcard
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
self._browser = wxfile.FileBrowseButton(self._widgetPanel, wx.ID_ANY, labelText="", initialValue=cfg.default, startDirectory=cfg.default,fileMask=cfg.wildcard) self._browser = wxfile.FileBrowseButton(self._widgetPanel, wx.ID_ANY, labelText="", initialValue=default, startDirectory=default,fileMask=wildcard)
sizer.Add(self._browser, 1, wx.ALL|wx.EXPAND, 5) sizer.Add(self._browser, 1, wx.ALL|wx.EXPAND, 5)
......
...@@ -191,7 +191,7 @@ class InstrumentResolutionConfigurator(IWidget): ...@@ -191,7 +191,7 @@ class InstrumentResolutionConfigurator(IWidget):
sizer = wx.BoxSizer(wx.HORIZONTAL) sizer = wx.BoxSizer(wx.HORIZONTAL)
self._resolution = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=str(self.configurator.default)) self._resolution = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=str(self._configurator.default))
self._setResolution = wx.Button(self._widgetPanel, wx.ID_ANY, label="Set") self._setResolution = wx.Button(self._widgetPanel, wx.ID_ANY, label="Set")
self._setResolution.Enable(False) self._setResolution.Enable(False)
...@@ -212,7 +212,7 @@ class InstrumentResolutionConfigurator(IWidget): ...@@ -212,7 +212,7 @@ class InstrumentResolutionConfigurator(IWidget):
def on_set_instrument_resolution(self, event): def on_set_instrument_resolution(self, event):
frameCfgName = self.configurator.dependencies["frames"] frameCfgName = self._configurator.dependencies["frames"]
time = self.Parent.widgets[frameCfgName].time time = self.Parent.widgets[frameCfgName].time
timeStep = time[1] - time[0] timeStep = time[1] - time[0]
nSteps = len(time) nSteps = len(time)
......
...@@ -45,7 +45,7 @@ class IntegerWidget(IWidget): ...@@ -45,7 +45,7 @@ class IntegerWidget(IWidget):
cfg = self._configurator cfg = self._configurator
if cfg.choices: if self._configurator.choices:
self._integer = wx.SpinCtrl(self._widgetPanel, wx.ID_ANY, min=cfg.choices[0], max=cfg.choices[-1], initial=cfg.default, style=wx.SP_ARROW_KEYS|wx.SP_WRAP) self._integer = wx.SpinCtrl(self._widgetPanel, wx.ID_ANY, min=cfg.choices[0], max=cfg.choices[-1], initial=cfg.default, style=wx.SP_ARROW_KEYS|wx.SP_WRAP)
else: else:
self._integer = wxintctrl.IntCtrl(self._widgetPanel, wx.ID_ANY, value=cfg.default, min=cfg.mini, max=cfg.maxi, limited=True, allow_none=False, style=wx.ALIGN_RIGHT) self._integer = wxintctrl.IntCtrl(self._widgetPanel, wx.ID_ANY, value=cfg.default, min=cfg.mini, max=cfg.maxi, limited=True, allow_none=False, style=wx.ALIGN_RIGHT)
......
...@@ -47,19 +47,16 @@ class InterpolationOrderWidget(IWidget): ...@@ -47,19 +47,16 @@ class InterpolationOrderWidget(IWidget):
label = wx.StaticText(self._widgetPanel, wx.ID_ANY, label="interpolation order") label = wx.StaticText(self._widgetPanel, wx.ID_ANY, label="interpolation order")
self._interpolationOrder = wx.Choice(self._widgetPanel, wx.ID_ANY, choices=self.configurator.orders) self._interpolationOrder = wx.Choice(self._widgetPanel, wx.ID_ANY)
self._interpolationOrder.SetStringSelection(InterpolationOrderWidget.orders[self.configurator.default])
sizer.Add(label, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) sizer.Add(label, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
sizer.Add(self._interpolationOrder, 0, wx.ALL, 5) sizer.Add(self._interpolationOrder, 0, wx.ALL, 5)
pub.subscribe(self.set_wigdet_value, ("set_trajectory")) pub.subscribe(self.on_set_trajectory, ("set_trajectory"))
self._interpolationOrder.SetValue(self.configurator.orders[0])
return sizer return sizer
def set_wigdet_value(self, message): def on_set_trajectory(self, message):
window, filename = message window, filename = message
...@@ -69,9 +66,11 @@ class InterpolationOrderWidget(IWidget): ...@@ -69,9 +66,11 @@ class InterpolationOrderWidget(IWidget):
trajectory = DATA_CONTROLLER[filename] trajectory = DATA_CONTROLLER[filename]
if "velocities" in trajectory.data.variables(): if "velocities" in trajectory.data.variables():
self._interpolationOrder.SetStringSelection(self.configurator.orders) self._interpolationOrder.SetItems(self._configurator.choices)
else: else:
self._interpolationOrder.SetStringSelection(self.configurator.orders[1:]) self._interpolationOrder.SetItems(self._configurator.choices[1:])
self._interpolationOrder.SetStringSelection(self._configurator.choices[0])
def get_widget_value(self): def get_widget_value(self):
......
...@@ -34,7 +34,7 @@ import wx ...@@ -34,7 +34,7 @@ import wx
from MDANSE.Framework.Jobs.McStasVirtualInstrument import McStasOptions from MDANSE.Framework.Jobs.McStasVirtualInstrument import McStasOptions
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget
from MDANSE.App.GUI.ConfigurationPanel import ConfigurationPanel from MDANSE.App.GUI.ComboWidgets.ConfigurationPanel import ConfigurationPanel
class McStasOptionsConfiguratorWidget(IWidget): class McStasOptionsConfiguratorWidget(IWidget):
......
...@@ -36,7 +36,7 @@ from MDANSE.Externals.pubsub import pub ...@@ -36,7 +36,7 @@ from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.Configurable import ConfigurationError from MDANSE.Framework.Configurable import ConfigurationError
from MDANSE.Framework.Jobs.McStasVirtualInstrument import McStasParameters from MDANSE.Framework.Jobs.McStasVirtualInstrument import McStasParameters
from MDANSE.App.GUI.ConfigurationPanel import ConfigurationPanel from MDANSE.App.GUI.ComboWidgets.ConfigurationPanel import ConfigurationPanel
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget
class McStasParametersWidget(IWidget): class McStasParametersWidget(IWidget):
...@@ -63,14 +63,14 @@ class McStasParametersWidget(IWidget): ...@@ -63,14 +63,14 @@ class McStasParametersWidget(IWidget):
if not window in self.Parent.widgets.values(): if not window in self.Parent.widgets.values():
return return
for k in self.configurator.exclude: for k in self._configurator.exclude:
parameters.pop(k) parameters.pop(k)
self._mcstasParameters = McStasParameters() self._mcstasParameters = McStasParameters()
for name, value in parameters.items(): for name, value in parameters.items():
typ, default = value typ, default = value
self._mcstasParameters.configurators[name] = (self._mcStasTypes[typ], {"default":default}) self._mcstasParameters.settings[name] = (self._mcStasTypes[typ], {"default":default})
self._sizer.Clear(deleteWindows=True) self._sizer.Clear(deleteWindows=True)
......
...@@ -42,11 +42,13 @@ class MultipleChoicesWidget(IWidget): ...@@ -42,11 +42,13 @@ class MultipleChoicesWidget(IWidget):
def add_widgets(self): def add_widgets(self):
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
cfg = self._configurator
self._choices = wx.combo.ComboCtrl(self._widgetPanel, value=self.configurator.label, style=wx.CB_READONLY) self._choices = wx.combo.ComboCtrl(self._widgetPanel, value=cfg.label, style=wx.CB_READONLY)
tcp = ComboCheckbox(self.configurator.choices,self.configurator.nChoices) tcp = ComboCheckbox(cfg.choices,cfg.nChoices)
self._choices.SetPopupControl(tcp) self._choices.SetPopupControl(tcp)
tcp.checklistbox.SetCheckedStrings(self.configurator.default) tcp.checklistbox.SetCheckedStrings(cfg.default)
sizer.Add(self._choices, 1, wx.ALL|wx.EXPAND, 5) sizer.Add(self._choices, 1, wx.ALL|wx.EXPAND, 5)
......
...@@ -110,7 +110,7 @@ class ProjectionWidget(IWidget): ...@@ -110,7 +110,7 @@ class ProjectionWidget(IWidget):
try: try:
val = ("axial", tuple([float(v.GetValue()) for v in (self._ax,self._ay,self._az)])) val = ("axial", tuple([float(v.GetValue()) for v in (self._ax,self._ay,self._az)]))
except ValueError: except ValueError:
raise ConfigurationError("Invalid value for %r entry" % self.configurator.name) raise ConfigurationError("Invalid value for %r entry" % self.name)
else: else:
return val return val
...@@ -118,7 +118,7 @@ class ProjectionWidget(IWidget): ...@@ -118,7 +118,7 @@ class ProjectionWidget(IWidget):
try: try:
val = ("planar", tuple([v.GetValue() for v in (self._px,self._py,self._pz)])) val = ("planar", tuple([v.GetValue() for v in (self._px,self._py,self._pz)]))
except ValueError: except ValueError:
raise ConfigurationError("Invalid value for %r entry" % self.configurator.name) raise ConfigurationError("Invalid value for %r entry" % self.name)
else: else:
return val return val
......
...@@ -44,7 +44,7 @@ class PythonObjectWidget(IWidget): ...@@ -44,7 +44,7 @@ class PythonObjectWidget(IWidget):
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
self._string = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=repr(self.configurator.default)) self._string = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=repr(self._configurator[self._name].default))
sizer.Add(self._string, 0, wx.ALL, 5) sizer.Add(self._string, 0, wx.ALL, 5)
......
<
...@@ -54,11 +54,11 @@ class RangeWidget(IWidget): ...@@ -54,11 +54,11 @@ class RangeWidget(IWidget):
self._last = wx.TextCtrl(self._widgetPanel, wx.ID_ANY) self._last = wx.TextCtrl(self._widgetPanel, wx.ID_ANY)
self._step = wx.TextCtrl(self._widgetPanel, wx.ID_ANY) self._step = wx.TextCtrl(self._widgetPanel, wx.ID_ANY)
cfg = self.configurator first, last, step = self._configurator.default
self._first.SetValue(str(cfg.default[0])) self._first.SetValue(str(first))
self._last.SetValue(str(cfg.default[1])) self._last.SetValue(str(last))
self._step.SetValue(str(cfg.default[2])) self._step.SetValue(str(step))
gbSizer.Add(firstLabel, (0,0), flag=wx.ALIGN_CENTER_VERTICAL) gbSizer.Add(firstLabel, (0,0), flag=wx.ALIGN_CENTER_VERTICAL)
gbSizer.Add(labelLabel, (0,3), flag=wx.ALIGN_CENTER_VERTICAL) gbSizer.Add(labelLabel, (0,3), flag=wx.ALIGN_CENTER_VERTICAL)
...@@ -75,10 +75,10 @@ class RangeWidget(IWidget): ...@@ -75,10 +75,10 @@ class RangeWidget(IWidget):
def get_widget_value(self): def get_widget_value(self):
try: try:
val = (self.configurator.valueType(self._first.GetValue()), val = (self._configurator.valueType(self._first.GetValue()),
self.configurator.valueType(self._last.GetValue()), self._configurator.valueType(self._last.GetValue()),