| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
from wxPython import wx |
|---|
| 27 |
|
|---|
| 28 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 29 |
#~ Definitions |
|---|
| 30 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 31 |
|
|---|
| 32 |
class wxWindowExpander(object): |
|---|
| 33 |
def __init__(self, window, horizontal=False, vertical=False): |
|---|
| 34 |
self.window = window |
|---|
| 35 |
self.horizontal = horizontal |
|---|
| 36 |
self.vertical = vertical |
|---|
| 37 |
|
|---|
| 38 |
def CanAdjust(self): |
|---|
| 39 |
try: |
|---|
| 40 |
return not self.window.IsMaximized() and not self.window.IsIconized() and not self.window.IsFullScreen() |
|---|
| 41 |
except AttributeError: |
|---|
| 42 |
return True |
|---|
| 43 |
|
|---|
| 44 |
def AdjustDimensions(self, item, prepend=False, *args, **kw): |
|---|
| 45 |
if self.CanAdjust(): |
|---|
| 46 |
width, height = item.GetSize().asTuple() |
|---|
| 47 |
try: |
|---|
| 48 |
minsize = item.GetMinSize().asTuple() |
|---|
| 49 |
width = max(width, minsize[0]) |
|---|
| 50 |
height = max(height , minsize[1]) |
|---|
| 51 |
except AttributeError: |
|---|
| 52 |
pass |
|---|
| 53 |
|
|---|
| 54 |
if prepend: |
|---|
| 55 |
self.AdjustDimensionsEx(-width, -height, width, height, *args, **kw) |
|---|
| 56 |
else: |
|---|
| 57 |
self.AdjustDimensionsEx(0, 0, width, height, *args, **kw) |
|---|
| 58 |
|
|---|
| 59 |
def AdjustDimensionsEx(self, dx,dy,dw,dh, horizontal=False,vertical=False, sign=1): |
|---|
| 60 |
if self.CanAdjust(): |
|---|
| 61 |
x,y = self.window.GetPosition() |
|---|
| 62 |
w,h = self.window.GetSize() |
|---|
| 63 |
|
|---|
| 64 |
if vertical or self.vertical: dx = dw = 0 |
|---|
| 65 |
if horizontal or self.horizontal: dy = dh = 0 |
|---|
| 66 |
|
|---|
| 67 |
self.window.SetDimensions(x+sign*dx, y+sign*dy, w+sign*dw, h+sign*dh, wx.wxSIZE_ALLOW_MINUS_ONE) |
|---|
| 68 |
|
|---|
| 69 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 70 |
|
|---|
| 71 |
class wxExpandableBoxSizer(wx.wxBoxSizer): |
|---|
| 72 |
def __init__(self, expandwindow, orientation, enabled=False): |
|---|
| 73 |
wx.wxBoxSizer.__init__(self, orientation) |
|---|
| 74 |
self.SetExpandingEnabled(enabled) |
|---|
| 75 |
|
|---|
| 76 |
self.expander = wxWindowExpander(expandwindow, orientation==wx.wxHORIZONTAL, orientation== wx.wxVERTICAL) |
|---|
| 77 |
|
|---|
| 78 |
def GetExpandingEnabled(self, value): |
|---|
| 79 |
return self.ExpandingEnabled |
|---|
| 80 |
def SetExpandingEnabled(self, value): |
|---|
| 81 |
self.ExpandingEnabled = value |
|---|
| 82 |
|
|---|
| 83 |
def Add(self, item, sizerOption=0, sizerFlag=0, sizerBorder=0): |
|---|
| 84 |
if self.ExpandingEnabled: |
|---|
| 85 |
self.expander.AdjustDimensions(item, False) |
|---|
| 86 |
result = wx.wxBoxSizer.Add(self, item, sizerOption, sizerFlag, sizerBorder, False) |
|---|
| 87 |
return result |
|---|
| 88 |
|
|---|
| 89 |
def Prepend(self, item, sizerOption=0, sizerFlag=0, sizerBorder=0): |
|---|
| 90 |
if self.ExpandingEnabled: |
|---|
| 91 |
self.expander.AdjustDimensions(item, True) |
|---|
| 92 |
result = wx.wxBoxSizer.Prepend(self, item, sizerOption, sizerFlag, sizerBorder, True) |
|---|
| 93 |
return result |
|---|
| 94 |
|
|---|
| 95 |
def Remove(self, item, *args, **kw): |
|---|
| 96 |
if self.ExpandingEnabled: |
|---|
| 97 |
for child in self.GetChildren(): |
|---|
| 98 |
if child.GetWindow() is item: |
|---|
| 99 |
width, height = child.GetSize().asTuple() |
|---|
| 100 |
reposition = child.GetUserData() |
|---|
| 101 |
break |
|---|
| 102 |
|
|---|
| 103 |
if reposition is True: |
|---|
| 104 |
self.expander.AdjustDimensionsEx(width, height, -width, -height) |
|---|
| 105 |
elif reposition is False: |
|---|
| 106 |
self.expander.AdjustDimensionsEx(0, 0, -width, -height) |
|---|
| 107 |
return wx.wxBoxSizer.Remove(self, item, *args, **kw) |
|---|
| 108 |
|
|---|