First Commit

This commit is contained in:
2025-11-18 14:18:26 -07:00
parent 33eb6e3707
commit 27277ec342
6106 changed files with 3571167 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
set(PYTHON_BINDING_NAMESPACE "PyKDDockWidgets")
# Just to fix warnings with --warn-uninitialized
if(NOT DEFINED SHIBOKEN_CUSTOM_PREFIX) # look for shiboken in a custom location
set(SHIBOKEN_CUSTOM_PREFIX "")
endif()
if(NOT DEFINED PYSIDE_CUSTOM_PREFIX) # look for pyside in a custom location
set(PYSIDE_CUSTOM_PREFIX "")
endif()
if(${PROJECT_NAME}_QT6)
set(PYSIDE_MAJOR_VERSION "6")
set(PYTHON_BINDING_NAMESPACE "${PYTHON_BINDING_NAMESPACE}Qt${PYSIDE_MAJOR_VERSION}")
set(QtWidgets_VERSION ${Qt6Widgets_VERSION})
else()
set(PYSIDE_MAJOR_VERSION "2")
set(QtWidgets_VERSION ${Qt5Widgets_VERSION})
endif()
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development)
find_package(Shiboken${PYSIDE_MAJOR_VERSION} REQUIRED)
find_package(PySide${PYSIDE_MAJOR_VERSION} ${QtWidgets_VERSION} EXACT REQUIRED)
if(NOT ${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX)
# cmake-lint: disable=C0103
set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX
${INSTALL_LIBRARY_DIR}
CACHE FILEPATH "Custom path to install python bindings."
)
endif()
if(NOT WIN32)
set(Python3_VERSION_MAJORMINOR "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}")
set(BINDINGS_DIR "python${Python3_VERSION_MAJORMINOR}/site-packages/${PYTHON_BINDING_NAMESPACE}")
else()
set(BINDINGS_DIR "site-packages/${PYTHON_BINDING_NAMESPACE}")
endif()
set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX "${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}/${BINDINGS_DIR}")
include(KDPySide${PYSIDE_MAJOR_VERSION}ModuleBuild)
add_subdirectory(PyKDDockWidgets)
if(${PROJECT_NAME}_TESTS)
add_subdirectory(tests)
endif()

View File

@@ -0,0 +1,83 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
# Auto-Genereate files every class will have his cpp/h files
set(PyKDDockWidgets_SRC
# individual classes
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_config_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_config_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_core_dockwidgetviewinterface_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_core_dockwidgetviewinterface_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_core_mainwindowviewinterface_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_core_mainwindowviewinterface_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_initialoption_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_initialoption_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_layoutsaver_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_layoutsaver_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_qtwidgets_dockwidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_qtwidgets_dockwidget_wrapper.h
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_qtwidgets_mainwindow_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_qtwidgets_mainwindow_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}/src)
# 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 Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets ${Python3_LIBRARIES}
)
# changes on these files should trigger a new generation
set(PyKDDockWidgets_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/kddockwidgets_global.h ${CMAKE_SOURCE_DIR}/src/qtwidgets/views/MainWindow.h
${CMAKE_SOURCE_DIR}/src/qtwidgets/views/DockWidget.h ${CMAKE_SOURCE_DIR}/src/Config.h
${CMAKE_SOURCE_DIR}/src/LayoutSaver.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 module import from build dir work
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.cmake ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY)
# install
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py $<TARGET_FILE:KDAB::kddockwidgets>
DESTINATION ${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}
)
if(NOT WIN32)
install(FILES $<TARGET_LINKER_FILE:KDAB::kddockwidgets> $<TARGET_SONAME_FILE:KDAB::kddockwidgets>
DESTINATION ${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}
)
endif()

View File

@@ -0,0 +1,47 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
import sys
import os
__all__ = ['KDDockWidgets']
def setupLibraryPath():
if sys.platform != 'win32':
return
if "@PYSIDE_MAJOR_VERSION@" == "6":
from shiboken@PYSIDE_MAJOR_VERSION@ import Shiboken
else:
from shiboken@PYSIDE_MAJOR_VERSION@ import shiboken@PYSIDE_MAJOR_VERSION@ as Shiboken
from PySide@PYSIDE_MAJOR_VERSION@ import QtCore
extra_dll_dirs = [ os.path.abspath(os.path.dirname(Shiboken.__file__)),
os.path.abspath(os.path.dirname(QtCore.__file__)),
os.path.abspath(os.path.dirname(__file__)) ]
if sys.version_info[0] == 3 and sys.version_info[1] >= 8:
for dll_dir in extra_dll_dirs:
os.add_dll_directory(dll_dir)
for dll_dir in extra_dll_dirs:
os.environ['PATH'] = os.fspath(dll_dir) + os.pathsep + os.environ['PATH']
# Preload PySide libraries to avoid missing libraries while loading KDDockWidgets
try:
from PySide@PYSIDE_MAJOR_VERSION@ import QtCore
# Create a alias for PySide module so we can use a single import in source files
import PySide@PYSIDE_MAJOR_VERSION@
sys.modules["PySide"] = PySide@PYSIDE_MAJOR_VERSION@
except Exception:
print("Failed to load PySide")
raise
setupLibraryPath()

View File

@@ -0,0 +1,35 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#pragma once
// We only support Qt backend
#define KDDW_FRONTEND_QT 1
#define KDDW_FRONTEND_QTWIDGETS 1
// 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
#ifndef QT_WIDGETS_LIB
#define QT_WIDGETS_LIB
#endif
#include <kddockwidgets/KDDockWidgets.h>
#include <kddockwidgets/LayoutSaver.h>
#include <kddockwidgets/Config.h>
#include <kddockwidgets/core/views/MainWindowViewInterface.h>
#include <kddockwidgets/core/views/DockWidgetViewInterface.h>
#include <kddockwidgets/qtwidgets/views/MainWindow.h>
#include <kddockwidgets/qtwidgets/views/DockWidget.h>
#include <kddockwidgets/qtcommon/View.h>

View File

@@ -0,0 +1,88 @@
<?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" />
<rejection class="KDDockWidgets" function-name="qt_getEnumName" />
<rejection class="KDDockWidgets" function-name="qt_getEnumMetaObject" />
<rejection class="KDDockWidgets" function-name="qt_getEnumName" />
<!-- Our classes are declared in a namespace, so we should define this -->
<namespace-type name="KDDockWidgets" visible="no">
<!-- 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="DropArea" />
<primitive-type name="SideBar" />
<!-- Some plublic enum and flags -->
<enum-type name="Location"/>
<enum-type name="MainWindowOption" flags="MainWindowOptions" />
<enum-type name="DockWidgetOption" flags="DockWidgetOptions" />
<enum-type name="LayoutSaverOption" flags="LayoutSaverOptions" />
<enum-type name="IconPlace" flags="IconPlaces" />
<enum-type name="FrontendType" />
<enum-type name="InitialVisibilityOption" />
<enum-type name="RestoreOption" flags="RestoreOptions" />
<enum-type name="DropIndicatorType" />
<enum-type name="SizePolicy" />
<enum-type name="SideBarLocation" />
<enum-type name="TitleBarButtonType" />
<enum-type name="DropLocation" />
<enum-type name="DropIndicatorType" />
<enum-type name="AddingOption" />
<enum-type name="WindowState" flags="WindowStates" />
<!-- Internal - just to avoid generation warning -->
<enum-type name="SuggestedGeometryHint" flags="SuggestedGeometryHints" />
<enum-type name="CursorPosition" flags="CursorPositions" />
<enum-type name="FrameOption" flags="FrameOptions" />
<enum-type name="StackOption" flags="StackOptions" />
<enum-type name="FloatingWindowFlag" flags="FloatingWindowFlags" />
<enum-type name="FloatingWindowFlag" flags="FloatingWindowFlags" />
<enum-type name="DefaultSizeMode" />
<!-- 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
-->
<value-type name="InitialOption">
<include file-name="kddockwidgets/KDDockWidgets.h" location="global"/>
</value-type>
<object-type name="LayoutSaver">
<include file-name="kddockwidgets/LayoutSaver.h" location="global"/>
</object-type>
<object-type name="Config">
<include file-name="kddockwidgets/Config.h" location="global"/>
<enum-type name="Flag" flags="Flags" />
<enum-type name="CustomizableWidget" flags="CustomizableWidgets" />
<enum-type name="InternalFlag" flags="InternalFlags" />
</object-type>
<namespace-type name="Core" visible="no">
<enum-type name="ViewType" />
<object-type name="DockWidgetViewInterface" >
<include file-name="kddockwidgets/core/views/DockWidgetViewInterface.h" location="global"/>
</object-type>
<object-type name="MainWindowViewInterface">
<include file-name="kddockwidgets/core/views/MainWindowViewInterface.h" location="global"/>
<modify-function signature="addDockWidget(KDDockWidgets::Core::DockWidgetViewInterface*,KDDockWidgets::Location,KDDockWidgets::Core::DockWidgetViewInterface*,KDDockWidgets::InitialOption)" rename="addKDockWidget" />
</object-type>
</namespace-type>
<namespace-type name="QtWidgets" visible="no">
<object-type name="MainWindow">
<include file-name="kddockwidgets/qtwidgets/views/MainWindow.h" location="global"/>
</object-type>
<object-type name="DockWidget">
<include file-name="kddockwidgets/qtwidgets/views/DockWidget.h" location="global"/>
</object-type>
</namespace-type>
</namespace-type>
</typesystem>

View File

@@ -0,0 +1,55 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
from PySide6 import QtWidgets, QtGui, QtCore
# pylint: disable=too-few-public-methods
class MyWidget(QtWidgets.QWidget):
s_images = {}
def __init__(self, backgroundFile="", logoFile="", parent=None):
super().__init__(parent)
self.background = self._lookupImage(backgroundFile)
self.logo = self._lookupImage(logoFile)
# pylint: disable=no-self-use
def _lookupImage(self, imageName):
if imageName == "":
return None
if imageName not in MyWidget.s_images:
MyWidget.s_images[imageName] = QtGui.QImage(imageName)
return MyWidget.s_images[imageName]
def drawLogo(self, p):
if not self.logo:
return
ratio = self.logo.height() / (self.logo.width() * 1.0)
maxWidth = int(0.80 * self.size().width())
maxHeight = int(0.80 * self.size().height())
proposedHeight = int(maxWidth * ratio)
if proposedHeight <= maxHeight:
width = maxWidth
else:
width = int(maxHeight / ratio)
height = int(width * ratio)
targetLogoRect = QtCore.QRect(0, 0, width, height)
targetLogoRect.moveCenter(self.rect().center(
) + QtCore.QPoint(0, -int(self.size().height() * 0.00)))
p.drawImage(targetLogoRect, self.logo, self.logo.rect())

View File

@@ -0,0 +1,11 @@
Running python example
======================
Generate resource file with:
~# rcc -g python -o rc_assets.py ../../examples/dockwidgets/resources_example.qrc
(on some systems, rcc might be invoked as rcc-qt6)
Make sure you installed kddockwidgets and set PYTHONPATH accordingly.
Run the app:
~# python3 main.py

View File

@@ -0,0 +1,86 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
''' KDDockWidgets example (Qt6) '''
import sys
from PySide6 import QtWidgets, QtCore
# pylint: disable=no-name-in-module
from PyKDDockWidgets import KDDockWidgets
from MyWidget import MyWidget
try:
# pylint: disable=unused-import
import rc_assets
except ImportError:
sys.exit(
'''
Oops.. rc_assets needs to be generated first.
Please run:
rcc -g python -o rc_assets.py ../../examples/dockwidgets/resources_example.qrc
(Make sure to use the rcc from the Qt6 version used to generate the bindings!)
On some systems rcc might be invoked as rcc-qt6.
'''
)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
app.setOrganizationName("KDAB")
app.setApplicationName("Test app")
KDDockWidgets.initFrontend(KDDockWidgets.FrontendType.QtWidgets)
app.setStyle(QtWidgets.QStyleFactory.create("Fusion"))
# 1. Create our main window
mainWindow = KDDockWidgets.MainWindow("MyMainWindow")
mainWindow.setWindowTitle("Main Window")
mainWindow.resize(1200, 1200)
mainWindow.show()
# 2. Create a dock widget, it needs a unique name
dock1 = KDDockWidgets.DockWidget("MyDock1")
widget1 = MyWidget("", "")
dock1.setWidget(widget1)
dock2 = KDDockWidgets.DockWidget("MyDock2")
widget2 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock2.setWidget(widget2)
dock3 = KDDockWidgets.DockWidget("MyDock3")
widget3 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock3.setWidget(widget3)
dock4 = KDDockWidgets.DockWidget("MyDock4")
widget4 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock4.setWidget(widget4)
dock5 = KDDockWidgets.DockWidget("MyDock5")
widget5 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock5.setWidget(widget5)
# 3. Add them to the main window
mainWindow.addKDockWidget(dock1, KDDockWidgets.Location.Location_OnLeft)
mainWindow.addKDockWidget(dock2, KDDockWidgets.Location.Location_OnTop)
# 4. Add dock3 to the right of dock2
mainWindow.addKDockWidget(dock3, KDDockWidgets.Location.Location_OnRight, dock2)
# 5. dock4 is docked at the bottom, with 200px height
preferredSize = QtCore.QSize(0, 200)
mainWindow.addKDockWidget(dock4, KDDockWidgets.Location.Location_OnBottom, None, preferredSize)
# 5. dock5 will be its own top level (floating window)
dock5.open()
app.exec()

View File

@@ -0,0 +1,56 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
from PySide2 import QtWidgets, QtGui, QtCore
# pylint: disable=too-few-public-methods
class MyWidget(QtWidgets.QWidget):
s_images = {}
def __init__(self, backgroundFile="", logoFile="", parent=None):
super().__init__(parent)
self.background = self._lookupImage(backgroundFile)
self.logo = self._lookupImage(logoFile)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
# pylint: disable=no-self-use
def _lookupImage(self, imageName):
if imageName == "":
return None
if imageName not in MyWidget.s_images:
MyWidget.s_images[imageName] = QtGui.QImage(imageName)
return MyWidget.s_images[imageName]
def drawLogo(self, p):
if not self.logo:
return
ratio = self.logo.height() / (self.logo.width() * 1.0)
maxWidth = int(0.80 * self.size().width())
maxHeight = int(0.80 * self.size().height())
proposedHeight = int(maxWidth * ratio)
if proposedHeight <= maxHeight:
width = maxWidth
else:
width = int(maxHeight / ratio)
height = int(width * ratio)
targetLogoRect = QtCore.QRect(0, 0, width, height)
targetLogoRect.moveCenter(self.rect().center(
) + QtCore.QPoint(0, -int(self.size().height() * 0.00)))
p.drawImage(targetLogoRect, self.logo, self.logo.rect())

View File

@@ -0,0 +1,11 @@
Running python example
======================
Generate resource file with:
~# rcc -g python -o rc_assets.py ../../examples/dockwidgets/resources_example.qrc
(on some systems, rcc might be invoked as rcc-qt5)
Make sure you installed kddockwidgets and set PYTHONPATH accordingly.
Run the app:
~# python3 main.py

View File

@@ -0,0 +1,87 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
''' KDDockWidgets example (Qt5) '''
import sys
from PySide2 import QtWidgets, QtCore
# pylint: disable=no-name-in-module
from PyKDDockWidgets import KDDockWidgets
from MyWidget import MyWidget
try:
# pylint: disable=unused-import
import rc_assets
except ImportError:
sys.exit(
'''
Oops.. rc_assets needs to be generated first.
Please run:
rcc -g python -o rc_assets.py ../../examples/dockwidgets/resources_example.qrc
(Make sure to use the rcc from the Qt5 version used to generate the bindings!)
On some systems rcc might be invoked as rcc-qt5.
'''
)
if __name__ == "__main__":
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
app = QtWidgets.QApplication(sys.argv)
app.setOrganizationName("KDAB")
app.setApplicationName("Test app")
KDDockWidgets.initFrontend(KDDockWidgets.FrontendType.QtWidgets)
app.setStyle(QtWidgets.QStyleFactory.create("Fusion"))
# 1. Create our main window
mainWindow = KDDockWidgets.MainWindow("MyMainWindow")
mainWindow.setWindowTitle("Main Window")
mainWindow.resize(1200, 1200)
mainWindow.show()
# 2. Create a dock widget, it needs a unique name
dock1 = KDDockWidgets.DockWidget("MyDock1")
widget1 = MyWidget("", "")
dock1.setWidget(widget1)
dock2 = KDDockWidgets.DockWidget("MyDock2")
widget2 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock2.setWidget(widget2)
dock3 = KDDockWidgets.DockWidget("MyDock3")
widget3 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock3.setWidget(widget3)
dock4 = KDDockWidgets.DockWidget("MyDock4")
widget4 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock4.setWidget(widget4)
dock5 = KDDockWidgets.DockWidget("MyDock5")
widget5 = MyWidget(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png")
dock5.setWidget(widget5)
# 3. Add them to the main window
mainWindow.addKDockWidget(dock1, KDDockWidgets.Location.Location_OnLeft)
mainWindow.addKDockWidget(dock2, KDDockWidgets.Location.Location_OnTop)
# 4. Add dock3 to the right of dock2
mainWindow.addKDockWidget(dock3, KDDockWidgets.Location.Location_OnRight, dock2)
# 5. dock4 is docked at the bottom, with 200px height
preferredSize = QtCore.QSize(0, 200)
mainWindow.addKDockWidget(dock4, KDDockWidgets.Location.Location_OnBottom, None, preferredSize)
# 5. dock5 will be its own top level (floating window)
dock5.open()
app.exec_()

View File

@@ -0,0 +1,35 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo Oliveira Filho <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.py.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.py @ONLY)
set(TEST_PYTHONPATH ${CMAKE_BINARY_DIR}/python ${CMAKE_CURRENT_BINARY_DIR})
set(TEST_LIBRARYPATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
if(WIN32)
set(TEST_LIBRARY_VAR "PATH")
string(REPLACE "\\" "/" TEST_PYTHONPATH "${TEST_PYTHONPATH}")
string(REPLACE "\\" "/" TEST_LIBRARYPATH "${TEST_LIBRARYPATH}")
list(JOIN TEST_PYTHONPATH "\\;" TEST_PYTHONPATH)
list(JOIN TEST_LIBRARYPATH "\\;" TEST_LIBRARYPATH)
else()
set(TEST_LIBRARY_VAR "LD_LIBRARY_PATH")
list(JOIN TEST_PYTHONPATH ":" TEST_PYTHONPATH)
list(JOIN TEST_LIBRARYPATH ":" TEST_LIBRARYPATH)
endif()
set(PYTHON_ENV_COMMON "PYTHONPATH=${TEST_PYTHONPATH};${TEST_LIBRARY_VAR}=${TEST_LIBRARYPATH}")
file(GLOB TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tst_*.py)
foreach(test_file ${TEST_FILES})
get_filename_component(test_name ${test_file} NAME_WE)
add_test(${test_name} ${Python3_EXECUTABLE} ${test_file})
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "${PYTHON_ENV_COMMON}")
endforeach()

View File

@@ -0,0 +1,19 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
import os
import sys
class TstConfig(object):
bindingsNamespace = "PyKDDockWidgets"
def initLibraryPath():
if sys.platform == 'win32' and sys.version_info[0] == 3 and sys.version_info[1] >= 8:
os.add_dll_directory("@CMAKE_RUNTIME_OUTPUT_DIRECTORY@")

View File

@@ -0,0 +1,34 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
# Author: Renato Araujo <renato.araujo@kdab.com>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <info@kdab.com> for commercial licensing options.
#
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
import unittest
import importlib
import inspect
from config import TstConfig
class TestImportModules(unittest.TestCase):
def test_importModules(self):
m = importlib.import_module(TstConfig.bindingsNamespace + '.KDDockWidgets')
moduleSymbols = []
for t in inspect.getmembers(m):
moduleSymbols.append(t[0])
symbols = ['MainWindow', 'DockWidget']
for symbol in symbols:
self.assertIn(symbol, moduleSymbols)
if __name__ == '__main__':
TstConfig.initLibraryPath()
unittest.main()