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): ...@@ -25,12 +25,7 @@ class ProgressBar(wx.Panel,Status):
self.Bind(wx.EVT_BUTTON,self.on_stop,self._stop) self.Bind(wx.EVT_BUTTON,self.on_stop,self._stop)
def finish_status(self,message): def finish_status(self):
status = message
if status != self:
return
self._progress.SetBarColor(wx.BLUE) self._progress.SetBarColor(wx.BLUE)
self._progress.Refresh() self._progress.Refresh()
...@@ -46,34 +41,19 @@ class ProgressBar(wx.Panel,Status): ...@@ -46,34 +41,19 @@ class ProgressBar(wx.Panel,Status):
self._stop.Disable() self._stop.Disable()
self.stop() self.stop()
def start_status(self, message): def start_status(self):
status = message
if status != self:
return
self._stop.Enable() self._stop.Enable()
self._progress.SetValue(self.currentStep) self._progress.SetValue(self.currentStep)
self._progress.SetRange(self.nSteps) self._progress.SetRange(self.nSteps)
self._progress.SetBarColor(wx.GREEN) self._progress.SetBarColor(wx.GREEN)
def stop_status(self, message): def stop_status(self):
status = message
if status != self:
return
self._progress.SetBarColor(wx.RED) self._progress.SetBarColor(wx.RED)
self._progress.Refresh() self._progress.Refresh()
def update_status(self,message): def update_status(self):
status = message
if status != self:
return
self._progress.SetValue(self.currentStep) self._progress.SetValue(self.currentStep)
self._progress.Refresh() self._progress.Refresh()
...@@ -49,7 +49,7 @@ class DataController(collections.OrderedDict): ...@@ -49,7 +49,7 @@ class DataController(collections.OrderedDict):
return return
else: else:
collections.OrderedDict.__delitem__(self,item) collections.OrderedDict.__delitem__(self,item)
Publisher.sendMessage("delete_input_data", message = item) Publisher.sendMessage("msg_delete_input_data", message = item)
def __getitem__(self, key): def __getitem__(self, key):
...@@ -64,7 +64,7 @@ class DataController(collections.OrderedDict): ...@@ -64,7 +64,7 @@ class DataController(collections.OrderedDict):
collections.OrderedDict.__setitem__(self, item,value) 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): def has_proxy(self, item):
''' '''
......
...@@ -57,8 +57,8 @@ class DataTreePanel(wx.Panel): ...@@ -57,8 +57,8 @@ class DataTreePanel(wx.Panel):
self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_drag_data) self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_drag_data)
self.Bind(wx.EVT_TREE_KEY_DOWN, self.on_delete_data, self._tree) 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_load_input_data, ('msg_load_input_data'))
pub.subscribe(self.msg_delete_input_data, ('delete_input_data')) pub.subscribe(self.msg_delete_input_data, ('msg_delete_input_data'))
@property @property
def tree(self): def tree(self):
......
...@@ -102,17 +102,15 @@ class AnimationPlugin(ComponentPlugin): ...@@ -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_first_frame, firstButton)
self.Bind(wx.EVT_BUTTON, self.on_goto_last_frame, lastButton) self.Bind(wx.EVT_BUTTON, self.on_goto_last_frame, lastButton)
Publisher.subscribe(self.on_update_animation_icon, ('Animation')) Publisher.subscribe(self.on_update_animation_icon, ('msg_animate_trajectory'))
Publisher.subscribe(self.on_set_up_frame_slider, ('Load trajectory')) Publisher.subscribe(self.on_set_up_frame_slider, ('msg_load_trajectory'))
Publisher.subscribe(self.on_timer, ('On timer')) Publisher.subscribe(self.on_timer, ('msg_timer'))
def plug(self): def plug(self):
self._parent._mgr.GetPane(self).LeftDockable(False).RightDockable(False).Dock().Bottom().CloseButton(True) self._parent._mgr.GetPane(self).LeftDockable(False).RightDockable(False).Dock().Bottom().CloseButton(True)
self._parent._mgr.Update() self._parent._mgr.Update()
Publisher.sendMessage(('Load trajectory'), message = self.parent)
def on_change_frame_rate(self, event=None): def on_change_frame_rate(self, event=None):
laps = self.speedSlider.GetValue() laps = self.speedSlider.GetValue()
...@@ -151,14 +149,12 @@ class AnimationPlugin(ComponentPlugin): ...@@ -151,14 +149,12 @@ class AnimationPlugin(ComponentPlugin):
self.speedSlider.SetValue(int(self.speedEntry.GetValue())) self.speedSlider.SetValue(int(self.speedEntry.GetValue()))
self._parent.change_frame_rate() self._parent.change_frame_rate()
def on_timer(self, message): def on_timer(self, plugin):
mv = message if not plugin.is_parent(self):
if not has_parent(self,mv):
return return
frame = mv.current_frame frame = plugin.current_frame
self.frameEntry.SetValue(str(frame)) self.frameEntry.SetValue(str(frame))
self.frameSlider.SetValue(int(frame)) self.frameSlider.SetValue(int(frame))
......
...@@ -57,9 +57,9 @@ class DataPlugin(IPlugin): ...@@ -57,9 +57,9 @@ class DataPlugin(IPlugin):
ancestor = None 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 self._datakey = datakey
...@@ -115,14 +115,16 @@ class DataPlugin(IPlugin): ...@@ -115,14 +115,16 @@ class DataPlugin(IPlugin):
plugin.plug() plugin.plug()
plugin.SetFocus() plugin.SetFocus()
self._currentWindow = plugin
def on_changing_pane(self, event): def on_changing_pane(self, event):
window = plugin_parent(event.GetWindow()) window = plugin_parent(event.GetWindow())
if window is None: if window is None:
return return
self._currentWindow = window 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): ...@@ -124,6 +124,16 @@ class IPlugin(wx.Panel):
continue continue
self.close() 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): def close(self):
pass pass
......
...@@ -122,7 +122,7 @@ class JobPlugin(ComponentPlugin): ...@@ -122,7 +122,7 @@ class JobPlugin(ComponentPlugin):
time.sleep(1) time.sleep(1)
pub.sendMessage("on_start_job",message=None) pub.sendMessage("msg_start_job",message=None)
def on_save(self, event=None): def on_save(self, event=None):
...@@ -131,8 +131,7 @@ class JobPlugin(ComponentPlugin): ...@@ -131,8 +131,7 @@ class JobPlugin(ComponentPlugin):
if not parameters: if not parameters:
return 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: if d.ShowModal() == wx.ID_CANCEL:
return return
...@@ -147,12 +146,12 @@ class JobPlugin(ComponentPlugin): ...@@ -147,12 +146,12 @@ class JobPlugin(ComponentPlugin):
self._jobClass.save(path, parameters) self._jobClass.save(path, parameters)
def plug(self): def plug(self):
pub.sendMessage("on_set_data", message = (self,self.datakey)) self._parent._mgr.GetPane(self).Float().Center().Floatable(True).Dockable(True).CloseButton(True).BestSize((800,600))
self._parent._mgr.GetPane(self).Float().Center().Dockable(False).CloseButton(True).BestSize((800,600))
self._parent.mgr.Update() self._parent.mgr.Update()
pub.sendMessage("msg_set_data", plugin=self)
def on_close(self, event): def on_close(self, event):
...@@ -160,61 +159,52 @@ class JobPlugin(ComponentPlugin): ...@@ -160,61 +159,52 @@ class JobPlugin(ComponentPlugin):
class JobFrame(wx.Frame): 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) 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._jobType = jobType
self._datakey = datakey
data = REGISTRY['input_data']['mmtk_trajectory'](self._datakey)
DATA_CONTROLLER[filename] = data
self.build_dialog() self.build_dialog()
def build_dialog(self): 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) workingPanel.active_page.drop(self._jobType)
mainSizer.Add(self._jobPlugin, 1, wx.ALL|wx.EXPAND) workingPanel.active_page.mgr.GetPane(workingPanel.active_page.currentWindow).Dock()
mainPanel.SetSizer(mainSizer)
mainSizer.Fit(mainPanel)
mainPanel.Layout()
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) self.Bind(wx.EVT_CLOSE, self.on_quit)
def on_quit(self, event): def on_quit(self, event):
d = wx.MessageDialog(None, d = wx.MessageDialog(None,'Do you really want to quit ?','Question',wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
'Do you really want to quit ?',
'Question',
wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
if d.ShowModal() == wx.ID_YES: if d.ShowModal() == wx.ID_YES:
self.Destroy() self.Destroy()
if __name__ == "__main__": if __name__ == "__main__":
from MMTK.Trajectory import Trajectory
from MDANSE.App.GUI import DATA_CONTROLLER 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__)))))) 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') 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) app = wx.App(False)
f = JobFrame(None,'msd') f = JobFrame(None,'msd',filename)
f._jobPlugin._datakey = filename
pub.sendMessage("on_set_data", message = (f._jobPlugin,filename))
f.Show() f.Show()
app.MainLoop() app.MainLoop()
\ No newline at end of file
...@@ -167,10 +167,7 @@ class MolecularViewerPanel(ComponentPlugin): ...@@ -167,10 +167,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.enable_picking(True) self.enable_picking(True)
pub.subscribe(self.on_set_selection, ('set_selection')) pub.subscribe(self.on_set_selection, ('msg_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'))
def build_panel(self): def build_panel(self):
...@@ -201,7 +198,7 @@ class MolecularViewerPanel(ComponentPlugin): ...@@ -201,7 +198,7 @@ class MolecularViewerPanel(ComponentPlugin):
self._iren.AddObserver("CharEvent", self.on_keyboard_input) self._iren.AddObserver("CharEvent", self.on_keyboard_input)
self._iren.AddObserver("LeftButtonPressEvent", self.emulate_focus) 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) self._iren.Bind(wx.EVT_CONTEXT_MENU, self.on_show_popup_menu)
...@@ -276,7 +273,7 @@ class MolecularViewerPanel(ComponentPlugin): ...@@ -276,7 +273,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.clear_universe() 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): def set_trajectory(self, trajectory, selection=None, frame=0):
...@@ -316,7 +313,7 @@ class MolecularViewerPanel(ComponentPlugin): ...@@ -316,7 +313,7 @@ class MolecularViewerPanel(ComponentPlugin):
self._trajectoryLoaded = True self._trajectoryLoaded = True
pub.sendMessage(('Load trajectory'), message = self) pub.sendMessage(('msg_load_trajectory'), message = self)
def color_string_to_RGB(self, s): def color_string_to_RGB(self, s):
...@@ -579,7 +576,7 @@ class MolecularViewerPanel(ComponentPlugin): ...@@ -579,7 +576,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.set_configuration(self._timerCounter) self.set_configuration(self._timerCounter)
self._timerCounter += 1 self._timerCounter += 1
pub.sendMessage(("On timer"), message = self) pub.sendMessage(("msg_timer"), plugin=self)
def set_rendering_mode(self, mode): def set_rendering_mode(self, mode):
if not self._trajectoryLoaded: if not self._trajectoryLoaded:
...@@ -657,7 +654,7 @@ class MolecularViewerPanel(ComponentPlugin): ...@@ -657,7 +654,7 @@ class MolecularViewerPanel(ComponentPlugin):
self.show_selection(list(self.__pickedAtoms)) 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): def box_atoms(self, atomsList):
...@@ -727,9 +724,9 @@ class MolecularViewerPanel(ComponentPlugin): ...@@ -727,9 +724,9 @@ class MolecularViewerPanel(ComponentPlugin):
else: else:
self.stop_animation() self.stop_animation()
if check: 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): def check_switch_consistancy(self, message):
......
...@@ -171,7 +171,7 @@ class AtomSelectionDialog(UserDefinitionsDialog): ...@@ -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) 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): def build_dialog(self):
...@@ -316,7 +316,7 @@ class AtomSelectionDialog(UserDefinitionsDialog): ...@@ -316,7 +316,7 @@ class AtomSelectionDialog(UserDefinitionsDialog):
self._selectionSummary.Clear() self._selectionSummary.Clear()
pub.sendMessage('clear_selection',message=self) pub.sendMessage('msg_clear_selection',message=self)
def on_close(self, event=None): def on_close(self, event=None):
...@@ -371,7 +371,7 @@ class AtomSelectionDialog(UserDefinitionsDialog): ...@@ -371,7 +371,7 @@ class AtomSelectionDialog(UserDefinitionsDialog):
_, self._selection = self._query.parse() _, 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): def validate(self):
......
...@@ -33,8 +33,6 @@ Created on Mar 30, 2015 ...@@ -33,8 +33,6 @@ Created on Mar 30, 2015
import wx import wx
import wx.lib.intctrl as wxintctrl import wx.lib.intctrl as wxintctrl
from MDANSE.Externals.pubsub import pub
from MDANSE.App.GUI import DATA_CONTROLLER from MDANSE.App.GUI import DATA_CONTROLLER
from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget from MDANSE.App.GUI.Framework.Widgets.IWidget import IWidget
...@@ -71,8 +69,6 @@ class FramesWidget(IWidget): ...@@ -71,8 +69,6 @@ class FramesWidget(IWidget):
sizer.Add(gbSizer, 1, wx.ALL|wx.EXPAND, 5) sizer.Add(gbSizer, 1, wx.ALL|wx.EXPAND, 5)
pub.subscribe(self.on_set_trajectory, ("set_trajectory"))
return sizer return sizer
def get_widget_value(self): def get_widget_value(self):
...@@ -81,17 +77,9 @@ class FramesWidget(IWidget): ...@@ -81,17 +77,9 @@ class FramesWidget(IWidget):
return val return val
def on_set_trajectory(self, message): def set_data(self, datakey):
window, filename = message
if not window in self.Parent.widgets.values():
return
if not DATA_CONTROLLER:
return
self._trajectory = DATA_CONTROLLER[filename] self._trajectory = DATA_CONTROLLER[datakey]
nFrames = len(self._trajectory.data) - 1 nFrames = len(self._trajectory.data) - 1