diff --git a/enaml/qt/qt_factories.py b/enaml/qt/qt_factories.py index 1009f17a5..14419078a 100644 --- a/enaml/qt/qt_factories.py +++ b/enaml/qt/qt_factories.py @@ -185,6 +185,11 @@ def radio_button_factory(): return QtRadioButton +def raw_widget_factory(): + from .qt_raw_widget import QtRawWidget + return QtRawWidget + + def scroll_area_factory(): from .qt_scroll_area import QtScrollArea return QtScrollArea @@ -296,6 +301,7 @@ def window_factory(): 'PushButton': push_button_factory, 'ProgressBar': progress_bar_factory, 'RadioButton': radio_button_factory, + 'RawWidget': raw_widget_factory, 'ScrollArea': scroll_area_factory, 'Separator': separator_factory, 'Slider': slider_factory, diff --git a/enaml/qt/qt_raw_widget.py b/enaml/qt/qt_raw_widget.py new file mode 100644 index 000000000..a1dc104cd --- /dev/null +++ b/enaml/qt/qt_raw_widget.py @@ -0,0 +1,30 @@ +#------------------------------------------------------------------------------ +# Copyright (c) 2013, Nucleic Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#------------------------------------------------------------------------------ +from enaml.widgets.raw_widget import ProxyRawWidget + +from .qt_control import QtControl + + +class QtRawWidget(QtControl, ProxyRawWidget): + """ A Qt implementation of an Enaml ProxyRawWidget. + + """ + def create_widget(self): + """ Create the underlying widget for the control. + + """ + self.widget = self.declaration.create_widget(self.parent_widget()) + + #-------------------------------------------------------------------------- + # ProxyRawWidget API + #-------------------------------------------------------------------------- + def get_widget(self): + """ Retrieve the underlying toolkit widget. + + """ + return self.widget diff --git a/enaml/widgets/api.py b/enaml/widgets/api.py index f600f7866..96fce025d 100644 --- a/enaml/widgets/api.py +++ b/enaml/widgets/api.py @@ -40,6 +40,7 @@ from .progress_bar import ProgressBar from .push_button import PushButton from .radio_button import RadioButton +from .raw_widget import RawWidget from .scroll_area import ScrollArea from .separator import Separator from .slider import Slider diff --git a/enaml/widgets/raw_widget.py b/enaml/widgets/raw_widget.py new file mode 100644 index 000000000..58e6623ee --- /dev/null +++ b/enaml/widgets/raw_widget.py @@ -0,0 +1,66 @@ +#------------------------------------------------------------------------------ +# Copyright (c) 2013, Nucleic Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#------------------------------------------------------------------------------ +from atom.api import Typed, ForwardTyped + +from .control import Control, ProxyControl + + +class ProxyRawWidget(ProxyControl): + """ The abstract definition of a proxy RawWidget object. + + """ + #: A reference to the RawWidget declaration. + declaration = ForwardTyped(lambda: RawWidget) + + def get_widget(self): + raise NotImplementedError + + +class RawWidget(Control): + """ A raw toolkit-specific control. + + Use this widget when the toolkit backend for the application is + known ahead of time, and Enaml does provide an implementation of + the required widget. This can be used as a hook to inject custom + widgets into an Enaml widget hierarchy. + + """ + #: A reference to the proxy Control object. + proxy = Typed(ProxyRawWidget) + + def create_widget(self, parent): + """ Create the toolkit widget for the control. + + This method should create and initialize the widget. + + Parameters + ---------- + parent : toolkit widget or None + The parent toolkit widget for the control. + + Returns + ------- + result : toolkit widget + The toolkit specific widget for the control. + + """ + raise NotImplementedError + + def get_widget(self): + """ Retrieve the toolkit widget for the control. + + Returns + ------- + result : toolkit widget or None + The toolkit widget that was previously created by the + call to 'create_widget' or None if the proxy is not + active or the widget has been destroyed. + + """ + if self.proxy_is_active: + return self.proxy.get_widget()