-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |