Skip to content

Commit

Permalink
Add a RawWidget widget
Browse files Browse the repository at this point in the history
This widget allows embedding custom toolkit-specific widgets into the
Enaml widget hierarchy.
  • Loading branch information
sccolbert committed Jun 14, 2013
1 parent fd53715 commit e9d25a2
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions enaml/qt/qt_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions enaml/qt/qt_raw_widget.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions enaml/widgets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions enaml/widgets/raw_widget.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit e9d25a2

Please sign in to comment.