[plugins] Remove dependency on pyuic

Eases plugin development and deployment
This commit is contained in:
Matthias Kuhn 2024-06-22 13:37:53 +02:00
parent cfb57fd75a
commit fd663cc021
14 changed files with 50 additions and 124 deletions

View File

@ -1103,7 +1103,6 @@ if (WITH_CORE AND WITH_BINDINGS)
find_package(Qsci REQUIRED)
include(PythonMacros)
include(PyQtMacros)
include(SIPMacros)
set(SIP_INCLUDES ${PYQT_SIP_DIR} ${CMAKE_SOURCE_DIR}/python)

View File

@ -1,98 +0,0 @@
# Macros for PyQt
# ~~~~~~~~~~~~~~~~
# Copyright (c) 2009, Juergen E. Fischer <jef at norbit dot de>
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
IF(BUILD_WITH_QT6)
SET(PYUIC_PROG_NAME pyuic6)
SET(PYUIC_PROG_NAMES pyuic6)
ELSE()
SET(PYUIC_PROG_NAME pyuic5)
SET(PYUIC_PROG_NAMES pyuic5)
SET(PYRCC_PROG_NAME pyrcc5)
ENDIF()
IF(NOT PYUIC_PROGRAM)
FIND_PROGRAM(PYUIC_PROGRAM NAMES ${PYUIC_PROG_NAMES} PATHS $ENV{LIB_DIR}/bin)
IF (NOT PYUIC_PROGRAM)
MESSAGE(FATAL_ERROR "pyuic5 not found - aborting")
ENDIF (NOT PYUIC_PROGRAM)
ENDIF(NOT PYUIC_PROGRAM)
# Adapted from QT4_WRAP_UI
MACRO(PYQT_WRAP_UI outfiles )
SET(PYUIC_WRAPPER_OUTPUT_DIRECTORY "${PYTHON_OUTPUT_DIRECTORY}")
SET(PYUIC_WRAPPER_PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
IF(CMAKE_HOST_WIN32)
IF(USING_NINJA OR USING_NMAKE)
SET(PYUIC_WRAPPER "${CMAKE_SOURCE_DIR}/scripts/pyuic_wrapper.bat")
SET(PYUIC_WRAPPER_PATH "${QGIS_OUTPUT_DIRECTORY}/bin")
ELSE(USING_NINJA OR USING_NMAKE)
SET(PYUIC_WRAPPER "${CMAKE_SOURCE_DIR}/scripts/pyuic_wrapper.bat")
SET(PYUIC_WRAPPER_PATH "${QGIS_OUTPUT_DIRECTORY}/bin/${CMAKE_BUILD_TYPE}")
ENDIF(USING_NINJA OR USING_NMAKE)
ELSEIF(MINGW)
# Clear all variables to invoke PYUIC_PROGRAM directly
SET(PYUIC_WRAPPER_OUTPUT_DIRECTORY "")
SET(PYUIC_WRAPPER_PYTHON_EXECUTABLE "")
ELSE()
# TODO osx
SET(PYUIC_WRAPPER "${CMAKE_SOURCE_DIR}/scripts/pyuic_wrapper.sh")
SET(PYUIC_WRAPPER_PATH "${QGIS_OUTPUT_DIRECTORY}/lib${LIB_SUFFIX}")
ENDIF()
FOREACH(it ${ARGN})
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.py)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${PYUIC_WRAPPER} "${PYUIC_PROGRAM}" "${PYUIC_WRAPPER_PATH}" "${PYUIC_WRAPPER_OUTPUT_DIRECTORY}" "${PYUIC_WRAPPER_PYTHON_EXECUTABLE}" ${infile} -o ${outfile}
MAIN_DEPENDENCY ${infile}
DEPENDS pygui pycore pyqtcompat
)
SET(${outfiles} ${${outfiles}} ${outfile})
ENDFOREACH(it)
ENDMACRO(PYQT_WRAP_UI)
IF(NOT PYRCC_PROGRAM AND NOT BUILD_WITH_QT6)
FIND_PROGRAM(PYRCC_PROGRAM NAMES ${PYRCC_PROG_NAME} PATHS $ENV{LIB_DIR}/bin)
IF (NOT PYRCC_PROGRAM)
MESSAGE(FATAL_ERROR "pyrcc5 not found - aborting")
ENDIF (NOT PYRCC_PROGRAM)
ENDIF(NOT PYRCC_PROGRAM AND NOT BUILD_WITH_QT6)
# Adapted from QT4_ADD_RESOURCES
MACRO (PYQT_ADD_RESOURCES outfiles )
FOREACH (it ${ARGN})
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
GET_FILENAME_COMPONENT(rc_path ${infile} PATH)
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}_rc.py)
# parse file for dependencies
# all files are absolute paths or relative to the location of the qrc file
FILE(READ "${infile}" _RC_FILE_CONTENTS)
STRING(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
SET(_RC_DEPENDS)
FOREACH(_RC_FILE ${_RC_FILES})
STRING(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
STRING(REGEX MATCH "^/|([A-Za-z]:/)" _ABS_PATH_INDICATOR "${_RC_FILE}")
IF(NOT _ABS_PATH_INDICATOR)
SET(_RC_FILE "${rc_path}/${_RC_FILE}")
ENDIF(NOT _ABS_PATH_INDICATOR)
SET(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
ENDFOREACH(_RC_FILE)
IF (BUILD_WITH_QT6)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND Qt6::rcc -g python -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile}
DEPENDS ${_RC_DEPENDS})
ELSE()
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${PYRCC_PROGRAM} ${_name_opt} -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile}
DEPENDS ${_RC_DEPENDS})
ENDIF()
SET(${outfiles} ${${outfiles}} ${outfile})
ENDFOREACH (it)
ENDMACRO (PYQT_ADD_RESOURCES)

View File

@ -11,11 +11,13 @@ set(PY_CONSOLE_FILES
__init__.py
)
file(GLOB UI_FILES *.ui)
PYQT_WRAP_UI(PYUI_FILES ${UI_FILES})
add_custom_target(pyconsole ALL DEPENDS ${PYUI_FILES})
set(UI_FILES
console_compile_apis.ui
console_settings.ui)
foreach(pyfile ${PY_CONSOLE_FILES} ${PYUI_FILES})
add_custom_target(pyconsole ALL)
foreach(pyfile ${PY_CONSOLE_FILES})
add_custom_command(TARGET pyconsole
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_OUTPUT_DIRECTORY}/console
@ -26,5 +28,5 @@ foreach(pyfile ${PY_CONSOLE_FILES} ${PYUI_FILES})
endforeach(pyfile)
PY_COMPILE(pyconsole "${PYTHON_OUTPUT_DIRECTORY}/console")
install(FILES ${PY_CONSOLE_FILES} ${PYUI_FILES} DESTINATION "${QGIS_CONSOLE_DIR}")
install(FILES ${PY_CONSOLE_FILES} ${UI_FILES} DESTINATION "${QGIS_CONSOLE_DIR}")

View File

@ -20,11 +20,14 @@ Portions of this file contain code from Eric4 APIsManager module.
import os
from pathlib import Path
from qgis.PyQt import uic
from qgis.PyQt.Qsci import QsciAPIs, QsciLexerPython
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
from qgis.PyQt.QtCore import QCoreApplication
from .ui_console_compile_apis import Ui_APIsDialogPythonConsole
Ui_APIsDialogPythonConsole, _ = uic.loadUiType(Path(__file__).parent / 'console_compile_apis.ui')
class PrepareAPIDialog(QDialog):

View File

@ -18,6 +18,9 @@ email : lrssvtml (at) gmail (dot) com
Some portions of code were taken from https://code.google.com/p/pydee/
"""
from pathlib import Path
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QCoreApplication, QUrl
from qgis.PyQt.QtWidgets import QWidget, QFileDialog, QMessageBox, QTableWidgetItem, QHBoxLayout
from qgis.PyQt.QtGui import QIcon, QDesktopServices
@ -26,7 +29,8 @@ from qgis.core import QgsSettings, QgsApplication, QgsSettingsTree
from qgis.gui import QgsOptionsPageWidget, QgsOptionsWidgetFactory
from .console_compile_apis import PrepareAPIDialog
from .ui_console_settings import Ui_SettingsDialogPythonConsole
Ui_SettingsDialogPythonConsole, _ = uic.loadUiType(Path(__file__).parent / 'console_settings.ui')
class ConsoleOptionsFactory(QgsOptionsWidgetFactory):

View File

@ -6,5 +6,5 @@ file(GLOB PY_FILES *.py)
file(GLOB UI_FILES ui/*.ui)
PLUGIN_INSTALL(db_manager . ${OTHER_FILES} ${PY_FILES} ${PYRC_FILES} metadata.txt)
PLUGIN_INSTALL(db_manager . ${OTHER_FILES} ${PY_FILES} metadata.txt)
PLUGIN_INSTALL(db_manager ui ${UI_FILES})

View File

@ -1,4 +1,3 @@
file(GLOB PY_FILES *.py)
file(GLOB UI_FILES *.ui)
PYQT_WRAP_UI(PYUI_FILES ${UI_FILES})
PLUGIN_INSTALL(db_manager db_plugins/postgis/plugins/versioning ${PY_FILES} ${PYUI_FILES})
PLUGIN_INSTALL(db_manager db_plugins/postgis/plugins/versioning ${PY_FILES} ${UI_FILES})

View File

@ -19,14 +19,17 @@ Based on PG_Manager by Martin Dobias <wonder.sk@gmail.com> (GPLv2 license)
***************************************************************************/
"""
from pathlib import Path
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QMessageBox, QApplication
from .ui_DlgVersioning import Ui_DlgVersioning
from .....dlg_db_error import DlgDbError
from ....plugin import BaseError, Table
Ui_DlgVersioning, _ = uic.loadUiType(Path(__file__).parent / 'DlgVersioining.ui')
class DlgVersioning(QDialog, Ui_DlgVersioning):

View File

@ -14,10 +14,7 @@ set(PY_PLUGININSTALLER_FILES
version_compare.py
)
# file(GLOB UI_FILES *.ui)
# PYQT_WRAP_UI(PYUI_FILES ${UI_FILES})
PYQT_WRAP_UI(PYUI_FILES
set(UI_FILES
qgsplugininstallerfetchingbase.ui
qgsplugininstallerinstallingbase.ui
qgsplugininstallerpluginerrorbase.ui
@ -25,7 +22,7 @@ PYQT_WRAP_UI(PYUI_FILES
qgsplugindependenciesdialogbase.ui
)
add_custom_target(pyplugin-installer ALL DEPENDS ${PYUI_FILES})
add_custom_target(pyplugin-installer ALL)
add_custom_command(TARGET pyplugin-installer
POST_BUILD
@ -33,7 +30,7 @@ add_custom_command(TARGET pyplugin-installer
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
foreach(pyfile ${PY_PLUGININSTALLER_FILES} ${PYUI_FILES})
foreach(pyfile ${PY_PLUGININSTALLER_FILES})
add_custom_command(TARGET pyplugin-installer
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${pyfile} ${PYTHON_OUTPUT_DIRECTORY}/pyplugin_installer
@ -43,4 +40,4 @@ foreach(pyfile ${PY_PLUGININSTALLER_FILES} ${PYUI_FILES})
endforeach(pyfile)
PY_COMPILE(pyplugin-installer "${PYTHON_OUTPUT_DIRECTORY}/pyplugin_installer")
install(FILES ${PY_PLUGININSTALLER_FILES} ${PYUI_FILES} DESTINATION "${QGIS_PLUGININSTALLER_DIR}")
install(FILES ${PY_PLUGININSTALLER_FILES} ${UI_FILES} DESTINATION "${QGIS_PLUGININSTALLER_DIR}")

View File

@ -12,13 +12,16 @@ __author__ = 'elpaso@itopen.it'
__date__ = '2018-09-19'
__copyright__ = 'Copyright 2018, GISCE-TI S.L.'
import os
from pathlib import Path
from qgis.PyQt import uic
from qgis.PyQt import QtWidgets, QtCore
from .ui_qgsplugindependenciesdialogbase import Ui_QgsPluginDependenciesDialogBase
from qgis.utils import iface
Ui_QgsPluginDependenciesDialogBase, _ = uic.loadUiType(Path(__file__).parent / 'qgsplugindependenciesdialogbase.ui')
class QgsPluginDependenciesDialog(QtWidgets.QDialog, Ui_QgsPluginDependenciesDialogBase):
"""A dialog that shows plugin dependencies and offers a way to install or upgrade the

View File

@ -24,13 +24,16 @@
***************************************************************************/
"""
from pathlib import Path
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QCoreApplication
from qgis.PyQt.QtWidgets import QDialog, QTreeWidgetItem
from .ui_qgsplugininstallerfetchingbase import Ui_QgsPluginInstallerFetchingDialogBase
from .installer_data import repositories
from qgis.gui import QgsGui
Ui_QgsPluginInstallerFetchingDialogBase, _ = uic.loadUiType(Path(__file__).parent / 'qgsplugininstallerfetchingbase.ui')
class QgsPluginInstallerFetchingDialog(QDialog, Ui_QgsPluginInstallerFetchingDialogBase):

View File

@ -25,6 +25,9 @@
"""
from builtins import str
from pathlib import Path
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QDir, QUrl, QFile, QCoreApplication
from qgis.PyQt.QtWidgets import QDialog
from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
@ -32,10 +35,11 @@ from qgis.PyQt.QtNetwork import QNetworkRequest, QNetworkReply
from qgis.core import QgsNetworkAccessManager, QgsApplication, QgsNetworkRequestParameters
from qgis.utils import HOME_PLUGIN_PATH
from .ui_qgsplugininstallerinstallingbase import Ui_QgsPluginInstallerInstallingDialogBase
from .installer_data import removeDir, repositories
from .unzip import unzip
Ui_QgsPluginInstallerInstallingDialogBase, _ = uic.loadUiType(Path(__file__).parent / 'qgsplugininstallerinstallingbase.ui')
class QgsPluginInstallerInstallingDialog(QDialog, Ui_QgsPluginInstallerInstallingDialogBase):
# ----------------------------------------- #

View File

@ -26,7 +26,11 @@
from qgis.PyQt.QtWidgets import QDialog
from .ui_qgsplugininstallerpluginerrorbase import Ui_QgsPluginInstallerPluginErrorDialogBase
from pathlib import Path
from qgis.PyQt import uic
Ui_QgsPluginInstallerPluginErrorDialogBase, _ = uic.loadUiType(Path(__file__).parent / 'qgsplugininstallerpluginerrorbase.ui')
class QgsPluginInstallerPluginErrorDialog(QDialog, Ui_QgsPluginInstallerPluginErrorDialogBase):

View File

@ -24,11 +24,14 @@
***************************************************************************/
"""
from pathlib import Path
from qgis.PyQt import uic
from qgis.gui import QgsAuthConfigSelect
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout
from qgis.PyQt.QtCore import Qt
from .ui_qgsplugininstallerrepositorybase import Ui_QgsPluginInstallerRepositoryDetailsDialogBase
Ui_QgsPluginInstallerRepositoryDetailsDialogBase, _ = uic.loadUiType(Path(__file__).parent / 'qgsplugininstallerrepositorybase.ui')
class QgsPluginInstallerRepositoryDialog(QDialog, Ui_QgsPluginInstallerRepositoryDetailsDialogBase):