Skip to content

Commit

Permalink
add a Frame widget type
Browse files Browse the repository at this point in the history
  • Loading branch information
sccolbert committed Jul 8, 2013
1 parent 1d1cb49 commit d1316f4
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 1 deletion.
68 changes: 68 additions & 0 deletions enaml/qt/qt_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#------------------------------------------------------------------------------
# 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

from enaml.widgets.frame import ProxyFrame

from .QtGui import QFrame

from .qt_constraints_widget import QtConstraintsWidget


STYLE = {
'box': QFrame.Box,
'panel': QFrame.Panel,
'styled_panel': QFrame.StyledPanel,
}


LINE_STYLE = {
'plain': QFrame.Plain,
'sunken': QFrame.Sunken,
'raised': QFrame.Raised,
}


class QtFrame(QtConstraintsWidget, ProxyFrame):
""" A Qt implementation of an Enaml ProxyFrame.
"""
#: A reference to the toolkit widget created by the proxy.
widget = Typed(QFrame)

#--------------------------------------------------------------------------
# Initialization API
#--------------------------------------------------------------------------
def create_widget(self):
""" Creates the QContainer widget.
"""
self.widget = QFrame(self.parent_widget())

def init_widget(self):
""" Initialize the widget.
"""
super(QtFrame, self).init_widget()
self.set_border(self.declaration.border)

#--------------------------------------------------------------------------
# ProxyFrame API
#--------------------------------------------------------------------------
def set_border(self, border):
""" Set the border for the widget.
"""
widget = self.widget
if border is None:
widget.setFrameShape(QFrame.NoFrame)
return
widget.setFrameShape(STYLE[border.style])
widget.setFrameShadow(LINE_STYLE[border.line_style])
widget.setLineWidth(border.line_width)
widget.setMidLineWidth(border.midline_width)
3 changes: 2 additions & 1 deletion enaml/widgets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .calendar import Calendar
from .check_box import CheckBox
from .combo_box import ComboBox
from .container import Container, Border
from .container import Container
from .date_selector import DateSelector
from .datetime_selector import DatetimeSelector
from .dock_area import DockArea
Expand All @@ -23,6 +23,7 @@
from .flow_area import FlowArea
from .flow_item import FlowItem
from .form import Form
from .frame import Border
from .group_box import GroupBox
from .html import Html
from .image_view import ImageView
Expand Down
69 changes: 69 additions & 0 deletions enaml/widgets/frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#------------------------------------------------------------------------------
# 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 Atom, Enum, Range, ForwardTyped, Typed, observe

from enaml.core.declarative import d_

from .constraints_widget import ConstraintsWidget, ProxyConstraintsWidget


class Border(Atom):
""" A class for defining a border on a Frame.
Border instances should be treated as read-only once created.
"""
#: The style of the border.
style = Enum('box', 'panel', 'styled_panel')

#: The showdow style applied to the border.
line_style = Enum('plain', 'sunken', 'raised')

#: The thickness of the outer border line.
line_width = Range(low=0, value=1)

#: The thickness of the inner border line. This only has an effect
#: for the 'sunken' and 'raised' line styles.
midline_width = Range(low=0, value=0)


class ProxyFrame(ProxyConstraintsWidget):
""" The abstract definition of a proxy Frame object.
"""
#: A reference to the Frame declaration.
declaration = ForwardTyped(lambda: Frame)

def set_border(self, border):
raise NotImplementedError


class Frame(ConstraintsWidget):
""" A ConstraintsWidget that draws an optional border.
This class serves as a base class for widgets such as Container and
ScrollArea. It should not normally be used directly by user code.
"""
#: The border to apply to the frame. This may not be supported by
#: all toolkit backends.
border = d_(Typed(Border))

#: A reference to the ProxyContainer object.
proxy = Typed(ProxyFrame)

#--------------------------------------------------------------------------
# Observers
#--------------------------------------------------------------------------
@observe('border')
def _update_proxy(self, change):
""" An observer which updates the proxy when the border changes.
"""
# The superclass handler is sufficient
super(Frame, self)._update_proxy(change)
42 changes: 42 additions & 0 deletions enaml/wx/wx_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#------------------------------------------------------------------------------
# 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

from enaml.widgets.frame import ProxyFrame

import wx

from .wx_constraints_widget import WxConstraintsWidget


class WxFrame(WxConstraintsWidget, ProxyFrame):
""" A Wx implementation of an Enaml ProxyFrame.
"""
#: A reference to the toolkit widget created by the proxy.
widget = Typed(wx.Panel)

#--------------------------------------------------------------------------
# Initialization API
#--------------------------------------------------------------------------
def create_widget(self):
""" Creates the QContainer widget.
"""
self.widget = wx.Panel(self.parent_widget())

#--------------------------------------------------------------------------
# ProxyFrame API
#--------------------------------------------------------------------------
def set_border(self, border):
""" Set the border for the widget.
This is not supported on Wx.
"""
pass

0 comments on commit d1316f4

Please sign in to comment.