def ReloadView(self, newId): self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) # this will activate the window self.activateWindow() QtGui.qApp.processEvents() self.selected_features = qgsutils.getToFeature(self.canvas, self.layer, newId) self.current_image = self.GetImage() #Check if image exist if os.path.exists(self.current_image) is False: qgsutils.showUserAndLogMessage( self, u"Information: ", u"It is not in the associated image.", QgsMessageBar.INFO) self.ChangeUrlViewer(config.DEFAULT_EMPTY) self.setPosition() return #Set RubberBand self.setOrientation() self.setPosition() #Copy file to local server self.CopyFile(self.current_image) self.ChangeUrlViewer(config.DEFAULT_URL) QtGui.qApp.processEvents() return
def CopyFile(self, src): ''' Copy Image File in Local Server ''' qgsutils.showUserAndLogMessage( self, u"Information: ", u"Copiar imagem", QgsMessageBar.INFO, onlyLog=True) pattern = "^(?P<photo_id>\d+)[^\d].*jpg$" src_dir = src dst_dir = self.plugin_path + "\\viewer" # Delete images on first time for root, dirs, files in os.walk(dst_dir): for file in filter(lambda x: re.match(pattern, x), files): os.remove(os.path.join(root, file)) # Copy image in local folder # Uncomment for large images if viewer is blank screen img = Image.open(src_dir) newwidth = 8000 dst_dir = dst_dir + "\\image.jpg" width, height = img.size if width > newwidth: wpercent = (newwidth / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((newwidth, hsize), Image.ANTIALIAS) img.save(dst_dir, optimize=True, quality=95) # Comment for large images if viewer is blank screen else: shutil.copy(src_dir, dst_dir) qApp.processEvents() return
def __init__(self, iface, parent=None, featuresId=None, layer=None): """Constructor.""" QDialog.__init__(self) self.setupUi(self) self.s = QSettings() self.plugin_path = os.path.dirname(os.path.realpath(__file__)) QTextCodec.setCodecForCStrings(QTextCodec.codecForName("UTF-8")) Gui.loadLatin1Encoding() self.iface = iface self.canvas = self.iface.mapCanvas() self.parent = parent #Orientation from image self.yaw = math.pi self.bearing = None self.layer = layer self.featuresId = featuresId #Restore Previous size self.RestoreSize() #defaults self.actualPointDx = None self.actualPointSx = None self.actualPointOrientation = None self.selected_features = qgsutils.getToFeature(self.canvas, self.layer, self.featuresId) #Get image path self.current_image = self.GetImage() QtGui.qApp.processEvents() #Creamos el visor self.CreateViewer() QtGui.qApp.processEvents() #Check if image exist if os.path.exists(self.current_image) is False: qgsutils.showUserAndLogMessage(self, u"Information: ", u"There is no associated image.", QgsMessageBar.INFO) self.ChangeUrlViewer(config.DEFAULT_EMPTY) self.setPosition() return #Set RubberBand self.setOrientation() self.setPosition() QtGui.qApp.processEvents() #Copy file to local server self.CopyFile(self.current_image) QtGui.qApp.processEvents()
def FullScreen(self, bool): qgsutils.showUserAndLogMessage(self, u"Information: ", u"Fullscreen.", QgsMessageBar.INFO, onlyLog=True) if (bool): self.showFullScreen() else: self.showNormal() QtGui.qApp.processEvents() return
def closeEvent(self, evt): ''' Close dialog ''' qgsutils.showUserAndLogMessage( self, u"Information: ", u"Close dialog", QgsMessageBar.INFO, onlyLog=True) qgsutils.removeAllHighlightFeaturesFromCanvasScene(self.canvas) qApp.processEvents() self.canvas.refresh() self.iface.actionPan().trigger() self.SaveSize() qApp.processEvents() return
def GetImage(self): try: path = qgsutils.getAttributeFromFeature(self.selected_features, config.column_name) except: qgsutils.showUserAndLogMessage(self, u"Information: ", u"Column not found.", QgsMessageBar.INFO) return qgsutils.showUserAndLogMessage(self, u"Information: ", str(path), QgsMessageBar.INFO, onlyLog=True) return path
def CreateViewer(self): ''' Create Viewer ''' qgsutils.showUserAndLogMessage( self, u"Information: ", u"Create viewer", QgsMessageBar.INFO, onlyLog=True) self.view = CefWidget(self) self.m_vbox = QVBoxLayout() self.m_vbox.addWidget(self.view) qApp.processEvents() self.frame.setLayout(self.m_vbox) qApp.processEvents() self.view.embed() qApp.processEvents() return
def GetImage(self): ''' Get Selected Image ''' try: path = qgsutils.getAttributeFromFeature( self.selected_features, config.column_name) if not os.path.isabs(path): # Relative Path to Project path_project = QgsProject.instance().readPath("./") path = os.path.normpath(os.path.join(path_project, path)) except: qgsutils.showUserAndLogMessage( self, u"Information: ", u"Column not found.", QgsMessageBar.INFO) return qgsutils.showUserAndLogMessage(self, u"Information: ", str( path), QgsMessageBar.INFO, onlyLog=True) return path
def StartCefPython(self): ''' Start CefPython ''' qgsutils.showUserAndLogMessage(self, u"Information: ", u"Create Viewer.", QgsMessageBar.INFO, onlyLog=True) settings = {} settings["browser_subprocess_path"] = "%s/%s" % ( cefpython.GetModuleDirectory(), "subprocess") settings["log_severity"] = cefpython.LOGSEVERITY_DISABLE settings["context_menu"] = { "enabled": False, "navigation": False, # Back, Forward, Reload "print": False, "view_source": False, "external_browser": False, # Open in external browser "devtools": False, # Developer Tools } cefpython.Initialize(settings)
def run(self): ''' Run click feature ''' self.encontrado = False # Check if mapa foto is loaded lys = self.canvas.layers() if len(lys) == 0: qgsutils.showUserAndLogMessage( self, u"Information: ", u"You need to upload the photo layer.", QgsMessageBar.INFO) return # Folder viewer for local server folder = self.plugin_path + "\\viewer" # Start local server in plugin folder openWebApp(folder) QtGui.qApp.processEvents() self.StartCefPython() QtGui.qApp.processEvents() # Create Timer is necessary for cefpython self.createTimer() QtGui.qApp.processEvents() for layer in lys: if layer.name() == config.layer_name: self.encontrado = True self.mapTool = SelectTool(self.iface, parent=self, layer=layer) self.iface.mapCanvas().setMapTool(self.mapTool) if self.encontrado is False: qgsutils.showUserAndLogMessage( self, u"Information: ", u"You need to upload the photo layer.", level=QgsMessageBar.INFO) return
def GetBackNextImage(self): qgsutils.removeAllHighlightFeaturesFromCanvasScene(self.canvas) sender = QObject.sender(self) lys = self.canvas.layers() #Check if mapa foto is loaded if len(lys) == 0: qgsutils.showUserAndLogMessage( self, u"Information: ", u"You need to upload the photo layer.", QgsMessageBar.INFO) return for layer in lys: if layer.name() == config.layer_name: self.encontrado = True self.iface.setActiveLayer(layer) QtGui.qApp.processEvents() f = self.selected_features ac_lordem = f.attribute(config.column_order) if sender.objectName() == "btn_back": new_lordem = int(ac_lordem) - 1 else: new_lordem = int(ac_lordem) + 1 #Filter mapa foto layer ids = [ feat.id() for feat in layer.getFeatures(QgsFeatureRequest( ).setFilterExpression("order ='" + str(new_lordem) + "'")) ] if len(ids) == 0: qgsutils.showUserAndLogMessage( self, u"Information: ", u"There is no superiority that follows.", QgsMessageBar.INFO) #Filter mapa foto layer ids = [ feat.id() for feat in layer.getFeatures(QgsFeatureRequest( ).setFilterExpression("order ='" + str(ac_lordem) + "'")) ] #Update selected feature self.ReloadView(ids[0]) return self.ReloadView(ids[0]) QtGui.qApp.processEvents() if self.encontrado == False: qgsutils.showUserAndLogMessage( self, u"Information: ", u"You need to upload the photo layer.", QgsMessageBar.INFO) return
def CopyFile(self, src): qgsutils.showUserAndLogMessage(self, u"Information: ", u"Copiar imagem", QgsMessageBar.INFO, onlyLog=True) pattern = "^(?P<photo_id>\d+)[^\d].*jpg$" src_dir = src dst_dir = self.plugin_path + "\\viewer" #Delete images on first time for root, dirs, files in os.walk(dst_dir): for file in filter(lambda x: re.match(pattern, x), files): os.remove(os.path.join(root, file)) #Copy image in local folder dst_dir = dst_dir + "\\image.jpg" shutil.copy(src_dir, dst_dir) QtGui.qApp.processEvents() return