def __init__(self, parent, dstack = None, aspect=1, horizOptions = False, wantUpdates = [], mdh=None, **kwds): kwds["style"] = wx.TAB_TRAVERSAL wx.Panel.__init__(self, parent, **kwds) self.showOptsPanel = 1 self.WantUpdateNotification = [] self.WantUpdateNotification += wantUpdates self._mgr = aui.AuiManager(agwFlags = aui.AUI_MGR_DEFAULT) # tell AuiManager to manage this frame self._mgr.SetManagedWindow(self) self.view = ArrayViewPanel(self, dstack, aspect) self._mgr.AddPane(self.view, aui.AuiPaneInfo(). Name("Data").Caption("Data").Centre().CloseButton(False).CaptionVisible(False)) self.do = self.view.do self.optionspanel = OptionsPanel(self, self.view.do,horizOrientation = horizOptions) self.optionspanel.SetSize(self.optionspanel.GetBestSize()) pinfo = aui.AuiPaneInfo().Name("optionsPanel").Right().Caption('Display Settings').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.optionspanel, pinfo) self.overlaypanel = OverlayPanel(self, self.view, mdh) self.overlaypanel.SetSize(self.overlaypanel.GetBestSize()) pinfo2 = aui.AuiPaneInfo().Name("overlayPanel").Right().Caption('Overlays').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.overlaypanel, pinfo2) self._mgr.AddPane(self.view.CreateToolBar(self), aui.AuiPaneInfo().Name("ViewTools").Caption("View Tools").CloseButton(False). ToolbarPane().Right().GripperTop()) if self.do.ds.shape[2] > 1: self.playbackpanel = playback.PlayPanel(self, self) self.playbackpanel.SetSize(self.playbackpanel.GetBestSize()) pinfo1 = aui.AuiPaneInfo().Name("playbackPanel").Bottom().Caption('Playback').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.playbackpanel, pinfo1) if (self.do.ds.ndim >= 5) and (self.do.ds.shape[3] > 1): self.playbackpanel = playback.PlayPanel(self, self, axis='t') self.playbackpanel.SetSize(self.playbackpanel.GetBestSize()) pinfo1 = aui.AuiPaneInfo().Name("playbackPanelT").Bottom().Caption('Playback (t)').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.playbackpanel, pinfo1) # self.toolbar = aui.AuiToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,agwStyle=aui.AUI_TB_DEFAULT_STYLE | aui.AUI_TB_OVERFLOW| aui.AUI_TB_VERTICAL) # self.toolbar.AddSimpleTool(-1, "Clockwise 1", wx.ArtProvider.GetBitmap(wx.ART_ERROR, wx.ART_OTHER, wx.Size(16, 16))) # self.toolbar.Realize() # self._mgr.AddPane(self.toolbar, aui.AuiPaneInfo(). # Name("toolbar").Caption("Toolbar"). # ToolbarPane().Right().GripperTop()); self._mgr.Update() self._mgr.MinimizePane(pinfo) self._mgr.MinimizePane(pinfo2) #pinfo.Minimize() #self._mgr.Update() self.updating = False
def __init__(self, image, parent=None, title='', mode='LM', size = (800,700), glCanvas=None): AUIFrame.__init__(self,parent, -1, title,size=size, pos=wx.DefaultPosition) self.mode = mode self.glCanvas = glCanvas self.updateHooks = [] self.statusHooks = [] self.installedModules = [] # will store weakrefs to things that modules previously injected into our namespace #self._module_injections = weakref.WeakValueDictionary() self.dataChangeHooks = [] self.updating = False if glCanvas: self.glCanvas.wantViewChangeNotification.add(self) self.timer = mytimer() self.timer.Start(10000) self.image = image #self.image = ImageStack(data = dstack, mdh = mdh, filename = filename, queueURI = queueURI, events = None) if not self.image.filename is None and title == '': self.SetTitle(self.image.filename) self.do = DisplayOpts(self.image.data) if self.image.data.shape[1] == 1: self.do.slice = self.do.SLICE_XZ self.do.Optimise() if self.image.mdh and 'ChannelNames' in self.image.mdh.getEntryNames(): chan_names = self.image.mdh.getEntry('ChannelNames') if len(chan_names) == self.image.data.shape[3]: self.do.names = chan_names #self.vp = ArraySettingsAndViewPanel(self, self.image.data, wantUpdates=[self.update], mdh=self.image.mdh) #self.view = ArrayViewPanel(self, do=self.do) #self.AddPage(self.view, True, 'Data') #self._mgr.AddPane(self.vp, aui.AuiPaneInfo(). # Name("Data").Caption("Data").Centre().CloseButton(False).CaptionVisible(False)) self.mainFrame = weakref.ref(self) #self.do = self.vp.do tmp_menu = wx.Menu() tmp_menu.Append(wx.ID_OPEN, '&Open', "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVE, "&Save As", "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVEAS, "&Export Cropped", "", wx.ITEM_NORMAL) #a submenu for modules to hook and install saving functions into self.save_menu = wx.Menu() self._menus['Save'] = self.save_menu tmp_menu.AppendMenu(-1, 'Save &Results', self.save_menu) #tmp_menu.AppendSeparator() #tmp_menu.Append(wx.ID_CLOSE, "Close", "", wx.ITEM_NORMAL) self.menubar.Append(tmp_menu, "File") self._menus['File'] = tmp_menu self.view_menu = wx.Menu() self.menubar.Append(self.view_menu, "&View") self._menus['View'] = self.view_menu #'extras' menu for modules to install stuff into self.mProcessing = wx.Menu() self.menubar.Append(self.mProcessing, "&Processing") self._menus['Processing'] = self.mProcessing # Menu Bar end self.Bind(wx.EVT_MENU, self.OnOpen, id=wx.ID_OPEN) self.Bind(wx.EVT_MENU, self.OnSave, id=wx.ID_SAVE) self.Bind(wx.EVT_MENU, self.OnExport, id=wx.ID_SAVEAS) #self.Bind(wx.EVT_MENU, lambda e: self.Close(), id=wx.ID_CLOSE) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.statusbar = self.CreateStatusBar(1, wx.STB_SIZEGRIP) self.panesToMinimise = [] modules.loadMode(self.mode, self) self.CreateModuleMenu() self.add_common_menu_items() self.optionspanel = OptionsPanel(self, self.do, thresholdControls=True) self.optionspanel.SetSize(self.optionspanel.GetBestSize()) pinfo = aui.AuiPaneInfo().Name("optionsPanel").Right().Caption('Display Settings').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.optionspanel, pinfo) self.panesToMinimise.append(pinfo) self._mgr.AddPane(self.optionspanel.CreateToolBar(self), aui.AuiPaneInfo().Name("ViewTools").Caption("View Tools").CloseButton(False). ToolbarPane().Right().GripperTop()) if self.do.ds.shape[2] > 1: from PYME.DSView.modules import playback self.playbackpanel = playback.PlayPanel(self, self) self.playbackpanel.SetSize(self.playbackpanel.GetBestSize()) pinfo1 = aui.AuiPaneInfo().Name("playbackPanel").Bottom().Caption('Playback').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.playbackpanel, pinfo1) self.do.WantChangeNotification.append(self.playbackpanel.update) #self.mWindows = wx.Menu() #self.menubar.append(self.mWindows, '&Composite With') self.do.WantChangeNotification.append(self.update) self.CreateFoldPanel() for pn in self.panesToMinimise: self._mgr.MinimizePane(pn) #self._mgr.MinimizePane(pinfo2) self.Layout() if 'view' in dir(self): sc = np.floor(np.log2(1.0*self.view.Size[0]/self.do.ds.shape[0])) #print self.view.Size[0], self.do.ds.shape[0], sc self.do.SetScale(sc) self.view.Refresh() self.update() self.drop = dt() self.SetDropTarget(self.drop) self.AddMenuItem('Save', 'To Cluster', self.OnSaveToCluster) openViewers[self.image.filename] = self
class DSViewFrame(AUIFrame): def __init__(self, image, parent=None, title='', mode='LM', size = (800,700), glCanvas=None): AUIFrame.__init__(self,parent, -1, title,size=size, pos=wx.DefaultPosition) self.mode = mode self.glCanvas = glCanvas self.updateHooks = [] self.statusHooks = [] self.installedModules = [] # will store weakrefs to things that modules previously injected into our namespace #self._module_injections = weakref.WeakValueDictionary() self.dataChangeHooks = [] self.updating = False if glCanvas: self.glCanvas.wantViewChangeNotification.add(self) self.timer = mytimer() self.timer.Start(10000) self.image = image #self.image = ImageStack(data = dstack, mdh = mdh, filename = filename, queueURI = queueURI, events = None) if not self.image.filename is None and title == '': self.SetTitle(self.image.filename) self.do = DisplayOpts(self.image.data) if self.image.data.shape[1] == 1: self.do.slice = self.do.SLICE_XZ self.do.Optimise() if self.image.mdh and 'ChannelNames' in self.image.mdh.getEntryNames(): chan_names = self.image.mdh.getEntry('ChannelNames') if len(chan_names) == self.image.data.shape[3]: self.do.names = chan_names #self.vp = ArraySettingsAndViewPanel(self, self.image.data, wantUpdates=[self.update], mdh=self.image.mdh) #self.view = ArrayViewPanel(self, do=self.do) #self.AddPage(self.view, True, 'Data') #self._mgr.AddPane(self.vp, aui.AuiPaneInfo(). # Name("Data").Caption("Data").Centre().CloseButton(False).CaptionVisible(False)) self.mainFrame = weakref.ref(self) #self.do = self.vp.do tmp_menu = wx.Menu() tmp_menu.Append(wx.ID_OPEN, '&Open', "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVE, "&Save As", "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVEAS, "&Export Cropped", "", wx.ITEM_NORMAL) #a submenu for modules to hook and install saving functions into self.save_menu = wx.Menu() self._menus['Save'] = self.save_menu tmp_menu.AppendMenu(-1, 'Save &Results', self.save_menu) #tmp_menu.AppendSeparator() #tmp_menu.Append(wx.ID_CLOSE, "Close", "", wx.ITEM_NORMAL) self.menubar.Append(tmp_menu, "File") self._menus['File'] = tmp_menu self.view_menu = wx.Menu() self.menubar.Append(self.view_menu, "&View") self._menus['View'] = self.view_menu #'extras' menu for modules to install stuff into self.mProcessing = wx.Menu() self.menubar.Append(self.mProcessing, "&Processing") self._menus['Processing'] = self.mProcessing # Menu Bar end self.Bind(wx.EVT_MENU, self.OnOpen, id=wx.ID_OPEN) self.Bind(wx.EVT_MENU, self.OnSave, id=wx.ID_SAVE) self.Bind(wx.EVT_MENU, self.OnExport, id=wx.ID_SAVEAS) #self.Bind(wx.EVT_MENU, lambda e: self.Close(), id=wx.ID_CLOSE) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.statusbar = self.CreateStatusBar(1, wx.STB_SIZEGRIP) self.panesToMinimise = [] modules.loadMode(self.mode, self) self.CreateModuleMenu() self.add_common_menu_items() self.optionspanel = OptionsPanel(self, self.do, thresholdControls=True) self.optionspanel.SetSize(self.optionspanel.GetBestSize()) pinfo = aui.AuiPaneInfo().Name("optionsPanel").Right().Caption('Display Settings').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.optionspanel, pinfo) self.panesToMinimise.append(pinfo) self._mgr.AddPane(self.optionspanel.CreateToolBar(self), aui.AuiPaneInfo().Name("ViewTools").Caption("View Tools").CloseButton(False). ToolbarPane().Right().GripperTop()) if self.do.ds.shape[2] > 1: from PYME.DSView.modules import playback self.playbackpanel = playback.PlayPanel(self, self) self.playbackpanel.SetSize(self.playbackpanel.GetBestSize()) pinfo1 = aui.AuiPaneInfo().Name("playbackPanel").Bottom().Caption('Playback').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.playbackpanel, pinfo1) self.do.WantChangeNotification.append(self.playbackpanel.update) #self.mWindows = wx.Menu() #self.menubar.append(self.mWindows, '&Composite With') self.do.WantChangeNotification.append(self.update) self.CreateFoldPanel() for pn in self.panesToMinimise: self._mgr.MinimizePane(pn) #self._mgr.MinimizePane(pinfo2) self.Layout() if 'view' in dir(self): sc = np.floor(np.log2(1.0*self.view.Size[0]/self.do.ds.shape[0])) #print self.view.Size[0], self.do.ds.shape[0], sc self.do.SetScale(sc) self.view.Refresh() self.update() self.drop = dt() self.SetDropTarget(self.drop) self.AddMenuItem('Save', 'To Cluster', self.OnSaveToCluster) openViewers[self.image.filename] = self def CreateModuleMenu(self): #self.modMenuIds = {} self.moduleNameByID = {} self.moduleMenuIDByName = {} self.mModules = wx.Menu() for mn in modules.allmodules(): id = wx.NewId() self.mModules.AppendCheckItem(id, mn) self.moduleNameByID[id] = mn self.moduleMenuIDByName[mn] = id if mn in self.installedModules: self.mModules.Check(id, True) self.mModules.Enable(id, False) self.Bind(wx.EVT_MENU, self.OnToggleModule, id=id) self.menubar.Append(self.mModules, "&Modules") self._menus["&Modules"] = self.mModules def OnToggleModule(self, event): id = event.GetId() mn = self.moduleNameByID[id] #if self.mModules.IsChecked(id): self.LoadModule(mn) def LoadModule(self, moduleName): """Load a module with the given name and update GUI """ modules.loadModule(moduleName, self) if moduleName in self.installedModules: id = self.moduleMenuIDByName[moduleName] self.mModules.Check(id, True) self.mModules.Enable(id, False) self.CreateFoldPanel() self._mgr.Update() def GetSelectedPage(self): nbs = self._mgr.GetNotebooks() currPage = nbs[0].GetCurrentPage() return currPage def create_overlay_panel(self): from PYME.DSView.OverlaysPanel import OverlayPanel if not 'overlaypanel' in dir(self): self.overlaypanel = OverlayPanel(self, self.view, self.image.mdh) self.overlaypanel.SetSize(self.overlaypanel.GetBestSize()) pinfo2 = aui.AuiPaneInfo().Name("overlayPanel").Right().Caption('Overlays').CloseButton( False).MinimizeButton(True).MinimizeMode( aui.AUI_MINIMIZE_CAPT_SMART | aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.overlaypanel, pinfo2) self.panesToMinimise.append(pinfo2) def update(self): if not self.updating: self.updating = True #if 'view' in dir(self): # self.view.Refresh() statusText = 'Slice No: (%d/%d) x: %d y: %d' % (self.do.zp, self.do.ds.shape[2], self.do.xp, self.do.yp) #grab status from modules which supply it for sCallback in self.statusHooks: statusText += '\t' + sCallback() #'Frames Analysed: %d Events detected: %d' % (self.vp.do.zp, self.vp.do.ds.shape[2], self.vp.do.xp, self.vp.do.yp, self.LMAnalyser.numAnalysed, self.LMAnalyser.numEvents) self.statusbar.SetStatusText(statusText) #if 'playbackpanel' in dir(self): # self.playbackpanel.update() #update any modules which require it for uCallback in self.updateHooks: #print uCallback uCallback(self) self.updating = False #def Redraw(self): # self.v def DataChanged(self): for uCallback in self.dataChangeHooks: uCallback(self) def OnOpen(self, event=None): ViewIm3D(ImageStack()) def OnSave(self, event=None): self.image.Save() self.SetTitle(self.image.filename) def OnSaveToCluster(self, event=None): from PYME.IO import clusterExport seriesName = clusterExport.suggest_cluster_filename(self.image) ted = wx.TextEntryDialog(None, 'Cluster filename:', 'Save file to cluster', seriesName) if ted.ShowModal() == wx.ID_OK: #pd = wx.ProgressDialog() clusterExport.ExportImageToCluster(self.image, ted.GetValue()) ted.Destroy() def OnExport(self, event=None): bx = min(self.do.selection_begin_x, self.do.selection_end_x) ex = max(self.do.selection_begin_x, self.do.selection_end_x) by = min(self.do.selection_begin_y, self.do.selection_end_y) ey = max(self.do.selection_begin_y, self.do.selection_end_y) roi = [[bx, ex + 1],[by, ey + 1], [0, self.image.data.shape[2]]] self.image.Save(crop = True, roi=roi) def OnCrop(self): pass #View3D(self.image.data[]) def OnCloseWindow(self, event): plt.close('all') if (not self.image.saved): dialog = wx.MessageDialog(self, "Save data stack?", "PYME", wx.YES_NO|wx.CANCEL) ans = dialog.ShowModal() if(ans == wx.ID_YES): self.OnSave() self._cleanup() elif (ans == wx.ID_NO): self._cleanup() else: #wxID_CANCEL: if (not event.CanVeto()): self._cleanup() else: event.Veto() else: self._cleanup() def _cleanup(self): self.timer.Stop() del(self.image) AUIFrame._cleanup(self) def dsRefresh(self): #zp = self.vp.do.zp #save z -position self.do.SetDataStack(self.image.dataSource) #self.vp.do.zp = zp #restore z position self.elv.SetEventSource(self.image.dataSource.getEvents()) self.elv.SetRange([0, self.image.dataSource.getNumSlices()]) if b'ProtocolFocus' in self.elv.evKeyNames: self.zm = piecewiseMapping.GeneratePMFromEventList(self.elv.eventSource, self.mdh.getEntry('Camera.CycleTime'), self.mdh.getEntry('StartTime'), self.mdh.getEntry('Protocol.PiezoStartPos')) self.elv.SetCharts([('Focus [um]', self.zm, b'ProtocolFocus'),]) self.update()
def __init__(self, image, parent=None, title='', mode='LM', size = (800,700), glCanvas=None): wx.Frame.__init__(self,parent, -1, title,size=size, pos=(1100, 300)) self.SetAutoLayout(True) self.mode = mode self.glCanvas = glCanvas self.paneHooks = [] self.updateHooks = [] self.statusHooks = [] self.installedModules = [] self.dataChangeHooks = [] self.updating = False if glCanvas: self.glCanvas.wantViewChangeNotification.add(self) self.pane0 = None self.timer = mytimer() self.timer.Start(10000) self.image = image #self.image = ImageStack(data = dstack, mdh = mdh, filename = filename, queueURI = queueURI, events = None) if not self.image.filename == None and title == '': self.SetTitle(self.image.filename) self._mgr = aui.AuiManager(agwFlags = aui.AUI_MGR_DEFAULT | aui.AUI_MGR_AUTONB_NO_CAPTION) atabstyle = self._mgr.GetAutoNotebookStyle() self._mgr.SetAutoNotebookStyle((atabstyle ^ aui.AUI_NB_BOTTOM) | aui.AUI_NB_TOP) # tell AuiManager to manage this frame self._mgr.SetManagedWindow(self) self.do = DisplayOpts(self.image.data) if self.image.data.shape[1] == 1: self.do.slice = self.do.SLICE_XZ self.do.Optimise() if self.image.mdh and 'ChannelNames' in self.image.mdh.getEntryNames(): self.do.names = self.image.mdh.getEntry('ChannelNames') #self.vp = ArraySettingsAndViewPanel(self, self.image.data, wantUpdates=[self.update], mdh=self.image.mdh) #self.view = ArrayViewPanel(self, do=self.do) #self.AddPage(self.view, True, 'Data') #self._mgr.AddPane(self.vp, aui.AuiPaneInfo(). # Name("Data").Caption("Data").Centre().CloseButton(False).CaptionVisible(False)) self.mainFrame = weakref.ref(self) #self.do = self.vp.do self._menus = {} # Menu Bar self.menubar = wx.MenuBar() self.SetMenuBar(self.menubar) tmp_menu = wx.Menu() tmp_menu.Append(wx.ID_OPEN, '&Open', "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVE, "&Save As", "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVEAS, "&Export Cropped", "", wx.ITEM_NORMAL) #a submenu for modules to hook and install saving functions into self.save_menu = wx.Menu() self._menus['Save'] = self.save_menu tmp_menu.AppendMenu(-1, 'Save &Results', self.save_menu) tmp_menu.AppendSeparator() tmp_menu.Append(wx.ID_CLOSE, "Close", "", wx.ITEM_NORMAL) self.menubar.Append(tmp_menu, "File") self.view_menu = wx.Menu() self.menubar.Append(self.view_menu, "&View") self._menus['View'] = self.view_menu #'extras' menu for modules to install stuff into self.mProcessing = wx.Menu() self.menubar.Append(self.mProcessing, "&Processing") self._menus['Processing'] = self.mProcessing # Menu Bar end wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpen) wx.EVT_MENU(self, wx.ID_SAVE, self.OnSave) wx.EVT_MENU(self, wx.ID_SAVEAS, self.OnExport) wx.EVT_CLOSE(self, self.OnCloseWindow) wx.EVT_SIZE(self, self.OnSize) self.statusbar = self.CreateStatusBar(1, wx.ST_SIZEGRIP) self.panesToMinimise = [] modules.loadMode(self.mode, self) self.CreateModuleMenu() self.optionspanel = OptionsPanel(self, self.do, thresholdControls=True) self.optionspanel.SetSize(self.optionspanel.GetBestSize()) pinfo = aui.AuiPaneInfo().Name("optionsPanel").Right().Caption('Display Settings').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.optionspanel, pinfo) self.panesToMinimise.append(pinfo) self._mgr.AddPane(self.optionspanel.CreateToolBar(self), aui.AuiPaneInfo().Name("ViewTools").Caption("View Tools").CloseButton(False). ToolbarPane().Right().GripperTop()) if self.do.ds.shape[2] > 1: from PYME.DSView.modules import playback self.playbackpanel = playback.PlayPanel(self, self) self.playbackpanel.SetSize(self.playbackpanel.GetBestSize()) pinfo1 = aui.AuiPaneInfo().Name("playbackPanel").Bottom().Caption('Playback').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.playbackpanel, pinfo1) self.do.WantChangeNotification.append(self.playbackpanel.update) #self.mWindows = wx.Menu() #self.menubar.append(self.mWindows, '&Composite With') self.do.WantChangeNotification.append(self.update) self.CreateFoldPanel() self._mgr.Update() for pn in self.panesToMinimise: self._mgr.MinimizePane(pn) #self._mgr.MinimizePane(pinfo2) self.Layout() if 'view' in dir(self): sc = pylab.floor(pylab.log2(1.0*self.view.Size[0]/self.do.ds.shape[0])) #print self.view.Size[0], self.do.ds.shape[0], sc self.do.SetScale(sc) self.view.Refresh() self.update() self.drop = dt() self.SetDropTarget(self.drop) openViewers[self.image.filename] = self
class DSViewFrame(wx.Frame): def __init__(self, image, parent=None, title='', mode='LM', size = (800,700), glCanvas=None): wx.Frame.__init__(self,parent, -1, title,size=size, pos=(1100, 300)) self.SetAutoLayout(True) self.mode = mode self.glCanvas = glCanvas self.paneHooks = [] self.updateHooks = [] self.statusHooks = [] self.installedModules = [] self.dataChangeHooks = [] self.updating = False if glCanvas: self.glCanvas.wantViewChangeNotification.add(self) self.pane0 = None self.timer = mytimer() self.timer.Start(10000) self.image = image #self.image = ImageStack(data = dstack, mdh = mdh, filename = filename, queueURI = queueURI, events = None) if not self.image.filename == None and title == '': self.SetTitle(self.image.filename) self._mgr = aui.AuiManager(agwFlags = aui.AUI_MGR_DEFAULT | aui.AUI_MGR_AUTONB_NO_CAPTION) atabstyle = self._mgr.GetAutoNotebookStyle() self._mgr.SetAutoNotebookStyle((atabstyle ^ aui.AUI_NB_BOTTOM) | aui.AUI_NB_TOP) # tell AuiManager to manage this frame self._mgr.SetManagedWindow(self) self.do = DisplayOpts(self.image.data) if self.image.data.shape[1] == 1: self.do.slice = self.do.SLICE_XZ self.do.Optimise() if self.image.mdh and 'ChannelNames' in self.image.mdh.getEntryNames(): self.do.names = self.image.mdh.getEntry('ChannelNames') #self.vp = ArraySettingsAndViewPanel(self, self.image.data, wantUpdates=[self.update], mdh=self.image.mdh) #self.view = ArrayViewPanel(self, do=self.do) #self.AddPage(self.view, True, 'Data') #self._mgr.AddPane(self.vp, aui.AuiPaneInfo(). # Name("Data").Caption("Data").Centre().CloseButton(False).CaptionVisible(False)) self.mainFrame = weakref.ref(self) #self.do = self.vp.do self._menus = {} # Menu Bar self.menubar = wx.MenuBar() self.SetMenuBar(self.menubar) tmp_menu = wx.Menu() tmp_menu.Append(wx.ID_OPEN, '&Open', "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVE, "&Save As", "", wx.ITEM_NORMAL) tmp_menu.Append(wx.ID_SAVEAS, "&Export Cropped", "", wx.ITEM_NORMAL) #a submenu for modules to hook and install saving functions into self.save_menu = wx.Menu() self._menus['Save'] = self.save_menu tmp_menu.AppendMenu(-1, 'Save &Results', self.save_menu) tmp_menu.AppendSeparator() tmp_menu.Append(wx.ID_CLOSE, "Close", "", wx.ITEM_NORMAL) self.menubar.Append(tmp_menu, "File") self.view_menu = wx.Menu() self.menubar.Append(self.view_menu, "&View") self._menus['View'] = self.view_menu #'extras' menu for modules to install stuff into self.mProcessing = wx.Menu() self.menubar.Append(self.mProcessing, "&Processing") self._menus['Processing'] = self.mProcessing # Menu Bar end wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpen) wx.EVT_MENU(self, wx.ID_SAVE, self.OnSave) wx.EVT_MENU(self, wx.ID_SAVEAS, self.OnExport) wx.EVT_CLOSE(self, self.OnCloseWindow) wx.EVT_SIZE(self, self.OnSize) self.statusbar = self.CreateStatusBar(1, wx.ST_SIZEGRIP) self.panesToMinimise = [] modules.loadMode(self.mode, self) self.CreateModuleMenu() self.optionspanel = OptionsPanel(self, self.do, thresholdControls=True) self.optionspanel.SetSize(self.optionspanel.GetBestSize()) pinfo = aui.AuiPaneInfo().Name("optionsPanel").Right().Caption('Display Settings').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.optionspanel, pinfo) self.panesToMinimise.append(pinfo) self._mgr.AddPane(self.optionspanel.CreateToolBar(self), aui.AuiPaneInfo().Name("ViewTools").Caption("View Tools").CloseButton(False). ToolbarPane().Right().GripperTop()) if self.do.ds.shape[2] > 1: from PYME.DSView.modules import playback self.playbackpanel = playback.PlayPanel(self, self) self.playbackpanel.SetSize(self.playbackpanel.GetBestSize()) pinfo1 = aui.AuiPaneInfo().Name("playbackPanel").Bottom().Caption('Playback').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False) self._mgr.AddPane(self.playbackpanel, pinfo1) self.do.WantChangeNotification.append(self.playbackpanel.update) #self.mWindows = wx.Menu() #self.menubar.append(self.mWindows, '&Composite With') self.do.WantChangeNotification.append(self.update) self.CreateFoldPanel() self._mgr.Update() for pn in self.panesToMinimise: self._mgr.MinimizePane(pn) #self._mgr.MinimizePane(pinfo2) self.Layout() if 'view' in dir(self): sc = pylab.floor(pylab.log2(1.0*self.view.Size[0]/self.do.ds.shape[0])) #print self.view.Size[0], self.do.ds.shape[0], sc self.do.SetScale(sc) self.view.Refresh() self.update() self.drop = dt() self.SetDropTarget(self.drop) openViewers[self.image.filename] = self def OnSize(self, event): #self.Layout() self._mgr.Update() #self.Refresh() #self.Update() def AddPage(self, page=None, select=True,caption='Dummy'): if self.pane0 == None: name = caption.replace(' ', '') self._mgr.AddPane(page, aui.AuiPaneInfo(). Name(name).Caption(caption).Centre().CloseButton(False).CaptionVisible(False)) self.pane0 = name else: self._mgr.Update() pn = self._mgr.GetPaneByName(self.pane0) if pn.IsNotebookPage(): print((pn.notebook_id)) nbs = self._mgr.GetNotebooks() if len(nbs) > pn.notebook_id: currPage = nbs[pn.notebook_id].GetSelection() self._mgr.AddPane(page, aui.AuiPaneInfo(). Name(caption.replace(' ', '')).Caption(caption).CloseButton(False).NotebookPage(pn.notebook_id)) if (not select) and len(nbs) > pn.notebook_id: self._mgr.Update() nbs[pn.notebook_id].SetSelection(currPage) else: self._mgr.AddPane(page, aui.AuiPaneInfo(). Name(caption.replace(' ', '')).Caption(caption).CloseButton(False), target=pn) if not select: self._mgr.Update() nb = self._mgr.GetNotebooks()[0] nb.SetSelection(0) wx.CallAfter(self._mgr.Update) #self.Layout() #self.OnSize(None) #self.OnSize(None) def CreateModuleMenu(self): self.modMenuIds = {} self.mModules = wx.Menu() for mn in modules.allmodules(): id = wx.NewId() self.mModules.AppendCheckItem(id, mn) self.modMenuIds[id] = mn if mn in self.installedModules: self.mModules.Check(id, True) wx.EVT_MENU(self, id, self.OnToggleModule) self.menubar.Append(self.mModules, "&Modules") def AddMenuItem(self, menuName, itemName='', itemCallback = None, itemType='normal', helpText = ''): mItem = None if not menuName in self._menus.keys(): menu = wx.Menu() self.menubar.Insert(self.menubar.GetMenuCount()-1, menu, menuName) self._menus[menuName] = menu else: menu = self._menus[menuName] if itemType == 'normal': mItem = menu.Append(wx.ID_ANY, itemName, helpText, wx.ITEM_NORMAL) self.Bind(wx.EVT_MENU, itemCallback, mItem) elif itemType == 'separator': menu.AppendSeparator() return mItem def OnToggleModule(self, event): id = event.GetId() mn = self.modMenuIds[id] if self.mModules.IsChecked(id): modules.loadModule(mn, self) if mn in self.installedModules: self.mModules.Check(id, True) self.CreateFoldPanel() self._mgr.Update() def GetSelectedPage(self): nbs = self._mgr.GetNotebooks() currPage = nbs[0].GetCurrentPage() return currPage def CreateFoldPanel(self): pinfo = self._mgr.GetPaneByName('sidePanel') if pinfo.IsOk(): #we already have a sidepanel, clear self.sidePanel.Clear() else: self.sidePanel = afp.foldPanel(self, -1, wx.DefaultPosition,size = wx.Size(180, 1000)) pinfo = aui.AuiPaneInfo().Name("sidePanel").Left().CloseButton(False).CaptionVisible(False) self._mgr.AddPane(self.sidePanel, pinfo) if len(self.paneHooks) > 0: pinfo.Show() for genFcn in self.paneHooks: genFcn(self.sidePanel) else: pinfo.Hide() self._mgr.Update() self.Refresh() self.Update() def update(self): if not self.updating: self.updating = True #if 'view' in dir(self): # self.view.Refresh() statusText = 'Slice No: (%d/%d) x: %d y: %d' % (self.do.zp, self.do.ds.shape[2], self.do.xp, self.do.yp) #grab status from modules which supply it for sCallback in self.statusHooks: statusText += '\t' + sCallback() #'Frames Analysed: %d Events detected: %d' % (self.vp.do.zp, self.vp.do.ds.shape[2], self.vp.do.xp, self.vp.do.yp, self.LMAnalyser.numAnalysed, self.LMAnalyser.numEvents) self.statusbar.SetStatusText(statusText) #if 'playbackpanel' in dir(self): # self.playbackpanel.update() #update any modules which require it for uCallback in self.updateHooks: #print uCallback uCallback(self) self.updating = False #def Redraw(self): # self.v def DataChanged(self): for uCallback in self.dataChangeHooks: uCallback(self) def OnOpen(self, event=None): ViewIm3D(ImageStack()) def OnSave(self, event=None): self.image.Save() self.SetTitle(self.image.filename) def OnExport(self, event=None): self.image.Save(crop = True, view = self.view) def OnCrop(self): pass #View3D(self.image.data[]) def OnCloseWindow(self, event): pylab.close('all') if (not self.image.saved): dialog = wx.MessageDialog(self, "Save data stack?", "PYME", wx.YES_NO|wx.CANCEL) ans = dialog.ShowModal() if(ans == wx.ID_YES): self.OnSave() self._cleanup() elif (ans == wx.ID_NO): self._cleanup() else: #wxID_CANCEL: if (not event.CanVeto()): self._cleanup() else: event.Veto() else: self._cleanup() def _cleanup(self): self.timer.Stop() #for some reason AUI doesn't clean itself up properly and stops the #window from being garbage collected - fix this here self._mgr.UnInit() self._mgr._frame = None #if self.glCanvas: # self.glCanvas.wantViewChangeNotification.remove(self) self.Destroy() def dsRefresh(self): #zp = self.vp.do.zp #save z -position self.do.SetDataStack(self.image.dataSource) #self.vp.do.zp = zp #restore z position self.elv.SetEventSource(self.image.dataSource.getEvents()) self.elv.SetRange([0, self.image.dataSource.getNumSlices()]) if 'ProtocolFocus' in self.elv.evKeyNames: self.zm = piecewiseMapping.GeneratePMFromEventList(self.elv.eventSource, self.mdh.getEntry('Camera.CycleTime'), self.mdh.getEntry('StartTime'), self.mdh.getEntry('Protocol.PiezoStartPos')) self.elv.SetCharts([('Focus [um]', self.zm, 'ProtocolFocus'),]) self.update()