Changeset 1576


Ignore:
Timestamp:
Nov 21, 2014 9:58:58 AM (7 years ago)
Author:
toby
Message:

add scroll for masks; fix up image import after GPX/image file move

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r1574 r1576  
    136136
    137137    '''
    138     if not ospath.exists(imagefile):
    139         dlg = wx.FileDialog(G2frame, 'Bad image file name; choose name', '.', '',\
     138    if not os.path.exists(imagefile):
     139        print 'Image file '+imagefile+' not found'
     140        fil = imagefile.replace('\\','/') # windows?!
     141        # see if we can find a file with same name or in a similarly named sub-dir
     142        pth,fil = os.path.split(fil)
     143        prevpth = None
     144        while pth and pth != prevpth:
     145            prevpth = pth
     146            if os.path.exists(os.path.join(G2frame.dirname,fil)):
     147                print 'found image file '+os.path.join(G2frame.dirname,fil)
     148                return os.path.join(G2frame.dirname,fil)
     149            pth,enddir = os.path.split(pth)
     150            fil = os.path.join(enddir,fil)
     151        # not found as a subdirectory, drop common parts of path for last saved & image file names
     152        #    if image was .../A/B/C/imgs/ima.ge
     153        #      & GPX was  .../A/B/C/refs/fil.gpx but is now .../NEW/TEST/TEST1
     154        #    will look for .../NEW/TEST/TEST1/imgs/ima.ge, .../NEW/TEST/imgs/ima.ge, .../NEW/imgs/ima.ge and so on
     155        Controls = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls'))
     156        gpxPath = Controls.get('LastSavedAs','').replace('\\','/').split('/') # blank in older .GPX files
     157        imgPath = imagefile.replace('\\','/').split('/')
     158        for p1,p2 in zip(gpxPath,imgPath):
     159            if p1 == p2:
     160                gpxPath.pop(0),imgPath.pop(0)
     161            else:
     162                break
     163        fil = os.path.join(*imgPath) # file with non-common prefix elements
     164        prevpth = None
     165        pth = os.path.abspath(G2frame.dirname)
     166        while pth and pth != prevpth:
     167            prevpth = pth
     168            if os.path.exists(os.path.join(pth,fil)):
     169                print 'found image file '+os.path.join(pth,fil)
     170                return os.path.join(pth,fil)
     171            pth,enddir = os.path.split(pth)
     172        GSASIIpath.IPyBreak()
     173
     174    if not os.path.exists(imagefile):
     175        dlg = wx.FileDialog(G2frame, 'Previous image file not found; open here', '.', '',\
    140176        'Any image file (*.edf;*.tif;*.tiff;*.mar*;*.ge*;*.avg;*.sum;*.img)\
    141177        |*.edf;*.tif;*.tiff;*.mar*;*.ge*;*.avg;*.sum;*.img|\
     
    242278    ext = ospath.splitext(imagefile)[1]
    243279    Comments = []
     280    Image = None
    244281    if ext == '.tif' or ext == '.tiff':
    245282        Comments,Data,Npix,Image = GetTifData(imagefile)
     
    270307        if not imageOnly:
    271308            EditImageParms(G2frame,Data,Comments,Image,imagefile)
     309    else:
     310        print 'Extension for file '+imagefile+' not recognized'
     311    if Image is None:
     312        raise Exception('No image read')
    272313    if imageOnly:
    273314        if TRANSP:
     
    940981        file = open(G2frame.GSASprojectfile,'wb')
    941982        print 'save to file: ',G2frame.GSASprojectfile
     983        # stick the file name into the tree
     984        Controls = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Controls'))
     985        Controls['LastSavedAs'] = G2frame.GSASprojectfile
    942986        wx.BeginBusyCursor()
    943987        try:
  • trunk/GSASIIimgGUI.py

    r1571 r1576  
    10241024   
    10251025def UpdateMasks(G2frame,data):
    1026     '''Shows and handles the controls on the "Masks"
    1027     data tree entry
     1026    '''Shows and handles the controls on the "Masks" data tree entry
    10281027    '''
    10291028   
     
    12351234        G2frame.dataFrame.GetStatusBar().SetStatusText('Ring mask active - LB pick ring location')
    12361235    else:
    1237         G2frame.dataFrame.GetStatusBar().SetStatusText("To add mask: On 2D Powder Image, key a:arc, r:ring, s:spot, p:polygon, f:frame")
    1238     G2frame.dataDisplay = wx.Panel(G2frame.dataFrame)
     1236        G2frame.dataFrame.GetStatusBar().SetStatusText("To add mask: press a,r,s,p or f on 2D image for arc/ring/spot/polygon/frame")
     1237    G2frame.dataDisplay = wxscroll.ScrolledPanel(G2frame.dataFrame)
    12391238    mainSizer = wx.BoxSizer(wx.VERTICAL)
    12401239    mainSizer.Add((5,10),0)
     
    12721271    delSpotId = []
    12731272    if spots:
     1273        lbl = wx.StaticText(parent=G2frame.dataDisplay,label=' Spot masks')
     1274        lbl.SetBackgroundColour(wx.Colour(200,200,210))
     1275        mainSizer.Add(lbl,0,wx.EXPAND|wx.ALIGN_CENTER,0)
    12741276        littleSizer = wx.FlexGridSizer(0,3,0,5)
    1275         littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Spot masks:'),0,WACV)
    1276         littleSizer.Add((5,0),0)
    1277         littleSizer.Add((5,0),0)
    12781277        littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' position, mm'),0,WACV)
    12791278        littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' diameter, mm'),0,WACV)
     
    13011300    delRingId = []
    13021301    if rings:
     1302        lbl = wx.StaticText(parent=G2frame.dataDisplay,label=' Ring masks')
     1303        lbl.SetBackgroundColour(wx.Colour(200,200,210))
     1304        mainSizer.Add(lbl,0,wx.EXPAND|wx.ALIGN_CENTER,0)
    13031305        littleSizer = wx.FlexGridSizer(0,3,0,5)
    1304         littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Ring masks:'),0,WACV)
    1305         littleSizer.Add((5,0),0)
    1306         littleSizer.Add((5,0),0)
    13071306        littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' 2-theta,deg'),0,WACV)
    13081307        littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' thickness, deg'),0,WACV)
     
    13301329    delArcId = []
    13311330    if arcs:
     1331        lbl = wx.StaticText(parent=G2frame.dataDisplay,label=' Arc masks')
     1332        lbl.SetBackgroundColour(wx.Colour(200,200,210))
     1333        mainSizer.Add(lbl,0,wx.EXPAND|wx.ALIGN_CENTER,0)
    13321334        littleSizer = wx.FlexGridSizer(0,4,0,5)
    1333         littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Arc masks:'),0,WACV)
    1334         littleSizer.Add((5,0),0)
    1335         littleSizer.Add((5,0),0)
    1336         littleSizer.Add((5,0),0)
    13371335        littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' 2-theta,deg'),0,WACV)
    13381336        littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' azimuth, deg'),0,WACV)
     
    13671365    delFrameId = []
    13681366    if polygons:
     1367        lbl = wx.StaticText(parent=G2frame.dataDisplay,label=' Polygon masks (on plot RB vertex drag to move,\nLB vertex drag to insert)')
     1368        lbl.SetBackgroundColour(wx.Colour(200,200,210))
     1369        mainSizer.Add(lbl,0,wx.EXPAND|wx.ALIGN_CENTER,0)
    13691370        littleSizer = wx.FlexGridSizer(0,2,0,5)
    1370         littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Polygon masks:'),0,WACV)
    1371         littleSizer.Add((5,0),0)
    13721371        for polygon in polygons:
    13731372            if polygon:
     
    13831382        mainSizer.Add(littleSizer,0,)
    13841383    if frame:
     1384        lbl = wx.StaticText(parent=G2frame.dataDisplay,label=' Frame mask (on plot RB vertex drag to move,\nLB vertex drag to insert)')
     1385        lbl.SetBackgroundColour(wx.Colour(200,200,210))
     1386        mainSizer.Add(lbl,0,wx.EXPAND|wx.ALIGN_CENTER,0)
    13851387        littleSizer = wx.FlexGridSizer(0,2,0,5)
    1386         littleSizer.Add(wx.StaticText(parent=G2frame.dataDisplay,label=' Frame mask:'),0,
    1387             WACV)
    1388         littleSizer.Add((5,0),0)
    13891388        frameList = []
    13901389        for x,y in frame:
     
    13971396        littleSizer.Add(frameDelete,0,WACV)
    13981397        mainSizer.Add(littleSizer,0,)
    1399     if (frame or polygons):
    1400         mainSizer.Add(wx.StaticText(G2frame.dataDisplay,
    1401             label=' For frame and polygons: on plot RB vertex drag to move, LB vertex drag to insert'),0,WACV)
     1398    #if (frame or polygons):
     1399    #    mainSizer.Add(wx.StaticText(G2frame.dataDisplay,
     1400    #        label=' For frame and polygons: on plot RB vertex drag to move, LB vertex drag to insert'),0,WACV)
    14021401    mainSizer.Layout()   
    14031402    G2frame.dataDisplay.SetSizer(mainSizer)
    14041403    G2frame.dataDisplay.SetSize(mainSizer.Fit(G2frame.dataFrame))
     1404    G2frame.dataDisplay.SetupScrolling()
    14051405    Size = mainSizer.Fit(G2frame.dataFrame)
    1406     Size[0] = 450
     1406    Size[0] += 50 # room for scrollbar & status msg
     1407    Size[1] = min(Size[1],500)
     1408    G2frame.dataDisplay.SetSize(Size)
    14071409    G2frame.dataFrame.setSizePosLeft(Size)   
    14081410
Note: See TracChangeset for help on using the changeset viewer.