Commit d16df5b8 authored by eric pellegrini's avatar eric pellegrini
Browse files

Bug fix and improved ergonomy for user definition settings dialog

parent 1420c57e
...@@ -34,7 +34,6 @@ import wx ...@@ -34,7 +34,6 @@ import wx
import wx.aui as wxaui import wx.aui as wxaui
from MDANSE.Core.Error import Error from MDANSE.Core.Error import Error
from MDANSE.Framework.UserDefinitions.IUserDefinition import IUserDefinition
from MDANSE.Framework.UserDefinitionsStore import UD_STORE from MDANSE.Framework.UserDefinitionsStore import UD_STORE
from MDANSE.App.GUI.Framework.Plugins.ComponentPlugin import ComponentPlugin from MDANSE.App.GUI.Framework.Plugins.ComponentPlugin import ComponentPlugin
...@@ -57,7 +56,7 @@ class UserDefinitionViewerPlugin(ComponentPlugin): ...@@ -57,7 +56,7 @@ class UserDefinitionViewerPlugin(ComponentPlugin):
ComponentPlugin.__init__(self, parent, size = parent.GetSize(), *args, **kwargs) ComponentPlugin.__init__(self, parent, size = parent.GetSize(), *args, **kwargs)
self.build_plugins_tree() self.build_plugins_tree()
def build_panel(self): def build_panel(self):
self._treePanel = wx.Panel(self, wx.ID_ANY, size=self.GetSize()) self._treePanel = wx.Panel(self, wx.ID_ANY, size=self.GetSize())
...@@ -123,57 +122,84 @@ class UserDefinitionViewerPlugin(ComponentPlugin): ...@@ -123,57 +122,84 @@ class UserDefinitionViewerPlugin(ComponentPlugin):
if keycode == wx.WXK_DELETE: if keycode == wx.WXK_DELETE:
item = self._tree.GetSelection() currentItem = self._tree.GetSelection()
itemData = self._tree.GetItemData(item)
itemText = str(self._tree.GetItemText(item)) level = self.get_item_level(currentItem)
if itemData is None: if level > 3:
return return
data = itemData.GetData() d = wx.MessageDialog(None, 'Do you really want to delete this definition ?', 'Question', wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
if isinstance(data, IUserDefinition): if d.ShowModal() == wx.ID_YES:
d = wx.MessageDialog(None, 'Do you really want to delete this definition ?', 'Question', wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
if d.ShowModal() == wx.ID_YES: currentItemName = str(self._tree.GetItemText(currentItem))
UD_STORE.remove_definition(data.target,data.type,itemText)
UD_STORE.save() if level == 1:
self._tree.DeleteAllItems() UD_STORE.remove_target(currentItemName)
self._udTree.clear() elif level == 2:
self.build_plugins_tree() targetItem = self._tree.GetParent(currentItem)
self._info.Clear() targetItemName = str(self._tree.GetItemText(targetItem))
UD_STORE.remove_section(targetItemName,currentItemName)
elif level == 3:
sectionItem = self._tree.GetParent(currentItem)
sectionItemName = str(self._tree.GetItemText(sectionItem))
targetItem = self._tree.GetParent(sectionItem)
targetItemName = str(self._tree.GetItemText(targetItem))
UD_STORE.remove_definition(targetItemName,sectionItemName,currentItemName)
else:
return
UD_STORE.save()
self._tree.DeleteAllItems()
self._udTree.clear()
self.build_plugins_tree()
self._info.Clear()
def on_try_rename(self, event): def on_try_rename(self, event):
item = self._tree.GetSelection()
itemData = self._tree.GetItemData(item) currentItem = self._tree.GetSelection()
if itemData is None: level = self.get_item_level(currentItem)
if level != 3:
event.Veto() event.Veto()
return return
data = itemData.GetData()
if not isinstance(data, IUserDefinition):
event.Veto()
def on_rename(self, event): def on_rename(self, event):
newtext = self._tree.GetEditControl().GetValue()
item = self._tree.GetSelection() currentItem = self._tree.GetSelection()
oldtext = str(self._tree.GetItemText(item))
itemData = self._tree.GetItemData(item) currentItemName = str(self._tree.GetItemText(currentItem))
newItemName = self._tree.GetEditControl().GetValue()
if itemData is None:
if currentItemName == newItemName:
return return
data = itemData.GetData() sectionItem = self._tree.GetItemParent(currentItem)
if isinstance(data, IUserDefinition): sectionItemName = str(self._tree.GetItemText(sectionItem))
UD_STORE.set_definition(data.target,data.type,newtext,data) targetItem = self._tree.GetItemParent(sectionItem)
UD_STORE.remove_definition(data.target,data.type,oldtext) targetItemName = str(self._tree.GetItemText(targetItem))
UD_STORE.save()
self.build_plugins_tree() currentItemData = self._tree.GetItemData(currentItem)
UD_STORE.set_definition(targetItemName,sectionItemName,newItemName,currentItemData.GetData())
UD_STORE.remove_definition(targetItemName,sectionItemName,currentItemName)
UD_STORE.save()
def close(self): def close(self):
pass pass
def plug(self): def plug(self):
self.parent.mgr.GetPane(self).Float().CloseButton(True).BestSize((800, 300)) self.parent.mgr.GetPane(self).Float().CloseButton(True).BestSize((800, 300))
self.parent.mgr.Update() self.parent.mgr.Update()
def get_item_level(self,item):
parent = self._tree.GetItemParent(item)
if parent == self._tree.GetRootItem():
return 1
else:
return 1 + self.get_item_level(parent)
class UserDefinitionViewerFrame(wx.Frame): class UserDefinitionViewerFrame(wx.Frame):
......
...@@ -16,11 +16,7 @@ class UserDefinitionsStore(dict): ...@@ -16,11 +16,7 @@ class UserDefinitionsStore(dict):
Basically, user definitions are used to keep track of definitions made on a given target. The target can Basically, user definitions are used to keep track of definitions made on a given target. The target can
be a file or any kind of object that has to be associated with the user definitions. be a file or any kind of object that has to be associated with the user definitions.
This definitions can be selections of atoms, Q vectors definitions, axis definitions ... The This definitions can be selections of atoms, Q vectors definitions, axis definitions ... The
user definitions are loaded when MDANSE starts through a cPickle file that will store these definitions. user definitions are loaded when MDANSE starts through a cPickle file that will store these definitions.
They are stored internally as MDANSE.Framework.UserDefinition.IUserDefinition derived objects in a nested
dictionary whose primary key is the target name, secondary key is the category of the user definition and
tertiary key is the name of the user definition.
''' '''
__metaclass__ = Singleton __metaclass__ = Singleton
...@@ -84,6 +80,16 @@ class UserDefinitionsStore(dict): ...@@ -84,6 +80,16 @@ class UserDefinitionsStore(dict):
ud = self[target][section][name] ud = self[target][section][name]
return ud return ud
def remove_target(self,target):
if self.has_target(target):
del self[target]
def remove_section(self,target,section):
if self.has_section(target, section):
del self[target][section]
def remove_definition(self,target,section,name): def remove_definition(self,target,section,name):
...@@ -100,6 +106,17 @@ class UserDefinitionsStore(dict): ...@@ -100,6 +106,17 @@ class UserDefinitionsStore(dict):
def filter(self,target,section): def filter(self,target,section):
return self.get(target,{}).get(section,{}).keys() return self.get(target,{}).get(section,{}).keys()
def has_target(self,target):
return self.has_key(target)
def has_section(self,target,section):
if not self.has_key(target):
return False
return self[target].has_key(section)
def has_definition(self,target,section,name): def has_definition(self,target,section,name):
......
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