diff --git a/autotests/pythontest.py b/autotests/pythontest.py new file mode 100644 index 0000000..0c2b2df --- /dev/null +++ b/autotests/pythontest.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- + +import sys + +sys.path.append(sys.argv[1]) + +from PyQt5 import QtWidgets + +from PyKF5 import KCompletion + +def main(): + app = QtWidgets.QApplication(sys.argv) + + kc = KCompletion.KCompletion() + kc.insertItems(["Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday", "Sunday"]) + + kl = KCompletion.KLineEdit() + kl.setCompletionObject(kc) + kl.setCompletionMode(KCompletion.KCompletion.CompletionAuto) + + kl.makeCompletion("M") + assert(kl.text() == "Monday") + +if __name__ == '__main__': + sys.exit(main()) diff --git a/cmake/rules_PyKF5.py b/cmake/rules_PyKF5.py new file mode 100644 index 0000000..19c74e7 --- /dev/null +++ b/cmake/rules_PyKF5.py @@ -0,0 +1,53 @@ +# +# Copyright 2016 Stephen Kelly +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os, sys + +import rules_engine +sys.path.append(os.path.dirname(os.path.dirname(rules_engine.__file__))) +import Qt5Ruleset + +def _container_discard_base(container, sip, matcher): + sip["base_specifiers"] = "" + +def local_container_rules(): + return [ + [".*", "KCompletionMatches", ".*", ".*", ".*", _container_discard_base], + ] + +def local_function_rules(): + return [ + ["KCompletionBase", "keyBindingMap", ".*", ".*", ".*", rules_engine.function_discard], + ["KCompletionBase", "getKeyBindings", ".*", ".*", ".*", rules_engine.function_discard], + ["KCompletionBase", "setKeyBindingMap", ".*", ".*", ".*", rules_engine.function_discard], + ["KCompletionMatches", "KCompletionMatches", ".*", ".*", ".*KCompletionMatchesWrapper.*", rules_engine.function_discard], + ] + +class RuleSet(Qt5Ruleset.RuleSet): + def __init__(self): + Qt5Ruleset.RuleSet.__init__(self) + self._fn_db = rules_engine.FunctionRuleDb(lambda: local_function_rules() + Qt5Ruleset.function_rules()) + self._container_db = rules_engine.ContainerRuleDb(lambda: local_container_rules() + Qt5Ruleset.container_rules()) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11bc890..0e0f4b5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,59 +1,82 @@ ecm_create_qm_loader(kcompletion_QM_LOADER kcompletion5_qt) set(kcompletion_SRCS kcombobox.cpp kcompletion.cpp kcompletionbase.cpp kcompletionbox.cpp klineedit.cpp khistorycombobox.cpp kpixmapprovider.cpp kzoneallocator.cpp kcompletionbase.cpp kcompletionmatches.cpp ${kcompletion_QM_LOADER} ) add_library(KF5Completion ${kcompletion_SRCS}) generate_export_header(KF5Completion BASE_NAME KCompletion) add_library(KF5::Completion ALIAS KF5Completion) target_include_directories(KF5Completion INTERFACE "$") target_link_libraries(KF5Completion PUBLIC Qt5::Widgets PRIVATE KF5::ConfigCore # KConfigGroup, used in many places KF5::ConfigGui # KStandardShortcut KF5::WidgetsAddons # KCursor ) set_target_properties(KF5Completion PROPERTIES VERSION ${KCOMPLETION_VERSION_STRING} SOVERSION ${KCOMPLETION_SOVERSION} EXPORT_NAME Completion ) ecm_generate_headers(KCompletion_HEADERS HEADER_NAMES KComboBox KCompletion KCompletionBase KCompletionBox KLineEdit KHistoryComboBox KPixmapProvider KSortableList KCompletionMatches REQUIRED_HEADERS KCompletion_HEADERS ) +find_package(PythonModuleGeneration) + +if (PythonModuleGeneration_FOUND) + ecm_generate_python_binding( + TARGET KF5::Completion + PYTHONNAMESPACE PyKF5 + MODULENAME KCompletion + RULES_FILE "${CMAKE_SOURCE_DIR}/cmake/rules_PyKF5.py" + SIP_DEPENDS + QtWidgets/QtWidgetsmod.sip + HEADERS + kcombobox.h + kcompletion.h + kcompletionbase.h + kcompletionbox.h + klineedit.h + khistorycombobox.h + kpixmapprovider.h + ksortablelist.h + kcompletionmatches.h + ) +endif() + install(TARGETS KF5Completion EXPORT KF5CompletionTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kcompletion_export.h ${KCompletion_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KCompletion COMPONENT Devel ) include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KCompletion LIB_NAME KF5Completion DEPS "widgets" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KCompletion) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})