home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / gui / chevron.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  6.3 KB  |  163 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. from gui.textutil import GetTextWidth
  6. from gui import skin
  7. from gui.toolbox import prnt
  8. from cgui import SimplePanel
  9. from config import platformName
  10.  
  11. class Chevron(SimplePanel):
  12.     
  13.     def __init__(self, parent, label = '', callapsedicon = None, expandedicon = None):
  14.         SimplePanel.__init__(self, parent)
  15.         if not callapsedicon:
  16.             pass
  17.         self.callapsedicon = skin.get('AppDefaults.icons.chevroncolapsed')
  18.         if not expandedicon:
  19.             pass
  20.         self.expandedicon = skin.get('AppDefaults.icons.chevronexpanded')
  21.         self.Label = label
  22.         self._expanded = False
  23.         self.CalcSize()
  24.         self.isdown = False
  25.         Bind = self.Bind
  26.         Bind(wx.EVT_PAINT, self.OnPaint)
  27.         Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
  28.         Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
  29.         Bind(wx.EVT_LEFT_DCLICK, self.OnDClick)
  30.         Bind(wx.EVT_ENTER_WINDOW, self.OnMouseIn)
  31.         Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseOut)
  32.  
  33.     
  34.     def OnMouseIn(self, e):
  35.         self.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
  36.  
  37.     
  38.     def OnMouseOut(self, e):
  39.         self.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
  40.  
  41.     
  42.     def CalcSize(self):
  43.         iwidth = max([
  44.             self.callapsedicon.Width,
  45.             self.expandedicon.Width])
  46.         iheight = max([
  47.             self.callapsedicon.Height,
  48.             self.expandedicon.Height])
  49.         self.iconspace = wx.Size(iwidth, iheight)
  50.         fwidth = GetTextWidth(self.Label, self.Font)
  51.         fheight = self.Font.Height
  52.         self.MinSize = wx.Size(iwidth + fwidth + 12, max([
  53.             iheight,
  54.             fheight]) + 6)
  55.  
  56.     
  57.     def GetExpanded(self):
  58.         return self._expanded
  59.  
  60.     
  61.     def SetExpanded(self, expand):
  62.         self._expanded = expand
  63.         e = wx.CommandEvent(wx.wxEVT_COMMAND_CHECKBOX_CLICKED)
  64.         e.EventObject = self
  65.         e.SetInt(expand)
  66.         self.AddPendingEvent(e)
  67.  
  68.     Expanded = property(GetExpanded, SetExpanded)
  69.     
  70.     def OnPaint(self, event):
  71.         dc = wx.PaintDC(self)
  72.         rect = wx.RectS(self.Size)
  73.         if platformName != 'mac':
  74.             dc.Brush = wx.Brush(self.BackgroundColour)
  75.             dc.Pen = wx.TRANSPARENT_PEN
  76.             dc.DrawRectangleRect(rect)
  77.         
  78.         dc.Font = self.Font
  79.         (iwidth, iheight) = self.iconspace
  80.         icon = None if self.Expanded else self.callapsedicon
  81.         textrect = wx.Rect(iwidth + 9, 0, rect.width - (iwidth + 9) - 3, rect.height)
  82.         dc.DrawBitmap(icon, (iwidth // 2 - icon.Width // 2) + 3, (iheight // 2 - icon.Height // 2) + 3, True)
  83.         dc.DrawLabel(self.Label, textrect, wx.ALIGN_LEFT | wx.ALIGN_TOP)
  84.  
  85.     
  86.     def OnDClick(self, event):
  87.         self.OnLeftDown(event)
  88.         self.OnLeftUp(event)
  89.  
  90.     
  91.     def OnLeftDown(self, event):
  92.         self.isdown = True
  93.  
  94.     
  95.     def OnLeftUp(self, event):
  96.         if self.isdown:
  97.             self.Expanded = not (self.Expanded)
  98.             self.isdown = False
  99.         
  100.         self.Refresh()
  101.  
  102.  
  103.  
  104. class ChevronPanel(SimplePanel):
  105.     
  106.     def __init__(self, parent, label = '', collapsedicon = None, expandedicon = None):
  107.         SimplePanel.__init__(self, parent)
  108.         self.construct(label, collapsedicon, expandedicon)
  109.         self.layout()
  110.         self.bind_events()
  111.         self.ToggleContents()
  112.         self.Label = 'chevron panel'
  113.  
  114.     
  115.     def construct(self, label, collapsedicon, expandedicon):
  116.         self.chevron = Chevron(self, label, collapsedicon, expandedicon)
  117.         self.contents = wx.Panel(self, -1)
  118.         self.contents.Label = 'chevron contents panel'
  119.         self.contents.Sizer = wx.BoxSizer(wx.VERTICAL)
  120.  
  121.     
  122.     def layout(self):
  123.         self.Sizer = wx.BoxSizer(wx.VERTICAL)
  124.         self.Sizer.Add(self.chevron, 0, wx.EXPAND | wx.ALL)
  125.         self.Sizer.Add(self.contents, 1, wx.EXPAND | wx.ALL)
  126.  
  127.     
  128.     def bind_events(self):
  129.         self.chevron.Bind(wx.EVT_COMMAND_CHECKBOX_CLICKED, self.ToggleContents)
  130.  
  131.     
  132.     def ToggleContents(self, evt = None):
  133.         if evt is not None:
  134.             obj = evt.GetEventObject()
  135.         else:
  136.             obj = self.chevron
  137.         self.contents.Show(obj.Expanded)
  138.         self.Top.Fit()
  139.  
  140.  
  141.  
  142. class F(wx.Frame):
  143.     
  144.     def __init__(self):
  145.         wx.Frame.__init__(self, None)
  146.         S = self.Sizer = wx.BoxSizer(wx.VERTICAL)
  147.         p = self.panel = wx.Panel(self)
  148.         S.Add(p, 1, wx.EXPAND)
  149.         s = p.Sizer = wx.BoxSizer(wx.VERTICAL)
  150.         chev = self.chev = Chevron(p, 'Expand')
  151.         chev.Bind(wx.EVT_CHECKBOX, (lambda e: prnt('clixxd', e.IsChecked())))
  152.         s.Add(chev, 0, wx.ALL, 10)
  153.  
  154.  
  155. if __name__ == '__main__':
  156.     from tests.testapp import testapp
  157.     hit = wx.FindWindowAtPointer
  158.     a = testapp('../../')
  159.     f = F()
  160.     f.Show(True)
  161.     a.MainLoop()
  162.  
  163.