def addReflections(self, file, points):
        "add reflection points from a set in the 'points' argument for a file in the argument"
        if file in self.addedReflections:
            self.addedReflections[file].update(points)
        else:
            self.addedReflections[file] = points

        if file in self.reflections:
            self.reflections[file].update(points)
        else:
            if file in self.pairedfiles:
                cm = CM(file, nameR = self.pairedfiles[file])
            else:
                cm = CM(file, nameR = "auto")
            reflections = cm.findReflections(results = "indices")
            self.reflections[file] = set(reflections[0]) | set(reflections[1]) | points
Beispiel #2
0
    def addReflections(self, file, points):
        "add reflection points from a set in the 'points' argument for a file in the argument"
        if file in self.addedReflections:
            self.addedReflections[file].update(points)
        else:
            self.addedReflections[file] = points

        if file in self.reflections:
            self.reflections[file].update(points)
        else:
            if file in self.pairedfiles:
                cm = CM(file, nameR=self.pairedfiles[file])
            else:
                cm = CM(file, nameR="auto")
            reflections = cm.findReflections(results="indices")
            self.reflections[file] = set(reflections[0]) | set(
                reflections[1]) | points
Beispiel #3
0
class ShowTracks(Toplevel):
    "displays Canvases with trajectory of a selected track"
    def __init__(self, root, tracks, nameA, time = "auto", controlled = False):
        super().__init__(root)
        self["padx"] = 4
        self["pady"] = 4
        self.title("Track images")
        self.grab_set()
        self.focus_set()
        self.resizable(FALSE, FALSE)
        self.geometry("+8+40")

        self.controlled = controlled
        self.tracks = tracks
        self.root = root
        self.fileStorage = self.root.fileStorage
        self.index = self.tracks.index(nameA)
        self.enabledManualReflectionsRemoval = False
        self.size = 6 # size of a mouse circle for reflection removal


        # number of canvases
        self.columns = ((self.winfo_screenwidth() - 515) // 290) or 1
        self.rows = ((self.winfo_screenheight() - 50 )// 290) or 1
        self.numberOfCanvases = self.columns * self.rows
        
        # canvases
        self.canvasFrame = ttk.Frame(self)
        self.canvasFrame.grid(column = 0, row = 0)
        self.canvasFrame.root = self

        for canvasNumber in range(0, self.numberOfCanvases):
            exec("self.canvas{} = TrackCanvas(self.canvasFrame)".format(canvasNumber))
            exec("self.canvas{}.grid(column = {}, row = {}, padx = 2, pady = 2)"\
                 .format(canvasNumber, canvasNumber % self.columns, canvasNumber // self.columns))

        # fileTree (the entire right part)
        self.fileTree = FileTree(self, files = self.tracks, time = time, controlled = controlled)
        self.fileTree.grid(column = 1, row = 0, sticky = (N, S, E, W), padx = 3, pady = 3) 
        
        # initialization of selected track
        self.drawTracks(new = True)

        # event binding
        self.bind("<Up>", lambda e: self.fileTree.previousFun())
        self.bind("<Left>", lambda e: self.fileTree.previousFun())
        self.bind("<Down>", lambda e: self.fileTree.nextFun())
        self.bind("<Right>", lambda e: self.fileTree.nextFun())
        self.bind("<Return>", lambda e: self.drawTracks(new = False))
        self.bind("<MouseWheel>", lambda e: self.mouseWheel(e))

        self.canvasFrame.bind("<3>", lambda e: self.popUp(e))

        # on exit
        self.protocol("WM_DELETE_WINDOW", lambda: self.closeFun())


    def popUp(self, event, canvas = None):
        "makes pop-up menu with options related to manual reflection removal"
        menu = Menu(self, tearoff = 0)
        if not self.enabledManualReflectionsRemoval:
            label = "Enable manual reflection removal"
        else:
            label = "Disable manual reflection removal"
        menu.add_command(label = label, command = self.toggleManualReflectionRemoval)
        if canvas:
            if canvas.addedReflections:
                menu.add_command(label = "Undo manual changes", command = canvas.undoChanges)
            else:
                menu.add_command(label = "Undo manual changes", command = canvas.undoChanges,
                                 state = "disabled")
        for canvasNumber in range(0, self.numberOfCanvases):
            if eval("self.canvas{}.addedReflections".format(canvasNumber)):
                menu.add_command(label = "Undo all manual changes", command = self.undoChanges)
                break
        else:
            menu.add_command(label = "Undo all manual changes", command = self.undoChanges,
                             state = "disabled")
        menu.post(event.x_root, event.y_root)


    def undoChanges(self):
        "removes all manually added reflections"
        self._initializeCM(self.cm.nameA)
        reflections = self.cm.findReflections(results = "indices")
        self.fileStorage.reflections[self.cm.nameA] = set(reflections[0] + reflections[1])
        self.fileStorage.addedReflections[self.cm.nameA] = set()
        self.drawTracks(new = True)


    def mouseWheel(self, event):
        "changes size of a mouse circle used for reflection removal"
        if self.enabledManualReflectionsRemoval:
            if event.num == 5 or event.delta == - 120:
                self.size -= 1
            elif event.num == 4 or event.delta == 120:
                self.size += 1


    def toggleManualReflectionRemoval(self):
        "enables or disables manual reflection removal"
        self.enabledManualReflectionsRemoval = not self.enabledManualReflectionsRemoval
        for canvasNumber in range(0, self.numberOfCanvases):
            exec("self.canvas{}.toggleReflectionRemoval()".format(canvasNumber))
            

    def setTime(self):
        "redraws tracks when time is changed"
        self.drawTracks(new = False)


    def closeFun(self):
        "closes the window"
        if self.controlled:
            self.root.checkProcessing()
        else:
            self.root.root.checkProcessing()

        self.destroy()


    def _initializeCM(self, file):
        "initializes self.cm"
        if file in self.fileStorage.pairedfiles:
            self.cm = CM(file, nameR = self.fileStorage.pairedfiles[file])
        else:
            self.cm = CM(file, nameR = "auto")                     
        
                        
    def drawTracks(self, new = True):
        "draws selected track"
        if new:
            file = self.fileTree.files[self.fileTree.index]
            self._initializeCM(file)
            
        if self.fileTree.removeReflectionsVar.get():
            if self.cm.nameA not in self.fileStorage.reflections:
                reflections = self.cm.findReflections(results = "indices")
                self.fileStorage.reflections[self.cm.nameA] = set(reflections[0] + reflections[1])
                
            self.cm.removeReflections(points = self.fileStorage.reflections[self.cm.nameA],
                                      deleteSame = True)               
            
        d = self.cm.getComputedDiameter()
    
        stopTime = int(self.fileTree.timeFrame.timeVar.get()) * 60000
        startTime = int(self.fileTree.timeFrame.startTimeVar.get()) * 60000
        timeRange = stopTime - startTime
       
        # draws the track divided in equal time intervals 
        for canvasNumber in range(0, self.numberOfCanvases):
            rangeBegin = startTime + timeRange * canvasNumber / self.numberOfCanvases
            rangeEnd = startTime + timeRange * (canvasNumber + 1) / self.numberOfCanvases
            if self.fileTree.frameVar.get() == "arena":
                selectData = [line[7:9] + [line[0]] for line in self.cm.data if \
                              rangeBegin <= line[1] <= rangeEnd]
            if self.fileTree.frameVar.get() == "room":
                selectData = [line[2:4] + [line[0]] for line in self.cm.data if \
                              rangeBegin <= line[1] <= rangeEnd]
            exec("self.canvas{}.drawTrack(d, data = selectData)".format(canvasNumber))
Beispiel #4
0
class ShowTracks(Toplevel):
    "displays Canvases with trajectory of a selected track"

    def __init__(self, root, tracks, nameA, controlled=False):
        super().__init__(root)
        self["padx"] = 4
        self["pady"] = 4
        self.title("Track images")
        self.grab_set()
        self.focus_set()
        self.resizable(FALSE, FALSE)
        self.geometry("+8+40")

        self.controlled = controlled
        self.tracks = tracks
        self.root = root
        self.fileStorage = self.root.fileStorage
        self.index = self.tracks.index(nameA)
        self.enabledManualReflectionsRemoval = False
        self.size = 6  # size of a mouse circle for reflection removal

        # number of canvases
        self.columns = ((self.winfo_screenwidth() - 515) // 290) or 1
        self.rows = ((self.winfo_screenheight() - 50) // 290) or 1
        self.numberOfCanvases = self.columns * self.rows

        # canvases
        self.canvasFrame = ttk.Frame(self)
        self.canvasFrame.grid(column=0, row=0)
        self.canvasFrame.root = self

        for canvasNumber in range(0, self.numberOfCanvases):
            exec("self.canvas{} = TrackCanvas(self.canvasFrame)".format(
                canvasNumber))
            exec("self.canvas{}.grid(column = {}, row = {}, padx = 2, pady = 2)"\
                 .format(canvasNumber, canvasNumber % self.columns, canvasNumber // self.columns))

        # fileTree (the entire right part)
        self.fileTree = FileTree(self,
                                 files=self.tracks,
                                 controlled=controlled)
        self.fileTree.grid(column=1,
                           row=0,
                           sticky=(N, S, E, W),
                           padx=3,
                           pady=3)

        # initialization of selected track
        self.drawTracks(new=True)

        # event binding
        self.bind("<Up>", lambda e: self.fileTree.previousFun())
        self.bind("<Left>", lambda e: self.fileTree.previousFun())
        self.bind("<Down>", lambda e: self.fileTree.nextFun())
        self.bind("<Right>", lambda e: self.fileTree.nextFun())
        self.bind("<Return>", lambda e: self.drawTracks(new=False))
        self.bind("<MouseWheel>", lambda e: self.mouseWheel(e))

        self.canvasFrame.bind("<3>", lambda e: self.popUp(e))

        # on exit
        self.protocol("WM_DELETE_WINDOW", lambda: self.closeFun())

    def popUp(self, event, canvas=None):
        "makes pop-up menu with options related to manual reflection removal"
        menu = Menu(self, tearoff=0)
        if not self.enabledManualReflectionsRemoval:
            label = "Enable manual reflection removal"
        else:
            label = "Disable manual reflection removal"
        menu.add_command(label=label,
                         command=self.toggleManualReflectionRemoval)
        menu.add_separator()
        if canvas:
            if canvas.addedReflections:
                menu.add_command(label="Undo manual changes",
                                 command=canvas.undoChanges)
            else:
                menu.add_command(label="Undo manual changes",
                                 command=canvas.undoChanges,
                                 state="disabled")
        for canvasNumber in range(0, self.numberOfCanvases):
            if eval("self.canvas{}.addedReflections".format(canvasNumber)):
                menu.add_command(label="Undo all manual changes",
                                 command=self.undoChanges)
                break
        else:
            menu.add_command(label="Undo all manual changes",
                             command=self.undoChanges,
                             state="disabled")
        menu.post(event.x_root, event.y_root)

    def undoChanges(self):
        "removes all manually added reflections"
        self._initializeCM(self.cm.nameA)
        reflections = self.cm.findReflections(results="indices")
        self.fileStorage.reflections[self.cm.nameA] = set(reflections[0] +
                                                          reflections[1])
        self.fileStorage.addedReflections[self.cm.nameA] = set()
        self.drawTracks(new=True)

    def mouseWheel(self, event):
        "changes size of a mouse circle used for reflection removal"
        if self.enabledManualReflectionsRemoval:
            if event.num == 5 or event.delta == -120:
                self.size -= 1
            elif event.num == 4 or event.delta == 120:
                self.size += 1

    def toggleManualReflectionRemoval(self):
        "enables or disables manual reflection removal"
        if not self.fileTree.removeReflectionsVar.get():
            self.fileTree.removeReflectionsVar.set(True)
            self.fileTree.toggleReflections()
        self.enabledManualReflectionsRemoval = not self.enabledManualReflectionsRemoval
        for canvasNumber in range(0, self.numberOfCanvases):
            exec(
                "self.canvas{}.toggleReflectionRemoval()".format(canvasNumber))

    def setTime(self):
        "redraws tracks when time is changed"
        self.drawTracks(new=False)

    def closeFun(self):
        "closes the window"
        if self.controlled:
            self.root.checkProcessing()
        else:
            self.root.root.checkProcessing()

        self.destroy()

    def _initializeCM(self, file):
        "initializes self.cm"
        if file in self.fileStorage.pairedfiles:
            self.cm = CM(file, nameR=self.fileStorage.pairedfiles[file])
        else:
            self.cm = CM(file, nameR="auto")

    def drawTracks(self, new=True):
        "draws selected track"
        if new:
            file = self.fileTree.files[self.fileTree.index]
            self._initializeCM(file)

        if self.fileTree.removeReflectionsVar.get():
            if self.cm.nameA not in self.fileStorage.reflections:
                reflections = self.cm.findReflections(results="indices")
                self.fileStorage.reflections[self.cm.nameA] = set(
                    reflections[0] + reflections[1])

            self.cm.removeReflections(
                points=self.fileStorage.reflections[self.cm.nameA],
                deleteSame=True)

        d = self.cm.getComputedDiameter()

        stopTime = int(self.fileTree.timeFrame.timeVar.get()) * 60000
        startTime = int(self.fileTree.timeFrame.startTimeVar.get()) * 60000
        timeRange = stopTime - startTime

        # draws the track divided in equal time intervals
        for canvasNumber in range(0, self.numberOfCanvases):
            rangeBegin = startTime + timeRange * canvasNumber / self.numberOfCanvases
            rangeEnd = startTime + timeRange * (canvasNumber +
                                                1) / self.numberOfCanvases
            if self.fileTree.frameVar.get() == "arena":
                selectData = [line[7:9] + [line[0]] for line in self.cm.data if \
                              rangeBegin <= line[1] <= rangeEnd]
            if self.fileTree.frameVar.get() == "room":
                selectData = [line[2:4] + [line[0]] for line in self.cm.data if \
                              rangeBegin <= line[1] <= rangeEnd]
            exec("self.canvas{}.drawTrack(d, data = selectData)".format(
                canvasNumber))