Commit 19e47fa0 authored by eric pellegrini's avatar eric pellegrini
Browse files

Add a dialog + icon for saving job template from the GUI.

Added a _configured attribute fro IConfigurator class + setter and
checker
parent d4831f2b
...@@ -153,6 +153,8 @@ class Configurable(object): ...@@ -153,6 +153,8 @@ class Configurable(object):
conf.configure(parameters[name]) conf.configure(parameters[name])
conf.set_configured(True)
self._configuration[name]=conf self._configuration[name]=conf
self._info += conf.get_information() self._info += conf.get_information()
......
...@@ -126,6 +126,8 @@ class IConfigurator(dict): ...@@ -126,6 +126,8 @@ class IConfigurator(dict):
self._label = kwargs.get('label'," ".join(name.split('_')).strip()) self._label = kwargs.get('label'," ".join(name.split('_')).strip())
self._widget = kwargs.get('widget',self.type) self._widget = kwargs.get('widget',self.type)
self._configured = False
@property @property
def default(self): def default(self):
...@@ -193,6 +195,14 @@ class IConfigurator(dict): ...@@ -193,6 +195,14 @@ class IConfigurator(dict):
:note: this is an abstract method. :note: this is an abstract method.
''' '''
def set_configured(self,configured):
self._configured = configured
def is_configured(self):
return self._configured
def set_configurable(self,configurable): def set_configurable(self,configurable):
self._configurable = configurable self._configurable = configurable
......
...@@ -465,19 +465,16 @@ class IJob(Configurable): ...@@ -465,19 +465,16 @@ class IJob(Configurable):
return self._info return self._info
@classmethod @classmethod
def save_template(cls, shortname,longname=None): def save_template(cls, shortname,classname):
if longname is None:
longname = shortname
if REGISTRY['job'].has_key(shortname): if REGISTRY['job'].has_key(shortname):
LOGGER('A job with %r name is already stored in the registry' % shortname,'error') LOGGER('A job with %r name is already stored in the registry' % shortname,'error')
return return None
from MDANSE import PREFERENCES from MDANSE import PREFERENCES
macrosDir = PREFERENCES["macros_directory"].get_value() macrosDir = PREFERENCES["macros_directory"].get_value()
templateFile = os.path.join(macrosDir,"%s.py" % longname) templateFile = os.path.join(macrosDir,"%s.py" % classname)
try: try:
f = open(templateFile,'w') f = open(templateFile,'w')
...@@ -545,11 +542,11 @@ class %s(IJob): ...@@ -545,11 +542,11 @@ class %s(IJob):
# The trajectory is closed # The trajectory is closed
self.configuration['trajectory']['instance'].close() self.configuration['trajectory']['instance'].close()
''' % (longname,shortname,longname)) ''' % (classname,shortname,classname))
except IOError: except IOError:
LOGGER('The job template could not be save to %r. Maybe a permission problem.' % templateFile,'error') LOGGER('The job template could not be save to %r. Maybe a permission problem.' % templateFile,'error')
return None
else: else:
f.close() f.close()
return templateFile
return templateFile \ No newline at end of file
\ No newline at end of file
...@@ -100,7 +100,7 @@ class PropertyDialog(wx.Dialog): ...@@ -100,7 +100,7 @@ class PropertyDialog(wx.Dialog):
""" """
Handler called when the user clicks on the OK button of the property dialog. Handler called when the user clicks on the OK button of the property dialog.
""" """
pname = str(self.name.GetValue().strip()) pname = str(self.name.GetValue().strip())
pdefault = str(self.propertyType.GetValue()) pdefault = str(self.propertyType.GetValue())
......
#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 Oct 12, 2015
:author: Eric C. Pellegrini
'''
import wx
from MDANSE import LOGGER
class JobTemplateEditor(wx.Dialog):
def __init__(self,*args,**kwargs):
"""
The constructor.
"""
# The base class constructor
wx.Dialog.__init__(self,*args,**kwargs)
self.Center()
panel = wx.Panel(self,wx.ID_ANY)
staticLabel0 = wx.StaticText(panel, -1, "Enter property settings")
subPanel = wx.Panel(panel,wx.ID_ANY)
staticLabel1 = wx.StaticText(subPanel, wx.ID_ANY, "Short name")
self._shortName = wx.TextCtrl(subPanel, wx.ID_ANY)
staticLabel2 = wx.StaticText(subPanel, wx.ID_ANY, "Class name")
self._className = wx.TextCtrl(subPanel, id = wx.ID_ANY)
staticLine = wx.StaticLine(self, wx.ID_ANY)
buttonPanel = wx.Panel(self,wx.ID_ANY)
cancelButton = wx.Button(buttonPanel, wx.ID_CANCEL, "Cancel")
saveButton = wx.Button(buttonPanel, wx.ID_OK, "Save")
saveButton.SetDefault()
panelSizer = wx.BoxSizer(wx.VERTICAL)
panelSizer.Add(staticLabel0, 0, wx.ALL|wx.ALIGN_LEFT, 5)
subsizer = wx.GridBagSizer(5,5)
subsizer.AddGrowableCol(1)
subsizer.Add(staticLabel1,pos=(0,0),flag=wx.ALIGN_CENTER_VERTICAL)
subsizer.Add(self._shortName ,pos=(0,1),flag=wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
subsizer.Add(staticLabel2,pos=(1,0),flag=wx.ALIGN_CENTER_VERTICAL)
subsizer.Add(self._className,pos=(1,1),flag=wx.ALIGN_CENTER_VERTICAL|wx.EXPAND)
subPanel.SetSizer(subsizer)
panelSizer.Add(subPanel, 0, wx.ALL|wx.EXPAND, 5)
panel.SetSizer(panelSizer)
btnsizer = wx.StdDialogButtonSizer()
btnsizer.AddButton(cancelButton)
btnsizer.AddButton(saveButton)
btnsizer.Realize()
buttonPanel.SetSizer(btnsizer)
dlgsizer = wx.BoxSizer(wx.VERTICAL)
dlgsizer.Add(panel, 1, wx.ALL|wx.EXPAND, 5)
dlgsizer.Add(staticLine, 0, wx.ALL|wx.EXPAND, 5)
dlgsizer.Add(buttonPanel, 0, wx.ALL|wx.ALIGN_RIGHT|wx.EXPAND, 5)
# Bind the top sizer to the dialog.
self.SetSizer(dlgsizer)
self.Bind(wx.EVT_BUTTON,self.on_save,saveButton)
def on_save(self,event):
shortName = str(self._shortName.GetValue()).strip()
className = str(self._className.GetValue()).strip()
if not shortName or not className:
wx.MessageBox('You must provide a short name and a class name', 'Invalid input', wx.OK | wx.ICON_ERROR)
return
from MDANSE.Framework.Jobs.IJob import IJob
filename = IJob.save_template(shortName,className)
if filename is not None:
LOGGER('Job template successfully saved to %r.' % filename,'info',['console'])
self.EndModal(wx.ID_OK)
if __name__ == "__main__":
app = wx.App(False)
f = JobTemplateEditor(None)
f.ShowModal()
f.Destroy()
app.MainLoop()
...@@ -193,6 +193,7 @@ class MainFrame(wx.Frame): ...@@ -193,6 +193,7 @@ class MainFrame(wx.Frame):
udButton = self._toolbar.AddSimpleTool(wx.ID_ANY,ICONS["user",32,32], 'Launch the user definitions editor') udButton = self._toolbar.AddSimpleTool(wx.ID_ANY,ICONS["user",32,32], 'Launch the user definitions editor')
preferencesButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["preferences",32,32], 'Launch the preferences editor') preferencesButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["preferences",32,32], 'Launch the preferences editor')
registryButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["registry",32,32], 'Inspect MDANSE classes framework') registryButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["registry",32,32], 'Inspect MDANSE classes framework')
templateButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["template",32,32], 'Save a template for a new analysis')
apiButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["api",32,32], 'Open MDANSE API') apiButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["api",32,32], 'Open MDANSE API')
websiteButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["web",32,32], 'Open MDANSE website') websiteButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["web",32,32], 'Open MDANSE website')
aboutButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["about",32,32], 'About MDANSE') aboutButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["about",32,32], 'About MDANSE')
...@@ -211,6 +212,7 @@ class MainFrame(wx.Frame): ...@@ -211,6 +212,7 @@ class MainFrame(wx.Frame):
self.Bind(wx.EVT_MENU, self.on_set_preferences, preferencesButton) self.Bind(wx.EVT_MENU, self.on_set_preferences, preferencesButton)
self.Bind(wx.EVT_MENU, self.on_open_user_definitions, udButton) self.Bind(wx.EVT_MENU, self.on_open_user_definitions, udButton)
self.Bind(wx.EVT_MENU, self.on_open_classes_registry, registryButton) self.Bind(wx.EVT_MENU, self.on_open_classes_registry, registryButton)
self.Bind(wx.EVT_MENU, self.on_save_job_template, templateButton)
self.Bind(wx.EVT_MENU, self.on_about, aboutButton) self.Bind(wx.EVT_MENU, self.on_about, aboutButton)
self.Bind(wx.EVT_MENU, self.on_quit, quitButton) self.Bind(wx.EVT_MENU, self.on_quit, quitButton)
self.Bind(wx.EVT_MENU, self.on_open_api, apiButton) self.Bind(wx.EVT_MENU, self.on_open_api, apiButton)
...@@ -295,6 +297,16 @@ or directly to the MDANSE mailing list: ...@@ -295,6 +297,16 @@ or directly to the MDANSE mailing list:
f.ShowModal() f.ShowModal()
f.Destroy() f.Destroy()
def on_save_job_template(self,event):
from MDANSE.GUI.JobTemplateEditor import JobTemplateEditor
f = JobTemplateEditor(self)
f.ShowModal()
f.Destroy()
def on_open_api(self, event): def on_open_api(self, event):
......
...@@ -333,14 +333,12 @@ class CommandLineParser(optparse.OptionParser): ...@@ -333,14 +333,12 @@ class CommandLineParser(optparse.OptionParser):
from MDANSE.Framework.Jobs.IJob import IJob from MDANSE.Framework.Jobs.IJob import IJob
if nargs == 1: if nargs != 2:
shortname = longname = parser.rargs[0]
elif nargs == 2:
shortname,longname = parser.rargs
else:
raise CommandLineParserError("Invalid number of arguments for %r option" % opt_str) raise CommandLineParserError("Invalid number of arguments for %r option" % opt_str)
shortname,classname = parser.rargs
IJob.save_template(shortname,longname) IJob.save_template(shortname,classname)
if __name__ == "__main__": if __name__ == "__main__":
......
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