1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
import logging
import wx
# Multiple AUI versions are no longer supported; the C version in wx.aui is not
# capable of supporting the windowing flexibility needed by tasks. Therefore,
# only AGW's pure-python AUI implementation is used.
from wx.lib.agw import aui
# Logger.
logger = logging.getLogger(__name__)
# AGW's library does need some patching for some usability differences desired
# for pyface but not for the standard wxPython version
class PyfaceAuiNotebook(aui.AuiNotebook):
if wx.version() >= "3.":
SetPageToolTip = aui.AuiNotebook.SetPageTooltip
GetPageToolTip = aui.AuiNotebook.GetPageTooltip
class PyfaceAuiManager(aui.AuiManager):
# The standard AuiManager dock resizing attempts to adjust all the docks to
# provide some sort of best fit, but when there are more than two panes in
# a dock it isn't very intuitive. The modifications to these three methods
# tries to keep as many sizers fixes as it can and only adjust the one that
# is added.
def CalculateDockSizerLimits(self, dock):
# Replacement for default calculation for min/max dock sizes. Instead
# of adjusting the sizes of all the docks, only adjusts one to make the
# dock insertion process a little more like what the user expected.
docks, panes = aui.CopyDocksAndPanes2(self._docks, self._panes)
sash_size = self._art.GetMetric(aui.AUI_DOCKART_SASH_SIZE)
opposite_size = self.GetOppositeDockTotalSize(
docks, dock.dock_direction
)
for tmpDock in docks:
if (
tmpDock.dock_direction == dock.dock_direction
and tmpDock.dock_layer == dock.dock_layer
and tmpDock.dock_row == dock.dock_row
):
tmpDock.size = 1
break
neighbor_docks = []
horizontal = (
dock.dock_direction == aui.AUI_DOCK_LEFT
or dock.dock_direction == aui.AUI_DOCK_RIGHT
)
right_or_down = (
dock.dock_direction == aui.AUI_DOCK_RIGHT
or dock.dock_direction == aui.AUI_DOCK_BOTTOM
)
for d in docks:
if (
d.dock_direction == dock.dock_direction
and d.dock_layer == dock.dock_layer
):
if horizontal:
neighbor_docks.append((d.rect.x, d.rect.width))
else:
neighbor_docks.append((d.rect.y, d.rect.height))
neighbor_docks.sort()
sizer, panes, docks, uiparts = self.LayoutAll(
panes, docks, [], True, False
)
client_size = self._frame.GetClientSize()
sizer.SetDimension(0, 0, client_size.x, client_size.y)
sizer.Layout()
for part in uiparts:
part.rect = wx.Rect(
part.sizer_item.GetPosition(), part.sizer_item.GetSize()
)
if part.type == aui.AuiDockUIPart.typeDock:
part.dock.rect = part.rect
sizer.Destroy()
new_dock = None
for tmpDock in docks:
if (
tmpDock.dock_direction == dock.dock_direction
and tmpDock.dock_layer == dock.dock_layer
and tmpDock.dock_row == dock.dock_row
):
new_dock = tmpDock
break
partnerDock = self.GetPartnerDock(dock)
if partnerDock:
if horizontal:
pos = dock.rect.x
size = dock.rect.width
else:
pos = dock.rect.y
size = dock.rect.height
min_pos = pos
max_pos = pos + size
if right_or_down:
for p, s in neighbor_docks:
if p >= pos:
max_pos = p + s - sash_size
break
else:
min_pos = p + sash_size
else:
for p, s in neighbor_docks:
if p > pos:
max_pos = p + s - sash_size
break
else:
min_pos = p + sash_size
return min_pos, max_pos
direction = new_dock.dock_direction
if direction == aui.AUI_DOCK_LEFT:
minPix = new_dock.rect.x + new_dock.rect.width
maxPix = client_size.x - opposite_size - sash_size
elif direction == aui.AUI_DOCK_TOP:
minPix = new_dock.rect.y + new_dock.rect.height
maxPix = client_size.y - opposite_size - sash_size
elif direction == aui.AUI_DOCK_RIGHT:
minPix = opposite_size
maxPix = new_dock.rect.x - sash_size
elif direction == aui.AUI_DOCK_BOTTOM:
minPix = opposite_size
maxPix = new_dock.rect.y - sash_size
return minPix, maxPix
def GetPartnerDockFromPos(self, dock, point):
"""Get the neighboring dock located at the given position, used to
find the other dock that is going to change size when resizing the
specified dock.
"""
horizontal = (
dock.dock_direction == aui.AUI_DOCK_LEFT
or dock.dock_direction == aui.AUI_DOCK_RIGHT
)
right_or_down = (
dock.dock_direction == aui.AUI_DOCK_RIGHT
or dock.dock_direction == aui.AUI_DOCK_BOTTOM
)
if horizontal:
pos = point.x
else:
pos = point.y
neighbor_docks = []
for d in self._docks:
if (
d.dock_direction == dock.dock_direction
and d.dock_layer == dock.dock_layer
):
if horizontal:
neighbor_docks.append((d.rect.x, d.rect.width, d))
else:
neighbor_docks.append((d.rect.y, d.rect.height, d))
neighbor_docks.sort()
last = None
if right_or_down:
for p, s, d in neighbor_docks:
if pos < p + s:
if d.dock_row == dock.dock_row:
d = last
break
last = d
else:
neighbor_docks.reverse()
for p, s, d in neighbor_docks:
if pos > p:
if d.dock_row == dock.dock_row:
d = last
break
last = d
return d
def RestrictResize(self, clientPt, screenPt, createDC):
""" Common method between :meth:`DoEndResizeAction` and :meth:`OnLeftUp_Resize`. """
dock = self._action_part.dock
pane = self._action_part.pane
if createDC:
if wx.Platform == "__WXMAC__":
dc = wx.ClientDC(self._frame)
else:
dc = wx.ScreenDC()
aui.DrawResizeHint(dc, self._action_rect)
self._action_rect = wx.Rect()
newPos = clientPt - self._action_offset
if self._action_part.type == aui.AuiDockUIPart.typeDockSizer:
minPix, maxPix = self.CalculateDockSizerLimits(dock)
else:
if not self._action_part.pane:
return
minPix, maxPix = self.CalculatePaneSizerLimits(dock, pane)
if self._action_part.orientation == wx.HORIZONTAL:
newPos.y = aui.Clip(newPos.y, minPix, maxPix)
else:
newPos.x = aui.Clip(newPos.x, minPix, maxPix)
if self._action_part.type == aui.AuiDockUIPart.typeDockSizer:
partner = self.GetPartnerDockFromPos(dock, newPos)
sash_size = self._art.GetMetric(aui.AUI_DOCKART_SASH_SIZE)
button_size = self._art.GetMetric(aui.AUI_DOCKART_PANE_BUTTON_SIZE)
new_dock_size = 0
direction = dock.dock_direction
if direction == aui.AUI_DOCK_LEFT:
new_dock_size = newPos.x - dock.rect.x
elif direction == aui.AUI_DOCK_TOP:
new_dock_size = newPos.y - dock.rect.y
elif direction == aui.AUI_DOCK_RIGHT:
new_dock_size = (
dock.rect.x + dock.rect.width - newPos.x - sash_size
)
elif direction == aui.AUI_DOCK_BOTTOM:
new_dock_size = (
dock.rect.y + dock.rect.height - newPos.y - sash_size
)
delta = new_dock_size - dock.size
if delta < -dock.size + sash_size:
delta = -dock.size + sash_size
elif -button_size < delta < button_size:
delta = button_size * (1 if delta > 0 else -1)
if partner:
if delta > partner.size - sash_size:
delta = partner.size - sash_size
partner.size -= delta
dock.size += delta
self.Update()
else:
# determine the new pixel size that the user wants
# this will help us recalculate the pane's proportion
if dock.IsHorizontal():
oldPixsize = pane.rect.width
newPixsize = oldPixsize + newPos.x - self._action_part.rect.x
else:
oldPixsize = pane.rect.height
newPixsize = oldPixsize + newPos.y - self._action_part.rect.y
totalPixsize, totalProportion = self.GetTotalPixSizeAndProportion(
dock
)
partnerPane = self.GetPartnerPane(dock, pane)
# prevent division by zero
if totalPixsize <= 0 or totalProportion <= 0 or not partnerPane:
return
# adjust for the surplus
while (
oldPixsize > 0
and totalPixsize > 10
and oldPixsize * totalProportion / totalPixsize
< pane.dock_proportion
):
totalPixsize -= 1
# calculate the new proportion of the pane
newProportion = newPixsize * totalProportion / totalPixsize
newProportion = aui.Clip(newProportion, 1, totalProportion)
deltaProp = newProportion - pane.dock_proportion
if partnerPane.dock_proportion - deltaProp < 1:
deltaProp = partnerPane.dock_proportion - 1
newProportion = pane.dock_proportion + deltaProp
# borrow the space from our neighbor pane to the
# right or bottom (depending on orientation)
partnerPane.dock_proportion -= deltaProp
pane.dock_proportion = newProportion
self.Update()
return True
def UpdateWithoutLayout(self):
"""If the layout in the AUI manager is not changing, this can be called
to refresh all the panes but preventing a big time usage doing a re-
layout that isn't necessary.
"""
pane_count = len(self._panes)
for ii in range(pane_count):
p = self._panes[ii]
if p.window and p.IsShown() and p.IsDocked():
p.window.Refresh()
p.window.Update()
if wx.Platform == "__WXMAC__":
self._frame.Refresh()
else:
self.Repaint()
|