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

Removed (unused ?) pubsub mechanism for status objects

Factorized the set_data mechanism for IWidget based classes
parent 5977036a
......@@ -25,12 +25,7 @@ class ProgressBar(wx.Panel,Status):
self.Bind(wx.EVT_BUTTON,self.on_stop,self._stop)
def finish_status(self,message):
status = message
if status != self:
return
def finish_status(self):
self._progress.SetBarColor(wx.BLUE)
self._progress.Refresh()
......@@ -46,34 +41,19 @@ class ProgressBar(wx.Panel,Status):
self._stop.Disable()
self.stop()
def start_status(self, message):
status = message
def start_status(self):
if status != self:
return
self._stop.Enable()
self._progress.SetValue(self.currentStep)
self._progress.SetRange(self.nSteps)
self._progress.SetBarColor(wx.GREEN)
def stop_status(self, message):
status = message
if status != self:
return
def stop_status(self):
self._progress.SetBarColor(wx.RED)
self._progress.Refresh()
def update_status(self,message):
status = message
if status != self:
return
def update_status(self):
self._progress.SetValue(self.currentStep)
self._progress.Refresh()
......@@ -49,7 +49,7 @@ class DataController(collections.OrderedDict):
return
else:
collections.OrderedDict.__delitem__(self,item)
Publisher.sendMessage("delete_input_data", message = item)
Publisher.sendMessage("msg_delete_input_data", message = item)
def __getitem__(self, key):
......@@ -64,7 +64,7 @@ class DataController(collections.OrderedDict):
collections.OrderedDict.__setitem__(self, item,value)
Publisher.sendMessage("load_input_data", message = value)
Publisher.sendMessage("msg_load_input_data", message = value)
def has_proxy(self, item):
'''
......
......@@ -57,8 +57,8 @@ class DataTreePanel(wx.Panel):
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_drag_data)
self.Bind(wx.EVT_TREE_KEY_DOWN, self.on_delete_data, self._tree)
pub.subscribe(self.msg_load_input_data, ('load_input_data'))
pub.subscribe(self.msg_delete_input_data, ('delete_input_data'))
pub.subscribe(self.msg_load_input_data, ('msg_load_input_data'))
pub.subscribe(self.msg_delete_input_data, ('msg_delete_input_data'))
@property
def tree(self):
......
......@@ -102,17 +102,15 @@ class AnimationPlugin(ComponentPlugin):
self.Bind(wx.EVT_BUTTON, self.on_goto_first_frame, firstButton)
self.Bind(wx.EVT_BUTTON, self.on_goto_last_frame, lastButton)
Publisher.subscribe(self.on_update_animation_icon, ('Animation'))
Publisher.subscribe(self.on_set_up_frame_slider, ('Load trajectory'))
Publisher.subscribe(self.on_timer, ('On timer'))
Publisher.subscribe(self.on_update_animation_icon, ('msg_animate_trajectory'))
Publisher.subscribe(self.on_set_up_frame_slider, ('msg_load_trajectory'))
Publisher.subscribe(self.on_timer, ('msg_timer'))
def plug(self):
self._parent._mgr.GetPane(self).LeftDockable(False).RightDockable(False).Dock().Bottom().CloseButton(True)
self._parent._mgr.Update()
Publisher.sendMessage(('Load trajectory'), message = self.parent)
def on_change_frame_rate(self, event=None):
laps = self.speedSlider.GetValue()
......@@ -151,14 +149,12 @@ class AnimationPlugin(ComponentPlugin):
self.speedSlider.SetValue(int(self.speedEntry.GetValue()))
self._parent.change_frame_rate()
def on_timer(self, message):
def on_timer(self, plugin):
mv = message
if not has_parent(self,mv):
if not plugin.is_parent(self):
return
frame = mv.current_frame
frame = plugin.current_frame
self.frameEntry.SetValue(str(frame))
self.frameSlider.SetValue(int(frame))
......
......@@ -57,9 +57,9 @@ class DataPlugin(IPlugin):
ancestor = None
def __init__(self, parent, datakey):
def __init__(self, parent, datakey, **kwargs):
IPlugin.__init__(self, parent, wx.ID_ANY)
IPlugin.__init__(self, parent, wx.ID_ANY, **kwargs)
self._datakey = datakey
......@@ -115,14 +115,16 @@ class DataPlugin(IPlugin):
plugin.plug()
plugin.SetFocus()
self._currentWindow = plugin
def on_changing_pane(self, event):
window = plugin_parent(event.GetWindow())
if window is None:
return
self._currentWindow = window
pub.sendMessage(('set_plugins_tree'), message= window)
pub.sendMessage(('msg_set_plugins_tree'), message=window)
......@@ -124,6 +124,16 @@ class IPlugin(wx.Panel):
continue
self.close()
def is_parent(self,window):
if window == self:
return True
if window.TopLevelParent == window:
return False
return self.is_parent(window.Parent)
def close(self):
pass
......
......@@ -122,7 +122,7 @@ class JobPlugin(ComponentPlugin):
time.sleep(1)
pub.sendMessage("on_start_job",message=None)
pub.sendMessage("msg_start_job",message=None)
def on_save(self, event=None):
......@@ -131,8 +131,7 @@ class JobPlugin(ComponentPlugin):
if not parameters:
return
d = wx.FileDialog(self, "Save MDANSE python script", style = wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT, wildcard = "Python files (*.py)|*.py")
d = wx.FileDialog(self, "Save MDANSE python script", style = wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT, wildcard = "Python files (*.py)|*.py")
if d.ShowModal() == wx.ID_CANCEL:
return
......@@ -147,12 +146,12 @@ class JobPlugin(ComponentPlugin):
self._jobClass.save(path, parameters)
def plug(self):
pub.sendMessage("on_set_data", message = (self,self.datakey))
self._parent._mgr.GetPane(self).Float().Center().Dockable(False).CloseButton(True).BestSize((800,600))
self._parent._mgr.GetPane(self).Float().Center().Floatable(True).Dockable(True).CloseButton(True).BestSize((800,600))
self._parent.mgr.Update()
pub.sendMessage("msg_set_data", plugin=self)
def on_close(self, event):
......@@ -160,61 +159,52 @@ class JobPlugin(ComponentPlugin):
class JobFrame(wx.Frame):
def __init__(self, parent, jobType):
def __init__(self, parent, jobType, datakey):
wx.Frame.__init__(self, parent, wx.ID_ANY, size = (800,400), style=wx.DEFAULT_DIALOG_STYLE|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX|wx.RESIZE_BORDER)
self._jobType = jobType
self._datakey = datakey
data = REGISTRY['input_data']['mmtk_trajectory'](self._datakey)
DATA_CONTROLLER[filename] = data
self.build_dialog()
def build_dialog(self):
mainPanel = wx.Panel(self, wx.ID_ANY, size = self.GetSize())
workingPanel = WorkingPanel(self)
mainSizer = wx.BoxSizer(wx.VERTICAL)
workingPanel.drop(self._datakey)
self._jobPlugin = REGISTRY['plugin'][self._jobType](mainPanel, wx.ID_ANY)
mainSizer.Add(self._jobPlugin, 1, wx.ALL|wx.EXPAND)
mainPanel.SetSizer(mainSizer)
mainSizer.Fit(mainPanel)
mainPanel.Layout()
workingPanel.active_page.drop(self._jobType)
workingPanel.active_page.mgr.GetPane(workingPanel.active_page.currentWindow).Dock()
self.SetTitle("Run %s job" % self._jobPlugin._jobClass.label)
workingPanel.active_page.mgr.Update()
self.SetTitle("Run %s job" % self._jobType)
self.Bind(wx.EVT_CLOSE, self.on_quit)
def on_quit(self, event):
d = wx.MessageDialog(None,
'Do you really want to quit ?',
'Question',
wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
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()
if __name__ == "__main__":
from MMTK.Trajectory import Trajectory
from MDANSE.App.GUI import DATA_CONTROLLER
from MDANSE.App.GUI.WorkingPanel import WorkingPanel
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))))
filename = os.path.join(root,'Data','Trajectories','MMTK','protein_in_periodic_universe.nc')
data = REGISTRY['input_data']['mmtk_trajectory'](filename)
basename = os.path.basename(filename)
t = Trajectory(None,filename,"r")
DATA_CONTROLLER[filename] = data
app = wx.App(False)
f = JobFrame(None,'msd')
f._jobPlugin._datakey = filename
pub.sendMessage("on_set_data", message = (f._jobPlugin,filename))
f = JobFrame(None,'msd',filename)
f.Show()
app.MainLoop()
\ No newline at end of file
......@@ -167,10 +167,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.enable_picking(True)
pub.subscribe(self.on_set_selection, ('set_selection'))
# pub.subscribe(self.on_clear_selection, ('clear_selection'))
# pub.subscribe(self.on_show_selection_box, ('show_selection_box'))
# pub.subscribe(self.on_enable_picking, ('enable_picking'))
pub.subscribe(self.on_set_selection, ('msg_set_selection'))
def build_panel(self):
......@@ -201,7 +198,7 @@ class MolecularViewerPanel(ComponentPlugin):
self._iren.AddObserver("CharEvent", self.on_keyboard_input)
self._iren.AddObserver("LeftButtonPressEvent", self.emulate_focus)
pub.subscribe(self.check_switch_consistancy, ('Switch'))
pub.subscribe(self.check_switch_consistancy, ('msg_switch'))
self._iren.Bind(wx.EVT_CONTEXT_MENU, self.on_show_popup_menu)
......@@ -276,7 +273,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.clear_universe()
pub.unsubscribe(self.check_switch_consistancy, "Switch")
pub.unsubscribe(self.check_switch_consistancy, "msg_switch")
def set_trajectory(self, trajectory, selection=None, frame=0):
......@@ -316,7 +313,7 @@ class MolecularViewerPanel(ComponentPlugin):
self._trajectoryLoaded = True
pub.sendMessage(('Load trajectory'), message = self)
pub.sendMessage(('msg_load_trajectory'), message = self)
def color_string_to_RGB(self, s):
......@@ -579,7 +576,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.set_configuration(self._timerCounter)
self._timerCounter += 1
pub.sendMessage(("On timer"), message = self)
pub.sendMessage(("msg_timer"), plugin=self)
def set_rendering_mode(self, mode):
if not self._trajectoryLoaded:
......@@ -657,7 +654,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.show_selection(list(self.__pickedAtoms))
pub.sendMessage(('select_atoms_from_viewer'), message = (self.dataplugin,list(self.__pickedAtoms)))
pub.sendMessage(('msg_select_atoms_from_viewer'), message = (self.dataplugin,list(self.__pickedAtoms)))
def box_atoms(self, atomsList):
......@@ -727,9 +724,9 @@ class MolecularViewerPanel(ComponentPlugin):
else:
self.stop_animation()
if check:
pub.sendMessage(('Switch'), message = self)
pub.sendMessage(('msg_switch'), message = self)
pub.sendMessage(('Animation'), message = self)
pub.sendMessage(('msg_animate_trajectory'), message = self)
def check_switch_consistancy(self, message):
......
......@@ -171,7 +171,7 @@ class AtomSelectionDialog(UserDefinitionsDialog):
UserDefinitionsDialog.__init__(self, parent, target, wx.ID_ANY, title="Atom selection dialog",style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX)
pub.subscribe(self.on_select_atoms_from_viewer, ('select_atoms_from_viewer'))
pub.subscribe(self.on_select_atoms_from_viewer, ('msg_select_atoms_from_viewer'))
def build_dialog(self):
......@@ -316,7 +316,7 @@ class AtomSelectionDialog(UserDefinitionsDialog):
self._selectionSummary.Clear()
pub.sendMessage('clear_selection',message=self)
pub.sendMessage('msg_clear_selection',message=self)
def on_close(self, event=None):
......@@ -371,7 +371,7 @@ class AtomSelectionDialog(UserDefinitionsDialog):
_, self._selection = self._query.parse()
pub.sendMessage("set_selection", message = (self,self._selection))
pub.sendMessage("msg_set_selection", message = (self,self._selection))
def validate(self):
......
......@@ -33,8 +33,6 @@ Created on Mar 30, 2015
import wx
import wx.lib.intctrl as wxintctrl
from MDANSE.Externals.pubsub import pub
from MDANSE.App.GUI import DATA_CONTROLLER
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget
......@@ -71,8 +69,6 @@ class FramesWidget(IWidget):
sizer.Add(gbSizer, 1, wx.ALL|wx.EXPAND, 5)
pub.subscribe(self.on_set_trajectory, ("set_trajectory"))
return sizer
def get_widget_value(self):
......@@ -81,17 +77,9 @@ class FramesWidget(IWidget):
return val
def on_set_trajectory(self, message):
window, filename = message
if not window in self.Parent.widgets.values():
return
if not DATA_CONTROLLER:
return
def set_data(self, datakey):
self._trajectory = DATA_CONTROLLER[filename]
self._trajectory = DATA_CONTROLLER[datakey]
nFrames = len(self._trajectory.data) - 1
......
......@@ -35,6 +35,7 @@ import abc
import wx
from MDANSE import REGISTRY
from MDANSE.Externals.pubsub import pub
class IWidget(wx.Panel):
......@@ -57,7 +58,9 @@ class IWidget(wx.Panel):
self.initialize()
self.build_panel()
pub.subscribe(self._set_data, ('msg_set_data'))
@property
def label(self):
return self._label
......@@ -96,3 +99,13 @@ class IWidget(wx.Panel):
def get_value(self):
return self.get_widget_value()
def set_data(self,datakey):
pass
def _set_data(self,plugin):
if not plugin.is_parent(self):
return
self.set_data(plugin.datakey)
......@@ -201,8 +201,7 @@ class InstrumentResolutionConfigurator(IWidget):
self.Bind(wx.EVT_BUTTON, self.on_set_instrument_resolution, self._setResolution)
pub.subscribe(self.on_set_trajectory, ("set_trajectory"))
pub.subscribe(self.on_set_trajectory, ("set_netcdf"))
pub.subscribe(self.set_data, ("msg_set_netcdf"))
return sizer
......@@ -228,16 +227,8 @@ class InstrumentResolutionConfigurator(IWidget):
self._instrumentResolutionDialog.Destroy()
def on_set_trajectory(self, message):
window, filename = message
if not window in self.Parent.widgets.values():
return
if not DATA_CONTROLLER:
return
self._trajectory = DATA_CONTROLLER[filename]
def set_data(self, datakey):
self._trajectory = DATA_CONTROLLER[datakey]
self._setResolution.Enable(True)
\ No newline at end of file
......@@ -32,8 +32,6 @@ Created on Mar 30, 2015
import wx
from MDANSE.Externals.pubsub import pub
from MDANSE.App.GUI import DATA_CONTROLLER
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget
......@@ -51,19 +49,12 @@ class InterpolationOrderWidget(IWidget):
sizer.Add(label, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
sizer.Add(self._interpolationOrder, 0, wx.ALL, 5)
pub.subscribe(self.on_set_trajectory, ("set_trajectory"))
return sizer
def on_set_trajectory(self, message):
window, filename = message
if not window in self.Parent.widgets.values():
return
def set_data(self, datakey):
trajectory = DATA_CONTROLLER[filename]
trajectory = DATA_CONTROLLER[datakey]
if "velocities" in trajectory.data.variables():
self._interpolationOrder.SetItems(self._configurator.choices)
......
......@@ -34,11 +34,9 @@ import wx
from MMTK.Trajectory import Trajectory
from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.Configurable import ConfigurationError
from MDANSE.App.GUI import DATA_CONTROLLER
from MDANSE.App.GUI.Framework import has_parent
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget
class MMTKTrajectoryWidget(IWidget):
......@@ -49,43 +47,24 @@ class MMTKTrajectoryWidget(IWidget):
sizer = wx.BoxSizer(wx.VERTICAL)
self._trajectory = wx.Choice(self._widgetPanel, wx.ID_ANY)
self._trajectory = wx.StaticText(self._widgetPanel, wx.ID_ANY)
sizer.Add(self._trajectory, 1, wx.ALL|wx.EXPAND, 5)
self.Bind(wx.EVT_CHOICE, self.on_select_trajectory, self._trajectory)
pub.subscribe(self.set_trajectory, ('on_set_data'))
return sizer
def on_select_trajectory(self, event):
filename = event.GetString()
pub.sendMessage("set_trajectory", message=(self,filename))
def set_trajectory(self, message):
window, filename = message
if not has_parent(self,window):
return
data = DATA_CONTROLLER[filename].data
def set_data(self, datakey):
data = DATA_CONTROLLER[datakey].data
if not isinstance(data, Trajectory):
return
self._trajectory.SetItems(DATA_CONTROLLER.keys())
self._trajectory.SetStringSelection(filename)
pub.sendMessage("set_trajectory", message = (self,filename))
self._trajectory.SetLabel(datakey)
def get_widget_value(self):
filename = self._trajectory.GetStringSelection()
filename = self._trajectory.GetLabelText()
if not filename:
raise ConfigurationError("No MMTK trajectory file selected", self)
......
......@@ -80,7 +80,7 @@ class McStasInstrumentWidget(IWidget):
self._instrument.Append(path)
self._instrument.Select(self._instrument.GetCount()-1)
pub.sendMessage("set_instrument", message = (self, instrParams))
pub.sendMessage("msg_set_instrument", message = (self, instrParams))
def on_select_instrument(self, event):
......