1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from atom.api import Typed
from enaml.widgets.stack_item import ProxyStackItem
from .QtWidgets import QFrame
from .q_single_widget_layout import QSingleWidgetLayout
from .qt_container import QtContainer
from .qt_widget import QtWidget
class QStackItem(QFrame):
""" A QFrame subclass which acts as an item QStack.
"""
def __init__(self, *args, **kwargs):
""" Initialize a QStackItem.
Parameters
----------
*args, **kwargs
The position and keyword arguments required to initialize
a QWidget.
"""
super(QStackItem, self).__init__(*args, **kwargs)
self._stack_widget = None
self.setLayout(QSingleWidgetLayout())
def stackWidget(self):
""" Get the stack widget for this stack item.
Returns
-------
result : QWidget or None
The stack widget being managed by this item.
"""
return self._stack_widget
def setStackWidget(self, widget):
""" Set the stack widget for this stack item.
Parameters
----------
widget : QWidget
The QWidget to use as the stack widget in this item.
"""
self._stack_widget = widget
self.layout().setWidget(widget)
class QtStackItem(QtWidget, ProxyStackItem):
""" A Qt implementation of an Enaml ProxyStackItem.
"""
#: A reference to the widget created by the proxy.
widget = Typed(QStackItem)
#--------------------------------------------------------------------------
# Initialization API
#--------------------------------------------------------------------------
def create_widget(self):
""" Create the underlying QStackItem widget.
"""
self.widget = QStackItem(self.parent_widget())
def init_layout(self):
""" Initialize the layout for the underlying widget.
"""
super(QtStackItem, self).init_layout()
self.widget.setStackWidget(self.stack_widget())
#--------------------------------------------------------------------------
# Utility Methods
#--------------------------------------------------------------------------
def stack_widget(self):
""" Find and return the stack widget child for this widget.
"""
d = self.declaration.stack_widget()
if d is not None:
return d.proxy.widget
#--------------------------------------------------------------------------
# Child Events
#--------------------------------------------------------------------------
def child_added(self, child):
""" Handle the child added event for a QtStackItem.
"""
super(QtStackItem, self).child_added(child)
if isinstance(child, QtContainer):
self.widget.setStackWidget(self.stack_widget())
def child_removed(self, child):
""" Handle the child added event for a QtStackItem.
"""
super(QtStackItem, self).child_removed(child)
if isinstance(child, QtContainer):
self.widget.setStackWidget(self.stack_widget())
#--------------------------------------------------------------------------
# Widget Update Methods
#--------------------------------------------------------------------------
def set_visible(self, visible):
""" An overridden visibility setter.
This setter disables changing visibility on the widget since
the visibility is controlled entirely by the parent stack.
"""
pass
|