Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- #781

Closed
wants to merge 2 commits into from
Closed

- #781

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
491 changes: 491 additions & 0 deletions plugins/basic_input_plugin.py

Large diffs are not rendered by default.

228 changes: 228 additions & 0 deletions plugins/container_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# coding: utf-8
from PySide6.QtWidgets import QWidget
from PySide6.QtDesigner import (QDesignerCustomWidgetInterface, QDesignerFormWindowInterface, QExtensionFactory,
QPyDesignerContainerExtension)

from qfluentwidgets import (ScrollArea, SmoothScrollArea, SingleDirectionScrollArea, OpacityAniStackedWidget,
PopUpAniStackedWidget, CardWidget, ElevatedCardWidget, SimpleCardWidget,
HeaderCardWidget)

from plugin_base import PluginBase


class ContainerPlugin(PluginBase):

def group(self):
return super().group() + ' (Container)'

def isContainer(self):
return True


class CardWidgetPlugin(ContainerPlugin, QDesignerCustomWidgetInterface):
""" Card widget plugin """

def createWidget(self, parent):
return CardWidget(parent)

def icon(self):
return super().icon("CommandBar")

def name(self):
return "CardWidget"


class ElevatedCardWidgetPlugin(ContainerPlugin, QDesignerCustomWidgetInterface):
""" Elevated card widget plugin """

def createWidget(self, parent):
return ElevatedCardWidget(parent)

def icon(self):
return super().icon("CommandBar")

def name(self):
return "ElevatedCardWidget"


class SimpleCardWidgetPlugin(ContainerPlugin, QDesignerCustomWidgetInterface):
""" Simple card widget plugin """

def createWidget(self, parent):
return SimpleCardWidget(parent)

def icon(self):
return super().icon("CommandBar")

def name(self):
return "SimpleCardWidget"


class HeaderCardWidgetPlugin(ContainerPlugin, QDesignerCustomWidgetInterface):
""" Header card widget plugin """

def createWidget(self, parent):
return HeaderCardWidget(parent)

def icon(self):
return super().icon("CommandBar")

def name(self):
return "HeaderCardWidget"


class ScrollAreaPluginBase(ContainerPlugin):
""" Scroll area plugin base """

def domXml(self):
return f"""
<widget class="{self.name()}" name="{self.name()}">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents" />
</widget>
"""


class ScrollAreaPlugin(ScrollAreaPluginBase, QDesignerCustomWidgetInterface):
""" Scroll area plugin """

def createWidget(self, parent):
return ScrollArea(parent)

def icon(self):
return super().icon("ScrollViewer")

def name(self):
return "ScrollArea"

def toolTip(self):
return "Smooth scroll area"


class SmoothScrollAreaPlugin(ScrollAreaPluginBase, QDesignerCustomWidgetInterface):
""" Smooth scroll area plugin """

def createWidget(self, parent):
return SmoothScrollArea(parent)

def icon(self):
return super().icon("ScrollViewer")

def name(self):
return "SmoothScrollArea"


class SingleDirectionScrollAreaPlugin(ScrollAreaPluginBase, QDesignerCustomWidgetInterface):
""" Single direction scroll area plugin """

def createWidget(self, parent):
return SingleDirectionScrollArea(parent)

def icon(self):
return super().icon("ScrollViewer")

def name(self):
return "SingleDirectionScrollArea"


class StackedWidgetPlugin(ContainerPlugin):

def domXml(self):
return f"""
<widget class="{self.name()}" name="{self.name()}">'
<widget class="QWidget" name="page" />'
</widget>
"""

def onCurrentIndexChanged(self, index):
widget = self.sender()
form = QDesignerFormWindowInterface.findFormWindow(widget)
if form:
form.emitSelectionChanged()


class StackedWidgetExtension(QPyDesignerContainerExtension):
""" Stacked widget extension """

def __init__(self, stacked, parent=None) -> None:
super().__init__(parent)
self.stacked = stacked

def addWidget(self, widget) -> None:
self.stacked.addWidget(widget)

def count(self):
return self.stacked.count()

def currentIndex(self):
return self.stacked.currentIndex()

def insertWidget(self, index, widget):
self.stacked.insertWidget(index, widget)

def remove(self, index):
self.stacked.removeWidget(self.stacked.widget(index))

def setCurrentIndex(self, index):
self.stacked.setCurrentIndex(index)

def widget(self, index):
return self.stacked.widget(index)


class StackedWidgetExtensionFactory(QExtensionFactory):
""" Stacked widget extension factory """

widgets = []
IID = "org.qt-project.Qt.Designer.Container"

def createExtension(self, object, iid, parent):
if iid != StackedWidgetExtensionFactory.IID:
return None

if object.__class__.__name__ not in self.widgets:
return None

return StackedWidgetExtension(object, parent)

@classmethod
def register(cls, Plugin):
if Plugin.__name__ not in cls.widgets:
cls.widgets.append(Plugin().name())
Plugin.Factory = cls

return Plugin


@StackedWidgetExtensionFactory.register
class OpacityAniStackedWidgetPlugin(StackedWidgetPlugin, QDesignerCustomWidgetInterface):
""" opacity ani stacked widget plugin """

def createWidget(self, parent):
w = OpacityAniStackedWidget(parent)
w.currentChanged.connect(self.onCurrentIndexChanged)
return w

def icon(self):
return super().icon("StackPanel")

def name(self):
return "OpacityAniStackedWidget"


@StackedWidgetExtensionFactory.register
class PopUpAniStackedWidgetPlugin(StackedWidgetPlugin, QDesignerCustomWidgetInterface):
""" pop up ani stacked widget plugin """

def createWidget(self, parent):
w = PopUpAniStackedWidget(parent)
w.currentChanged.connect(self.onCurrentIndexChanged)
return w

def icon(self):
return super().icon("StackPanel")

def name(self):
return "PopUpAniStackedWidget"
87 changes: 87 additions & 0 deletions plugins/date_time_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# coding: utf-8
from PySide6.QtCore import Qt
from PySide6.QtDesigner import QDesignerCustomWidgetInterface

from qfluentwidgets import DatePicker, TimePicker, ZhDatePicker, AMTimePicker, CalendarPicker

from plugin_base import PluginBase


class DateTimePlugin(PluginBase):

def group(self):
return super().group() + ' (Date Time)'


class CalendarPickerPlugin(DateTimePlugin, QDesignerCustomWidgetInterface):
""" Calendar picker plugin """

def createWidget(self, parent):
return CalendarPicker(parent)

def icon(self):
return super().icon("CalendarDatePicker")

def name(self):
return "CalendarPicker"


class DatePickerPlugin(DateTimePlugin, QDesignerCustomWidgetInterface):
""" Date picker plugin """

def createWidget(self, parent):
return DatePicker(parent)

def icon(self):
return super().icon("DatePicker")

def name(self):
return "DatePicker"


class ZhDatePickerPlugin(DateTimePlugin, QDesignerCustomWidgetInterface):
""" Chinese Date picker plugin """

def createWidget(self, parent):
return ZhDatePicker(parent)

def icon(self):
return super().icon("DatePicker")

def name(self):
return "ZhDatePicker"

def toolTip(self):
return "Chinese date picker"


class TimePickerPlugin(DateTimePlugin, QDesignerCustomWidgetInterface):
""" Time picker plugin """

def createWidget(self, parent):
return TimePicker(parent)

def icon(self):
return super().icon("TimePicker")

def name(self):
return "TimePicker"

def toolTip(self):
return "24 hours time picker"


class AMTimePickerPlugin(DateTimePlugin, QDesignerCustomWidgetInterface):
""" AM/PM time picker plugin """

def createWidget(self, parent):
return AMTimePicker(parent)

def icon(self):
return super().icon("TimePicker")

def name(self):
return "AMTimePicker"

def toolTip(self):
return "AM/PM time picker"
Loading