Skip to content

Commit 9136f1a

Browse files
committed
Wrap KRunner API and pass match to subobj
1 parent 04a97b7 commit 9136f1a

17 files changed

+2219
-128
lines changed

CMakeLists.txt

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
cmake_minimum_required(VERSION 3.6)
22

3-
project(pyrunner)
3+
project(python-runner)
44

55
find_package(ECM 0.0.11 REQUIRED NO_MODULE)
66
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
77

88
include(KDEInstallDirs)
99
include(KDECMakeSettings)
10-
# include(KDECompilerSettings)
1110
include(FeatureSummary)
1211

1312
find_package(Qt5 REQUIRED COMPONENTS Widgets)
1413
find_package(KF5 REQUIRED COMPONENTS CoreAddons Solid KIO Runner I18n)
1514

1615
find_package(PythonLibs 3.5 REQUIRED)
16+
find_program(PYTHON "python" REQUIRED)
1717
include_directories(${PYTHON_INCLUDE_DIRS})
1818

1919
find_package(Boost COMPONENTS python3 REQUIRED)
2020
include_directories(${Boost_INCLUDE_DIR})
2121

2222
add_definitions(-DQT_NO_KEYWORDS)
23+
add_definitions(-DNDEBUG)
24+
include(CheckCXXCompilerFlag)
2325

24-
include_directories(src)
25-
26-
set(example_SRCS src/pyrunner.cpp)
27-
28-
add_library(plasma_runner_pyrunner MODULE ${example_SRCS})
29-
target_link_libraries(plasma_runner_pyrunner KF5::Runner KF5::KIOCore KF5::KIOWidgets KF5::I18n KF5::CoreAddons)
30-
target_link_libraries(plasma_runner_pyrunner Qt5::Widgets)
31-
target_link_libraries(plasma_runner_pyrunner ${Boost_LIBRARIES})
32-
target_link_libraries(plasma_runner_pyrunner ${PYTHON_LIBRARIES})
26+
# http://stackoverflow.com/a/33266748/3946766
27+
function(enable_cxx_compiler_flag_if_supported flag)
28+
string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set)
29+
if(flag_already_set EQUAL -1)
30+
check_cxx_compiler_flag("${flag}" flag_supported)
31+
if(flag_supported)
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
33+
endif()
34+
endif()
35+
endfunction()
3336

37+
enable_cxx_compiler_flag_if_supported("-Wall")
38+
enable_cxx_compiler_flag_if_supported("-Wextra")
39+
enable_cxx_compiler_flag_if_supported("-pedantic")
3440

3541
# https://github.com/lxde/lxqt-qtplugin/blob/master/src/CMakeLists.txt
3642
get_target_property(QT_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE} IMPORTED_LOCATION)
@@ -49,12 +55,40 @@ else()
4955
message(FATAL_ERROR "Qt5 plugin directory cannot be detected.")
5056
endif()
5157

58+
set(SETUP_PY ${CMAKE_CURRENT_SOURCE_DIR}/setup.py)
59+
60+
execute_process(COMMAND ${PYTHON}-config --ldflags
61+
OUTPUT_VARIABLE PYTHON_LDFLAGS
62+
OUTPUT_STRIP_TRAILING_WHITESPACE
63+
ERROR_QUIET)
64+
string(STRIP "${PYTHON_LDFLAGS}" PYTHON_LDFLAGS)
65+
66+
67+
add_custom_target(sip_krunner DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.py)
68+
add_custom_command(TARGET sip_krunner
69+
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/sip_krunnerpart0.cpp ${CMAKE_CURRENT_BINARY_DIR}/sipAPI_krunner.cpp
70+
PRE_BUILD
71+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.py
72+
COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/config.py)
73+
74+
add_library(plasma_runner_python MODULE src/python-krunner.cpp ${CMAKE_CURRENT_BINARY_DIR}/sip_krunnerpart0.cpp)
75+
add_dependencies(plasma_runner_python sip_krunner)
76+
target_link_libraries(plasma_runner_python KF5::Runner KF5::KIOCore KF5::KIOWidgets KF5::I18n KF5::CoreAddons)
77+
target_link_libraries(plasma_runner_python Qt5::Widgets)
78+
target_link_libraries(plasma_runner_python ${Boost_LIBRARIES})
79+
target_link_libraries(plasma_runner_python ${PYTHON_LDFLAGS})
80+
81+
add_custom_target(link_target ALL COMMAND ${CMAKE_COMMAND} -E create_symlink plasma_runner_python.so _krunner.so)
82+
add_dependencies(link_target plasma_runner_python)
5283

5384
# Install the library and .desktop file
54-
install(TARGETS plasma_runner_pyrunner DESTINATION ${QT_PLUGINS_DIR})
85+
# TODO make the qt plugin a symlink
86+
install(TARGETS plasma_runner_python DESTINATION ${QT_PLUGINS_DIR})
5587
install(FILES plasma-runner-pyrunner-a.desktop DESTINATION ${SERVICES_INSTALL_DIR})
5688
install(FILES plasma-runner-pyrunner-b.desktop DESTINATION ${SERVICES_INSTALL_DIR})
57-
#
89+
90+
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)")
91+
5892
# get_cmake_property(_variableNames VARIABLES)
5993
# foreach (_variableName ${_variableNames})
6094
# message(STATUS "${_variableName}=${${_variableName}}")

a.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
class Runner:
2-
name = "hello from a"
1+
import krunner
2+
3+
4+
class Runner(krunner.AbstractRunner):
5+
def match(self, context):
6+
m = krunner.QueryMatch(self)
7+
m.setText("Hello from a " + context.query())
8+
m.setIconName("text-x-python")
9+
context.addMatch(m)

b.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
class Runner:
2-
name = "hello from b"
1+
import krunner
2+
3+
4+
class Runner(krunner.AbstractRunner):
5+
def match(self, context):
6+
m = krunner.QueryMatch(self)
7+
m.setText("Hello from b")
8+
m.setIconName("text-x-python")
9+
context.addMatch(m)

0 commit comments

Comments
 (0)