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 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 Plug(dsviewer): dsviewer.blobFinder = blobFinder(dsviewer) if not 'overlaypanel' in dir(dsviewer): dsviewer.overlaypanel = OverlayPanel(dsviewer, dsviewer.view, dsviewer.image.mdh) dsviewer.overlaypanel.SetSize(dsviewer.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) dsviewer._mgr.AddPane(dsviewer.overlaypanel, pinfo2) dsviewer.panesToMinimise.append(pinfo2)
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()