def testImportFeature(self): '''Simulate user moves and check results.''' # Open python console iface.actionShowPythonDialog().trigger() # Get map tool action that is activated previousActivatedMapToolActionName = iface.mapCanvas().mapTool().action().text() #Add test layers to map registry layerDest = self.addTestVectorLayer() layerSource = self.addTestVectorLayer('test/data/segment2.shp') iface.setActiveLayer(layerDest) # Simulate click on edit mode button self.clickOnWidgetByActionName(iface.actionToggleEditing().text()) # Simulate click on plugin fusion button self.clickOnWidgetByActionName('Import Feature') # Move and click on the feature to import self.clickOnMapPoint(QgsPoint(785519,6528705)) # Feature must have been added if not self.printTest(38, self.featuresCount(layerDest), 'Import feature', 'Features count'): return # End of test ? if self.TESTS_TO_CHECK == 'up_to_import_feature': return # Test undo action self.ctrlZ() if not self.printTest(37, self.featuresCount(layerDest), 'Undo Import feature(Ctrl + z)', 'Features count'): return # End of test ? if self.TESTS_TO_CHECK == 'up_to_undo_import_feat': return # Quit edit mode self.clickOnWidgetByActionName(iface.actionToggleEditing().text()) # Fusion button must be enabled if not self.printTest(False, self.findButtonByActionName('Import Feature').isEnabled(), 'Disable fusion button', 'Fusion button status'): return # Previous map tool button must be re-checked if not self.printTest(True, self.findButtonByActionName(previousActivatedMapToolActionName).isChecked(), 'Check previous map tool button ('+previousActivatedMapToolActionName+')', 'Previous map tool button ('+previousActivatedMapToolActionName+') status'): return # End of test ? if self.TESTS_TO_CHECK == 'up_to_quit_edit_import_feat': return # Clear layers #QgsMapLayerRegistry.instance().removeAllMapLayers() iface.mapCanvas().refresh()
def applyPanels(profile): if profile.panels is None: return currentPanels = [el for el in iface.mainWindow().children() if isinstance(el, QDockWidget)] panels = profile.panels if "PythonConsole" in panels: iface.actionShowPythonDialog().trigger() iface.actionShowPythonDialog().trigger() panels.append("TesterPluginPanel") for panel in currentPanels: panel.setVisible(_objectName(panel) in panels)
def testFusion(self): '''Simulate user moves and check results.''' # Open python console iface.actionShowPythonDialog().trigger() # Get map tool action that is activated previousActivatedMapToolActionName = iface.mapCanvas().mapTool().action().text() # Simulate click on edit mode button # self.clickOnWidgetByActionName(iface.actionToggleEditing().text()) # Simulate click on plugin fusion button JobManager().create_carhab_lyr('test')
def applyPanels(profile): if profile.panels is None: return currentPanels = [ el for el in iface.mainWindow().children() if isinstance(el, QDockWidget) ] panels = profile.panels if "PythonConsole" in panels: iface.actionShowPythonDialog().trigger() iface.actionShowPythonDialog().trigger() panels.append("TesterPluginPanel") for panel in currentPanels: panel.setVisible(_objectName(panel) in panels)
def show_console(): """ called from QGIS to open the console """ global _console if _console is None: parent = iface.mainWindow() if iface else None _console = PythonConsole(parent) if iface: _console.visibilityChanged.connect(iface.actionShowPythonDialog().setChecked) _console.show() # force show even if it was restored as hidden # set focus to the console so the user can start typing # defer the set focus event so it works also whether the console not visible yet QTimer.singleShot(0, _console.activate) else: _console.setUserVisible(not _console.isUserVisible()) # set focus to the console so the user can start typing if _console.isUserVisible(): _console.activate() return _console
def open_close_python_console(): """ Open and close the python console This is a workaround for getting gui message bar to appear """ try: b_python_console_open = False python_console_panel = iface.mainWindow().findChild(QDockWidget, 'PythonConsole') b_python_console_open = python_console_panel.isVisible() if not python_console_panel.isVisible(): iface.actionShowPythonDialog().trigger() except: # the above will bail if sitting on RecentProjects empty view. iface.actionShowPythonDialog().trigger() if not b_python_console_open: iface.actionShowPythonDialog().trigger()
def mostrarConsola(self): iface.actionShowPythonDialog().trigger() print ('CONSOLA INICIADA')
from qgis.core import QgsProject, QgsPoint, QgsRasterLayer, QgsMapLayerRegistry from PyQt4.QtCore import QFileInfo from qgis.utils import iface import time, os COORD_CENTER = QgsPoint(-5482440, -1884950) home_path = os.path.realpath(QgsProject.instance().readPath("./")) def load_project(): layer = QgsRasterLayer(home_path + "/GISData/my_file.xml", "map") QgsMapLayerRegistry.instance().addMapLayer(layer) print("") iface.mapCanvas().setCenter(COORD_CENTER) iface.mapCanvas().zoomScale(180000) update_canvas() def update_canvas(): iface.addRasterLayer(home_path + "/GISData/homicidios_gyn.tiff", "homicidios") iface.addVectorLayer(home_path + '/GISData/cameras_2016_final.shp', 'cameras', 'ogr') iface.addVectorLayer(home_path + '/GISData/expansao_gyn_sirgas.shp', 'expansao', 'ogr') #print('fim de update') iface.actionShowPythonDialog().trigger() iface.initializationCompleted.connect(load_project)