def loadTrayImage(self, image_fname, csv_fname): """Load the tray scan image and activate the camera. Keyword Arguments: image_fname -- the string filepath of the tray scan image""" # Export current csv if there is one ret = self.exportToCSV() if not ret: return # Clear data self.reset() self.cvImpl.reset() self.barcodeEntry.setCurrentBugId("") # Load the image self.trayPath = image_fname self.logger.log("LOAD image scan file %s" % self.trayPath, 1) self.trayImage = cv2.imread(self.trayPath, cv2.IMREAD_COLOR) self.csvPath = csv_fname # Load csv file if os.path.isfile(csv_fname): with open(csv_fname) as csvfile: reader = csv.reader(csvfile) self.bugBoxList = Util.BugBoxList() if (reader.next()[1] == " Rectangle x1"): for b in reader: box = Util.BugBox( b[0], None, (int(b[1]), int(b[2]), int(b[3]), int(b[4])), (int(b[5]), int(b[6]))) self.bugBoxList.newBox(box) self.window.statusBar().showMessage( "Also loaded CSV file: %s" % str(os.path.split(csv_fname)[1])) self.logger.log( "LOAD found corresponding csv file %s" % self.csvPath, 1) else: QtGui.QMessageBox.information( self.window, "Error Reading CSV", "It seems the file %s id badly formatted. Cannot load." % str(os.path.split(csv_fname)[1])) # Start the camera loop self.startCameraFeed() self.sigShowHint.emit(C.HINT_TRAYAREA_1) self.bugBoxList.clearUndoRedoStacks()
def editMousePress(self, ev): """Called when the application is in edit mode and the mouse is clicked on the big label. Keyword Arguments: ev -- PySide.QtGui.QMouseEvent object""" (mx, my) = self.mousePos pad = AppData.BOX_RESIZE_EDGE_PADDING sp = int(AppData.DRAW_DELTA / self.lblBig.imageScaleRatio) if ev.button() == QtCore.Qt.MouseButton.LeftButton: if self.selectedEditBox is not None: # If a box is selected, check for clicking on an editable point # (e. corners for resizing, center for panning) p = self.mousePos (x1, y1, x2, y2) =\ self.bugBoxList[self.selectedEditBox].static if Util.pointInBox( p, (x2 - 3 * sp, y1 + sp, x2 - sp, y1 + 3 * sp)): self.bugBoxList.delete(self.selectedEditBox) self.selectedEditBox = None self.sigDeletedBox.emit(self.selectedEditBox) self.barcodeEntry.setCurrentBugId("") elif Util.pointInBox(p, (x1 - pad, y1 - pad, x1 + pad, y1 + pad)): self.editAction = AppData.DG_NW elif Util.pointInBox(p, (x2 - pad, y2 - pad, x2 + pad, y2 + pad)): self.editAction = AppData.DG_SE elif Util.pointInBox(p, (x1 - pad, y2 - pad, x1 + pad, y2 + pad)): self.editAction = AppData.DG_SW elif Util.pointInBox(p, (x2 - pad, y1 - pad, x2 + pad, y1 + pad)): self.editAction = AppData.DG_NE elif Util.pointInBox(p, (x1 + pad, y1 - pad, x2 - pad, y1 + pad)): self.editAction = AppData.DG_N elif Util.pointInBox(p, (x1 + pad, y2 - pad, x2 - pad, y2 + pad)): self.editAction = AppData.DG_S elif Util.pointInBox(p, (x1 - pad, y1 + pad, x1 + pad, y2 - pad)): self.editAction = AppData.DG_W elif Util.pointInBox(p, (x2 - pad, y1 + pad, x2 + pad, y2 - pad)): self.editAction = AppData.DG_E elif Util.pointInBox(p, (x1 + pad, y1 + pad, x2 - pad, y2 - pad)): self.editAction = AppData.PAN if self.editAction != AppData.NO_ACTION: return # If a box is not selected, check for clicking on a box to # to select it clickedOn = False for i in range(len(self.bugBoxList)): (x1, y1, x2, y2) = self.bugBoxList[i].static if Util.pointInBox((mx, my), (x1 - pad, y1 - pad, x2 + pad, y2 + pad)): self.sigSelectedBox.emit(i) clickedOn = True self.selectedEditBox = i self.barcodeEntry.setCurrentBugId(self.bugBoxList[i].name) self.sigShowHint.emit(C.HINT_EDITBOX) # Check for deselect of box if not clickedOn: self.selectedEditBox = None self.sigShowHint.emit(C.HINT_REMOVEBUG) self.barcodeEntry.setCurrentBugId("") else: box = Util.BugBox( "Box %s" % str(len(self.bugBoxList)), None, (mx - 3 * sp, my - 3 * sp, mx + 3 * sp, my + 3 * sp), (mx, my)) self.bugBoxList.newBox(box) self.selectedEditBox = len(self.bugBoxList) - 1 self.barcodeEntry.setCurrentBugId( self.bugBoxList[self.selectedEditBox].name)