Exemplo n.º 1
0
    def removeLocation(self, loc):
        '''
		remove a location by index or reference
		loc is either a location, or index of the location
		'''
        locremove = None
        if type(loc) is int:
            locremove = self.stagelocations[loc]
            del self.stagelocations[loc]
        elif type(loc) in types.StringTypes:
            loccopy = list(self.stagelocations)
            for location in loccopy:
                if location['name'] == loc:
                    locremove = location
                    self.stagelocations.remove(location)
        else:
            locremove = loc
            self.stagelocations.remove(loc)

        if locremove is not None:
            removeloc = leginondata.StageLocationData(
                initializer=locremove.toDict())
            removeloc['removed'] = True
            self.locationToDB(removeloc)
        locnames = self.locationNames()
        self.panel.locationsEvent(locnames)
Exemplo n.º 2
0
    def fromScope(self, name, comment='', xyonly=True):
        '''
		create a new location with name
		if a location by this name already exists in my 
		list of managed locations, it will be replaced by the new one
		also returns the new location object
		'''
        errstr = 'Location from instrument failed: %s'
        try:
            allstagedata = self.instrument.tem.StagePosition
        except:
            self.logger.error(errstr % 'unable to get stage position')
            return
        stagedata = {}
        stagedata['x'] = allstagedata['x']
        stagedata['y'] = allstagedata['y']
        if not xyonly:
            stagedata['z'] = allstagedata['z']
            stagedata['a'] = allstagedata['a']

        loc = self.getLocation(name)
        if loc is None:
            newloc = leginondata.StageLocationData()
            newloc['name'] = name
            newloc['xy only'] = xyonly
        else:
            newloc = leginondata.StageLocationData(initializer=loc.toDict())

        newloc['session'] = self.session
        newloc.update(stagedata)

        ## save comment, remove the old location
        for loc in self.stagelocations:
            if loc['name'] == name:
                comment = loc['comment']
                self.stagelocations.remove(loc)
                break
        newloc['comment'] = comment
        newloc['removed'] = False

        self.stagelocations.append(newloc)

        self.locationToDB(newloc)
        locnames = self.locationNames()
        self.panel.locationsEvent(locnames)
        #self.logger.info('Location names %s' % (locnames,))
        return newloc
Exemplo n.º 3
0
    def getLocationsFromDB(self):
        '''
		get list of locations for this session from DB
		and use them to create self.stagelocations list
		'''
        ### get location from database
        locdata = leginondata.StageLocationData(session=self.session)
        locations = self.research(datainstance=locdata)

        ### only want most recent of each name
        ### since they are ordered by timestamp, just take the
        ### first one of each name
        mostrecent = []
        names = []
        for loc in locations:
            if loc['name'] not in names:
                names.append(loc['name'])
                if not loc['removed']:
                    mostrecent.append(loc)
        self.stagelocations[:] = mostrecent