A code.ill.fr update is planned this weekend, it will be unavailable during the day on Saturday.

Commit 6065ccb0 authored by eric pellegrini's avatar eric pellegrini

Merge tag '1.0.1' into develop

1.0.1
parents 78e7f856 5850fcd5
Pipeline #1070 passed with stages
in 11 minutes and 23 seconds
......@@ -367,21 +367,6 @@ class Platform(object):
'''
pass
def preferences_file(self):
'''
Returns the path for MDANSE preferences file.
:return: the path for the MDANSE preferences file
:rtype: string
:note: this path is OS specific.
'''
# The preferences files will be located in the application directory.
appdir = self.application_directory()
return os.path.join(appdir, 'mdanse_preferences')
class PlatformPosix(Platform):
'''
Base class for POSIX derived OS.
......
This diff is collapsed.
......@@ -36,11 +36,12 @@ class ControllerPanel(wx.Panel):
il.Add(ICONS["log",16,16])
il.Add(ICONS["shell",16,16])
il.Add(ICONS["hourglass",16,16])
self._notebook.AssignImageList(il)
self._notebook.AddPage(self._pages["logger"], 'Logger')
self._notebook.AddPage(self._pages["console"], 'Console')
self._notebook.AddPage(self._pages["jobs"], 'Jobs')
self._notebook.AssignImageList(il)
self._notebook.SetPageImage(0, 0)
self._notebook.SetPageImage(1, 1)
......
......@@ -193,7 +193,6 @@ class MainFrame(wx.Frame):
elementsDatabaseButton = self._toolbar.AddSimpleTool(wx.ID_ANY, ICONS["atom",32,32], 'Launch the elements database editor')
plotButton = self._toolbar.AddSimpleTool(wx.ID_ANY,ICONS["plot",32,32], 'Launch the NetCDF plotter')
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')
......@@ -211,7 +210,6 @@ class MainFrame(wx.Frame):
self.Bind(wx.EVT_MENU, self.on_open_periodic_table, periodicTableButton)
self.Bind(wx.EVT_MENU, self.on_open_elements_database, elementsDatabaseButton)
self.Bind(wx.EVT_MENU, self.on_start_plotter, plotButton)
# 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)
......@@ -379,16 +377,6 @@ or directly to the MDANSE mailing list:
d = wx.MessageDialog(None, 'Do you really want to quit ?', 'Question', wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
if d.ShowModal() == wx.ID_YES:
self.Destroy()
# def on_set_preferences(self, event):
#
# from MDANSE.GUI.PreferencesSettings import PreferencesSettings
#
# d = PreferencesSettings(self)
#
# d.ShowModal()
#
# d.Destroy()
def on_start_plotter(self, event = None):
......
#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 May 28, 2015
:author: Eric C. Pellegrini
'''
import abc
import collections
import wx
import wx.aui as wxaui
import wx.lib.filebrowsebutton as wxfile
from MDANSE import LOGGER, PLATFORM, PREFERENCES
from MDANSE.Core.Preferences import PreferencesError
class WritableDirectoryValidator(wx.PyValidator):
def Clone(self):
return WritableDirectoryValidator()
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True
class PreferencesItemWidget(wx.Panel):
__metaclass__ = abc.ABCMeta
def __init__(self, parent, name, item, *args, **kwargs):
wx.Panel.__init__(self, parent, wx.ID_ANY, *args, **kwargs)
self._parent = parent
self._name = name
self._item = item
self.build_panel()
@abc.abstractmethod
def validate(self):
pass
@abc.abstractmethod
def get_value(self):
pass
@abc.abstractmethod
def set_value(self,value):
pass
class InputDirectoryWidget(PreferencesItemWidget):
type = "input_directory"
def build_panel(self):
sb = wx.StaticBox(self, wx.ID_ANY, label=self._item.name)
self._widget = wxfile.DirBrowseButton(self, wx.ID_ANY, labelText="", startDirectory=self._item.value)
self._widget.SetValidator(WritableDirectoryValidator())
self._widget.SetValue(self._item.value)
sizer = wx.StaticBoxSizer(sb, wx.HORIZONTAL)
sizer.Add(self._widget, 1, wx.ALL|wx.EXPAND, 5)
self.SetSizer(sizer)
def get_value(self):
return self._widget.GetValue()
def set_value(self, value):
self._widget.SetValue(value)
def validate(self):
path = PLATFORM.get_path(self._widget.GetValue())
if PLATFORM.is_directory_writable(path):
return True
else:
wx.MessageBox("The directory %r is not writable." % path, "Invalid input",wx.OK | wx.ICON_ERROR)
return False
WIDGETS = dict([(v.type,v) for v in PreferencesItemWidget.__subclasses__()])
class PreferencesSettings(wx.Dialog):
def __init__(self, parent=None):
wx.Dialog.__init__(self, parent, wx.ID_ANY, title="Preferences settings", size=(400,400), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
self._parent = parent
self.build_dialog()
def build_dialog(self):
self._notebook = wxaui.AuiNotebook(self, wx.ID_ANY)
self._sectionPanels = collections.OrderedDict()
self._sectionSizers = collections.OrderedDict()
self._widgets = collections.OrderedDict()
for item in PREFERENCES.values():
section = item.section
name = item.name
typ = item.type
if not self._sectionPanels.has_key(section):
self._sectionPanels[section] = wx.ScrolledWindow(self, wx.ID_ANY)
self._sectionPanels[section].SetScrollbars(1,1,200,200)
self._sectionSizers[section] = wx.BoxSizer(wx.VERTICAL)
self._widgets[name] = WIDGETS[typ](self._sectionPanels[section], name, item)
self._sectionSizers[section].Add(self._widgets[name], 0, wx.ALL|wx.EXPAND, 5)
for k,v in self._sectionPanels.items():
v.SetSizer(self._sectionSizers[k])
self._notebook.AddPage(v, k)
sb = wx.StaticBox(self, wx.ID_ANY)
sbSizer = wx.StaticBoxSizer(sb, wx.HORIZONTAL)
defaultButton = wx.Button(self, wx.ID_ANY, label="Default")
applyButton = wx.Button(self, wx.ID_ANY, label="Apply")
okButton = wx.Button(self, wx.ID_ANY, label="OK")
sbSizer.Add(defaultButton, 0, wx.ALL, 5)
sbSizer.Add((-1,-1), 1, wx.ALL|wx.EXPAND, 5)
sbSizer.Add(applyButton, 0, wx.ALL, 5)
sbSizer.Add(okButton, 0, wx.ALL, 5)
self._sizer = wx.BoxSizer(wx.VERTICAL)
self._sizer.Add(self._notebook, 1, wx.ALL|wx.EXPAND, 5)
self._sizer.Add(sbSizer, 0, wx.ALL|wx.EXPAND, 5)
self.SetSizer(self._sizer)
self.Bind(wx.EVT_BUTTON, self.on_default, defaultButton)
self.Bind(wx.EVT_BUTTON, self.on_apply, applyButton)
self.Bind(wx.EVT_BUTTON, self.on_ok, okButton)
def validate(self):
for widget in self._widgets.values():
if not widget.validate():
return False
return True
def on_apply(self,event=None):
if not self.validate():
return False
valid = True
for k, widget in self._widgets.items():
try:
PREFERENCES[k].set_value(widget.get_value())
except PreferencesError as e:
LOGGER(str(e),'error',['console'])
valid = False
continue
return valid
def on_ok(self,event):
if not self.on_apply():
return
PREFERENCES.save()
self.Close()
def on_default(self, event):
for v in PREFERENCES.values():
self._widgets[v.name].set_value(v.default)
if __name__ == "__main__":
app = wx.App(False)
d = PreferencesSettings(None)
d.ShowModal()
app.MainLoop()
__version__ = "1.0"
__version__ = "1.0.1"
__date__ = "08-09-2016"
__date__ = "12-10-2016"
__author__ = "Eric Pellegrini"
#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 May 29, 2015
@author: Eric C. Pellegrini
'''
import os
import shutil
import unittest
from MDANSE.Core.Preferences import Preferences
from MDANSE.Core.Preferences import PreferencesError
from UnitTest import UnitTest
class UnStringable:
def __str__(self):
raise TypeError("Object not castable to a string.")
class TestPreferences(UnitTest):
def setUp(self):
self._preferences = Preferences()
def test_get_item(self):
self.assertRaises(PreferencesError,self._preferences.__getitem__,'xxxxx')
def test_set_item(self):
val = self._preferences["working_directory"].get_value()
self._preferences["working_directory"].set_value("test")
self.assertEqual(self._preferences["working_directory"].value,os.path.join(os.getcwd(),"test"))
self._preferences["working_directory"].set_value(val)
shutil.rmtree("test")
def test_load_preferences(self):
'''
Test the method that loads the preferences
'''
# Test that loading a preferences file whose type is not a basestring throw a PreferencesError
self.assertRaises(PreferencesError,self._preferences.load,10)
def test_save_preferences(self):
'''
Test the method that saves the preferences
'''
# Test that saving a preferences file whose type is not a basestring throw a PreferencesError
self.assertRaises(PreferencesError,self._preferences.save,10)
# Test that saving a preferences whose path does not exists throw a PreferencesError
self.assertRaises(PreferencesError,self._preferences.save,os.path.join('xxxx','yyyy'))
def suite():
loader = unittest.TestLoader()
s = unittest.TestSuite()
s.addTest(loader.loadTestsFromTestCase(TestPreferences))
return s
if __name__ == '__main__':
unittest.main(verbosity=2)
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