Big cleanup in pyfatogglepanel. Removed the animation stuff

This commit is contained in:
HomeWorld
2010-09-06 17:49:02 +03:00
parent 8908a54437
commit bad7e81a6d

View File

@@ -20,22 +20,35 @@ class TogglePanel ( wx.Panel ):
self._toggle = 1
self.parent = parent
self.bkColour = self.GetBackgroundColour()
# self.SetBackgroundColour( self.bkColour )
# Create the main sizer of this panel
self.mainSizer = wx.BoxSizer( wx.VERTICAL )
self.SetSizer( self.mainSizer )
# Create the header panel
self.headerPanel = wx.Panel(self)
self.headerPanel.SetBackgroundColour( self.bkColour)
self.mainSizer.Add(self.headerPanel,0,wx.EXPAND,5)
# Attempt to use native treeitembitmaps - fails on linux distros
# self.bmpExpanded = self.GetNativeTreeItemBitmap("expanded")
# self.bmpCollapsed = self.GetNativeTreeItemBitmap("")
#
# Load expanded/collapsed bitmaps from the icons folder
self.bmpExpanded = bitmapLoader.getBitmap("down-arrow2","icons")
self.bmpCollapsed = bitmapLoader.getBitmap("up-arrow2","icons")
# Make the bitmaps have the same color as window text
sysTextColour = wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOWTEXT )
img = self.bmpExpanded.ConvertToImage()
@@ -46,10 +59,13 @@ class TogglePanel ( wx.Panel ):
img.Replace(0, 0, 0, sysTextColour[0], sysTextColour[1], sysTextColour[2])
self.bmpCollapsed = wx.BitmapFromImage(img)
# Assign the bitmaps to the header static bitmap control
self.headerBmp = wx.StaticBitmap(self.headerPanel )
self.headerBmp.SetBitmap( self.bmpExpanded)
# Create the header sizer and append the static bitmap and static text controls
headerSizer = wx.BoxSizer( wx.HORIZONTAL )
self.headerPanel.SetSizer( headerSizer)
@@ -58,52 +74,34 @@ class TogglePanel ( wx.Panel ):
hbmpSizer.Add( self.headerBmp, 0,0, 5 )
self.headerLabel = wx.StaticText( self.headerPanel, wx.ID_ANY, u"Test", wx.DefaultPosition, wx.DefaultSize, 0 )
self.headerLabel = wx.StaticText( self.headerPanel, wx.ID_ANY, u"PYFA", wx.DefaultPosition, wx.DefaultSize, 0 )
hlblSizer.Add( self.headerLabel, 1, wx.EXPAND , 5 )
headerSizer.Add( hbmpSizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5 )
headerSizer.Add( hlblSizer, 0, wx.ALIGN_CENTER_VERTICAL, 5 )
# Set the static text font weight to BOLD
headerFont=parent.GetFont()
headerFont.SetWeight(wx.BOLD)
self.headerLabel.SetFont(headerFont)
# Create the content panel and its main sizer
self.contentSizer = wx.BoxSizer( wx.VERTICAL )
self.contentPanel = wx.Panel(self)
self.contentPanel.SetSizer(self.contentSizer)
self.SetBackgroundColour( self.bkColour )
self.mainSizer.Add( self.contentPanel, 1, wx.EXPAND, 5)
self.Layout()
self._timerId = wx.NewId()
self._timer = None
self._animStep = 0
self._period = 15
self._animDuration = 250
self._animValue = 0
self.contentPanelMaxSize = 0
self.currentSize = 0
self.targetSize = 0
# Connect Events
self.headerLabel.Bind( wx.EVT_LEFT_UP, self.toggleContent )
self.headerBmp.Bind( wx.EVT_LEFT_UP, self.toggleContent )
self.headerPanel.Bind( wx.EVT_LEFT_UP, self.toggleContent )
self.headerLabel.Bind( wx.EVT_ENTER_WINDOW, self.enterWindow )
self.headerLabel.Bind( wx.EVT_LEAVE_WINDOW, self.leaveWindow )
self.headerBmp.Bind( wx.EVT_ENTER_WINDOW, self.enterWindow )
self.headerBmp.Bind( wx.EVT_LEAVE_WINDOW, self.leaveWindow )
self.headerPanel.Bind( wx.EVT_ENTER_WINDOW, self.enterWindow )
self.headerPanel.Bind( wx.EVT_LEAVE_WINDOW, self.leaveWindow )
self.Bind(wx.EVT_TIMER, self.OnTimer)
def __del__( self ):
pass
@@ -132,33 +130,27 @@ class TogglePanel ( wx.Panel ):
return bitmap
# Virtual event handlers, overide them in your derived class
def toggleContent( self, event ):
if not self._timer:
self._timer = wx.Timer(self, self._timerId)
if self._timer.IsRunning():
return
# Toggle the content panel (hide/show)
def toggleContent( self, event ):
if self._toggle == 1:
# self.contentPanel.Hide()
self.contentPanel.Hide()
self.headerBmp.SetBitmap( self.bmpCollapsed)
if self._timer.IsRunning() == False:
self.contentPanelMaxSize = self.contentPanel.GetSize().GetHeight()
self.currentSize = self.contentPanelMaxSize
self.targetSize = 0
else:
# self.contentPanel.Show()
self.contentPanel.Show()
self.headerBmp.SetBitmap( self.bmpExpanded)
self.currentSize = 0
self.targetSize = self.contentPanelMaxSize
self._toggle *=-1
self._animStep = 0
self._timer.Start(self._period)
self.parent.Layout()
self.parent.Refresh()
event.Skip()
# Highlight stuff, not used for now
def enterWindow( self, event ):
self.headerPanel.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHT ) )
@@ -173,52 +165,3 @@ class TogglePanel ( wx.Panel ):
event.Skip()
def OUT_QUAD (self, t, b, c, d):
t=float(t)
b=float(b)
c=float(c)
d=float(d)
t/=d
return -c *(t)*(t-2) + b
def OnTimer( self, event ):
oldValue = self.currentSize
value = self.targetSize
if oldValue < value:
direction = 1
start = 0
end = value-oldValue
else:
direction = -1
start = 0
end = oldValue - value
step=self.OUT_QUAD(self._animStep, start, end, self._animDuration)
self._animStep += self._period
if self._timerId == event.GetId():
stop_timer = False
if self._animStep > self._animDuration:
stop_timer = True
if direction == 1:
if (oldValue+step) < value:
self._animValue = oldValue+step
else:
stop_timer = True
else:
if (oldValue-step) > value:
self._animValue = oldValue-step
else:
stop_timer = True
if stop_timer:
self._timer.Stop()
self.contentPanel.SetMinSize(wx.Size(-1, round(self._animValue)))
# self.contentPanel.Layout()
self.parent.Layout()
# self.parent.Fit()