I wasn't ready to add this yet.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71834 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2012-06-22 21:29:15 +00:00
parent c8c2e1d97b
commit a30dfe91e2
133 changed files with 0 additions and 68276 deletions

View File

@@ -1,79 +0,0 @@
#----------------------------------------------------------------------
# Name: wx.lib.utils
# Purpose: Miscelaneous utility functions
#
# Author: Robin Dunn
#
# Created: 18-Jan-2009
# RCS-ID: $Id$
# Copyright: (c) 2009 Total Control Software
# Licence: wxWidgets license
#----------------------------------------------------------------------
"""
A few useful functions. (Ok, only one so far...)
"""
import wx
#---------------------------------------------------------------------------
def AdjustRectToScreen(rect, adjust=(0,0)):
"""
Compare the rect with the dinmensions of the display that the rect's
upper left corner is positioned on. If it doesn't fit entirely on
screen then attempt to make it do so either by repositioning the
rectangle, resizing it, or both. Returns the adjusted rectangle.
If the adjustment value is given then it will be used to ensure that
the rectangle is at least that much smaller than the display's client
area.
"""
assert isinstance(rect, wx.Rect)
if -1 in rect.Get():
# bail out if there are any -1's in the dimensions
return rect
dispidx = wx.Display.GetFromPoint(rect.Position)
if dispidx == wx.NOT_FOUND:
dispidx = 0
ca = wx.Display(dispidx).GetClientArea()
assert isinstance(ca, wx.Rect)
# is it already fully visible?
if ca.ContainsRect(rect):
return rect
# if not then try adjusting the position
if not ca.Contains(rect.Position):
rect.Position = ca.Position
if ca.ContainsRect(rect):
return rect
dx = dy = 0
if rect.right > ca.right:
dx = ca.right - rect.right
if rect.bottom > ca.bottom:
dy = ca.bottom - rect.bottom
rect.OffsetXY(dx, dy)
# if the rectangle has been moved too far, then readjust the position
# and also adjust the size
if rect.left < ca.left:
rect.width -= (ca.left - rect.left)
rect.left = ca.left
if rect.top < ca.top:
rect.height -= (ca.top - rect.top)
rect.top = ca.top
# make final adjustments if needed
adjust = wx.Size(*adjust)
if rect.width > (ca.width - adjust.width):
rect.width = ca.width - adjust.width
if rect.height > (ca.height - adjust.height):
rect.height = ca.height - adjust.height
# return the result
return rect
#---------------------------------------------------------------------------