Merge branch 'master' into 2.0
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# This file is part of KDDockWidgets.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2022 Klarälvdalens Datakonsult AB, a KDAB Group
|
||||
# company <info@kdab.com> Author: Renato Araujo Oliveira Filho
|
||||
# <renato.araujo@kdab.com>
|
||||
# SPDX-FileCopyrightText: 2020-2022 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
|
||||
#
|
||||
@@ -13,20 +12,19 @@ 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 "")
|
||||
set(SHIBOKEN_CUSTOM_PREFIX "")
|
||||
endif()
|
||||
if(NOT DEFINED PYSIDE_CUSTOM_PREFIX) # look for pyside in a custom location
|
||||
set(PYSIDE_CUSTOM_PREFIX "")
|
||||
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})
|
||||
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})
|
||||
set(PYSIDE_MAJOR_VERSION "2")
|
||||
set(QtWidgets_VERSION ${Qt5Widgets_VERSION})
|
||||
endif()
|
||||
|
||||
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development)
|
||||
@@ -34,16 +32,14 @@ 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)
|
||||
set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||
set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
||||
endif()
|
||||
set(BINDINGS_DIR
|
||||
"${INSTALL_LIBRARY_DIR}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/${PYTHON_BINDING_NAMESPACE}"
|
||||
)
|
||||
set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX
|
||||
"${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}/${BINDINGS_DIR}")
|
||||
set(Python3_VERSION_MAJORMIONR "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}")
|
||||
set(BINDINGS_DIR "${INSTALL_LIBRARY_DIR}/python${Python3_VERSION_MAJORMINOR}/site-packages/${PYTHON_BINDING_NAMESPACE}")
|
||||
set(${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX "${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}/${BINDINGS_DIR}")
|
||||
|
||||
include(PySide${PYSIDE_MAJOR_VERSION}ModuleBuild)
|
||||
add_subdirectory(PyKDDockWidgets)
|
||||
if(${PROJECT_NAME}_TESTS)
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#
|
||||
# This file is part of KDDockWidgets.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2022 Klarälvdalens Datakonsult AB, a KDAB Group
|
||||
# company <info@kdab.com> Author: Renato Araujo Oliveira Filho
|
||||
# <renato.araujo@kdab.com>
|
||||
# SPDX-FileCopyrightText: 2020-2022 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
|
||||
#
|
||||
@@ -27,7 +26,8 @@ set(PyKDDockWidgets_SRC
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_layoutsaver_wrapper.h
|
||||
# global module wrapper
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_module_wrapper.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_python.h)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/KDDockWidgets/kddockwidgets_python.h
|
||||
)
|
||||
|
||||
# includes necessary to parse and build the classes specified on typesystem
|
||||
set(PyKDDockWidgets_include_paths
|
||||
@@ -37,48 +37,46 @@ set(PyKDDockWidgets_include_paths
|
||||
# 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})
|
||||
|
||||
${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})
|
||||
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/DockWidget.h
|
||||
${CMAKE_SOURCE_DIR}/src/DockWidget.h
|
||||
${CMAKE_SOURCE_DIR}/src/MainWindow.h
|
||||
${CMAKE_SOURCE_DIR}/src/MainWindow.h
|
||||
${CMAKE_SOURCE_DIR}/src/LayoutSaver.h)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kddockwidgets_global.h ${CMAKE_SOURCE_DIR}/src/DockWidget.h
|
||||
${CMAKE_SOURCE_DIR}/src/DockWidget.h ${CMAKE_SOURCE_DIR}/src/MainWindow.h ${CMAKE_SOURCE_DIR}/src/MainWindow.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})
|
||||
"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)
|
||||
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})
|
||||
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})
|
||||
install(FILES $<TARGET_LINKER_FILE:KDAB::kddockwidgets> $<TARGET_SONAME_FILE:KDAB::kddockwidgets>
|
||||
DESTINATION ${${PROJECT_NAME}_PYTHON_BINDINGS_INSTALL_PREFIX}
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
# pylint: disable=missing-module-docstring,missing-function-docstring,missing-class-docstring
|
||||
|
||||
from PyKDDockWidgetsQt6 import KDDockWidgets
|
||||
|
||||
from PySide6 import QtCore, QtWidgets, QtGui
|
||||
@@ -17,33 +19,41 @@ from MyWidget1 import MyWidget1
|
||||
from MyWidget2 import MyWidget2
|
||||
from MyWidget3 import MyWidget3
|
||||
|
||||
def newMyWidget(parent = None):
|
||||
|
||||
def newMyWidget(parent=None):
|
||||
randomNumber = QtCore.QRandomGenerator.global_().bounded(0, 100) + 1
|
||||
if (randomNumber < 50):
|
||||
if (randomNumber < 33):
|
||||
if randomNumber < 50:
|
||||
if randomNumber < 33:
|
||||
return MyWidget1(parent)
|
||||
else:
|
||||
return MyWidget3(parent)
|
||||
else:
|
||||
return MyWidget2(parent)
|
||||
return MyWidget3(parent)
|
||||
return MyWidget2(parent)
|
||||
|
||||
|
||||
class MyMainWindow(KDDockWidgets.MainWindow):
|
||||
s_count = 0
|
||||
s_menuCount = 0
|
||||
|
||||
def __init__(self, uniqueName, options = KDDockWidgets.MainWindowOption_None, dockWidget0IsNonClosable = False, nonDockableDockWidget9 = False, restoreIsRelative = False, maxSizeForDockWidget8 = False, affinityName = "", parent = None):
|
||||
def __init__(self,
|
||||
uniqueName,
|
||||
options=KDDockWidgets.MainWindowOption_None,
|
||||
dockWidget0IsNonClosable=False,
|
||||
nonDockableDockWidget9=False,
|
||||
restoreIsRelative=False,
|
||||
maxSizeForDockWidget8=False,
|
||||
affinityName="",
|
||||
parent=None):
|
||||
super().__init__(uniqueName, options, parent)
|
||||
self.m_dockWidget0IsNonClosable = dockWidget0IsNonClosable
|
||||
self.m_dockWidget9IsNonDockable = nonDockableDockWidget9
|
||||
self.m_restoreIsRelative = restoreIsRelative
|
||||
self.m_maxSizeForDockWidget8 = maxSizeForDockWidget8
|
||||
self.m_dockwidgets = []
|
||||
|
||||
self.dockWidget0IsNonClosable = dockWidget0IsNonClosable
|
||||
self.dockWidget9IsNonDockable = nonDockableDockWidget9
|
||||
self.restoreIsRelative = restoreIsRelative
|
||||
self.maxSizeForDockWidget8 = maxSizeForDockWidget8
|
||||
self.dockwidgets = []
|
||||
|
||||
menubar = self.menuBar()
|
||||
fileMenu = QtWidgets.QMenu("File")
|
||||
self.m_toggleMenu = QtWidgets.QMenu("Toggle")
|
||||
self.toggleMenu = QtWidgets.QMenu("Toggle")
|
||||
menubar.addMenu(fileMenu)
|
||||
menubar.addMenu(self.m_toggleMenu)
|
||||
menubar.addMenu(self.toggleMenu)
|
||||
|
||||
newAction = fileMenu.addAction("New DockWidget")
|
||||
newAction.triggered.connect(self._newDockWidget)
|
||||
@@ -63,101 +73,104 @@ class MyMainWindow(KDDockWidgets.MainWindow):
|
||||
quitAction = fileMenu.addAction("Quit")
|
||||
quitAction.triggered.connect(QtWidgets.QApplication.instance().quit)
|
||||
|
||||
self.setAffinities([ affinityName ])
|
||||
self.setAffinities([affinityName])
|
||||
self.createDockWidgets()
|
||||
|
||||
def _newDockWidget(self):
|
||||
MyMainWindow.s_menuCount += 1
|
||||
w = newMyWidget(self)
|
||||
w.setGeometry(100, 100, 400, 400)
|
||||
dock = KDDockWidgets.DockWidget("new dock %d"%(MyMainWindow.s_menuCount))
|
||||
dock = KDDockWidgets.DockWidget("new dock %d" % (MyMainWindow.s_menuCount))
|
||||
dock.setWidget(w)
|
||||
dock.resize(600, 600)
|
||||
dock.show()
|
||||
self.m_dockwidgets.append(dock)
|
||||
|
||||
self.dockwidgets.append(dock)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def _saveLayout(self):
|
||||
#saver = KDDockWidgets.LayoutSaver()
|
||||
#result = saver.saveToFile("mylayout.json")
|
||||
#print("Saving layout to disk. Result=", result)
|
||||
print("Not available")
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def _restoreLayout(self):
|
||||
#options = KDDockWidgets.RestoreOption_None
|
||||
#if self.m_restoreIsRelative:
|
||||
# if self.restoreIsRelative:
|
||||
# options |= KDDockWidgets.RestoreOption_RelativeToMainWindow
|
||||
#saver = KDDockWidgets.LayoutSaver(options)
|
||||
#saver.restoreFromFile("mylayout.json")
|
||||
# saver.restoreFromFile("mylayout.json")
|
||||
print("Not available")
|
||||
|
||||
def _closeAll(self):
|
||||
for dw in self.m_dockwidgets:
|
||||
dw.close()
|
||||
for widget in self.dockwidgets:
|
||||
widget.close()
|
||||
|
||||
def createDockWidgets(self):
|
||||
if self.m_dockWidget9IsNonDockable:
|
||||
if self.dockWidget9IsNonDockable:
|
||||
numDockWidgets = 10
|
||||
else:
|
||||
numDockWidgets = 9
|
||||
|
||||
# numDockWidgets = 2
|
||||
# Create 9 KDDockWidget::DockWidget and the respective widgets they're hosting (MyWidget instances)
|
||||
for i in range(numDockWidgets):
|
||||
self.m_dockwidgets.append(self.newDockWidget())
|
||||
for _ in range(numDockWidgets):
|
||||
self.dockwidgets.append(self.newDockWidget())
|
||||
|
||||
# MainWindow::addDockWidget() attaches a dock widget to the main window:
|
||||
initialOpts = KDDockWidgets.InitialOption(KDDockWidgets.InitialVisibilityOption.StartHidden, QtCore.QSize(500, 500))
|
||||
self.addDockWidget(self.m_dockwidgets[0], KDDockWidgets.Location_OnBottom, None, initialOpts)
|
||||
initialOpts = KDDockWidgets.InitialOption(KDDockWidgets.InitialVisibilityOption.StartHidden,
|
||||
QtCore.QSize(500, 500))
|
||||
self.addDockWidget(self.dockwidgets[0], KDDockWidgets.Location_OnBottom, None, initialOpts)
|
||||
|
||||
# Here, for finer granularity we specify right of dockwidgets[0]:
|
||||
self.addDockWidget(self.m_dockwidgets[1], KDDockWidgets.Location_OnRight, self.m_dockwidgets[0])
|
||||
|
||||
self.addDockWidget(self.m_dockwidgets[2], KDDockWidgets.Location_OnLeft)
|
||||
self.addDockWidget(self.m_dockwidgets[3], KDDockWidgets.Location_OnBottom)
|
||||
self.addDockWidget(self.m_dockwidgets[4], KDDockWidgets.Location_OnBottom)
|
||||
self.addDockWidget(self.dockwidgets[1], KDDockWidgets.Location_OnRight, self.dockwidgets[0])
|
||||
|
||||
self.addDockWidget(self.dockwidgets[2], KDDockWidgets.Location_OnLeft)
|
||||
self.addDockWidget(self.dockwidgets[3], KDDockWidgets.Location_OnBottom)
|
||||
self.addDockWidget(self.dockwidgets[4], KDDockWidgets.Location_OnBottom)
|
||||
|
||||
# Tab two dock widgets together
|
||||
self.m_dockwidgets[3].addDockWidgetAsTab(self.m_dockwidgets[5])
|
||||
self.dockwidgets[3].addDockWidgetAsTab(self.dockwidgets[5])
|
||||
|
||||
# 6 is floating, as it wasn't added to the main window via MainWindow::addDockWidget().
|
||||
# and we tab 7 with it.
|
||||
self.m_dockwidgets[6].addDockWidgetAsTab(self.m_dockwidgets[7])
|
||||
self.dockwidgets[6].addDockWidgetAsTab(self.dockwidgets[7])
|
||||
|
||||
# Floating windows also support nesting, here we add 8 to the bottom of the group
|
||||
self.m_dockwidgets[6].addDockWidgetToContainingWindow(self.m_dockwidgets[8], KDDockWidgets.Location_OnBottom)
|
||||
self.dockwidgets[6].addDockWidgetToContainingWindow(self.dockwidgets[8], KDDockWidgets.Location_OnBottom)
|
||||
|
||||
floatingWindow = self.m_dockwidgets[6].window()
|
||||
floatingWindow = self.dockwidgets[6].window()
|
||||
floatingWindow.move(100, 100)
|
||||
|
||||
def newDockWidget(self):
|
||||
# Passing options is optional, we just want to illustrate Option_NotClosable here
|
||||
options = KDDockWidgets.DockWidget.Option_None
|
||||
if (MyMainWindow.s_count == 0) and self.m_dockWidget0IsNonClosable:
|
||||
if (MyMainWindow.s_count == 0) and self.dockWidget0IsNonClosable:
|
||||
options |= KDDockWidgets.DockWidget.Option_NotClosable
|
||||
|
||||
if (MyMainWindow.s_count == 9) and self.m_dockWidget9IsNonDockable:
|
||||
if (MyMainWindow.s_count == 9) and self.dockWidget9IsNonDockable:
|
||||
options |= KDDockWidgets.DockWidget.Option_NotDockable
|
||||
|
||||
dock = KDDockWidgets.DockWidget("DockWidget #%d"%(MyMainWindow.s_count), options)
|
||||
dock.setAffinities(self.affinities()); # optional, just to show the feature. Pass -mi to the example to see incompatible dock widgets
|
||||
dock = KDDockWidgets.DockWidget("DockWidget #%d" % (MyMainWindow.s_count), options)
|
||||
# optional, just to show the feature. Pass -mi to the example to see incompatible dock widgets
|
||||
dock.setAffinities(self.affinities())
|
||||
|
||||
if MyMainWindow.s_count == 1:
|
||||
dock.setIcon(QtGui.QIcon.fromTheme("mail-message"))
|
||||
|
||||
myWidget = newMyWidget(self)
|
||||
if (MyMainWindow.s_count == 8) and self.m_maxSizeForDockWidget8:
|
||||
if (MyMainWindow.s_count == 8) and self.maxSizeForDockWidget8:
|
||||
# Set a maximum size on dock #8
|
||||
myWidget.setMaximumSize(200, 200)
|
||||
|
||||
dock.setWidget(myWidget)
|
||||
|
||||
if dock.options() & KDDockWidgets.DockWidget.Option_NotDockable:
|
||||
dock.setTitle("DockWidget #%d (%s)" %(MyMainWindow.s_count, "non dockable"))
|
||||
dock.setTitle("DockWidget #%d (%s)" % (MyMainWindow.s_count, "non dockable"))
|
||||
else:
|
||||
dock.setTitle("DockWidget #%d"%(MyMainWindow.s_count))
|
||||
dock.setTitle("DockWidget #%d" % (MyMainWindow.s_count))
|
||||
|
||||
dock.resize(600, 600)
|
||||
self.m_toggleMenu.addAction(dock.toggleAction())
|
||||
self.toggleMenu.addAction(dock.toggleAction())
|
||||
MyMainWindow.s_count += 1
|
||||
return dock
|
||||
|
||||
|
||||
@@ -9,18 +9,23 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgetsQt6
|
||||
# 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):
|
||||
|
||||
def __init__(self, backgroundFile, logoFile, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.m_background = self._lookupImage(backgroundFile)
|
||||
self.m_logo = self._lookupImage(logoFile)
|
||||
self.background = self._lookupImage(backgroundFile)
|
||||
self.logo = self._lookupImage(logoFile)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def _lookupImage(self, imageName):
|
||||
if imageName == "":
|
||||
return None
|
||||
@@ -29,23 +34,23 @@ class MyWidget(QtWidgets.QWidget):
|
||||
MyWidget.s_images[imageName] = QtGui.QImage(imageName)
|
||||
|
||||
return MyWidget.s_images[imageName]
|
||||
|
||||
|
||||
def drawLogo(self, p):
|
||||
|
||||
if not self.m_logo:
|
||||
if not self.logo:
|
||||
return
|
||||
|
||||
ratio = self.m_logo.height() / (self.m_logo.width() * 1.0)
|
||||
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):
|
||||
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.m_logo, self.m_logo.rect());
|
||||
|
||||
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())
|
||||
|
||||
@@ -9,21 +9,20 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgetsQt6
|
||||
|
||||
from PySide6 import QtWidgets, QtGui
|
||||
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||
|
||||
from PySide6 import QtGui
|
||||
from MyWidget import MyWidget
|
||||
|
||||
|
||||
class MyWidget1(MyWidget):
|
||||
def __init__(self, parent = None):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(":/assets/triangles.png", ":/assets/KDAB_bubble_white.png", parent)
|
||||
|
||||
|
||||
def paintEvent(self, ev):
|
||||
def paintEvent(self, event):
|
||||
del event # unused at this time
|
||||
p = QtGui.QPainter(self)
|
||||
p.fillRect(self.rect(), QtGui.QColor(0xCC, 0xCC, 0xCC))
|
||||
p.drawImage(self.m_background.rect(), self.m_background, self.m_background.rect())
|
||||
p.drawImage(self.background.rect(),
|
||||
self.background, self.background.rect())
|
||||
self.drawLogo(p)
|
||||
|
||||
|
||||
@@ -9,19 +9,19 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgetsQt6
|
||||
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||
|
||||
from PySide6 import QtWidgets, QtGui, QtCore
|
||||
|
||||
from PySide6 import QtGui, QtCore
|
||||
from MyWidget import MyWidget
|
||||
|
||||
|
||||
class MyWidget2(MyWidget):
|
||||
|
||||
def __init__(self, parent = None):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__("", ":/assets/KDAB_bubble_blue.png", parent)
|
||||
|
||||
def paintEvent(self, ev):
|
||||
def paintEvent(self, event):
|
||||
del event # unused at this time
|
||||
p = QtGui.QPainter(self)
|
||||
p.fillRect(self.rect(), QtCore.Qt.white);
|
||||
p.fillRect(self.rect(), QtCore.Qt.white)
|
||||
self.drawLogo(p)
|
||||
|
||||
|
||||
@@ -9,24 +9,27 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgetsQt6
|
||||
|
||||
from PySide6 import QtWidgets, QtGui, QtCore
|
||||
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||
|
||||
from PySide6 import QtGui, QtCore
|
||||
from MyWidget import MyWidget
|
||||
|
||||
|
||||
class MyWidget3(MyWidget):
|
||||
|
||||
def __init__(self, parent = None):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png", parent)
|
||||
self.m_triangle = QtGui.QImage(":/assets/tri.png")
|
||||
self.triangle = QtGui.QImage(":/assets/tri.png")
|
||||
|
||||
def paintEvent(self, ev):
|
||||
def paintEvent(self, event):
|
||||
del event # unused at this time
|
||||
p = QtGui.QPainter(self)
|
||||
p.fillRect(self.rect(), QtGui.QColor(0xD5, 0xD5, 0xD5))
|
||||
p.drawImage(self.m_background.rect(), self.m_background, self.m_background.rect())
|
||||
|
||||
targetRect = QtCore.QRect(QtCore.QPoint(self.width() - self.m_triangle.width(), self.height() - self.m_triangle.height()), self.m_triangle.size())
|
||||
p.drawImage(self.background.rect(),
|
||||
self.background, self.background.rect())
|
||||
|
||||
QtCore.QRect(QtCore.QPoint(self.width() - self.triangle.width(),
|
||||
self.height() - self.triangle.height()),
|
||||
self.triangle.size())
|
||||
|
||||
self.drawLogo(p)
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ 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
|
||||
|
||||
@@ -9,16 +9,26 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
from PyKDDockWidgetsQt6 import KDDockWidgets
|
||||
from MyMainWindow import MyMainWindow
|
||||
|
||||
from PySide6 import QtWidgets, QtCore
|
||||
''' KDDockWidgets example (Qt6) '''
|
||||
|
||||
import sys
|
||||
|
||||
from MyMainWindow import MyMainWindow
|
||||
from PySide6 import QtWidgets, QtCore
|
||||
|
||||
try:
|
||||
# pylint: disable=unused-import
|
||||
import rc_assets
|
||||
except:
|
||||
exit("Oops.. rc_assets needs to be generated first.\nPlease run:\n rcc -g python -o rc_assets.py ../../examples/dockwidgets/resources_example.qrc\n(Make sure to use the rcc from the Qt6 version used to generate the bindings!)")
|
||||
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__":
|
||||
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
|
||||
@@ -34,5 +44,4 @@ if __name__ == "__main__":
|
||||
mainWindow.resize(1200, 1200)
|
||||
mainWindow.show()
|
||||
|
||||
app.exec_()
|
||||
|
||||
app.exec()
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
# pylint: disable=missing-module-docstring,missing-function-docstring,missing-class-docstring
|
||||
|
||||
from PyKDDockWidgets import KDDockWidgets
|
||||
|
||||
from PySide2 import QtCore, QtWidgets, QtGui
|
||||
@@ -17,33 +19,41 @@ from MyWidget1 import MyWidget1
|
||||
from MyWidget2 import MyWidget2
|
||||
from MyWidget3 import MyWidget3
|
||||
|
||||
def newMyWidget(parent = None):
|
||||
|
||||
def newMyWidget(parent=None):
|
||||
randomNumber = QtCore.QRandomGenerator.global_().bounded(0, 100) + 1
|
||||
if (randomNumber < 50):
|
||||
if (randomNumber < 33):
|
||||
if randomNumber < 50:
|
||||
if randomNumber < 33:
|
||||
return MyWidget1(parent)
|
||||
else:
|
||||
return MyWidget3(parent)
|
||||
else:
|
||||
return MyWidget2(parent)
|
||||
return MyWidget3(parent)
|
||||
return MyWidget2(parent)
|
||||
|
||||
|
||||
class MyMainWindow(KDDockWidgets.MainWindow):
|
||||
s_count = 0
|
||||
s_menuCount = 0
|
||||
|
||||
def __init__(self, uniqueName, options = KDDockWidgets.MainWindowOption_None, dockWidget0IsNonClosable = False, nonDockableDockWidget9 = False, restoreIsRelative = False, maxSizeForDockWidget8 = False, affinityName = "", parent = None):
|
||||
def __init__(self,
|
||||
uniqueName,
|
||||
options=KDDockWidgets.MainWindowOption_None,
|
||||
dockWidget0IsNonClosable=False,
|
||||
nonDockableDockWidget9=False,
|
||||
restoreIsRelative=False,
|
||||
maxSizeForDockWidget8=False,
|
||||
affinityName="",
|
||||
parent=None):
|
||||
super().__init__(uniqueName, options, parent)
|
||||
self.m_dockWidget0IsNonClosable = dockWidget0IsNonClosable
|
||||
self.m_dockWidget9IsNonDockable = nonDockableDockWidget9
|
||||
self.m_restoreIsRelative = restoreIsRelative
|
||||
self.m_maxSizeForDockWidget8 = maxSizeForDockWidget8
|
||||
self.m_dockwidgets = []
|
||||
|
||||
self.dockWidget0IsNonClosable = dockWidget0IsNonClosable
|
||||
self.dockWidget9IsNonDockable = nonDockableDockWidget9
|
||||
self.restoreIsRelative = restoreIsRelative
|
||||
self.maxSizeForDockWidget8 = maxSizeForDockWidget8
|
||||
self.dockwidgets = []
|
||||
|
||||
menubar = self.menuBar()
|
||||
fileMenu = QtWidgets.QMenu("File")
|
||||
self.m_toggleMenu = QtWidgets.QMenu("Toggle")
|
||||
self.toggleMenu = QtWidgets.QMenu("Toggle")
|
||||
menubar.addMenu(fileMenu)
|
||||
menubar.addMenu(self.m_toggleMenu)
|
||||
menubar.addMenu(self.toggleMenu)
|
||||
|
||||
newAction = fileMenu.addAction("New DockWidget")
|
||||
newAction.triggered.connect(self._newDockWidget)
|
||||
@@ -63,101 +73,104 @@ class MyMainWindow(KDDockWidgets.MainWindow):
|
||||
quitAction = fileMenu.addAction("Quit")
|
||||
quitAction.triggered.connect(QtWidgets.QApplication.instance().quit)
|
||||
|
||||
self.setAffinities([ affinityName ])
|
||||
self.setAffinities([affinityName])
|
||||
self.createDockWidgets()
|
||||
|
||||
def _newDockWidget(self):
|
||||
MyMainWindow.s_menuCount += 1
|
||||
w = newMyWidget(self)
|
||||
w.setGeometry(100, 100, 400, 400)
|
||||
dock = KDDockWidgets.DockWidget("new dock %d"%(MyMainWindow.s_menuCount))
|
||||
dock = KDDockWidgets.DockWidget("new dock %d" % (MyMainWindow.s_menuCount))
|
||||
dock.setWidget(w)
|
||||
dock.resize(600, 600)
|
||||
dock.show()
|
||||
self.m_dockwidgets.append(dock)
|
||||
|
||||
self.dockwidgets.append(dock)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def _saveLayout(self):
|
||||
#saver = KDDockWidgets.LayoutSaver()
|
||||
#result = saver.saveToFile("mylayout.json")
|
||||
#print("Saving layout to disk. Result=", result)
|
||||
print("Not available")
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def _restoreLayout(self):
|
||||
#options = KDDockWidgets.RestoreOption_None
|
||||
#if self.m_restoreIsRelative:
|
||||
# if self.restoreIsRelative:
|
||||
# options |= KDDockWidgets.RestoreOption_RelativeToMainWindow
|
||||
#saver = KDDockWidgets.LayoutSaver(options)
|
||||
#saver.restoreFromFile("mylayout.json")
|
||||
# saver.restoreFromFile("mylayout.json")
|
||||
print("Not available")
|
||||
|
||||
def _closeAll(self):
|
||||
for dw in self.m_dockwidgets:
|
||||
dw.close()
|
||||
for widget in self.dockwidgets:
|
||||
widget.close()
|
||||
|
||||
def createDockWidgets(self):
|
||||
if self.m_dockWidget9IsNonDockable:
|
||||
if self.dockWidget9IsNonDockable:
|
||||
numDockWidgets = 10
|
||||
else:
|
||||
numDockWidgets = 9
|
||||
|
||||
# numDockWidgets = 2
|
||||
# Create 9 KDDockWidget::DockWidget and the respective widgets they're hosting (MyWidget instances)
|
||||
for i in range(numDockWidgets):
|
||||
self.m_dockwidgets.append(self.newDockWidget())
|
||||
for _ in range(numDockWidgets):
|
||||
self.dockwidgets.append(self.newDockWidget())
|
||||
|
||||
# MainWindow::addDockWidget() attaches a dock widget to the main window:
|
||||
initialOpts = KDDockWidgets.InitialOption(KDDockWidgets.InitialVisibilityOption.StartHidden, QtCore.QSize(500, 500))
|
||||
self.addDockWidget(self.m_dockwidgets[0], KDDockWidgets.Location_OnBottom, None, initialOpts)
|
||||
initialOpts = KDDockWidgets.InitialOption(KDDockWidgets.InitialVisibilityOption.StartHidden,
|
||||
QtCore.QSize(500, 500))
|
||||
self.addDockWidget(self.dockwidgets[0], KDDockWidgets.Location_OnBottom, None, initialOpts)
|
||||
|
||||
# Here, for finer granularity we specify right of dockwidgets[0]:
|
||||
self.addDockWidget(self.m_dockwidgets[1], KDDockWidgets.Location_OnRight, self.m_dockwidgets[0])
|
||||
|
||||
self.addDockWidget(self.m_dockwidgets[2], KDDockWidgets.Location_OnLeft)
|
||||
self.addDockWidget(self.m_dockwidgets[3], KDDockWidgets.Location_OnBottom)
|
||||
self.addDockWidget(self.m_dockwidgets[4], KDDockWidgets.Location_OnBottom)
|
||||
self.addDockWidget(self.dockwidgets[1], KDDockWidgets.Location_OnRight, self.dockwidgets[0])
|
||||
|
||||
self.addDockWidget(self.dockwidgets[2], KDDockWidgets.Location_OnLeft)
|
||||
self.addDockWidget(self.dockwidgets[3], KDDockWidgets.Location_OnBottom)
|
||||
self.addDockWidget(self.dockwidgets[4], KDDockWidgets.Location_OnBottom)
|
||||
|
||||
# Tab two dock widgets together
|
||||
self.m_dockwidgets[3].addDockWidgetAsTab(self.m_dockwidgets[5])
|
||||
self.dockwidgets[3].addDockWidgetAsTab(self.dockwidgets[5])
|
||||
|
||||
# 6 is floating, as it wasn't added to the main window via MainWindow::addDockWidget().
|
||||
# and we tab 7 with it.
|
||||
self.m_dockwidgets[6].addDockWidgetAsTab(self.m_dockwidgets[7])
|
||||
self.dockwidgets[6].addDockWidgetAsTab(self.dockwidgets[7])
|
||||
|
||||
# Floating windows also support nesting, here we add 8 to the bottom of the group
|
||||
self.m_dockwidgets[6].addDockWidgetToContainingWindow(self.m_dockwidgets[8], KDDockWidgets.Location_OnBottom)
|
||||
self.dockwidgets[6].addDockWidgetToContainingWindow(self.dockwidgets[8], KDDockWidgets.Location_OnBottom)
|
||||
|
||||
floatingWindow = self.m_dockwidgets[6].window()
|
||||
floatingWindow = self.dockwidgets[6].window()
|
||||
floatingWindow.move(100, 100)
|
||||
|
||||
def newDockWidget(self):
|
||||
# Passing options is optional, we just want to illustrate Option_NotClosable here
|
||||
options = KDDockWidgets.DockWidget.Option_None
|
||||
if (MyMainWindow.s_count == 0) and self.m_dockWidget0IsNonClosable:
|
||||
if (MyMainWindow.s_count == 0) and self.dockWidget0IsNonClosable:
|
||||
options |= KDDockWidgets.DockWidget.Option_NotClosable
|
||||
|
||||
if (MyMainWindow.s_count == 9) and self.m_dockWidget9IsNonDockable:
|
||||
if (MyMainWindow.s_count == 9) and self.dockWidget9IsNonDockable:
|
||||
options |= KDDockWidgets.DockWidget.Option_NotDockable
|
||||
|
||||
dock = KDDockWidgets.DockWidget("DockWidget #%d"%(MyMainWindow.s_count), options)
|
||||
dock.setAffinities(self.affinities()); # optional, just to show the feature. Pass -mi to the example to see incompatible dock widgets
|
||||
dock = KDDockWidgets.DockWidget("DockWidget #%d" % (MyMainWindow.s_count), options)
|
||||
# optional, just to show the feature. Pass -mi to the example to see incompatible dock widgets
|
||||
dock.setAffinities(self.affinities())
|
||||
|
||||
if MyMainWindow.s_count == 1:
|
||||
dock.setIcon(QtGui.QIcon.fromTheme("mail-message"))
|
||||
|
||||
myWidget = newMyWidget(self)
|
||||
if (MyMainWindow.s_count == 8) and self.m_maxSizeForDockWidget8:
|
||||
if (MyMainWindow.s_count == 8) and self.maxSizeForDockWidget8:
|
||||
# Set a maximum size on dock #8
|
||||
myWidget.setMaximumSize(200, 200)
|
||||
|
||||
dock.setWidget(myWidget)
|
||||
|
||||
if dock.options() & KDDockWidgets.DockWidget.Option_NotDockable:
|
||||
dock.setTitle("DockWidget #%d (%s)" %(MyMainWindow.s_count, "non dockable"))
|
||||
dock.setTitle("DockWidget #%d (%s)" % (MyMainWindow.s_count, "non dockable"))
|
||||
else:
|
||||
dock.setTitle("DockWidget #%d"%(MyMainWindow.s_count))
|
||||
dock.setTitle("DockWidget #%d" % (MyMainWindow.s_count))
|
||||
|
||||
dock.resize(600, 600)
|
||||
self.m_toggleMenu.addAction(dock.toggleAction())
|
||||
self.toggleMenu.addAction(dock.toggleAction())
|
||||
MyMainWindow.s_count += 1
|
||||
return dock
|
||||
|
||||
|
||||
@@ -9,18 +9,23 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgets
|
||||
# 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):
|
||||
|
||||
def __init__(self, backgroundFile, logoFile, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.m_background = self._lookupImage(backgroundFile)
|
||||
self.m_logo = self._lookupImage(logoFile)
|
||||
self.background = self._lookupImage(backgroundFile)
|
||||
self.logo = self._lookupImage(logoFile)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def _lookupImage(self, imageName):
|
||||
if imageName == "":
|
||||
return None
|
||||
@@ -29,23 +34,23 @@ class MyWidget(QtWidgets.QWidget):
|
||||
MyWidget.s_images[imageName] = QtGui.QImage(imageName)
|
||||
|
||||
return MyWidget.s_images[imageName]
|
||||
|
||||
|
||||
def drawLogo(self, p):
|
||||
|
||||
if not self.m_logo:
|
||||
if not self.logo:
|
||||
return
|
||||
|
||||
ratio = self.m_logo.height() / (self.m_logo.width() * 1.0)
|
||||
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):
|
||||
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.m_logo, self.m_logo.rect());
|
||||
|
||||
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())
|
||||
|
||||
@@ -9,21 +9,20 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgets
|
||||
|
||||
from PySide2 import QtWidgets, QtGui
|
||||
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||
|
||||
from PySide2 import QtGui
|
||||
from MyWidget import MyWidget
|
||||
|
||||
|
||||
class MyWidget1(MyWidget):
|
||||
def __init__(self, parent = None):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(":/assets/triangles.png", ":/assets/KDAB_bubble_white.png", parent)
|
||||
|
||||
|
||||
def paintEvent(self, ev):
|
||||
def paintEvent(self, event):
|
||||
del event # unused at this time
|
||||
p = QtGui.QPainter(self)
|
||||
p.fillRect(self.rect(), QtGui.QColor(0xCC, 0xCC, 0xCC))
|
||||
p.drawImage(self.m_background.rect(), self.m_background, self.m_background.rect())
|
||||
p.drawImage(self.background.rect(),
|
||||
self.background, self.background.rect())
|
||||
self.drawLogo(p)
|
||||
|
||||
|
||||
@@ -9,19 +9,19 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgets
|
||||
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||
|
||||
from PySide2 import QtWidgets, QtGui, QtCore
|
||||
|
||||
from PySide2 import QtGui, QtCore
|
||||
from MyWidget import MyWidget
|
||||
|
||||
|
||||
class MyWidget2(MyWidget):
|
||||
|
||||
def __init__(self, parent = None):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__("", ":/assets/KDAB_bubble_blue.png", parent)
|
||||
|
||||
def paintEvent(self, ev):
|
||||
def paintEvent(self, event):
|
||||
del event # unused at this time
|
||||
p = QtGui.QPainter(self)
|
||||
p.fillRect(self.rect(), QtCore.Qt.white);
|
||||
p.fillRect(self.rect(), QtCore.Qt.white)
|
||||
self.drawLogo(p)
|
||||
|
||||
|
||||
@@ -9,24 +9,27 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
import PyKDDockWidgets
|
||||
|
||||
from PySide2 import QtWidgets, QtGui, QtCore
|
||||
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||
|
||||
from PySide2 import QtGui, QtCore
|
||||
from MyWidget import MyWidget
|
||||
|
||||
|
||||
class MyWidget3(MyWidget):
|
||||
|
||||
def __init__(self, parent = None):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(":/assets/base.png", ":/assets/KDAB_bubble_fulcolor.png", parent)
|
||||
self.m_triangle = QtGui.QImage(":/assets/tri.png")
|
||||
self.triangle = QtGui.QImage(":/assets/tri.png")
|
||||
|
||||
def paintEvent(self, ev):
|
||||
def paintEvent(self, event):
|
||||
del event # unused at this time
|
||||
p = QtGui.QPainter(self)
|
||||
p.fillRect(self.rect(), QtGui.QColor(0xD5, 0xD5, 0xD5))
|
||||
p.drawImage(self.m_background.rect(), self.m_background, self.m_background.rect())
|
||||
|
||||
targetRect = QtCore.QRect(QtCore.QPoint(self.width() - self.m_triangle.width(), self.height() - self.m_triangle.height()), self.m_triangle.size())
|
||||
p.drawImage(self.background.rect(),
|
||||
self.background, self.background.rect())
|
||||
|
||||
QtCore.QRect(QtCore.QPoint(self.width() - self.triangle.width(),
|
||||
self.height() - self.triangle.height()),
|
||||
self.triangle.size())
|
||||
|
||||
self.drawLogo(p)
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ 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
|
||||
|
||||
@@ -9,16 +9,26 @@
|
||||
# Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||
#
|
||||
|
||||
from PyKDDockWidgets import KDDockWidgets
|
||||
from MyMainWindow import MyMainWindow
|
||||
|
||||
from PySide2 import QtWidgets, QtCore
|
||||
''' KDDockWidgets example (Qt5) '''
|
||||
|
||||
import sys
|
||||
|
||||
from MyMainWindow import MyMainWindow
|
||||
from PySide2 import QtWidgets, QtCore
|
||||
|
||||
try:
|
||||
# pylint: disable=unused-import
|
||||
import rc_assets
|
||||
except:
|
||||
exit("Oops.. rc_assets needs to be generated first.\nPlease run:\n rcc -g python -o rc_assets.py ../../examples/dockwidgets/resources_example.qrc\n(Make sure to use the rcc from the Qt5 version used to generate the bindings!)")
|
||||
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)
|
||||
@@ -35,4 +45,3 @@ if __name__ == "__main__":
|
||||
mainWindow.show()
|
||||
|
||||
app.exec_()
|
||||
|
||||
|
||||
@@ -1,40 +1,36 @@
|
||||
#
|
||||
# This file is part of KDDockWidgets.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2022 Klarälvdalens Datakonsult AB, a KDAB Group
|
||||
# company <info@kdab.com> Author: Renato Araujo Oliveira Filho
|
||||
# <renato.araujo@kdab.com>
|
||||
# SPDX-FileCopyrightText: 2020-2022 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)
|
||||
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)
|
||||
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)
|
||||
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}")
|
||||
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}")
|
||||
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()
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
# 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')
|
||||
@@ -25,6 +28,7 @@ class TestImportModules(unittest.TestCase):
|
||||
for symbol in symbols:
|
||||
self.assertIn(symbol, moduleSymbols)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
TstConfig.initLibraryPath()
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user