def resetPhoto(self): TOMsMessageLog.logMessage("In formCamera::resetPhoto ... ", level=Qgis.Info) pixmap = QPixmap(self.currFileName) if pixmap.isNull(): pass else: self.FIELD.setPixmap(pixmap) self.FIELD.setScaledContents(True)
def viewurl(self, url: QUrl) -> None: """ Open a URL in Roam :param url: The URL to view. bb :return: """ key = url.toString().lstrip('file://') try: # Hack. Eww fix me. data, imagetype = roam.htmlviewer.images[os.path.basename(key)] pix = QPixmap() if imagetype == 'base64': pix.loadFromData(data) else: pix.load(data) self.openimage(pix) except KeyError: pix = QPixmap() pix.load(key) if pix.isNull(): QDesktopServices.openUrl(url) return self.openimage(pix)
def photoDetails(self): # Function to deal with photo fields TOMsMessageLog.logMessage("In photoDetails", level=Qgis.Info) FIELD1 = self.ui.findChild(QLabel, "Photo_Widget_01") FIELD2 = self.ui.findChild(QLabel, "Photo_Widget_02") FIELD3 = self.ui.findChild(QLabel, "Photo_Widget_03") path_absolute = QgsExpressionContextUtils.projectScope( QgsProject.instance()).variable('PhotoPath') if path_absolute == None: reply = QMessageBox.information(None, "Information", "Please set value for PhotoPath.", QMessageBox.Ok) return layerName = self.currRestrictionLayer.name() # Generate the full path to the file fileName1 = "Photos_01" fileName2 = "Photos_02" fileName3 = "Photos_03" idx1 = self.currRestrictionLayer.fields().indexFromName(fileName1) idx2 = self.currRestrictionLayer.fields().indexFromName(fileName2) idx3 = self.currRestrictionLayer.fields().indexFromName(fileName3) TOMsMessageLog.logMessage("In photoDetails. idx1: " + str(idx1) + "; " + str(idx2) + "; " + str(idx3), level=Qgis.Info) #if currRestrictionFeature[idx1]: #TOMsMessageLog.logMessage("In photoDetails. photo1: " + str(currRestrictionFeature[idx1]), level=Qgis.Info) #TOMsMessageLog.logMessage("In photoDetails. photo2: " + str(currRestrictionFeature.attribute(idx2)), level=Qgis.Info) #TOMsMessageLog.logMessage("In photoDetails. photo3: " + str(currRestrictionFeature.attribute(idx3)), level=Qgis.Info) if FIELD1: TOMsMessageLog.logMessage("In photoDetails. FIELD 1 exisits", level=Qgis.Info) if self.currRestriction[idx1]: newPhotoFileName1 = os.path.join(path_absolute, self.currRestriction[idx1]) else: newPhotoFileName1 = None TOMsMessageLog.logMessage("In photoDetails. A. Photo1: " + str(newPhotoFileName1), level=Qgis.Info) pixmap1 = QPixmap(newPhotoFileName1) if pixmap1.isNull(): pass # FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1)) else: FIELD1.setPixmap(pixmap1) FIELD1.setScaledContents(True) TOMsMessageLog.logMessage("In photoDetails. Photo1: " + str(newPhotoFileName1), level=Qgis.Info) if FIELD2: TOMsMessageLog.logMessage("In photoDetails. FIELD 2 exisits", level=Qgis.Info) if self.currRestriction[idx2]: newPhotoFileName2 = os.path.join(path_absolute, self.currRestriction[idx2]) else: newPhotoFileName2 = None #newPhotoFileName2 = os.path.join(path_absolute, str(currRestrictionFeature[idx2])) #newPhotoFileName2 = os.path.join(path_absolute, str(currRestrictionFeature.attribute(fileName2))) TOMsMessageLog.logMessage("In photoDetails. A. Photo2: " + str(newPhotoFileName2), level=Qgis.Info) pixmap2 = QPixmap(newPhotoFileName2) if pixmap2.isNull(): pass # FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1)) else: FIELD1.setPixmap(pixmap2) FIELD1.setScaledContents(True) TOMsMessageLog.logMessage("In photoDetails. Photo2: " + str(newPhotoFileName2), level=Qgis.Info) if FIELD3: TOMsMessageLog.logMessage("In photoDetails. FIELD 3 exisits", level=Qgis.Info) if self.currRestriction[idx3]: newPhotoFileName3 = os.path.join(path_absolute, self.currRestriction[idx3]) else: newPhotoFileName3 = None #newPhotoFileName3 = os.path.join(path_absolute, str(currRestrictionFeature[idx3])) #newPhotoFileName3 = os.path.join(path_absolute, # str(currRestrictionFeature.attribute(fileName3))) #newPhotoFileName3 = os.path.join(path_absolute, str(layerName + "_Photos_03")) pixmap3 = QPixmap(newPhotoFileName3) if pixmap3.isNull(): pass # FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1)) else: FIELD1.setPixmap(pixmap3) FIELD1.setScaledContents(True) TOMsMessageLog.logMessage("In photoDetails. Photo3: " + str(newPhotoFileName3), level=Qgis.Info) pass
def photoDetails_field(self, restrictionDialog, currRestrictionLayer, currRestriction): # Function to deal with photo fields self.demandDialog = restrictionDialog self.currDemandLayer = currRestrictionLayer self.currFeature = currRestriction TOMsMessageLog.logMessage("In photoDetails", level=Qgis.Info) photoPath = QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable('PhotoPath') projectFolder = QgsExpressionContextUtils.projectScope(QgsProject.instance()).variable('project_folder') path_absolute = os.path.join(projectFolder, photoPath) if path_absolute == None: reply = QMessageBox.information(None, "Information", "Please set value for PhotoPath.", QMessageBox.Ok) return # Check path exists ... if os.path.isdir(path_absolute) == False: reply = QMessageBox.information(None, "Information", "PhotoPath folder " + str( path_absolute) + " does not exist. Please check value.", QMessageBox.Ok) return # if cv2 is available, check camera nr try: cameraNr = int(self.params.setParam("CameraNr")) except Exception as e: TOMsMessageLog.logMessage("In photoDetails_field: cameraNr issue: {}".format(e), level=Qgis.Info) if cv2_available: cameraNr = QMessageBox.information(None, "Information", "Please set value for CameraNr.", QMessageBox.Ok) cameraNr = None TOMsMessageLog.logMessage("In photoDetails_field: cameraNr is: {}".format(cameraNr), level=Qgis.Info) layerName = self.currDemandLayer.name() # Generate the full path to the file fileName1 = "Photos_01" fileName2 = "Photos_02" fileName3 = "Photos_03" idx1 = self.currDemandLayer.fields().indexFromName(fileName1) idx2 = self.currDemandLayer.fields().indexFromName(fileName2) idx3 = self.currDemandLayer.fields().indexFromName(fileName3) TOMsMessageLog.logMessage("In photoDetails. idx1: " + str(idx1) + "; " + str(idx2) + "; " + str(idx3), level=Qgis.Info) if cameraNr is not None: TOMsMessageLog.logMessage("Camera TRUE", level=Qgis.Info) takePhoto = True else: TOMsMessageLog.logMessage("Camera FALSE", level=Qgis.Info) takePhoto = False FIELD1 = self.demandDialog.findChild(QLabel, "Photo_Widget_01") FIELD2 = self.demandDialog.findChild(QLabel, "Photo_Widget_02") FIELD3 = self.demandDialog.findChild(QLabel, "Photo_Widget_03") if FIELD1: TOMsMessageLog.logMessage("In photoDetails. FIELD 1 exists", level=Qgis.Info) if self.currFeature[idx1]: newPhotoFileName1 = os.path.join(path_absolute, self.currFeature[idx1]) TOMsMessageLog.logMessage("In photoDetails. photo1: {}".format(newPhotoFileName1), level=Qgis.Info) else: newPhotoFileName1 = None pixmap1 = QPixmap(newPhotoFileName1) if pixmap1.isNull(): pass # FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1)) else: tab = FIELD1.parentWidget() grid = FIELD1.parentWidget().layout() photo_Widget1 = imageLabel(tab) TOMsMessageLog.logMessage( "In photoDetails. FIELD 1 w: {}; h: {}".format(FIELD1.width(), FIELD1.height()), level=Qgis.Info) photo_Widget1.setObjectName("Photo_Widget_01") photo_Widget1.setText("No photo is here") #photo_Widget1 = imageLabel(tab) grid.addWidget(photo_Widget1, 0, 0, 1, 1) FIELD1.hide() FIELD1.setParent(None) FIELD1 = photo_Widget1 FIELD1.set_Pixmap(pixmap1) TOMsMessageLog.logMessage("In photoDetails. FIELD 1 Photo1: " + str(newPhotoFileName1), level=Qgis.Info) TOMsMessageLog.logMessage("In photoDetails.pixmap1 size: {}".format(pixmap1.size()), level=Qgis.Info) FIELD1.pixmapUpdated.connect(functools.partial(self.displayPixmapUpdated, FIELD1)) #ZOOM_IN_1 = self.demandDialog.findChild(QPushButton, "pb_zoomIn_01") #ZOOM_IN_1.clicked.connect(FIELD1._zoomInButton) #ZOOM_OUT_1 = self.demandDialog.findChild(QPushButton, "pb_zoomOut_01") #ZOOM_OUT_1.clicked.connect(FIELD1._zoomOutButton) if takePhoto: START_CAMERA_1 = self.demandDialog.findChild(QPushButton, "startCamera1") TAKE_PHOTO_1 = self.demandDialog.findChild(QPushButton, "getPhoto1") TAKE_PHOTO_1.setEnabled(False) self.camera1 = formCamera(path_absolute, newPhotoFileName1, cameraNr) START_CAMERA_1.clicked.connect( functools.partial(self.camera1.useCamera, START_CAMERA_1, TAKE_PHOTO_1, FIELD1)) self.camera1.notifyPhotoTaken.connect(functools.partial(self.savePhotoTaken, idx1)) if FIELD2: TOMsMessageLog.logMessage("In photoDetails. FIELD 2 exisits", level=Qgis.Info) if self.currFeature[idx2]: newPhotoFileName2 = os.path.join(path_absolute, self.currFeature[idx2]) TOMsMessageLog.logMessage("In photoDetails. Photo1: " + str(newPhotoFileName2), level=Qgis.Info) else: newPhotoFileName2 = None # newPhotoFileName2 = os.path.join(path_absolute, str(self.currFeature[idx2])) # newPhotoFileName2 = os.path.join(path_absolute, str(self.currFeature.attribute(fileName2))) # TOMsMessageLog.logMessage("In photoDetails. Photo2: " + str(newPhotoFileName2), level=Qgis.Info) pixmap2 = QPixmap(newPhotoFileName2) if pixmap2.isNull(): pass # FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1)) else: tab = FIELD2.parentWidget() grid = FIELD2.parentWidget().layout() photo_Widget2 = imageLabel(tab) TOMsMessageLog.logMessage( "In photoDetails. FIELD 2 w: {}; h: {}".format(FIELD2.width(), FIELD2.height()), level=Qgis.Info) photo_Widget2.setObjectName("Photo_Widget_02") photo_Widget2.setText("No photo is here") #photo_Widget2 = imageLabel(tab) grid.addWidget(photo_Widget2, 0, 0, 1, 1) FIELD2.hide() FIELD2.setParent(None) FIELD2 = photo_Widget2 FIELD2.set_Pixmap(pixmap2) TOMsMessageLog.logMessage("In photoDetails. FIELD 2 Photo2: " + str(newPhotoFileName2), level=Qgis.Info) TOMsMessageLog.logMessage("In photoDetails.pixmap2 size: {}".format(pixmap2.size()), level=Qgis.Info) FIELD2.pixmapUpdated.connect(functools.partial(self.displayPixmapUpdated, FIELD2)) #ZOOM_IN_2 = self.demandDialog.findChild(QPushButton, "pb_zoomIn_02") #ZOOM_IN_2.clicked.connect(FIELD2._zoomInButton) #ZOOM_OUT_2 = self.demandDialog.findChild(QPushButton, "pb_zoomOut_02") #ZOOM_OUT_2.clicked.connect(FIELD2._zoomOutButton) """ FIELD2.setPixmap(pixmap2) FIELD2.setScaledContents(True) TOMsMessageLog.logMessage("In photoDetails. Photo2: " + str(newPhotoFileName2), level=Qgis.Info)""" if takePhoto: START_CAMERA_2 = self.demandDialog.findChild(QPushButton, "startCamera2") TAKE_PHOTO_2 = self.demandDialog.findChild(QPushButton, "getPhoto2") TAKE_PHOTO_2.setEnabled(False) self.camera2 = formCamera(path_absolute, newPhotoFileName2, cameraNr) START_CAMERA_2.clicked.connect( functools.partial(self.camera2.useCamera, START_CAMERA_2, TAKE_PHOTO_2, FIELD2)) self.camera2.notifyPhotoTaken.connect(functools.partial(self.savePhotoTaken, idx2)) if FIELD3: TOMsMessageLog.logMessage("In photoDetails. FIELD 3 exisits", level=Qgis.Info) if self.currFeature[idx3]: newPhotoFileName3 = os.path.join(path_absolute, self.currFeature[idx3]) TOMsMessageLog.logMessage("In photoDetails. Photo1: " + str(newPhotoFileName3), level=Qgis.Info) else: newPhotoFileName3 = None # newPhotoFileName3 = os.path.join(path_absolute, str(self.currFeature[idx3])) # newPhotoFileName3 = os.path.join(path_absolute, # str(self.currFeature.attribute(fileName3))) # newPhotoFileName3 = os.path.join(path_absolute, str(layerName + "_Photos_03")) # TOMsMessageLog.logMessage("In photoDetails. Photo3: " + str(newPhotoFileName3), level=Qgis.Info) pixmap3 = QPixmap(newPhotoFileName3) if pixmap3.isNull(): pass # FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1)) else: tab = FIELD3.parentWidget() grid = FIELD3.parentWidget().layout() photo_Widget3 = imageLabel(tab) TOMsMessageLog.logMessage( "In photoDetails. FIELD 3 w: {}; h: {}".format(FIELD3.width(), FIELD3.height()), level=Qgis.Info) photo_Widget3.setObjectName("Photo_Widget_03") photo_Widget3.setText("No photo is here") #photo_Widget3 = imageLabel(tab) grid.addWidget(photo_Widget3, 0, 0, 1, 1) FIELD3.hide() FIELD3.setParent(None) FIELD3 = photo_Widget3 FIELD3.set_Pixmap(pixmap3) TOMsMessageLog.logMessage("In photoDetails. FIELD 3 Photo3: " + str(newPhotoFileName3), level=Qgis.Info) TOMsMessageLog.logMessage("In photoDetails.pixmap3 size: {}".format(pixmap3.size()), level=Qgis.Info) FIELD3.pixmapUpdated.connect(functools.partial(self.displayPixmapUpdated, FIELD3)) #ZOOM_IN_3 = self.demandDialog.findChild(QPushButton, "pb_zoomIn_03") #ZOOM_IN_3.clicked.connect(FIELD3._zoomInButton) #ZOOM_OUT_3 = self.demandDialog.findChild(QPushButton, "pb_zoomOut_03") #ZOOM_OUT_3.clicked.connect(FIELD3._zoomOutButton) """FIELD3.setPixmap(pixmap3) FIELD3.setScaledContents(True) TOMsMessageLog.logMessage("In photoDetails. Photo3: " + str(newPhotoFileName3), level=Qgis.Info)""" if takePhoto: START_CAMERA_3 = self.demandDialog.findChild(QPushButton, "startCamera3") TAKE_PHOTO_3 = self.demandDialog.findChild(QPushButton, "getPhoto3") TAKE_PHOTO_3.setEnabled(False) self.camera3 = formCamera(path_absolute, newPhotoFileName3, cameraNr) START_CAMERA_3.clicked.connect( functools.partial(self.camera3.useCamera, START_CAMERA_3, TAKE_PHOTO_3, FIELD3)) self.camera3.notifyPhotoTaken.connect(functools.partial(self.savePhotoTaken, idx3)) pass