def qgis_iface_menu(qgis_iface: QgisInterface) -> QgisInterface:
    menu: QMenu = qgis_iface.mainWindow().menuBar()
    """
    Add menus to the QgisInterface. By default, the interface mock create only an empty menu.

    :param qgis_iface: The mocked interface provided by the qgis-pytest fixtures
    :type qgis_iface: QgisInterface
    :return: The same QgisInterface mock with three menus in the menu bar
    :rtype: QgisInterface
    """
    menu_a: QMenu = QMenu('A', menu)
    menu_b: QMenu = QMenu('B', menu)
    menu_c: QMenu = QMenu('C', menu)
    menu.addMenu(menu_a)
    menu.addMenu(menu_b)
    menu.addMenu(menu_c)

    yield qgis_iface

    qgis_iface.mainWindow().menuBar().removeAction(menu_a.menuAction())
    qgis_iface.mainWindow().menuBar().removeAction(menu_b.menuAction())
    qgis_iface.mainWindow().menuBar().removeAction(menu_c.menuAction())
    menu_a.deleteLater()
    menu_b.deleteLater()
    menu_c.deleteLater()
def test_plugin_is_loaded_06(qgis_app: QgsApplication,
                             qgis_iface_menu: QgisInterface,
                             qgis_plugin: Dict[str, Any]):
    """
    Tests that the menu is located in the penultimate position of an existing menu

    :param qgis_app: QGIS application fixture
    :type qgis_app: QgsApplication
    :param qgis_iface_menu: QGIS interface fixture with an existing menu bar with menus A, B and C
    :type qgis_iface_menu: QgisInterface
    :param qgis_plugin: QGIS loading and unloading fixture for plugins
    :type qgis_plugin: dict of Any
    """
    actions: List[QAction] = qgis_iface_menu.mainWindow().menuBar().actions()
    assert actions[-2].text() == 'Gis&FIRE'
예제 #3
0
def ensure_folder_empty(folder: str, iface: QgisInterface) -> bool:
    existing_files = os.listdir(folder)
    if not existing_files:
        return True
    reply = QMessageBox.question(
        iface.mainWindow(), 'Existing files',
        'The folder {} is not empty and its contents will be removed.'.format(
            folder), QMessageBox.Ok, QMessageBox.Cancel)
    if reply == QMessageBox.Cancel:
        return False
    for filename in existing_files:
        path = os.path.join(folder, filename)
        if os.path.isdir(path):
            shutil.rmtree(path)
        else:
            os.unlink(path)
    return True