def OnInit(self): import wx,sys #from wx.py import shell from Priithon import shell introText=' !!! Welcome to Priithon !!! \n' self.frame = shell.PriShellFrame(introText=introText,#ShellFrame( title="priithon on %s" % wx.GetHostName())#, 20141127 intro = 'Priithon: %s' % sys.argv self.frame.SetStatusText(intro.replace('\n', ', ')) from Priithon import fileDropPopup self.frame.shell.SetDropTarget( fileDropPopup.FileDropTarget(self.frame, self.frame.shell) ) self.frame.SetSize((750, 525)) self.frame.Show() self.SetTopWindow(self.frame) self.frame.shell.SetFocus() return True
def __init__(self, data, colorAxis=-3, title='', size=None, originLeftBottom=None, parent=None): """ splitter window for multi-color viewerer combines a "topBox" - zslider, OnMouse info, a viewer window and a set histogram windows (one for each color) if parent is None: makes a new frame with "smart" title and given size """ spvCommon.__init__(self) if not isinstance(data, F.mockNDarray): data = N.asanyarray( data) # 20060720 - numpy arrays don't have ndim attribute if min(data.shape) < 1: raise ValueError, "data shape contains zeros (%s)" % (data.shape, ) while data.ndim < 3: data.shape = (1, ) + data.shape #raise "multi-color viewer needs 3+D data" try: _1checkIt = repr( data ) # protect against crash from ""error: copy2bytes: access beyond buffer"" del _1checkIt except: raise self.dataOrig = data if colorAxis == 'smart': nonXYshape = list(data.shape[:-2]) # use shortest "z-dimension" as color - use smaller axisIndex if two are of same length notShort = 1 + max( nonXYshape) # use this to have axes of length 1 ignored nonXYshape = map(lambda x: x > 1 and x or notShort, nonXYshape) # ignore axes of length 1 colorAxis = nonXYshape.index(min(nonXYshape)) if colorAxis < 0: colorAxis += data.ndim if colorAxis < data.ndim - 3: self.data=data.transpose(*tuple(range(colorAxis) + \ range(colorAxis+1,data.ndim-2)+\ [colorAxis,data.ndim-2,data.ndim-1] )) elif colorAxis == data.ndim - 2: self.data = data.transpose(*tuple( range(data.ndim - 3) + [colorAxis, data.ndim - 3, data.ndim - 1])) elif colorAxis == data.ndim - 1: self.data = data.transpose(*tuple( range(data.ndim - 3) + [colorAxis, data.ndim - 3, data.ndim - 2])) else: self.data = data # now data[...,colorAxis,yAxis,xAxis] #self.nColors= self.data.shape[colorAxis] self.ColorAxisOrig = colorAxis self.nColors = self.data.shape[-3] if self.nColors > PriConfig.viewer2maxNumColors: raise ValueError, "You should not use more than %d colors (%s)" % ( PriConfig.viewer2maxNumColors, self.nColors) self.zshape = self.data.shape[:-3] self.zndim = self.data.ndim - 3 self.zsec = [0] * self.zndim self.zlast = [ 0 ] * self.zndim # remember - for checking if update needed self.recalcHist_todo_Set = set() from usefulX import viewers n = len(viewers) viewers.append(self) self.id = n if parent is None: parent = self.makeFrame(size, title) needShow = True else: needShow = False self.splitter = wx.SplitterWindow(parent, -1, style=wx.SP_LIVE_UPDATE | wx.SP_3DSASH) sizer = wx.BoxSizer(wx.VERTICAL) self.upperPanel = wx.Panel(self.splitter, -1) self.upperPanel.SetSizer(sizer) self.upperPanel.SetAutoLayout(True) self.boxAtTop = wx.BoxSizer(wx.HORIZONTAL) self.putZSlidersIntoTopBox( self.upperPanel, self.boxAtTop) #20070621 skipAxes = [colorAxis]) sizer.AddSizer(self.boxAtTop, 0, wx.GROW | wx.ALL, 2) import viewer2 v = viewer2.GLViewer(self.upperPanel, originLeftBottom=originLeftBottom) self.viewer = v self.viewer.my_spv = weakref.proxy(self) # CHECK 20070823 v.m_menu.Append(Menu_autoFit_all, "auto zoom + scale all") wx.EVT_MENU(wx.GetTopLevelParent(parent), Menu_autoFit_all, self.OnAutoFitAll) if self.zndim > 0: self.addZsubMenu() self.fixupViewer() #20080818 self.addHistPanel(self.splitter) self.histsPanel = wx.Panel(self.splitter, -1) self.initHists() self.viewer.Bind(wx.EVT_IDLE, self.OnIdle) #self.hist_min, self.hist_min, self.hist_avg, self.hist_dev sizer.Add(v, 1, wx.GROW | wx.ALL, 2) #CHECK - this might conflict with other onClose handlers of parent !! wx.EVT_CLOSE(wx.GetTopLevelParent(parent), self.onClose) if needShow: parent.Show() self.installKeyCommands(parent) self.keyShortcutTable[wx.MOD_CMD, ord('W')] = parent.Close self.setDefaultKeyShortcuts() self.autoHistEachSect = 0 self.scrollIncr = 1 self.noHistUpdate = 0 # used for debugging speed issues self.splitter.SetMinimumPaneSize(5) self.splitter.SetSashGravity(1.0) self.splitter.SplitHorizontally(self.upperPanel, self.histsPanel, -40 * self.nColors) self.imgL = self.data[tuple(self.zsec)] v.addImgL(self.imgL) #, smin=0, smax=0, alpha=1., interp=0) for i in range(self.nColors): rgb = _rgbDefaultColor(i) self.setColor(i, rgb, RefreshNow=(i == self.nColors - 1)) self.setupHistArrL() self.recalcHistL(postponeToIdle=False) self.autoFitHistL() from Priithon import fileDropPopup self.viewer.SetDropTarget(fileDropPopup.FileDropTarget(self.viewer))
def __init__(self, data, title='', size=None, originLeftBottom=None, parent=None, frameParent=None): """ splitter window for single-color viewerer combines a "topBox" - zslider, OnMouse info, a viewer window and a set histogram windows (one for each color) if parent is None: makes a new frame with "smart" title and given size """ spvCommon.__init__(self) # 20070715: what can we do with zeros in zshape - skip slider ?! if not isinstance(data, F.mockNDarray): data = N.asanyarray( data) # 20060720 - numpy arrays don't have ndim attribute if min(data.shape) < 1: raise ValueError, "data shape contains zeros (%s)" % (data.shape, ) if not 1 < data.ndim: raise ValueError("cannot display %dD data" % data.ndim) try: _1checkIt = repr( data ) # protect against crash from ""error: copy2bytes: access beyond buffer"" del _1checkIt except: raise ####self.copyDataIfUnsupportedType(data) self.data = data self.zshape = self.data.shape[:-2] self.zndim = len(self.zshape) self.zsec = [0] * self.zndim self.zlast = [ 0 ] * self.zndim # remember - for checking if update needed #FIMXE: next line should be done by calling helpNewData() instead - see below self.img = self.data[tuple(self.zsec)] if self.img.dtype.type in (N.complex64, N.complex128): if True: #self.m_viewComplexAsAbsNotPhase: (memo20051128-> viewComplexAsAbsNotPhase in viewer-class self.img = N.asarray(abs(self.img), N.float32) # check if this does temp copy else: #from Priithon.all import U #data = U.phase(self.m_imgArr.astype(na.float32) #not temp copy for type conversion: self.img = N.arctan2(N.asarray(self.img.imag, N.float32), N.asarray(self.img.real, N.float32)) self.recalcHist_todo_Set = set() from usefulX import viewers n = len(viewers) #self.__class__.viewers[ title ] = self viewers.append(self) self.id = n if parent is None: parent = self.makeFrame(size, title, frameParent) needShow = True else: self.downSizeToFitWindow = False needShow = False splitter = wx.SplitterWindow(parent, -1, style=wx.SP_LIVE_UPDATE | wx.SP_3DSASH) sizer = wx.BoxSizer(wx.VERTICAL) self.upperPanel = wx.Panel(splitter, -1) self.upperPanel.SetSizer(sizer) self.upperPanel.SetAutoLayout(True) self.boxAtTop = wx.BoxSizer(wx.HORIZONTAL) self.putZSlidersIntoTopBox(self.upperPanel, self.boxAtTop) sizer.AddSizer(self.boxAtTop, 0, wx.GROW | wx.ALL, 2) import viewer v = viewer.GLViewer(self.upperPanel, self.img, originLeftBottom=originLeftBottom) self.viewer = v self.viewer.Bind(wx.EVT_IDLE, self.OnIdle) if self.zndim > 0: v.m_menu.AppendSeparator() v.m_menu.AppendRadioItem(Menu_AutoHistSec0, "autoHist off") v.m_menu.AppendRadioItem(Menu_AutoHistSec1, "autoHist viewer") v.m_menu.AppendRadioItem(Menu_AutoHistSec2, "autoHist viewer+histAutoZoom") wx.EVT_MENU(parent, Menu_AutoHistSec0, self.OnMenuAutoHistSec) wx.EVT_MENU(parent, Menu_AutoHistSec1, self.OnMenuAutoHistSec) wx.EVT_MENU(parent, Menu_AutoHistSec2, self.OnMenuAutoHistSec) v.m_menu.AppendSeparator() self.vOnWheel_zoom = self.viewer.OnWheel menuSub0 = wx.Menu() menuSub0.Append(Menu_WheelWhatMenu + 1 + self.zndim, "zoom") for i in range(self.zndim): menuSub0.Append(Menu_WheelWhatMenu + 1 + i, "scroll axis %d" % i) v.m_menu.AppendMenu(Menu_WheelWhatMenu, "mouse wheel does", menuSub0) for i in range(self.zndim + 1): wx.EVT_MENU(parent, Menu_WheelWhatMenu + 1 + i, self.OnWheelWhat) menuSub1 = wx.Menu() for i in range(len(scrollIncrL)): menuSub1.Append(Menu_ScrollIncrementMenu + 1 + i, "%3s" % scrollIncrL[i]) v.m_menu.AppendMenu(Menu_ScrollIncrementMenu, "scroll increment", menuSub1) for i in range(len(scrollIncrL)): wx.EVT_MENU(parent, Menu_ScrollIncrementMenu + 1 + i, self.OnScrollIncr) menuSub2 = wx.Menu() from Priithon.all import Y self.plot_avgBandSize = 1 self.plot_s = '-+' def OnChProWi(ev): i = wx.GetNumberFromUser( "each line profile gets averaged over a band of given width", 'width:', "profile averaging width:", self.plot_avgBandSize, 1, 1000) self.plot_avgBandSize = i #Y.vLeftClickNone(self.id) # fixme: would be nice if #done!? Y._plotprofile_avgSize = self.plot_avgBandSize def OnSelectSubRegion(ev): Y.vLeftViewSubRegion(self.id) left_list = [ ('horizontal profile', lambda ev: Y.vLeftClickHorizProfile( self.id, self.plot_avgBandSize, self.plot_s)), ('vertical profile', lambda ev: Y.vLeftClickVertProfile( self.id, self.plot_avgBandSize, self.plot_s)), ('any-line-profile', lambda ev: Y.vLeftClickLineProfile( self.id, abscissa='line', s=self.plot_s)), ('any-line-profile over x', lambda ev: Y.vLeftClickLineProfile( self.id, abscissa='x', s=self.plot_s)), ('any-line-profile over y', lambda ev: Y.vLeftClickLineProfile( self.id, abscissa='y', s=self.plot_s)), ('Z-profile', lambda ev: Y.vLeftClickZProfile( self.id, self.plot_avgBandSize, self.plot_s)), ('line measure', lambda ev: Y.vLeftClickLineMeasure(self.id)), ('triangle measure', lambda ev: Y.vLeftClickTriangleMeasure(self.id)), ('mark-cross', lambda ev: Y.vLeftClickMarks(self.id, callFn=None)), ('<nothing>', lambda ev: Y.vLeftClickNone(self.id)), ('<clear graphics>', lambda ev: Y.vClearGraphics(self.id)), ('<change profile "width"', lambda ev: OnChProWi(ev)), ('select-view xy-sub-region', lambda ev: OnSelectSubRegion(ev)), ] for i in range(len(left_list)): itemId = Menu_LeftClickMenu + 1 + i menuSub2.Append(itemId, "%s" % left_list[i][0]) wx.EVT_MENU(parent, itemId, left_list[i][1]) v.m_menu.AppendMenu(Menu_LeftClickMenu, "on left click ...", menuSub2) v.m_menu_save.Append(Menu_SaveND, "save nd data stack") v.m_menu_save.Append(Menu_AssignND, "assign nd data stack to var name") wx.EVT_MENU(parent, Menu_SaveND, self.OnMenuSaveND) wx.EVT_MENU(parent, Menu_AssignND, self.OnMenuAssignND) #dt = MyFileDropTarget(self) #v.SetDropTarget(dt) from Priithon import fileDropPopup v.SetDropTarget(fileDropPopup.FileDropTarget(v)) def splitND_onMouse(x, y, ev): #20080707 ,xyEffVal): yy, xx = int(round(y)), int( round(x) ) # NEW 20080701: in new coord system, integer pixel coord go through the center of pixel try: pic_ny, pic_nx = self.img.shape except AttributeError: return # can happend when window just got closed (windows) if (0 <= yy < pic_ny and 0 <= xx < pic_nx): xyEffVal = self.img[yy, xx] #20080707 if N.issubdtype( self.data.dtype, N.integer): #(N.uint8, N.int16, N.uint16, N.int32): vs = "%6d" % (xyEffVal, ) elif self.data.dtype == bool: vs = "%4d" % (xyEffVal, ) else: if N.abs(xyEffVal) > .02: vs = "%7.2f" % (xyEffVal, ) else: vs = "%7.2e" % (xyEffVal, ) else: vs = "---" #self.label.SetLabel("xy: %3d %3d val: %7.2f"%(x,y, xyEffVal))#self.img[y,x])) if v.m_scale > 1 and self.showFloatCoordsWhenZoomingIn: self.label.SetLabel("%.1fx yx: %5.1f %5.1f val: %s" % (v.m_scale, y, x, vs)) elif v.m_scale != 1: self.label.SetLabel("%.1fx yx: %3d %3d val: %s" % (v.m_scale, yy, xx, vs)) else: self.label.SetLabel("yx: %3d %3d val: %s" % (yy, xx, vs)) v.doOnMouse.append(splitND_onMouse) import histogram h = histogram.HistogramCanvas(splitter, size=(400, 110)) self.hist = h #20070525-black_on_black h.SetCursor(wx.CROSS_CURSOR) import weakref # 20060823 # 20060823 v.hist4colmap = weakref.proxy( h ) # HACK # see viewer.py::updateHistColMap v.my_hist = weakref.proxy(h) # CHECK 20060823 h.my_viewer = weakref.proxy(v) # CHECK 20060823 v.my_spv = weakref.proxy(self) # CHECK 20070823 h.my_spv = weakref.proxy(self) # CHECK 20070823 def splitND_onBrace(s, gamma=None): l, r = s.leftBrace, s.rightBrace try: if gamma is not None: v.cmgray(gamma) v.changeHistogramScaling(l, r) except: pass h.doOnBrace.append(splitND_onBrace) #20080707 del splitND_onBrace def splitND_onMouseHist(xEff, ev): #20080707 , bin): l, r = h.leftBrace, h.rightBrace if self.data.dtype.type in (N.uint8, N.int16, N.uint16, N.int32): self.label.SetLabel("I: %6.0f l/r: %6.0f %6.0f" % (xEff, l, r)) else: self.label.SetLabel("I: %7.2g l/r: %7.2g %7.2g" % (xEff, l, r)) h.doOnMouse.append(splitND_onMouseHist) #20080707del splitND_onMouseHist #from Priithon import seb as S def splitND_onReload(event=None): self.helpNewData() v.OnReload = splitND_onReload wx.EVT_MENU(v, viewer.Menu_Reload, splitND_onReload) self.OnReload = splitND_onReload del splitND_onReload #self.hist_min, self.hist_min, self.hist_avg, self.hist_dev sizer.Add(v, 1, wx.GROW | wx.ALL, 2) if self.downSizeToFitWindow: fac = 1. / 1.189207115002721 # >>> 2 ** (1./4) #v.m_scale *= .05 # fac s = max(self.img.shape) while v.m_scale * s > 600: v.m_scale *= fac #20070809 wx.Yield() if needShow: parent.Show() self.installKeyCommands(parent) # ACCEL_CMD:"Cmd" is a pseudo key which is the same as Control for PC and Unix platforms but the special "Apple" (a.k.a as "Command") key on Macs. self.keyShortcutTable[wx.MOD_CMD, ord('W')] = parent.Close self.autoHistEachSect = 0 self.scrollIncr = 1 self.noHistUpdate = 0 # used for debugging speed issues #20040317 splitter.SetMinimumPaneSize(20) splitter.SetMinimumPaneSize(5) splitter.SetSashGravity(1.0) splitter.SplitHorizontally(self.upperPanel, h, -50) #77 splitter.SplitHorizontally(v, h, -50) #import pdb #pdb.set_trace() self.setupHistArr() self.recalcHist(triggeredFromIdle=True) #print "debug:", self.mmms self.hist.autoFit(amin=self.mmms[0], amax=self.mmms[1]) #20051128 wx.Yield() #v.changeHistogramScaling(self.mmms[0],self.mmms[1]) wx.Yield() v.center() wx.EVT_CLOSE(wx.GetTopLevelParent(parent), self.onClose) self.setDefaultKeyShortcuts()