Skip to content

Commit

Permalink
add a dock layout op for extend/retract dock bar
Browse files Browse the repository at this point in the history
  • Loading branch information
sccolbert committed Jul 22, 2013
1 parent bebba0a commit 00ee34a
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
2 changes: 1 addition & 1 deletion enaml/layout/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ItemLayout, TabLayout, SplitLayout, HSplitLayout, VSplitLayout,
DockBarLayout, AreaLayout, DockLayout, DockLayoutWarning,
InsertItem, InsertBorderItem, InsertDockBarItem, InsertTab,
FloatItem, FloatArea, RemoveItem
FloatItem, FloatArea, RemoveItem, ExtendItem, RetractItem
)
from .layout_helpers import (
align, hbox, vbox, horizontal, vertical, grid, spacer,
Expand Down
24 changes: 24 additions & 0 deletions enaml/layout/dock_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,30 @@ class RemoveItem(DockLayoutOp):
item = Unicode()


class ExtendItem(DockLayoutOp):
""" A layout operation which extends an item in a dock bar.
This layout operation will cause the named item to be extended to
from its dock bar. If the item does not exist in a dock bar, this
operation is a no-op.
"""
#: The name of the dock item to extend from its dock bar.
item = Unicode()


class RetractItem(DockLayoutOp):
""" A layout operation which retracts an item into a dock bar.
This layout operation will cause the named item to be retracted
into its dock bar. If the item does not exist in a dock bar, this
operation is a no-op.
"""
#: The name of the dock item to retract into its dock bar.
item = Unicode()


#------------------------------------------------------------------------------
# Deprecated Layout Classes
#------------------------------------------------------------------------------
Expand Down
28 changes: 28 additions & 0 deletions enaml/qt/docking/layout_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,31 @@ def visit_RemoveItem(self, op):
else:
container.unplug()
container.hide()

def visit_ExtendItem(self, op):
""" Handle the ExtendItem dock layout op.
This visitor will extend the item provided it lives in a
dock bar.
"""
container = self.containers.get(op.item)
if container is None:
return
area = container.parentDockArea()
if area is not None:
area.extendFromDockBar(container)

def visit_RetractItem(self, op):
""" Handle the RetractItem dock layout op.
This visitor will retract the item provided it lives in a
dock bar.
"""
container = self.containers.get(op.item)
if container is None:
return
area = container.parentDockArea()
if area is not None:
area.retractToDockBar(container)
26 changes: 26 additions & 0 deletions enaml/qt/docking/q_dock_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,32 @@ def dockBarPosition(self, container):
"""
return self._dock_bar_manager.dockBarPosition(container)

def extendFromDockBar(self, container):
""" Extend the given container from its dock bar.
If the container does not exist in a dock bar, this is a no-op.
Parameters
----------
container : QDockContainer
The dock container of interest.
"""
self._dock_bar_manager.extendContainer(container)

def retractToDockBar(self, container):
""" Retract the given container into it's dock bar.
If the container does not exist in a dock bar, this is a no-op.
Parameters
----------
container : QDockContainer
The dock container of interest.
"""
self._dock_bar_manager.retractContainer(container)

def clearDockBars(self):
""" Clear the dock bars from the dock area.
Expand Down
30 changes: 30 additions & 0 deletions enaml/qt/docking/q_dock_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,36 @@ def isEmpty(self):
"""
return len(self._widgets) == 0

def extendContainer(self, container):
""" Extend the specified container.
Parameters
----------
container : QDockContainer
The container to put in the extended position. If the
container does not exist in the manager, this method is
a no-op.
"""
button = self._widgets.get(container)
if button is not None:
button.setChecked(True)

def retractContainer(self, container):
""" Retract the specified container.
Parameters
----------
container : QDockContainer
The container to put in the retracted position. If the
container does not exist in the manager, this method is
a no-op.
"""
button = self._widgets.get(container)
if button is not None:
button.setChecked(False)

#--------------------------------------------------------------------------
# Protected API
#--------------------------------------------------------------------------
Expand Down

0 comments on commit 00ee34a

Please sign in to comment.