Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
MDANSE
Commits
19e47fa0
Commit
19e47fa0
authored
Oct 12, 2015
by
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
Changes
8
Hide whitespace changes
Inline
Side-by-side
MDANSE/Framework/Configurable.py
View file @
19e47fa0
...
...
@@ -153,6 +153,8 @@ class Configurable(object):
conf
.
configure
(
parameters
[
name
])
conf
.
set_configured
(
True
)
self
.
_configuration
[
name
]
=
conf
self
.
_info
+=
conf
.
get_information
()
...
...
MDANSE/Framework/Configurators/IConfigurator.py
View file @
19e47fa0
...
...
@@ -126,6 +126,8 @@ class IConfigurator(dict):
self
.
_label
=
kwargs
.
get
(
'label'
,
" "
.
join
(
name
.
split
(
'_'
)).
strip
())
self
.
_widget
=
kwargs
.
get
(
'widget'
,
self
.
type
)
self
.
_configured
=
False
@
property
def
default
(
self
):
...
...
@@ -193,6 +195,14 @@ class IConfigurator(dict):
: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
):
self
.
_configurable
=
configurable
...
...
MDANSE/Framework/Jobs/IJob.py
View file @
19e47fa0
...
...
@@ -465,19 +465,16 @@ class IJob(Configurable):
return
self
.
_info
@
classmethod
def
save_template
(
cls
,
shortname
,
longname
=
None
):
if
longname
is
None
:
longname
=
shortname
def
save_template
(
cls
,
shortname
,
classname
):
if
REGISTRY
[
'job'
].
has_key
(
shortname
):
LOGGER
(
'A job with %r name is already stored in the registry'
%
shortname
,
'error'
)
return
return
None
from
MDANSE
import
PREFERENCES
macrosDir
=
PREFERENCES
[
"macros_directory"
].
get_value
()
templateFile
=
os
.
path
.
join
(
macrosDir
,
"%s.py"
%
long
name
)
templateFile
=
os
.
path
.
join
(
macrosDir
,
"%s.py"
%
class
name
)
try
:
f
=
open
(
templateFile
,
'w'
)
...
...
@@ -545,11 +542,11 @@ class %s(IJob):
# The trajectory is closed
self.configuration['trajectory']['instance'].close()
'''
%
(
long
name
,
shortname
,
long
name
))
'''
%
(
class
name
,
shortname
,
class
name
))
except
IOError
:
LOGGER
(
'The job template could not be save to %r. Maybe a permission problem.'
%
templateFile
,
'error'
)
return
None
else
:
f
.
close
()
return
templateFile
\ No newline at end of file
f
.
close
()
return
templateFile
\ No newline at end of file
MDANSE/GUI/ElementsDatabaseEditor.py
View file @
19e47fa0
...
...
@@ -100,7 +100,7 @@ class PropertyDialog(wx.Dialog):
"""
Handler called when the user clicks on the OK button of the property dialog.
"""
pname
=
str
(
self
.
name
.
GetValue
().
strip
())
pdefault
=
str
(
self
.
propertyType
.
GetValue
())
...
...
MDANSE/GUI/Icons/template.png
0 → 100644
View file @
19e47fa0
17.2 KB
MDANSE/GUI/JobTemplateEditor.py
0 → 100644
View file @
19e47fa0
#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
()
MDANSE/GUI/MainFrame.py
View file @
19e47fa0
...
...
@@ -193,6 +193,7 @@ class MainFrame(wx.Frame):
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'
)
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'
)
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'
)
...
...
@@ -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_open_user_definitions
,
udButton
)
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_quit
,
quitButton
)
self
.
Bind
(
wx
.
EVT_MENU
,
self
.
on_open_api
,
apiButton
)
...
...
@@ -295,6 +297,16 @@ or directly to the MDANSE mailing list:
f
.
ShowModal
()
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
):
...
...
Scripts/mdanse
View file @
19e47fa0
...
...
@@ -333,14 +333,12 @@ class CommandLineParser(optparse.OptionParser):
from
MDANSE.Framework.Jobs.IJob
import
IJob
if
nargs
==
1
:
shortname
=
longname
=
parser
.
rargs
[
0
]
elif
nargs
==
2
:
shortname
,
longname
=
parser
.
rargs
else
:
if
nargs
!=
2
:
raise
CommandLineParserError
(
"Invalid number of arguments for %r option"
%
opt_str
)
shortname
,
classname
=
parser
.
rargs
IJob
.
save_template
(
shortname
,
long
name
)
IJob
.
save_template
(
shortname
,
class
name
)
if
__name__
==
"__main__"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment