Commit a8429c86 authored by eric pellegrini's avatar eric pellegrini

The user definition can now be viewed from the user definition widget

parent 201e2d38
......@@ -32,10 +32,8 @@ Created on Mar 30, 2015
import wx
from MDANSE.Externals.pubsub import pub
from MDANSE.GUI import DATA_CONTROLLER
from MDANSE.Framework.Plugins.IPlugin import IPlugin, plugin_parent
from MDANSE.Framework.Plugins.IPlugin import IPlugin
def get_data_plugin(window):
......@@ -62,21 +60,13 @@ class DataPlugin(IPlugin):
self._datakey = datakey
self._dataProxy = DATA_CONTROLLER[self._datakey]
self._mgr.Bind(wx.EVT_CHILD_FOCUS, self.on_changing_pane)
self._currentWindow = self
def build_panel(self):
pass
def plug(self, standalone=False):
pass
@property
def currentWindow(self):
return self._currentWindow
@property
def datakey(self):
return self._datakey
......@@ -93,14 +83,4 @@ class DataPlugin(IPlugin):
@property
def dataplugin(self):
return self
def on_changing_pane(self, event):
window = plugin_parent(event.GetWindow())
if window is None:
return
self._currentWindow = window
pub.sendMessage('msg_set_plugins_tree', plugin=window)
\ No newline at end of file
......@@ -91,11 +91,15 @@ class IPlugin(wx.Panel):
wx.Panel.__init__(self, parent, *args, **kwargs)
self._parent = parent
self._currentWindow = self
self.SetDropTarget(PluginDropTarget(self))
self.build_dialog()
self._mgr.Bind(wx.EVT_CHILD_FOCUS, self.on_changing_pane)
self._mgr.Bind(aui.EVT_AUI_PANE_CLOSE, self.on_close_pane)
@abc.abstractmethod
......@@ -123,11 +127,12 @@ class IPlugin(wx.Panel):
return False
return self.is_parent(window.Parent)
@property
def currentWindow(self):
def close(self):
pass
return self._currentWindow
def on_close_pane(self, event):
d = wx.MessageDialog(None, 'Closing this plugin will also close all the other ones you plugged in in so far. Do you really want to close ?', 'Question', wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
......@@ -135,9 +140,6 @@ class IPlugin(wx.Panel):
return
window = event.GetPane().window
# if isinstance(window,IPlugin):
# window.close_children()
self._mgr.DetachPane(window)
window.Destroy()
......@@ -145,6 +147,8 @@ class IPlugin(wx.Panel):
self.SetFocus()
self._currentWindow = self
pub.sendMessage('msg_set_plugins_tree', plugin=self)
def build_dialog(self):
......@@ -165,17 +169,7 @@ class IPlugin(wx.Panel):
plugin = REGISTRY["plugin"].get(pluginName,None)
if plugin is None:
return
# Get the list of ancestors of the plugin that will host the plugin to be dropped in.
ancestors = IPlugin.get_ancestors(plugin)
# klasses = tuple([REGISTRY['plugin'][anc] for anc in plugin.ancestor])
# if not issubclass(self.__class__,klasses):
# self.parent.drop(pluginName)
# return
if not plugin.ancestor[0] in ancestors:
return
plugin = plugin(self)
self._mgr.AddPane(plugin, aui.AuiPaneInfo().Caption(getattr(plugin, "label", pluginName)))
......@@ -186,14 +180,15 @@ class IPlugin(wx.Panel):
plugin.SetFocus()
@staticmethod
def get_ancestors(plugin):
if plugin.ancestor == ['empty_data']:
return [plugin.type]
def on_changing_pane(self, event):
parentPlugin = REGISTRY['plugin'][plugin.ancestor[0]]
window = plugin_parent(event.GetWindow())
if window is None:
return
return [plugin.type] + IPlugin.get_ancestors(parentPlugin)
self._currentWindow = window
pub.sendMessage('msg_set_plugins_tree', plugin=window)
\ No newline at end of file
......@@ -49,7 +49,7 @@ class UserDefinitionsStore(dict):
else:
self.update(UD)
f.close()
def save(self):
'''
Save the user definitions.
......
......@@ -44,7 +44,7 @@ class PartialChargesPlugin(UserDefinitionsPlugin):
type = 'partial_charges'
label = "Partial charges settings"
label = "Partial charges"
ancestor = ["molecular_viewer"]
......
......@@ -155,7 +155,7 @@ class QVectorsPlugin(UserDefinitionsPlugin):
type = 'q_vectors'
label = "Q vectors settings"
label = "Q vectors"
ancestor = ["molecular_viewer"]
......
......@@ -48,27 +48,38 @@ class UserDefinitionWidget(IWidget):
__metaclass__ = abc.ABCMeta
type = None
def initialize(self):
self._filename = None
self._basename = None
def add_widgets(self):
sizer = wx.BoxSizer(wx.HORIZONTAL)
self._availableUDs = wx.Choice(self._widgetPanel, wx.ID_ANY,style=wx.CB_SORT)
self._newUD = wx.Button(self._widgetPanel, wx.ID_ANY, label="New")
viewUD = wx.Button(self._widgetPanel, wx.ID_ANY, label="View selected definition")
newUD = wx.Button(self._widgetPanel, wx.ID_ANY, label="New definition")
sizer.Add(self._availableUDs, 1, wx.ALL|wx.EXPAND, 5)
sizer.Add(self._newUD, 0, wx.ALL|wx.EXPAND, 5)
sizer.Add(viewUD, 0, wx.ALL|wx.EXPAND, 5)
sizer.Add(newUD, 0, wx.ALL|wx.EXPAND, 5)
pub.subscribe(self.msg_save_definition, "msg_save_definition")
pub.subscribe(self.msg_set_ud, "msg_set_ud")
self.Bind(wx.EVT_BUTTON, self.on_new_user_definition, self._newUD)
self.Bind(wx.EVT_BUTTON, self.on_view_user_definition, viewUD)
self.Bind(wx.EVT_BUTTON, self.on_new_user_definition, newUD)
return sizer
def on_view_user_definition(self,event):
ud = self._availableUDs.GetStringSelection()
if not ud:
LOGGER("Please select a user definition","error",["dialog"])
return
from MDANSE.Framework.Plugins.UserDefinitionViewerPlugin import UserDefinitionViewerFrame
f = UserDefinitionViewerFrame(self,ud=[self._basename,self.type,ud])
f.Show()
def on_new_user_definition(self,event):
dlg = UserDefinitionsDialog(self,self._trajectory,self.type)
......@@ -87,21 +98,17 @@ class UserDefinitionWidget(IWidget):
self._basename = os.path.basename(self._filename)
self.msg_set_ud()
uds = UD_STORE.filter(self._basename, self.type)
self._availableUDs.SetItems(uds)
def msg_save_definition(self, message):
filename, section, name = message
if section is not self.type:
return
def msg_set_ud(self):
if filename != self._basename:
return
uds = UD_STORE.filter(self._basename, self.type)
self._availableUDs.Append(name)
self._availableUDs.SetItems(uds)
class UserDefinitionsDialog(wx.Dialog):
......@@ -152,7 +159,7 @@ class UserDefinitionsPlugin(ComponentPlugin):
actionsSizer = wx.StaticBoxSizer(sb, wx.HORIZONTAL)
self._udName = wx.TextCtrl(udPanel, wx.ID_ANY, style = wx.TE_PROCESS_ENTER)
saveButton = wx.Button(udPanel, wx.ID_ANY, label="Save")
saveButton = wx.Button(udPanel, wx.ID_ANY, label="Set")
actionsSizer.Add(self._udName, 1, wx.ALL|wx.EXPAND, 5)
actionsSizer.Add(saveButton, 0, wx.ALL, 5)
......@@ -161,9 +168,9 @@ class UserDefinitionsPlugin(ComponentPlugin):
self._mainPanel.GetSizer().Add(udPanel,0,wx.EXPAND|wx.ALL,5)
self.Bind(wx.EVT_BUTTON, self.on_save, saveButton)
self.Bind(wx.EVT_BUTTON, self.on_set_ud, saveButton)
def on_save(self, event):
def on_set_ud(self, event):
name = str(self._udName.GetValue().strip())
......@@ -180,8 +187,7 @@ class UserDefinitionsPlugin(ComponentPlugin):
return
UD_STORE.set_definition(self._target,self.type,name,value)
UD_STORE.save()
pub.sendMessage("msg_save_definition", message=(self._target,self.type,name))
pub.sendMessage("msg_set_ud")
LOGGER('User definition %r successfully saved.' % name,'info',['console'])
LOGGER('User definition %r successfully set.' % name,'info',['console'])
......@@ -321,7 +321,7 @@ or directly to the MDANSE mailing list:
self.load_data(dataType,filename)
LOGGER("Data %r successfully loaded" % filename, "info")
LOGGER("Data %r successfully loaded." % filename, "info", ["console"])
def on_open_user_definitions(self,event):
......
......@@ -110,7 +110,7 @@ class PluginsTreePanel(wx.Panel):
def on_double_click(self, event):
data = self._tree.GetPyData(event.GetItem())
self.TopLevelParent.panels["working"].active_page.currentWindow.drop(data)
def on_drag(self, event=None):
......
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