From ec70a90bd5fb83f6e1ab794f000d35e3b1706fa7 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Thu, 5 Jul 2012 11:00:52 -0700 Subject: [PATCH] CMake magic to find PyQt4 and build the main GUI from .ui. Also renamed uhd_modes.py -> modes_rx, and the GUI app -> modes_gui --- CMakeLists.txt | 3 +- apps/CMakeLists.txt | 3 +- res/testmain.py => apps/modes_gui | 1 + apps/{uhd_modes.py => modes_rx} | 0 cmake/Modules/FindPyQt.py | 24 ++++++++++++ cmake/Modules/FindPyQt4.cmake | 53 +++++++++++++++++++++++++ res/CMakeLists.txt | 64 +++++++++++++++++++++++++++++++ 7 files changed, 146 insertions(+), 2 deletions(-) rename res/testmain.py => apps/modes_gui (99%) rename apps/{uhd_modes.py => modes_rx} (100%) create mode 100644 cmake/Modules/FindPyQt.py create mode 100644 cmake/Modules/FindPyQt4.cmake create mode 100644 res/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 175679e..b00f759 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,4 +123,5 @@ add_subdirectory(swig) add_subdirectory(python) add_subdirectory(grc) add_subdirectory(apps) -add_subdirectory(docs) \ No newline at end of file +add_subdirectory(docs) +add_subdirectory(res) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 1203dc5..0583ff0 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -21,6 +21,7 @@ include(GrPython) GR_PYTHON_INSTALL( PROGRAMS - uhd_modes.py + modes_rx + modes_gui DESTINATION bin ) diff --git a/res/testmain.py b/apps/modes_gui similarity index 99% rename from res/testmain.py rename to apps/modes_gui index acc87fb..c4ace95 100755 --- a/res/testmain.py +++ b/apps/modes_gui @@ -113,6 +113,7 @@ class mainwindow(QtGui.QMainWindow): self.output_handler = None self.fg.stop() self.runner = None + self.fg = None if self.kmlgen is not None: self.kmlgen.done = True #TODO FIXME need a way to kill kmlgen safely without delay diff --git a/apps/uhd_modes.py b/apps/modes_rx similarity index 100% rename from apps/uhd_modes.py rename to apps/modes_rx diff --git a/cmake/Modules/FindPyQt.py b/cmake/Modules/FindPyQt.py new file mode 100644 index 0000000..5d2f951 --- /dev/null +++ b/cmake/Modules/FindPyQt.py @@ -0,0 +1,24 @@ +# Copyright (c) 2007, Simon Edwards +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +import PyQt4.pyqtconfig + +pyqtcfg = PyQt4.pyqtconfig.Configuration() +print("pyqt_version:%06.0x" % pyqtcfg.pyqt_version) +print("pyqt_version_str:%s" % pyqtcfg.pyqt_version_str) + +pyqt_version_tag = "" +in_t = False +for item in pyqtcfg.pyqt_sip_flags.split(' '): + if item=="-t": + in_t = True + elif in_t: + if item.startswith("Qt_4"): + pyqt_version_tag = item + else: + in_t = False +print("pyqt_version_tag:%s" % pyqt_version_tag) + +print("pyqt_sip_dir:%s" % pyqtcfg.pyqt_sip_dir) +print("pyqt_sip_flags:%s" % pyqtcfg.pyqt_sip_flags) diff --git a/cmake/Modules/FindPyQt4.cmake b/cmake/Modules/FindPyQt4.cmake new file mode 100644 index 0000000..37f645e --- /dev/null +++ b/cmake/Modules/FindPyQt4.cmake @@ -0,0 +1,53 @@ +# Find PyQt4 +# ~~~~~~~~~~ +# Copyright (c) 2007-2008, Simon Edwards +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +# PyQt4 website: http://www.riverbankcomputing.co.uk/pyqt/index.php +# +# Find the installed version of PyQt4. FindPyQt4 should only be called after +# Python has been found. +# +# This file defines the following variables: +# +# PYQT4_VERSION - The version of PyQt4 found expressed as a 6 digit hex number +# suitable for comparision as a string +# +# PYQT4_VERSION_STR - The version of PyQt4 as a human readable string. +# +# PYQT4_VERSION_TAG - The PyQt version tag using by PyQt's sip files. +# +# PYQT4_SIP_DIR - The directory holding the PyQt4 .sip files. +# +# PYQT4_SIP_FLAGS - The SIP flags used to build PyQt. + +IF(EXISTS PYQT4_VERSION) + # Already in cache, be silent + SET(PYQT4_FOUND TRUE) +ELSE(EXISTS PYQT4_VERSION) + + FIND_FILE(_find_pyqt_py FindPyQt.py PATHS ${CMAKE_MODULE_PATH}) + + EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} ${_find_pyqt_py} OUTPUT_VARIABLE pyqt_config) + IF(pyqt_config) + STRING(REGEX REPLACE "^pyqt_version:([^\n]+).*$" "\\1" PYQT4_VERSION ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_version_str:([^\n]+).*$" "\\1" PYQT4_VERSION_STR ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_version_tag:([^\n]+).*$" "\\1" PYQT4_VERSION_TAG ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT4_SIP_DIR ${pyqt_config}) + STRING(REGEX REPLACE ".*\npyqt_sip_flags:([^\n]+).*$" "\\1" PYQT4_SIP_FLAGS ${pyqt_config}) + + SET(PYQT4_FOUND TRUE) + ENDIF(pyqt_config) + + IF(PYQT4_FOUND) + IF(NOT PYQT4_FIND_QUIETLY) + MESSAGE(STATUS "Found PyQt4 version: ${PYQT4_VERSION_STR}") + ENDIF(NOT PYQT4_FIND_QUIETLY) + ELSE(PYQT4_FOUND) + IF(PYQT4_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Python") + ENDIF(PYQT4_FIND_REQUIRED) + ENDIF(PYQT4_FOUND) + +ENDIF(EXISTS PYQT4_VERSION) diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt new file mode 100644 index 0000000..225791e --- /dev/null +++ b/res/CMakeLists.txt @@ -0,0 +1,64 @@ +# Copyright 2011 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +# Include python install macros +######################################################################## +include(GrPython) +if(NOT PYTHONINTERP_FOUND) + return() +endif() + +find_package(PyQt4) +if(NOT PYQT4_FOUND) + message(STATUS "PyQt4 not found, not installing GUI application") + return() +endif() + + +set(PYUIC4_COMPILE pyuic4) +set(RX_UI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/modes_rx.ui) +set(RX_UI_PY ${CMAKE_CURRENT_BINARY_DIR}/modes_rx_ui.py) + +add_custom_target(rx_ui ALL + DEPENDS ${RX_UI_PY} +) + +add_custom_command(OUTPUT ${RX_UI_PY} + COMMAND ${PYUIC4_COMPILE} ${RX_UI_SRC} > ${RX_UI_PY} + MAIN_DEPENDENCY ${RX_UI_SRC} +) + +######################################################################## +# Install python sources +######################################################################## +GR_PYTHON_INSTALL( + FILES + ${RX_UI_PY} + DESTINATION ${GR_PYTHON_DIR}/air_modes +) + +######################################################################## +# Handle the unit tests +######################################################################## +#include(GrTest) + +#set(GR_TEST_TARGET_DEPS gnuradio-gr-air-modes) +#set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig) +#GR_ADD_TEST(qa_gr-air-modes ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr-air-modes.py)