Create Python bidings
Added Cmake files Ported examples
This commit is contained in:
71
python/PyKDDockWidgets/CMakeLists.txt
Normal file
71
python/PyKDDockWidgets/CMakeLists.txt
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
# Auto-Genereate files every class will have his cpp/h files
|
||||
set(PyKDDockWidgets_SRC
|
||||
# individual classes
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_dockwidgetbase_wrapper.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_dockwidgetbase_wrapper.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_dockwidget_wrapper.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_dockwidget_wrapper.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_mainwindowbase_wrapper.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_mainwindowbase_wrapper.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_mainwindow_wrapper.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_mainwindow_wrapper.h
|
||||
# namespace wrapper
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_wrapper.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_wrapper.h
|
||||
# global module wrapper
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_module_wrapper.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_python.h
|
||||
)
|
||||
|
||||
# includes necessary to parse and build the classes specified on typesystem
|
||||
set(PyKDDockWidgets_include_paths
|
||||
$<JOIN:$<TARGET_PROPERTY:KDAB::kddockwidgets,INTERFACE_INCLUDE_DIRECTORIES>,${PATH_SEP}>
|
||||
)
|
||||
|
||||
# A list of paths where shiboken should look for typesystem
|
||||
set(PyKDDockWidgets_typesystem_paths
|
||||
# PySide path, this variable was exposed by FindPySide2.cmake
|
||||
${PYSIDE_TYPESYSTEMS}
|
||||
)
|
||||
|
||||
# Include flags/path that will be set in 'target_include_directories'
|
||||
set(PyKDDockWidgets_target_include_directories
|
||||
${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
|
||||
# Libraries that will be necessary to link the target, this will used in the command 'target_link_libraries'
|
||||
set(PyKDDockWidgets_target_link_libraries
|
||||
KDAB::kddockwidgets
|
||||
Qt5::Core
|
||||
Qt5::Gui
|
||||
Qt5::Widgets
|
||||
)
|
||||
|
||||
# changes on these files should trigger a new generation
|
||||
set(PyKDDockWidgets_DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kddockwidgets_global.h
|
||||
${CMAKE_SOURCE_DIR}/src/DockWidgetBase.h
|
||||
${CMAKE_SOURCE_DIR}/src/DockWidget.h
|
||||
${CMAKE_SOURCE_DIR}/src/MainWindowBase.h
|
||||
${CMAKE_SOURCE_DIR}/src/MainWindow.h
|
||||
)
|
||||
|
||||
CREATE_PYTHON_BINDINGS(
|
||||
"KDDockWidgets"
|
||||
"${PyKDDockWidgets_typesystem_paths}"
|
||||
"${PyKDDockWidgets_include_paths}"
|
||||
"${PyKDDockWidgets_SRC}"
|
||||
"${PyKDDockWidgets_target_include_directories}"
|
||||
"${PyKDDockWidgets_target_link_libraries}"
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kddockwidgets_global.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/typesystem_kddockwidgets.xml
|
||||
"${PyKDDockWidgets_DEPENDS}"
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Make moduled import from build dir works
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py)
|
||||
|
||||
# install
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py DESTINATION ${Python3_SITELIB}/PyKDDockWidgets)
|
||||
14
python/PyKDDockWidgets/__init__.py
Normal file
14
python/PyKDDockWidgets/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
__all__ = ['KDDockWidgets']
|
||||
|
||||
# Preload PySide2 libraries to avoid missing libraries while loading KDDockWidgets
|
||||
try:
|
||||
from PySide2 import QtCore
|
||||
except Exception:
|
||||
print("Failed to lod PySide")
|
||||
raise
|
||||
|
||||
# avoid duplicate namespace, due the PYSIDE-1325 bug I will have my package like this
|
||||
# PyKDDockWidgets.KDDockWidgets.KDDockWidgets.MainWindow
|
||||
# To avoid this I add a WORKAROUND to reduce it
|
||||
from .KDDockWidgets import KDDockWidgets as _priv
|
||||
KDDockWidgets = _priv
|
||||
13
python/PyKDDockWidgets/kddockwidgets_global.h
Normal file
13
python/PyKDDockWidgets/kddockwidgets_global.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// Make "signals:", "slots:" visible as access specifiers
|
||||
#define QT_ANNOTATE_ACCESS_SPECIFIER(a) __attribute__((annotate(#a)))
|
||||
|
||||
// Define PYTHON_BINDINGS this will be used in some part of c++ to skip problematic parts
|
||||
#define PYTHON_BINDINGS
|
||||
|
||||
#include <MainWindowBase.h>
|
||||
#include <MainWindow.h>
|
||||
#include <DockWidgetBase.h>
|
||||
#include <DockWidget.h>
|
||||
|
||||
39
python/PyKDDockWidgets/typesystem_kddockwidgets.xml
Normal file
39
python/PyKDDockWidgets/typesystem_kddockwidgets.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- The package name -->
|
||||
<typesystem package="KDDockWidgets">
|
||||
<!-- Pre-defined typesystem that contains types used by our class
|
||||
PySide has one typesystem for each module, here we use only the widgets
|
||||
typesystem because it already include gui and core typesystem -->
|
||||
<load-typesystem name="typesystem_widgets.xml" generate="no"/>
|
||||
|
||||
<!-- Our classes are declared in a namespace, so we should define this -->
|
||||
<namespace-type name="KDDockWidgets">
|
||||
<!-- this is used in a public virtual pure function we need to declare it
|
||||
otherwise shiboken will ignore the function and will fail to create a wrapper -->
|
||||
<primitive-type name="DropAreaWithCentralFrame"/>
|
||||
|
||||
<!-- Some plublic enum and flags -->
|
||||
<enum-type name="Location"/>
|
||||
<enum-type name="MainWindowOption" flags="MainWindowOptions"/>
|
||||
<enum-type name="AddingOption"/>
|
||||
<enum-type name="RestoreOption" flags="RestoreOptions"/>
|
||||
<enum-type name="DefaultSizeMode"/>
|
||||
<enum-type name="FrameOption" flags="FrameOptions"/>
|
||||
|
||||
<!-- our classes
|
||||
For class we can use two types:
|
||||
object-type: class that does not have a copy-contructor and can not be passed as value to functions;
|
||||
value-type: class that can be passed as value for functions
|
||||
Here we only use 'object-type' since all our classes are derived from QWidget
|
||||
-->
|
||||
<object-type name="MainWindowBase" />
|
||||
<object-type name="MainWindow" />
|
||||
<object-type name="DockWidgetBase" >
|
||||
<!-- this class contains a internal enum, so it should be declared
|
||||
inside of the object-type -->
|
||||
<enum-type name="Option" flags="Options" />
|
||||
</object-type>
|
||||
|
||||
<object-type name="DockWidget" />
|
||||
</namespace-type>
|
||||
</typesystem>
|
||||
Reference in New Issue
Block a user