Example #1
0
    def onEditor(self, ev, checkPyFile=True):
        import sys,os, __main__
        try:
            #mod = os.path.basename( filenames )
            mod = self.fn_or_fns
            if checkPyFile:
                mod = os.path.splitext( mod )[0]
                mod += '.py'
                if not os.path.isfile(mod):
                    r= wx.MessageBox("do you want to start editing a new .py-file ?", 
                                     "py file not found !", 
                                     style=wx.CENTER|wx.YES_NO|wx.CANCEL|wx.ICON_EXCLAMATION)
                    if r != wx.YES:
                        return

            from Priithon.all import Y
            Y.editor(mod)
            self.pyshell.addHistory("Y.editor( %s )"%mod)
        except:
            if NO_SPECIAL_GUI_EXCEPT:
                raise
            import sys
            e = sys.exc_info()
            wx.MessageBox("Error on starting Y.editor: %s - %s" %\
                              (str(e[0]), str(e[1]) ),
                          "Error  !?",
                          style=wx.ICON_ERROR)
Example #2
0
 def onAppSysPath(self, ev):
     import sys
     from Priithon.all import Y
     sys.path.append( self.fn_or_fns )
     s = "sys.path.append(r\"%s\")"% (self.fn_or_fns,)
     Y.shellMessage("###  %s\n"% s)
     self.pyshell.addHistory(s)
Example #3
0
 def onImportAs(self, ev):
     v = wx.GetTextFromUser("import module as :", 'new mod name')
     if not v:
         return
     import sys,os, __main__
     p   = os.path.dirname( self.fn_or_fns )
     sys.path.insert(0, p)
     try:
         try:
             mod = os.path.basename( self.fn_or_fns )
             mod = os.path.splitext( mod )[0]
             s = 'import %s as %s' % (mod, v)
             exec((s), __main__.__dict__)
             self.pyshell.addHistory(s)
         except:
             if NO_SPECIAL_GUI_EXCEPT:
                 raise
             import sys
             e = sys.exc_info()
             wx.MessageBox("Error on 'import %s as %s': %s - %s" %\
                           (mod, v, str(e[0]), str(e[1]) ),
                           "Bad Varname  !?",
                           style=wx.ICON_ERROR)
         else:
             from Priithon.all import Y
             Y.shellMessage("### import %s as %s\n"% (mod,v))
     finally:
         if wx.MessageBox("leave '%s' in front of sys.path ?" % (p,), 
                          "Python import search path:", style=wx.YES_NO) != wx.YES:
             #20090319 del sys.path[0]
             sys.path.remove(p)
Example #4
0
 def onImportAs(self, ev):
     v = wx.GetTextFromUser("import module as :", 'new mod name')
     if not v:
         return
     import sys,os, __main__
     p   = os.path.dirname( self.fn_or_fns )
     sys.path.insert(0, p)
     try:
         try:
             mod = os.path.basename( self.fn_or_fns )
             mod = os.path.splitext( mod )[0]
             s = 'import %s as %s' % (mod, v)
             exec (s) in __main__.__dict__
             self.pyshell.addHistory(s)
         except:
             if NO_SPECIAL_GUI_EXCEPT:
                 raise
             import sys
             e = sys.exc_info()
             wx.MessageBox("Error on 'import %s as %s': %s - %s" %\
                           (mod, v, str(e[0]), str(e[1]) ),
                           "Bad Varname  !?",
                           style=wx.ICON_ERROR)
         else:
             from Priithon.all import Y
             Y.shellMessage("### import %s as %s\n"% (mod,v))
     finally:
         if wx.MessageBox("leave '%s' in front of sys.path ?" % (p,), 
                          "Python import search path:", style=wx.YES_NO) != wx.YES:
             #20090319 del sys.path[0]
             sys.path.remove(p)
    def onLeft2(self, xEff, yEff, ev):
        from Priithon.all import Y
        #self.yx1 = (yEff, xEff)
        def ppp(*args):
            pass
        self.viewer.doLDown = ppp

        if   self.gfxWhenDone == 'remove':
            self.gfxRemove()
        elif   self.gfxWhenDone == 'hide':
            self.gfxHide()


        #20070721 self.viewer.doOnMouse = self.oldOnMouse
        Y._registerEventHandler(self.viewer.doOnLDown, oldFcnName='vLeftClickDoes')
        Y._registerEventHandler(self.viewer.doOnMouse, oldFcnName='vLeftClickDoes')

        #sort indices
        y0,x0 = self.yx0
        y1,x1 = self.yx1
        if y1< y0:
            y0,y1 = y1,y0
        if x1< x0:
            x0,x1 = x1,x0
        self.yx0 = y0,x0 
        self.yx1 = y1,x1
        
        self.doThisAlsoOnDone()
Example #6
0
    def onLeft2(self, xEff, yEff, ev):
        from Priithon.all import Y

        #self.yx1 = (yEff, xEff)
        def ppp(*args):
            pass

        self.viewer.doLDown = ppp

        if self.gfxWhenDone == 'remove':
            self.gfxRemove()
        elif self.gfxWhenDone == 'hide':
            self.gfxHide()

        #20070721 self.viewer.doOnMouse = self.oldOnMouse
        Y._registerEventHandler(self.viewer.doOnLDown,
                                oldFcnName='vLeftClickDoes')
        Y._registerEventHandler(self.viewer.doOnMouse,
                                oldFcnName='vLeftClickDoes')

        #sort indices
        y0, x0 = self.yx0
        y1, x1 = self.yx1
        if y1 < y0:
            y0, y1 = y1, y0
        if x1 < x0:
            x0, x1 = x1, x0
        self.yx0 = y0, x0
        self.yx1 = y1, x1

        self.doThisAlsoOnDone()
Example #7
0
    def onEditor(self, ev, checkPyFile=True):
        import sys,os, __main__
        try:
            #mod = os.path.basename( filenames )
            mod = self.fn_or_fns
            if checkPyFile:
                mod = os.path.splitext( mod )[0]
                mod += '.py'
                if not os.path.isfile(mod):
                    r= wx.MessageBox("do you want to start editing a new .py-file ?", 
                                     "py file not found !", 
                                     style=wx.CENTER|wx.YES_NO|wx.CANCEL|wx.ICON_EXCLAMATION)
                    if r != wx.YES:
                        return

            from Priithon.all import Y
            Y.editor(mod)
            self.pyshell.addHistory("Y.editor( %s )"%mod)
        except:
            if NO_SPECIAL_GUI_EXCEPT:
                raise
            import sys
            e = sys.exc_info()
            wx.MessageBox("Error on starting Y.editor: %s - %s" %\
                              (str(e[0]), str(e[1]) ),
                          "Error  !?",
                          style=wx.ICON_ERROR)
Example #8
0
 def onAppSysPath(self, ev):
     import sys
     from Priithon.all import Y
     sys.path.append( self.fn_or_fns )
     s = "sys.path.append(r\"%s\")"% (self.fn_or_fns,)
     Y.shellMessage("###  %s\n"% s)
     self.pyshell.addHistory(s)
Example #9
0
    def gfxUpdate(self):
        from Priithon.all import Y
        if self.rubberWhat == 'box':
            self.gfxIdx = \
                Y.vgAddRect(self.id, [self.yx0 ,self.yx1], enclose=True, color=self.color,
                            width=1, name="ROI-%s"%(self.roiName,), idx=self.gfxIdx,
                            enable=True, refreshNow=True)
        elif self.rubberWhat == 'line':
            self.gfxIdx = \
                Y.vgAddLines(self.id, [self.yx0 ,self.yx1], color=self.color,
                            width=1, name="ROI-%s"%(self.roiName,), idx=self.gfxIdx,
                            enable=True, refreshNow=True)

        elif self.rubberWhat == 'circle':
            y0, x0 = self.yx0
            y1, x1 = self.yx1
            dx = x1 - x0
            dy = y1 - y0
            x = x0 + .5 * dx
            y = y0 + .5 * dy
            rx = abs(x1 - x)
            ry = abs(y1 - y)
            self.gfxIdx = \
                Y.vgAddEllipses(self.id, [(y,x,ry,rx)], color=self.color,
                            width=1, name="ROI-%s"%(self.roiName,), idx=self.gfxIdx,
                            enable=True, refreshNow=True)
    def __init__(self, id=-1, rubberWhat='box', color=(0,1,0), 
                 gfxWhenDone='hide', roiName='1'):
        """
        id can be a viewerID
               or a viewer.GLViewer object
        rubberWhat should be one of:
             'box'
             'line'
             'circle'
             'ellipse'

        gfxWhenDone should be one of: 'hide', 'remove', None
        """
        from Priithon.all import Y
        if type(id) is int:
            self.splitND = Y.viewers[id]
            self.viewer = Y.viewers[id].viewer
        else:
            self.splitND = None # CHECK Y.viewers[id]
            self.viewer = id

        self.id = id
        self.rubberWhat = rubberWhat
        self.color = color
        self.gfxWhenDone = gfxWhenDone
        self.roiName = roiName
        self.gfxIdx = None

        #20070721 self.oldOnMouse= self.viewer.doOnMouse
        #20070721 self.viewer.doLDown =self.onLeft1
        Y._registerEventHandler(self.viewer.doOnLDown, newFcn=self.onLeft1, newFcnName='vLeftClickDoes', oldFcnName=None)
    def gfxUpdate(self):
        from Priithon.all import Y
        if self.rubberWhat == 'box':
            self.gfxIdx = \
                Y.vgAddRect(self.id, [self.yx0 ,self.yx1], enclose=True, color=self.color, 
                            width=1, name="ROI-%s"%(self.roiName,), idx=self.gfxIdx, 
                            enable=True, refreshNow=True)
        elif self.rubberWhat == 'line':
            self.gfxIdx = \
                Y.vgAddLines(self.id, [self.yx0 ,self.yx1], color=self.color, 
                            width=1, name="ROI-%s"%(self.roiName,), idx=self.gfxIdx, 
                            enable=True, refreshNow=True)

        elif self.rubberWhat == 'circle':
            y0,x0 = self.yx0
            y1,x1 = self.yx1
            dx = x1-x0
            dy = y1-y0
            x = x0 + .5*dx
            y = y0 + .5*dy
            rx = abs(x1-x)
            ry = abs(y1-y)
            self.gfxIdx = \
                Y.vgAddEllipses(self.id, [(y,x,ry,rx)], color=self.color, 
                            width=1, name="ROI-%s"%(self.roiName,), idx=self.gfxIdx, 
                            enable=True, refreshNow=True)
Example #12
0
 def onExe(self, ev):
     import sys, os, __main__
     p = os.path.dirname(self.fn_or_fns)
     sys.path.insert(0, p)
     try:
         try:
             self.pyshell.addHistory("execfile(r\"%s\")" %
                                     (self.fn_or_fns, ))
             exec(
                 compile(
                     open(self.fn_or_fns).read(), self.fn_or_fns, 'exec'),
                 __main__.__dict__)
         except:
             if NO_SPECIAL_GUI_EXCEPT:
                 raise
             e = sys.exc_info()
             wx.MessageBox("Error on execfile: %s - %s" %\
                           (str(e[0]), str(e[1]) ),
                           "Bad Varname  !?",
                           style=wx.ICON_ERROR)
         else:
             from Priithon.all import Y
             Y.shellMessage("### execfile('%s')\n" % (self.fn_or_fns, ))
             self.pyshell.addHistory("execfile('%s')\n" %
                                     (self.fn_or_fns, ))
     finally:
         #20090319 del sys.path[0]
         sys.path.remove(p)
Example #13
0
 def onImport(self, ev):
     import sys, os, __main__
     p = os.path.dirname(self.fn_or_fns)
     sys.path.insert(0, p)
     try:
         try:
             mod = os.path.basename(self.fn_or_fns)
             mod = os.path.splitext(mod)[0]
             exec(('import %s' % mod), __main__.__dict__)
             self.pyshell.addHistory("import %s" % mod)
         except:
             if NO_SPECIAL_GUI_EXCEPT:
                 raise
             import sys
             e = sys.exc_info()
             wx.MessageBox("Error on import: %s - %s" %\
                           (str(e[0]), str(e[1]) ),
                           "Bad Varname  !?",
                           style=wx.ICON_ERROR)
         else:
             from Priithon.all import Y
             Y.shellMessage("### import %s\n" % (mod, ))
     finally:
         if wx.MessageBox("leave '%s' in front of sys.path ?" % (p, ),
                          "Python import search path:",
                          style=wx.YES_NO) != wx.YES:
             #20090319 del sys.path[0]
             sys.path.remove(p)
Example #14
0
 def onAssign(self, ev):
     fn = self.fn_or_fns
     from Priithon.all import Y
     a = Y.load(fn)
     if a is not None:
         v = Y.assignNdArrToVarname(a, "Y.load( r'%s' )"%fn)
         if v is not None:
             self.pyshell.addHistory("%s = Y.load( r'%s' )"%(v,fn))
 def onLeft1(self, xEff, yEff, ev):
     self.yx0 = (int(yEff), int(xEff))
     #20070721 self.viewer.doLDown =self.onLeft2
     #20070721 self.viewer.doOnMouse = self.onMove
     from Priithon.all import Y
     Y._registerEventHandler(self.viewer.doOnLDown, newFcn=self.onLeft2, newFcnName='vLeftClickDoes')
     Y._registerEventHandler(self.viewer.doOnMouse, newFcn=self.onMove, newFcnName='vLeftClickDoes', oldFcnName=None)
     self.doThisAlsoOnStart()
Example #16
0
 def onAssign(self, ev):
     fn = self.fn_or_fns
     from Priithon.all import Y
     a = Y.load(fn)
     if a is not None:
         v = Y.assignNdArrToVarname(a, "Y.load( r'%s' )"%fn)
         if v is not None:
             self.pyshell.addHistory("%s = Y.load( r'%s' )"%(v,fn))
Example #17
0
def _setSlider(v, handle, z, zaxis=0):  #copied from viewerCommon
    '''
    overloaded used for viewer for MrcHandler
    zaxis is a dummy argument, axis is always zero
    '''
    if zaxis == 0:
        arr = handle[z]
        v.viewer.my_spv.data[:] = arr[:]
        Y.vReload(v.id)
    else:
        pass
Example #18
0
 def onView2(self, ev):
     from Priithon.all import Y
     if isinstance(self.fn_or_fns, (list, tuple)) and len(self.fn_or_fns) > 1:
         f = tuple( self.fn_or_fns )  # 'tuple' for "view as mock-adarray"
         self.txt = '( '
         for fff in self.fn_or_fns:
             self.txt += 'r\"%s\" , ' % fff
         self.txt += ')'
     else:
         f = self.fn_or_fns
     Y.view2(f, colorAxis='smart')
     self.pyshell.addHistory("Y.view2( %s, colorAxis='smart')"%(self.txt,))
Example #19
0
 def onView2(self, ev):
     from Priithon.all import Y
     if isinstance(self.fn_or_fns, (list, tuple)) and len(self.fn_or_fns) > 1:
         f = tuple( self.fn_or_fns )  # 'tuple' for "view as mock-adarray"
         self.txt = '( '
         for fff in self.fn_or_fns:
             self.txt += 'r\"%s\" , ' % fff
         self.txt += ')'
     else:
         f = self.fn_or_fns
     Y.view2(f, colorAxis='smart')
     self.pyshell.addHistory("Y.view2( %s, colorAxis='smart')"%(self.txt,))
Example #20
0
    def OnSave(self, event=None):
        from Priithon.all import Mrc, U, Y
        fn = Y.FN(1)  #, verbose=0)
        if not fn:
            return
        if fn[-4:] in [".mrc", ".dat"]:
            Mrc.save(self.m_imgArr, fn)
        elif fn[-5:] in [".fits"]:
            U.saveFits(self.m_imgArr, fn)
        else:
            U.saveImg8(self.m_imgArr, fn)

        Y.shellMessage("### section saved to '%s'\n" % fn)
Example #21
0
    def OnSave(self, event=None):
        from Priithon.all import Mrc, U, Y
        fn = Y.FN(1)#, verbose=0)
        if not fn:
            return
        if fn[-4:] in [ ".mrc",  ".dat" ]:
            Mrc.save(self.m_imgArr, fn)
        elif fn[-5:] in [ ".fits" ]:
            U.saveFits(self.m_imgArr, fn)
        else:
            U.saveImg8(self.m_imgArr, fn)

        Y.shellMessage("### section saved to '%s'\n"%fn)
Example #22
0
 def onLeft1(self, xEff, yEff, ev):
     self.yx0 = (int(yEff), int(xEff))
     #20070721 self.viewer.doLDown =self.onLeft2
     #20070721 self.viewer.doOnMouse = self.onMove
     from Priithon.all import Y
     Y._registerEventHandler(self.viewer.doOnLDown,
                             newFcn=self.onLeft2,
                             newFcnName='vLeftClickDoes')
     Y._registerEventHandler(self.viewer.doOnMouse,
                             newFcn=self.onMove,
                             newFcnName='vLeftClickDoes',
                             oldFcnName=None)
     self.doThisAlsoOnStart()
Example #23
0
    def OnSaveScreenShort(self, event=None):
        """always flipY"""
        from Priithon.all import U, FN, Y
        fn = FN(1)  #, verbose=0)
        if not fn:
            return

        flipY = 1
        if flipY:
            U.saveImg(self.readGLviewport(copy=1)[:, ::-1], fn)
        else:
            U.saveImg(self.readGLviewport(copy=1), fn)

        Y.shellMessage("### screenshot saved to '%s'\n" % fn)
Example #24
0
    def OnAssign(self, event=None):
        from . import usefulX as Y
        ss = "<2d section shown>"

        for i in range(len(Y.viewers)):
            try:
                v = Y.viewers[i]
                if v.viewer is self:
                    ss = "Y.vd(%d)[%s]" % (i, ','.join(map(str, v.zsec)))
                    break
            except:
                pass

        Y.assignNdArrToVarname(self.m_imgArr, ss)
Example #25
0
    def OnSaveScreenShort(self, event=None):
        """always flipY"""
        from Priithon.all import U, FN, Y
        fn = FN(1)#, verbose=0)
        if not fn:
            return

        flipY=1
        if flipY:
            U.saveImg(self.readGLviewport(copy=1)[:, ::-1], fn)
        else:
            U.saveImg(self.readGLviewport(copy=1), fn)
        
        Y.shellMessage("### screenshot saved to '%s'\n"%fn)
Example #26
0
    def OnAssign(self, event=None):
        from . import usefulX as Y
        ss = "<2d section shown>"

        for i in range(len(Y.viewers)):
            try:
                v = Y.viewers[i]
                if v.viewer is self:
                    ss = "Y.vd(%d)[%s]"%(i, ','.join(map(str,v.zsec)))
                    break
            except:
                pass

        Y.assignNdArrToVarname(self.m_imgArr, ss)
Example #27
0
def debug(log, msg, level=logging.DEBUG):
    """
    do logging
    """
    levelName = _getLevelName(level)
    exec('log.%s(msg)' % levelName)
    level = _getLevel(level)
    if log.getEffectiveLevel() <= level:
        try:
            Y.refresh()
        except:
            pass
    else:
        pass
Example #28
0
def debug(log, msg, level=logging.DEBUG):
    """
    do logging
    """
    levelName = _getLevelName(level)
    exec('log.%s(msg)' % levelName)
    level = _getLevel(level)
    if log.getEffectiveLevel() <= level:
        try:
            Y.refresh()
        except:
            pass
    else:
        pass
Example #29
0
 def onViewSeq(self, ev):
     from Priithon.all import Y,U
     try:
         Y.view( U.loadImg_seq( self.fn_or_fns ) )
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when loading image sequence: %s - %s" %\
                       (str(e[0]), str(e[1]) ),
                       "Non consistent image shapes  !?",
                       style=wx.ICON_ERROR)
     else:
         s = "Y.view( U.loadImg_seq(<fileslist>) )"
         Y.shellMessage("###  %s\n"% s)
Example #30
0
 def onSaveScr(self, evt=None):
     from Priithon.all import Y
     fn = Y.FN(save=1)  #, verbose=0)
     if not fn:
         return
     # choose viewers
     if self.orthogonal_toggle.GetValue():
         vstr = self.viewerch.GetStringSelection()
         vid = self.choice_viewers.index(vstr)
     else:
         vid = 0
     v = self.viewers[vid]
     #refresh
     self.hist[0].setBraces(self.hist[0].leftBrace, self.hist[0].rightBrace)
     # save
     Y.vSaveRGBviewport(v, fn)
Example #31
0
 def onViewSeq(self, ev):
     from Priithon.all import Y,U
     try:
         Y.view( U.loadImg_seq( self.fn_or_fns ) )
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when loading image sequence: %s - %s" %\
                       (str(e[0]), str(e[1]) ),
                       "Non consistent image shapes  !?",
                       style=wx.ICON_ERROR)
     else:
         s = "Y.view( U.loadImg_seq(<fileslist>) )"
         Y.shellMessage("###  %s\n"% s)
Example #32
0
 def OnViewVTK(self, ev=77777):
     from . import usefulX as Y
     ####use tostring instead    self.m = Y.vtkMountain(self.img, "vtk of %d: %s" %  (self.id, self.title))
     #20060722 a = N.NumArray(shape=self.img.shape, type=self.img.type(), buffer=self.viewer.m_imgArrString)
     a = N.fromstring(self.viewer.m_imgArrString, self.img.dtype)
     a.shape = self.img.shape
     self.m = Y.vtkMountain(a, "vtk of %d: %s" % (self.id, self.title))
Example #33
0
 def onSaveScr(self, evt=None):
     from Priithon.all import Y
     fn = Y.FN(save=1)#, verbose=0)
     if not fn:
         return
     # choose viewers
     if self.orthogonal_toggle.GetValue():
         vstr = self.viewerch.GetStringSelection()
         vid = self.choice_viewers.index(vstr)
     else:
         vid = 0
     v = self.viewers[vid]
     #refresh
     self.hist[0].setBraces(self.hist[0].leftBrace, self.hist[0].rightBrace)
     # save
     Y.vSaveRGBviewport(v, fn)
Example #34
0
 def OnViewVTK(self, ev=77777):
     from . import usefulX as Y
     ####use tostring instead    self.m = Y.vtkMountain(self.img, "vtk of %d: %s" %  (self.id, self.title))
     #20060722 a = N.NumArray(shape=self.img.shape, type=self.img.type(), buffer=self.viewer.m_imgArrString)
     a = N.fromstring(self.viewer.m_imgArrString, self.img.dtype)
     a.shape = self.img.shape
     self.m = Y.vtkMountain(a, "vtk of %d: %s" %  (self.id, self.title))
Example #35
0
 def OnExecPy(self, evt=None):
     from Priithon.all import Y
     fn = wx.FileSelector("Select python file to execute")
     if fn == '':
         return
     import __main__
     try:
         execfile(fn, __main__.__dict__)
     except:
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error on execfile: %s - %s" %\
                       (str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         Y.shellMessage("### execfile('%s')\n"%fn)
Example #36
0
 def OnExecPy(self, evt=None):
     from Priithon.all import Y
     fn = wx.FileSelector("Select python file to execute")
     if fn == '':
         return
     import __main__
     try:
         execfile(fn, __main__.__dict__)
     except:
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error on execfile: %s - %s" %\
                       (str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         Y.shellMessage("### execfile('%s')\n" % fn)
Example #37
0
    def view(self, idx=0, color=None):
        """
        idx: if viewer if already open, simply go to this idx
        """
        global _ZSLIDER
        if self.vid is None or Y.viewers[self.vid] is None:
            if color:
                old_ignor_color_axis = self.ignor_color_axis
                self.ignor_color_axis = True  # don't know how to disable this
            arr = self[idx]

            if color and self.nw >= 2 and self.hdr.ImgSequence in [1, 2]:
                #colorAxis = mrcIO.findAxis(self.hdr, self.shape, tzw='w')
                if self.hdr.ImgSequence in (0, 2):
                    colorAxis = 0
                elif self.hdr.ImgSequence == 1:
                    colorAxis = -3
                Y.view2(arr, colorAxis, self.file, originLeftBottom=1)
            else:
                Y.view(arr, self.file, originLeftBottom=1)

            viewer = Y.viewers[-1]
            self.vid = viewer.id

            if (self.nt * self.nz) > 1 or (self.nw > 1 and not color):
                nz = self.__getattribute__('n%s' % self.sld_axs)
                self._zslider = vzslider(self,
                                         self.vid,
                                         nz=nz,
                                         title='slide: axis %s of [%i]' %
                                         (self.sld_axs, self.vid))
                viewer.setSlider2 = _setSlider

                self._zslider.zslider.SetValue(idx)
                _ZSLIDER = self._zslider
            viewer._zslider = self._zslider
        else:
            if (self.nt * self.nz) > 1:
                import wx
                try:
                    self._setSlider(idx)
                    self._zslider.zslider.SetValue(idx)
                except wx.PyDeadObjectError:
                    self.vid = None
                    self.view(idx)
Example #38
0
 def onAssignSeq(self, ev):
     from Priithon.all import Y
     v = wx.GetTextFromUser("assign image sequence to array varname:", 'new variable')
     if not v:
         return
     import __main__
     try:
         exec('%s = U.loadImg_seq(%s)' % (v,self.fn_or_fns), __main__.__dict__)
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when loading and assigning img.seq. to __main__.%s: %s - %s" %\
                       (v, str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         Y.shellMessage("### %s = U.loadImg_seq(<list of files>)\n"% (v,))
Example #39
0
 def onAssignList(self, ev):
     v = wx.GetTextFromUser("assign list to varname:", 'new variable')
     if not v:
         return
     import __main__
     try:
         exec '%s = %s' % (v, self.fn_or_fns) in __main__.__dict__
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when assigning list to __main__.%s: %s - %s" %\
                       (v, str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         from Priithon.all import Y
         Y.shellMessage("### %s = <list of files>\n"% (v,))
Example #40
0
 def onAssignSeq(self, ev):
     from Priithon.all import Y
     v = wx.GetTextFromUser("assign image sequence to array varname:", 'new variable')
     if not v:
         return
     import __main__
     try:
         exec '%s = U.loadImg_seq(%s)' % (v,self.fn_or_fns) in __main__.__dict__
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when loading and assigning img.seq. to __main__.%s: %s - %s" %\
                       (v, str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         Y.shellMessage("### %s = U.loadImg_seq(<list of files>)\n"% (v,))
Example #41
0
 def onAssignList(self, ev):
     v = wx.GetTextFromUser("assign list to varname:", 'new variable')
     if not v:
         return
     import __main__
     try:
         exec('%s = %s' % (v, self.fn_or_fns), __main__.__dict__)
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when assigning list to __main__.%s: %s - %s" %\
                       (v, str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         from Priithon.all import Y
         Y.shellMessage("### %s = <list of files>\n"% (v,))
Example #42
0
    def viewOneSec(self, t=0, z=0, w=0, dtype=None):
        i = mrcIO.sectIdx(t, self.nt, z, self.nz, w, self.nw,
                          self.hdr.ImgSequence)
        a = self.Mrc.readSec(i)
        if dtype:
            a = a.astype(dtype)

        if self.vid_single is None:
            Y.view(a, originLeftBottom=1)
            viewer = Y.viewers[-1]
            self.vid_single = viewer.id
        else:
            try:
                v = Y.viewers[self.vid_single]
                v.viewer.my_spv.data[:] = a[:]
                v.viewer.m_imgChanged = True
                v.viewer.Refresh()
            except AttributeError:
                self.vid_single = None
                self.viewOneSec(t, z, w)
Example #43
0
 def onAssignFN(self, ev):
     v = wx.GetTextFromUser("assign filename to varname:", 'new variable')
     if not v:
         return
     import __main__
     try:
         exec('%s = %s' % (v,self.txt), __main__.__dict__)
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when assigning filename to __main__.%s: %s - %s" %\
                       (v, str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         from Priithon.all import Y
         s = "%s = %s"% (v, self.txt)
         Y.shellMessage("### %s\n"% (s,))
         self.pyshell.addHistory(s)
Example #44
0
 def onAssignFN(self, ev):
     v = wx.GetTextFromUser("assign filename to varname:", 'new variable')
     if not v:
         return
     import __main__
     try:
         exec '%s = %s' % (v,self.txt) in __main__.__dict__
     except:
         if NO_SPECIAL_GUI_EXCEPT:
             raise
         import sys
         e = sys.exc_info()
         wx.MessageBox("Error when assigning filename to __main__.%s: %s - %s" %\
                       (v, str(e[0]), str(e[1]) ),
                       "Bad Varname  !?",
                       style=wx.ICON_ERROR)
     else:
         from Priithon.all import Y
         s = "%s = %s"% (v, self.txt)
         Y.shellMessage("### %s\n"% (s,))
         self.pyshell.addHistory(s)
Example #45
0
    def __init__(self,
                 id=-1,
                 rubberWhat='box',
                 color=(0, 1, 0),
                 gfxWhenDone='hide',
                 roiName='1'):
        """
        id can be a viewerID
               or a viewer.GLViewer object
        rubberWhat should be one of:
             'box'
             'line'
             'circle'
             'ellipse'

        gfxWhenDone should be one of: 'hide', 'remove', None
        """
        from Priithon.all import Y
        if type(id) is int:
            self.splitND = Y.viewers[id]
            self.viewer = Y.viewers[id].viewer
        else:
            self.splitND = None  # CHECK Y.viewers[id]
            self.viewer = id

        self.id = id
        self.rubberWhat = rubberWhat
        self.color = color
        self.gfxWhenDone = gfxWhenDone
        self.roiName = roiName
        self.gfxIdx = None

        #20070721 self.oldOnMouse= self.viewer.doOnMouse
        #20070721 self.viewer.doLDown =self.onLeft1
        Y._registerEventHandler(self.viewer.doOnLDown,
                                newFcn=self.onLeft1,
                                newFcnName='vLeftClickDoes',
                                oldFcnName=None)
Example #46
0
 def onExe(self, ev):
     import sys,os,__main__
     p   = os.path.dirname( self.fn_or_fns )
     sys.path.insert(0, p)
     try:
         try:
             self.pyshell.addHistory("execfile(r\"%s\")"%(self.fn_or_fns,))
             exec(compile(open(self.fn_or_fns).read(), self.fn_or_fns, 'exec'), __main__.__dict__)
         except:
             if NO_SPECIAL_GUI_EXCEPT:
                 raise
             e = sys.exc_info()
             wx.MessageBox("Error on execfile: %s - %s" %\
                           (str(e[0]), str(e[1]) ),
                           "Bad Varname  !?",
                           style=wx.ICON_ERROR)
         else:
             from Priithon.all import Y
             Y.shellMessage("### execfile('%s')\n"%(self.fn_or_fns,))
             self.pyshell.addHistory("execfile('%s')\n"%(self.fn_or_fns,))
     finally:
         #20090319 del sys.path[0]
         sys.path.remove(p)
Example #47
0
    def OnMenuSaveND(self, ev=None):
        if self.data.dtype.type in (N.complex64, N.complex128):
            dat = self.dataCplx
            datX = abs(self.data)  #CHECK
        else:
            dat = datX = self.data

        from Priithon.all import Mrc, U, FN, Y
        fn = FN(1, 0)
        if not fn:
            return
        if fn[-4:] in [".mrc", ".dat"]:
            Mrc.save(dat, fn)
        elif fn[-5:] in [".fits"]:
            U.saveFits(dat, fn)
        else:
            # save as sequence of image files
            # if fn does contain something like '%0d' auto-insert '_%0NNd'
            #      with NN to just fit the needed number of digits
            datX = datX.view()
            datX.shape = (-1, ) + datX.shape[-2:]
            U.saveImg8_seq(datX, fn)
        Y.shellMessage("### Y.vd(%d) saved to '%s'\n" % (self.id, fn))
Example #48
0
    def OnMenuSaveND(self, ev=None):
        if self.data.dtype.type in (N.complex64, N.complex128):
            dat = self.dataCplx
            datX = abs(self.data) #CHECK 
        else:
            dat = datX = self.data

        from Priithon.all import Mrc, U, FN, Y
        fn = FN(1,0)
        if not fn:
            return
        if fn[-4:] in [ ".mrc",  ".dat" ]:
            Mrc.save(dat, fn)
        elif fn[-5:] in [ ".fits" ]:
            U.saveFits(dat, fn)
        else:
            # save as sequence of image files
            # if fn does contain something like '%0d' auto-insert '_%0NNd'
            #      with NN to just fit the needed number of digits
            datX = datX.view()
            datX.shape = (-1,)+datX.shape[-2:]
            U.saveImg8_seq(datX, fn)
        Y.shellMessage("### Y.vd(%d) saved to '%s'\n"%(self.id, fn))
Example #49
0
def main(*args):
    """
    aks for filenames
    tells you finished files using shell Messages
    """
    import wx
    from Priithon.all import Y

    dlg = wx.FileDialog(None,
                        'Choose image files',
                        style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
    if dlg.ShowModal() == wx.ID_OK:
        fns = dlg.GetPaths()
        if fns:
            if isinstance(fns, basestring):
                fns = [fns]
            for fn in fns:
                #out = os.path.extsep.join((fn, DEF_EXT))
                out = byteSwap(fn)  #, out, DEF_BYTE)
                if hasattr(Y, 'shellMessage'):
                    Y.shellMessage(out.join(('#', '---done\n')))
                else:
                    print out.join(('#', '---done\n'))
                Y.refresh()
Example #50
0
def showInViewer(vid, slc):
    from Priithon.all import Y
    Y.vgAddRect(vid, ((slc[2],slc[4]),(slc[3],slc[5])))
Example #51
0
 def OnTest2(self, event):
     from Priithon.all import Y
     Y.test2()
Example #52
0
 def OnOSXBug(self, evt=None):
     from Priithon.all import Y
     Y._bugXiGraphics(evt.GetInt())
Example #53
0
 def OnVplotslider(self, evt=None):
     from Priithon.all import Y
     Y.vPlotAsSliderGUI()
Example #54
0
 def OnRotate(self, evt):
     from . import usefulX as Y
     Y.vRotate(self)
Example #55
0
 def OnListVars(self, evt=None):
     from Priithon.all import Y
     Y.listArrayViewer()
Example #56
0
 def OnTest2(self, event):
     from Priithon.all import Y
     Y.test2()
Example #57
0
 def OnOSXBug(self, evt=None):
     from Priithon.all import Y
     Y._bugXiGraphics( evt.GetInt() )
Example #58
0
 def OnVplotslider(self, evt=None):
     from Priithon.all import Y
     Y.vPlotAsSliderGUI()
Example #59
0
 def OnVanimate(self, evt=None):
     from Priithon.all import Y
     Y.vAnimate()
Example #60
0
 def OnCloneShell(self, evt=None):
     from Priithon.all import Y
     Y.shell(clone=True)