예제 #1
0
    def load_overlay(self, initialize):
        """
        Lays out display for spatial overlay for image probes
        :param initialize:
        :return:
        """
        edgeTuple = self.edgeTuple
        message = 'final image'
        if (len(self.link.split('->')) > 1):
            probe = [
                probe for probe in self.master.probes
                if probe.edgeId[1] in self.master.lookup[self.edgeTuple[0]]
                and probe.finalNodeId in self.master.lookup[self.edgeTuple[1]]
            ][0]
            n = self.master.scModel.G.get_node(probe.finalNodeId)
            finalFile = os.path.join(
                self.master.scModel.G.dir,
                self.master.scModel.G.get_node(probe.finalNodeId)['file'])
            final = openImage(finalFile)
            finalResized = imageResizeRelative(final, (500, 500), final.size)
            imResized = imageResizeRelative(
                probe.targetMaskImage, (500, 500), probe.targetMaskImage.size
                if probe.targetMaskImage is not None else finalResized.size)

        else:
            message = 'donor'
            probe = \
        [probe for probe in self.master.probes if probe.edgeId[1] in self.master.lookup[edgeTuple[0]] and probe.donorBaseNodeId in self.master.lookup[edgeTuple[1]]][0]
            final, final_file = self.master.scModel.G.get_image(
                probe.donorBaseNodeId)
            finalResized = imageResizeRelative(final, (500, 500), final.size)
            imResized = imageResizeRelative(
                probe.donorMaskImage, (500, 500), probe.donorMaskImage.size
                if probe.donorMaskImage is not None else finalResized.size)

        edge = self.master.scModel.getGraph().get_edge(probe.edgeId[0],
                                                       probe.edgeId[1])

        if initialize is True:
            self.c = Canvas(self.cImgFrame, width=510, height=510)
            self.c.pack()
        self.transitionString(None)
        try:
            finalResized = finalResized.overlay(imResized)
        except IndexError:
            tex = self.c.create_text(250, 250, width=400, font=("Courier", 20))
            self.c.itemconfig(
                tex,
                text="The mask of link {} did not match the size of the {}.".
                format(self.link, message))
            return
        self.master.photos[self.link] = ImageTk.PhotoImage(
            finalResized.toPIL())
        self.image_on_canvas = self.c.create_image(
            255,
            255,
            image=self.master.photos[self.link],
            anchor=CENTER,
            tag='imgc')
예제 #2
0
 def __init__(self, master):
     Frame.__init__(self, master)
     self.statusLabelText = StringVar()
     self.statusLabelText.set('Probes Generating')
     self.heading = Label(
         self,
         text=
         "Welcome to the QA Wizard. Press Next to begin the QA Process or Quit to stop. This is "
         "Manny; He is here to help you analyze the journal. The tool is currently generating the probes. "
         "This could take a while. When the next button is enabled you may begin.",
         wraplength=400)
     self.heading.grid(column=0, row=0, rowspan=2, columnspan=2)
     manny_color = maskgen.tool_set.get_icon('Manny_icon_color.jpg')
     manny_mask = maskgen.tool_set.get_icon('Manny_icon_mask.jpg')
     self.mannyFrame = Frame(self)
     self.mannyFrame.grid(column=0, row=2, columnspan=2)
     self.canvas = Canvas(self.mannyFrame, width=510, height=510)
     self.canvas.pack()
     manny_img = openImage(manny_color)
     manny_img_mask = openImage(manny_mask).to_mask()
     manny_img_mask = imageResizeRelative(manny_img_mask, (500, 500),
                                          manny_img_mask.size)
     self.manny = ImageTk.PhotoImage(
         imageResizeRelative(manny_img, (500, 500), manny_img.size).overlay(
             manny_img_mask, self.manny_colors[random.randint(
                 0,
                 len(self.manny_colors) - 1)]).toPIL())
     self.image_on_canvas = self.canvas.create_image(510 / 2,
                                                     510 / 2,
                                                     image=self.manny,
                                                     anchor=CENTER,
                                                     tag='things')
     self.statusLabelObject = Label(self, textvariable=self.statusLabelText)
     self.statusLabelObject.grid(column=0,
                                 row=3,
                                 columnspan=2,
                                 sticky=E + W)
     self.canvas.bind("<Double-Button-1>", master.help)
     self.wquit = Button(self,
                         text='Quit',
                         command=master.exitProgram,
                         width=20)
     self.wquit.grid(column=0, row=4, sticky=W, padx=5, pady=5)
     self.wnext = Button(self,
                         text='Next',
                         command=master.nex,
                         state=DISABLED,
                         width=20)
     self.wnext.grid(column=1, row=4, sticky=E, padx=5, pady=5)
예제 #3
0
 def __init__(self, master, image, composite):
     Frame.__init__(self, master, bd=2, relief=SUNKEN)
     self.im = image
     self.composite = composite
     compositeResized = imageResizeRelative(self.composite, (500, 500),
                                            self.composite.size)
     if self.im is not None:
         imResized = imageResizeRelative(self.im, (500, 500), self.im.size)
         imResized = imResized.overlay(compositeResized)
     else:
         imResized = compositeResized
     self.photo = ImageTk.PhotoImage(imResized.toPIL())
     self.c = Canvas(master,
                     width=compositeResized.size[0] + 10,
                     height=compositeResized.size[1] + 10)
     self.image_on_canvas = self.c.create_image(0,
                                                0,
                                                image=self.photo,
                                                anchor=NW,
                                                tag='imgd')
     self.c.grid(row=0, column=0)
예제 #4
0
 def load_image(self, event, initialize=False):
     filename = self.item.get()
     im, filename = self.scenarioModel.getGraph().get_image(
         self.mappings[filename])
     self.currentFileName = filename
     imResized = imageResizeRelative(im, (400, 400), im.size)
     self.photo = ImageTk.PhotoImage(imResized.toPIL())
     if initialize:
         self.c = Canvas(self.image_frame, width=400, height=400)
         self.image_on_canvas = self.c.create_image(0,
                                                    0,
                                                    image=self.photo,
                                                    anchor=NW)
         self.c.grid(row=1, column=0)
     else:
         self.c.itemconfig(self.image_on_canvas, image=self.photo)
     analytics = []
     for analytic in customAnalytics.values():
         sn = analytic.screenName()
         if analytic.appliesTo(filename):
             analytics.append(sn)
     self.analyticBox.config(values=analytics)
     self.analytic.set(self.first.screenName())
     self.load_analytic(None)
예제 #5
0
    def __init__(self, master, link):
        Frame.__init__(self, master=master)
        self.master = master
        self.link = link
        self.checkboxes = CheckboxGroup(boxes=[])
        #Find this probe- could probably do this elsewhere and pass it in.
        self.edgeTuple = tuple(link.split("<-"))
        if len(self.edgeTuple) < 2:
            self.finalNodeName = link.split("->")[1]
            self.edgeTuple = tuple(link.split("->"))
        else:
            self.finalNodeName = None
        if (len(link.split('->')) > 1):
            probe = [
                probe for probe in master.probes
                if probe.edgeId[1] in master.lookup[self.edgeTuple[0]]
                and probe.finalNodeId in master.lookup[self.edgeTuple[1]]
            ][0]
        else:
            probe = \
            [probe for probe in master.probes if
             probe.edgeId[1] in master.lookup[self.edgeTuple[0]] and probe.donorBaseNodeId in
             master.lookup[
                 self.edgeTuple[1]]][0]
        self.probe = probe
        iFrame = Frame(self)
        c = Canvas(iFrame, width=35, height=35)
        c.pack()

        #Success Icon
        img = openImage(
            maskgen.tool_set.get_icon('RedX.png') if probe.
            failure else maskgen.tool_set.get_icon('check.png'))
        self.successIcon = ImageTk.PhotoImage(
            imageResizeRelative(img, (30, 30), img.size).toPIL())
        c.create_image(15,
                       15,
                       image=self.successIcon,
                       anchor=CENTER,
                       tag='things')

        #Layout
        row = 0
        col = 0
        self.optionsLabel = Label(self, text=self.link, font=(None, 10))
        self.optionsLabel.grid(row=row,
                               columnspan=3,
                               sticky='EW',
                               padx=(40, 0),
                               pady=10)
        iFrame.grid(column=0, row=0, columnspan=1, sticky=W)
        row += 1
        self.operationVar = StringVar(value="Operation [ Semantic Groups ]:")
        self.operationLabel = Label(self,
                                    textvariable=self.operationVar,
                                    justify=LEFT)
        self.semanticFrame = SemanticFrame(self)
        self.semanticFrame.grid(row=row + 1,
                                column=0,
                                columnspan=2,
                                sticky=N + W,
                                rowspan=1,
                                pady=10)
        row += 2
        #cImageFrame is used for plot, image and overlay
        self.cImgFrame = ttk.Notebook(self)
        self.cImgFrame.bind('<<NotebookTabChanged>>',
                            lambda a: self.frameMove())
        self.cImgFrame.grid(row=row, rowspan=8)
        self.descriptionVar = StringVar()
        self.descriptionLabel = Label(self,
                                      textvariable=self.operationVar,
                                      justify=LEFT)
        row += 8
        self.operationLabel.grid(row=row, columnspan=3, sticky='W', padx=10)
        row += 1
        textscroll = Scrollbar(self)
        textscroll.grid(row=row, column=col + 1, sticky=NS)
        self.commentBox = Text(self,
                               height=5,
                               width=80,
                               yscrollcommand=textscroll.set,
                               relief=SUNKEN)
        self.master.commentsBoxes[self.link] = self.commentBox
        self.commentBox.grid(row=row,
                             column=col,
                             padx=5,
                             pady=5,
                             columnspan=1,
                             rowspan=2,
                             sticky=NSEW)
        textscroll.config(command=self.commentBox.yview)
        col = 3
        row = 0
        scroll = Scrollbar(self)
        scroll.grid(row=row,
                    column=col + 2,
                    rowspan=5,
                    columnspan=1,
                    sticky=NS)

        self.pathList = Listbox(self,
                                width=30,
                                yscrollcommand=scroll.set,
                                selectmode=EXTENDED,
                                exportselection=0)
        self.pathList.grid(row=row,
                           column=col - 1,
                           rowspan=5,
                           columnspan=3,
                           padx=(30, 10),
                           pady=(20, 20))
        self.master.pathboxes[self] = self.semanticFrame.getListbox()
        scroll.config(command=self.pathList.yview)
        self.transitionVar = StringVar()

        edge = master.scModel.getGraph().get_edge(probe.edgeId[0],
                                                  probe.edgeId[1])
        self.operationVar.set(self.operationVar.get() +
                              master._compose_label(edge))
        master.edges[self] = [edge, self.semanticFrame.getListbox()]
        for sg in edge['semanticGroups'] if 'semanticGroups' in edge else []:
            self.semanticFrame.insertListbox(ANCHOR, sg)
        operation = master.scModel.getGroupOperationLoader(
        ).getOperationWithGroups(edge['op'])

        #QA checkboxes
        if operation.qaList is not None:
            args = getValue(edge, 'arguments', {})
            self.curOpList = [x for x in operation.qaList]
            for item_pos in range(len(self.curOpList)):
                item = self.curOpList[item_pos]
                try:
                    self.curOpList[item_pos] = item.format(**args)
                except:
                    pass
        else:
            self.curOpList = []
        row += 5
        if self.curOpList is None:
            master.qaData.set_qalink_status(self.link, 'yes')

        for q in self.curOpList:
            box_label = Label(self, text=q, wraplength=250, justify=LEFT)
            ck = Chkbox(parent=self,
                        dialog=master,
                        label=box_label,
                        value=master.qaData.get_qalink_status(link=link))
            ck.box.grid(row=row, column=col - 1)
            ck.label.grid(row=row, column=col, columnspan=4, sticky='W')
            self.checkboxes.boxes.append(ck)
            row += 1
        master.checkboxes[self] = self.checkboxes

        # Main Features- load the overlay for images, load plot graph & overlay page for videos
        if ('<-' in self.link and probe.donorVideoSegments is None
            ) or probe.targetVideoSegments is None:
            self.load_overlay(initialize=True)
        else:
            self.transitionString(None)
            self.setUpFrames()

        #Comment section
        currentComment = master.qaData.get_qalink_caption(self.link)
        self.commentBox.delete(1.0, END)
        self.commentBox.insert(
            END, currentComment if currentComment is not None else '')

        #Navigation Buttons
        self.acceptButton = Button(self,
                                   text='Next',
                                   command=master.nex,
                                   width=15)
        self.acceptButton.grid(row=12,
                               column=col + 2,
                               columnspan=2,
                               sticky='E',
                               padx=(20, 20))
        self.prevButton = Button(self,
                                 text='Previous',
                                 command=master.pre,
                                 width=15)
        self.prevButton.grid(row=12,
                             column=col - 1,
                             columnspan=2,
                             sticky='W',
                             padx=(20, 20))

        self.acceptnButton = Button(self,
                                    text='Next Unchecked',
                                    command=master.nexCheck,
                                    width=15)
        self.acceptnButton.grid(row=13,
                                column=col + 2,
                                columnspan=2,
                                sticky='E',
                                padx=(20, 20))
        self.prevnButton = Button(self,
                                  text='Previous Unchecked',
                                  command=master.preCheck,
                                  width=15)
        self.prevnButton.grid(row=13,
                              column=col - 1,
                              columnspan=2,
                              sticky='W',
                              padx=(20, 20))
        row = 14
        #Progress Bar
        pb = ttk.Progressbar(self,
                             orient='horizontal',
                             mode='determinate',
                             maximum=100.0001)
        pb.grid(row=row, column=0, sticky=EW, columnspan=8)
        pb.step(master.progress * 100)

        master.progressBars.append(pb)