The code.ill.fr has been recreated and upgraded with the latest version this weekend, If you encounter any problem please inform the Helpdesk.

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
from MDANSE import REGISTRY
from MDANSE.Framework.Configurators.IConfigurator import ConfiguratorError
class ConfigurationPanel(wx.Panel):
......@@ -19,11 +18,15 @@ class ConfigurationPanel(wx.Panel):
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)
......@@ -41,21 +44,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()
#
# 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
......@@ -38,7 +38,6 @@ import wx
from MDANSE import LOGGER, REGISTRY
from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.AtomSelectionParser import AtomSelectionParser, AtomSelectionParserError
from MDANSE.Framework.Configurable import ConfigurationError
from MDANSE.MolecularDynamics.Trajectory import sorted_atoms
from MDANSE.App.GUI.Framework.Widgets.UserDefinitionWidget import UserDefinitionsDialog, UserDefinitionWidget
......@@ -389,6 +388,15 @@ class AtomSelectionWidget(UserDefinitionWidget):
dlg = AtomSelectionDialog(self,self._trajectory)
dlg.Show()
def get_widget_value(self):
ud = self._availableUDs.GetStringSelection()
if not ud:
return 'all'
else:
return str(ud)
if __name__ == "__main__":
......
......@@ -34,7 +34,8 @@ import wx
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):
......@@ -60,7 +61,7 @@ class AtomTransmutationDialog(AtomSelectionDialog):
return {'transmutation' : {'element' : element, 'selection' : self._selection}}
class AtomTransmutationWidget(AtomSelectionWidget):
class AtomTransmutationWidget(UserDefinitionWidget):
type = "atom_transmutation"
......@@ -69,6 +70,15 @@ class AtomTransmutationWidget(AtomSelectionWidget):
dlg = AtomTransmutationDialog(self,self._trajectory)
dlg.Show()
def get_widget_value(self):
ud = self._availableUDs.GetStringSelection()
if not ud:
return None
else:
return str(ud)
if __name__ == "__main__":
......
......@@ -166,11 +166,11 @@ class AtomListWidget(UserDefinitionWidget):
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):
atomsListDlg = AtomsListDialog(self,self._trajectory,self.configurator.nAtoms)
atomsListDlg = AtomsListDialog(self,self._trajectory,self.configuration[self._name].nAtoms)
atomsListDlg.ShowModal()
......
......@@ -42,10 +42,8 @@ class BooleanWidget(IWidget):
sizer = wx.BoxSizer(wx.VERTICAL)
default = self.configurator.default
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)
......
......@@ -44,7 +44,7 @@ class FloatWidget(StringWidget):
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)
......@@ -53,9 +53,8 @@ class FloatWidget(StringWidget):
def get_widget_value(self):
try:
_ = float(self._float.GetValue())
val = float(self._float.GetValue())
except ValueError:
raise ConfigurationError("Invalid value for %r entry" % self.configurator.name)
val = self._float.GetValue()
return val
raise ConfigurationError("Invalid value for %r entry" % self.name)
else:
return val
......@@ -42,28 +42,22 @@ class IWidget(wx.Panel):
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)
self._parent = parent
self._name = name
self._configurable = configurable
self._configurator = self._configurable.configurators[name]
self._label = self._configurator.label
self._configurator = configurator
self._label = name
self.initialize()
self.build_panel()
@property
def configurator(self):
return self._configurator
@property
def label(self):
return self._label
......
......@@ -41,12 +41,12 @@ class InputDirectoryWidget(IWidget):
def add_widgets(self):
cfg = self.configurator
default = self._configurator.default
sizer = wx.BoxSizer(wx.VERTICAL)
self._dirname = wxfile.DirBrowseButton(self._widgetPanel, wx.ID_ANY, startDirectory=cfg.default, newDirectory=True)
self._dirname.SetValue(cfg.default)
self._dirname = wxfile.DirBrowseButton(self._widgetPanel, wx.ID_ANY, startDirectory=default, newDirectory=True)
self._dirname.SetValue(default)
sizer.Add(self._dirname, 1, wx.ALL|wx.EXPAND, 0)
......
......@@ -43,11 +43,12 @@ class InputFileWidget(IWidget):
def add_widgets(self):
cfg = self.configurator
default = self._configurator.default
wildcard = self._configurator.wildcard
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)
......
......@@ -191,7 +191,7 @@ class InstrumentResolutionConfigurator(IWidget):
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.Enable(False)
......@@ -212,7 +212,7 @@ class InstrumentResolutionConfigurator(IWidget):
def on_set_instrument_resolution(self, event):
frameCfgName = self.configurator.dependencies["frames"]
frameCfgName = self._configurator.dependencies["frames"]
time = self.Parent.widgets[frameCfgName].time
timeStep = time[1] - time[0]
nSteps = len(time)
......
......@@ -45,7 +45,7 @@ class IntegerWidget(IWidget):
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)
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)
......
......@@ -47,19 +47,16 @@ class InterpolationOrderWidget(IWidget):
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.SetStringSelection(InterpolationOrderWidget.orders[self.configurator.default])
self._interpolationOrder = wx.Choice(self._widgetPanel, wx.ID_ANY)
sizer.Add(label, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 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
def set_wigdet_value(self, message):
def on_set_trajectory(self, message):
window, filename = message
......@@ -69,9 +66,11 @@ class InterpolationOrderWidget(IWidget):
trajectory = DATA_CONTROLLER[filename]
if "velocities" in trajectory.data.variables():
self._interpolationOrder.SetStringSelection(self.configurator.orders)
self._interpolationOrder.SetItems(self._configurator.choices)
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):
......
......@@ -34,7 +34,7 @@ import wx
from MDANSE.Framework.Jobs.McStasVirtualInstrument import McStasOptions
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):
......
......@@ -36,7 +36,7 @@ from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.Configurable import ConfigurationError
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
class McStasParametersWidget(IWidget):
......@@ -63,14 +63,14 @@ class McStasParametersWidget(IWidget):
if not window in self.Parent.widgets.values():
return
for k in self.configurator.exclude:
for k in self._configurator.exclude:
parameters.pop(k)
self._mcstasParameters = McStasParameters()
for name, value in parameters.items():
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)
......
......@@ -42,11 +42,13 @@ class MultipleChoicesWidget(IWidget):
def add_widgets(self):
sizer = wx.BoxSizer(wx.VERTICAL)
cfg = self._configurator
self._choices = wx.combo.ComboCtrl(self._widgetPanel, value=self.configurator.label, style=wx.CB_READONLY)
tcp = ComboCheckbox(self.configurator.choices,self.configurator.nChoices)
self._choices = wx.combo.ComboCtrl(self._widgetPanel, value=cfg.label, style=wx.CB_READONLY)
tcp = ComboCheckbox(cfg.choices,cfg.nChoices)
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)
......
......@@ -110,7 +110,7 @@ class ProjectionWidget(IWidget):
try:
val = ("axial", tuple([float(v.GetValue()) for v in (self._ax,self._ay,self._az)]))
except ValueError:
raise ConfigurationError("Invalid value for %r entry" % self.configurator.name)
raise ConfigurationError("Invalid value for %r entry" % self.name)
else:
return val
......@@ -118,7 +118,7 @@ class ProjectionWidget(IWidget):
try:
val = ("planar", tuple([v.GetValue() for v in (self._px,self._py,self._pz)]))
except ValueError:
raise ConfigurationError("Invalid value for %r entry" % self.configurator.name)
raise ConfigurationError("Invalid value for %r entry" % self.name)
else:
return val
......
......@@ -44,7 +44,7 @@ class PythonObjectWidget(IWidget):
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)
......
......@@ -54,11 +54,11 @@ class RangeWidget(IWidget):
self._last = 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._last.SetValue(str(cfg.default[1]))
self._step.SetValue(str(cfg.default[2]))
self._first.SetValue(str(first))
self._last.SetValue(str(last))
self._step.SetValue(str(step))
gbSizer.Add(firstLabel, (0,0), flag=wx.ALIGN_CENTER_VERTICAL)
gbSizer.Add(labelLabel, (0,3), flag=wx.ALIGN_CENTER_VERTICAL)
......@@ -75,10 +75,10 @@ class RangeWidget(IWidget):
def get_widget_value(self):
try:
val = (self.configurator.valueType(self._first.GetValue()),
self.configurator.valueType(self._last.GetValue()),
self.configurator.valueType(self._step.GetValue()))
val = (self._configurator.valueType(self._first.GetValue()),
self._configurator.valueType(self._last.GetValue()),
self._configurator.valueType(self._step.GetValue()))
except ValueError:
raise ConfigurationError("Invalid value for %r entry" % self.configurator.name)
raise ConfigurationError("Invalid value for %r entry" % self.name)
else:
return val
......@@ -42,8 +42,8 @@ class SingleChoiceWidget(IWidget):
sizer = wx.BoxSizer(wx.VERTICAL)
self._choices = wx.Choice(self._widgetPanel, wx.ID_ANY, choices=self.configurator.choices)
self._choices.SetStringSelection(self.configurator.default)
self._choices = wx.Choice(self._widgetPanel, wx.ID_ANY, choices=self._configurator.choices)
self._choices.SetStringSelection(self._configurator.default)
sizer.Add(self._choices, 1, wx.ALL|wx.EXPAND, 5)
......
......@@ -42,7 +42,7 @@ class StringWidget(IWidget):
sizer = wx.BoxSizer(wx.VERTICAL)
self._string = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=self.configurator.default)
self._string = wx.TextCtrl(self._widgetPanel, wx.ID_ANY, value=self._configurator.default)
sizer.Add(self._string, 0, wx.ALL, 5)
......
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