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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. from gui.uberwidgets.UberButton import UberButton
  6. from gui.uberwidgets.UberCombo import UberCombo
  7. from gui.uberwidgets.simplemenu import SimpleMenuItem
  8. from gui.skin.skinparse import makeFont
  9. from cgui import SimplePanel
  10. from gui.anylists import AnyList
  11. from gui.toolbox import AutoDC
  12. from wx import BoxSizer, BOTTOM, TOP, LEFT, RIGHT, EXPAND, VERTICAL, HORIZONTAL
  13. wxMac = 'wxMac' in wx.PlatformInfo
  14.  
  15. def PrefCollection(*workers, **options):
  16.     if 'layout' in options:
  17.         layout = options['layout']
  18.     else:
  19.         layout = wx.GridSizer(rows = 0, cols = 1)
  20.     if 'itemoptions' in options:
  21.         itemoptions = options['itemoptions']
  22.     else:
  23.         itemoptions = (0, EXPAND)
  24.     
  25.     def Factory(parent, prefix = (None, None, '')):
  26.         panel = wx.Panel(parent, style = wx.FULL_REPAINT_ON_RESIZE)
  27.         panel.Sizer = layout
  28.         for workerortuple in workers:
  29.             if isinstance(workerortuple, tuple):
  30.                 worker = workerortuple[0]
  31.                 addoptions = workerortuple[1:]
  32.             else:
  33.                 worker = workerortuple
  34.                 addoptions = None
  35.             if callable(worker):
  36.                 window = worker(panel, prefix)
  37.             elif isinstance(worker, wx.WindowClass):
  38.                 window = worker
  39.                 window.Reparent(panel)
  40.             
  41.             if not addoptions:
  42.                 pass
  43.             panel.Sizer.Add(window, *itemoptions)
  44.         
  45.         return panel
  46.  
  47.     return Factory
  48.  
  49. pref_sizer_style = EXPAND | LEFT | RIGHT | BOTTOM
  50. combo_sizer_flags = (LEFT | RIGHT, 7)
  51. if wxMac:
  52.     header_sizer_flags = (wx.ALIGN_BOTTOM,)
  53.     space_over_header = 3
  54.     space_under_header = 8
  55. else:
  56.     header_sizer_flags = (LEFT | wx.ALIGN_CENTER_VERTICAL, 7)
  57.     space_over_header = 0
  58.     space_under_header = 5
  59.  
  60. class PrefPanel(SimplePanel):
  61.     
  62.     def __init__(self, parent, content = None, title = '', buttonlabel = '', buttoncb = None, titlemaker = None, prefix = ''):
  63.         SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE)
  64.         sizer = self.Sizer = BoxSizer(VERTICAL)
  65.         self.headersizer = BoxSizer(HORIZONTAL)
  66.         self.bodysizer = BoxSizer(VERTICAL)
  67.         sizer.Add(self.headersizer, 0, EXPAND | TOP, space_over_header)
  68.         sizer.Add(self.bodysizer, 1, EXPAND | TOP, space_under_header)
  69.         self.title = None
  70.         self.combo = None
  71.         self.button = None
  72.         self.content = None
  73.         self.contents = { }
  74.         self.titlemaker = titlemaker
  75.         if wxMac:
  76.             self.menuitems = { }
  77.         
  78.         if title and isinstance(title, basestring):
  79.             self.title = wx.StaticText(self, -1, ' ' + title + ' ', style = wx.ALIGN_CENTER_VERTICAL)
  80.             if wxMac:
  81.                 self.title.BackgroundColour = wx.Color(232, 232, 232)
  82.             
  83.             self.title.Font = self.HeaderFont
  84.             self.headersizer.Add(self.title, 0, *header_sizer_flags)
  85.         
  86.         if callable(content):
  87.             content = self.content = content(self, prefix)
  88.             self.bodysizer.Add(self.content, 1, pref_sizer_style, 7)
  89.         elif isinstance(content, wx.WindowClass):
  90.             content.Reparent(self)
  91.             self.content = content
  92.             self.bodysizer.Add(self.content, 1, pref_sizer_style, 7)
  93.         elif isinstance(content, list):
  94.             self.SetContents(content)
  95.         
  96.         if buttoncb:
  97.             self.SetButton(buttonlabel, buttoncb)
  98.         
  99.         Bind = self.Bind
  100.         Bind(wx.EVT_PAINT, self.OnPaint)
  101.         if not wxMac:
  102.             self.pen = wx.Pen(wx.Colour(213, 213, 213))
  103.         else:
  104.             self.pen = wx.Pen(wx.Colour(155, 155, 155))
  105.  
  106.     
  107.     def SetTitle(self, title):
  108.         self.title.SetLabel(title)
  109.  
  110.     
  111.     def HeaderFont(self):
  112.         
  113.         try:
  114.             return self._headerfont
  115.         except AttributeError:
  116.             if not wxMac:
  117.                 PrefPanel._headerfont = makeFont('arial 8 bold')
  118.             else:
  119.                 PrefPanel._headerfont = makeFont('9 bold')
  120.             return self._headerfont
  121.  
  122.  
  123.     HeaderFont = property(HeaderFont)
  124.     _fg_brush = _bg_brush = _fg_pen = _bg_pen = (lambda self: pass)
  125.     
  126.     def get_bg_brush(self):
  127.         if not self._bg_brush():
  128.             pass
  129.         return wx.WHITE_BRUSH
  130.  
  131.     
  132.     def get_fg_brush(self):
  133.         if not self._fg_brush():
  134.             pass
  135.         return wx.TRANSPARENT_BRUSH
  136.  
  137.     
  138.     def get_bg_pen(self):
  139.         if not self._bg_pen():
  140.             pass
  141.         return wx.TRANSPARENT_PEN
  142.  
  143.     
  144.     def get_fg_pen(self):
  145.         if not self._fg_pen():
  146.             pass
  147.         return self.pen
  148.  
  149.     bg_brush = property(get_bg_brush)
  150.     fg_brush = property(get_fg_brush)
  151.     bg_pen = property(get_bg_pen)
  152.     fg_pen = property(get_fg_pen)
  153.     
  154.     def OnPaint(self, event):
  155.         size = self.Size
  156.         dc = AutoDC(self)
  157.         if not wxMac:
  158.             rect = wx.RectS(size)
  159.             dc.Brush = self.bg_brush
  160.             dc.Pen = self.bg_pen
  161.             dc.DrawRectangleRect(rect)
  162.             ypos = self.headersizer.Size.height // 2 + space_over_header
  163.             gc = wx.GraphicsContext.Create(dc)
  164.             gc.SetBrush(self.fg_brush)
  165.             gc.SetPen(self.fg_pen)
  166.             gc.DrawRoundedRectangle(0, ypos, size.width - 1, size.height - ypos - 1, 5)
  167.         else:
  168.             ypos = self.headersizer.Size.height // 2 + space_over_header + 2
  169.             dc.Pen = self.fg_pen
  170.             button_width = None if self.button is None else self.button.Size.width
  171.             dc.DrawLine(10, ypos, self.headersizer.Size.width - 10 - button_width, ypos)
  172.         content = self.content
  173.         if isinstance(content, AnyList):
  174.             crect = wx.Rect(*content.Rect)
  175.             crect = crect.Inflate(1, 1)
  176.             dc.SetBrush(wx.TRANSPARENT_BRUSH)
  177.             dc.SetPen(self.pen)
  178.             dc.DrawRectangleRect(crect)
  179.         
  180.  
  181.     
  182.     def ChangeShownContent(self, *a):
  183.         if self.content:
  184.             self.content.Show(False)
  185.         
  186.         if wxMac:
  187.             menu_item = self.menuitems[self.combo.GetStringSelection()]
  188.         else:
  189.             menu_item = self.combo.Value
  190.         self.content = self.contents[menu_item]
  191.         self.content.Show(True)
  192.         self.Layout()
  193.  
  194.     
  195.     def SetButton(self, label, callback):
  196.         if self.button:
  197.             self.headersizer.Detach(self.button)
  198.             self.button.Destroy()
  199.         
  200.         if not wxMac:
  201.             self.button = UberButton(self, -1, label, skin = 'AppDefaults.PrefButton')
  202.         else:
  203.             self.button = wx.Button(self, -1, label)
  204.             self.button.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
  205.         None((self.button.Bind, wx.EVT_BUTTON), (lambda e: callback(self.button)))
  206.         self.headersizer.AddStretchSpacer(1)
  207.         self.headersizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL | RIGHT, 7)
  208.  
  209.     
  210.     def MenuItems(self):
  211.         combo = self.combo
  212.         if wxMac:
  213.             return [ combo.GetClientData(i) for i in xrange(combo.Count) ]
  214.         return combo.menu.spine.items
  215.  
  216.     MenuItems = property(MenuItems)
  217.     
  218.     def SetContents(self, content, destroyold = False):
  219.         if destroyold:
  220.             if not self.contents:
  221.                 self.content.Destroy()
  222.             
  223.             for content in self.contents.values():
  224.                 content.Destroy()
  225.             
  226.         
  227.         if self.content:
  228.             self.content.Show(False)
  229.             self.content = None
  230.         
  231.         self.bodysizer.Clear()
  232.         contents = self.contents = { }
  233.         titlemaker = self.titlemaker
  234.         if self.combo is None:
  235.             if not wxMac:
  236.                 self.combo = UberCombo(self, value = '', skinkey = 'AppDefaults.PrefCombo', valuecallback = self.ChangeShownContent)
  237.             else:
  238.                 self.combo = wx.ComboBox(self, style = wx.CB_DROPDOWN | wx.CB_READONLY)
  239.                 self.combo.Bind(wx.EVT_COMBOBOX, self.ChangeShownContent)
  240.             newcombo = True
  241.         else:
  242.             self.combo.RemoveAllItems()
  243.             newcombo = False
  244.         for object in content:
  245.             if isinstance(object, tuple):
  246.                 (window, label) = object
  247.             elif isinstance(object, wx.WindowClass):
  248.                 window = object
  249.                 label = None if titlemaker else object.Label
  250.             
  251.             window.Show(False)
  252.             window.Reparent(self)
  253.             self.bodysizer.Add(window, 1, pref_sizer_style, 7)
  254.             menuitem = SimpleMenuItem(label)
  255.             contents[menuitem] = window
  256.             if wxMac:
  257.                 itemname = menuitem.GetContentAsString()
  258.                 self.combo.Append(itemname)
  259.                 self.menuitems[itemname] = menuitem
  260.                 continue
  261.             self.combo.AppendItem(menuitem)
  262.         
  263.         if self.combo:
  264.             if wxMac:
  265.                 self.combo.SetSelection(0)
  266.                 self.ChangeShownContent()
  267.             else:
  268.                 self.combo.Value = self.combo[0]
  269.         
  270.         if self.combo is not None and newcombo:
  271.             self.headersizer.Add(self.combo, 1, *combo_sizer_flags)
  272.         
  273.  
  274.  
  275.