def __init__(self, *args, **kwargs): try: caption = kwargs.pop('caption') except KeyError: caption = None #kwargs['folded'] = False foldingPane.__init__(self, *args, **kwargs) self.stCaption = wx.Panel(self, -1) self.bmR = BitmapFromBits(r_arrow, 16, 16, ColourFromStyle('BLACK')) self.bmD = BitmapFromBits(d_arrow, 16, 16, ColourFromStyle('BLACK')) hsizer = wx.BoxSizer(wx.HORIZONTAL) #self.bFold = wx.BitmapButton(capPan, -1, bitmap=self.bmR, style = wx.NO_BORDER) self.bFold = foldButton(self.stCaption, -1) hsizer.Add(self.bFold, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 2) hsizer.Add(wx.StaticText(self.stCaption, -1, caption), 1, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) self.stCaption.SetSizerAndFit(hsizer) self.sizer.Add(self.stCaption, 0, 0, 0) self.bFold.Bind(wx.EVT_LEFT_UP, self.OnFold)
def __init__(self, parent, id = wx.ID_ANY, pos=(-1,-1), caption="", foldIcons=None, cbstyle=DEFAULT_CAPTION_STYLE): wx.Window.__init__(self, parent, id, pos=pos, size=(-1,cbstyle['HEIGHT']), style=wx.NO_BORDER) self.style = cbstyle self.parent = parent self.caption = caption self.foldIcons = foldIcons self._inactive_pin_bitmap = BitmapFromBits(pin_bits, 16, 16, ColourFromStyle(self.style['INACTIVE_PIN_COLOUR'])) self._active_pin_bitmap = BitmapFromBits(pin_bits, 16, 16, ColourFromStyle(self.style['ACTIVE_PIN_COLOUR'])) self.pinButtonRect = (0,0,0,0) # if foldIcons is None: # foldIcons = wx.ImageList(16, 16) # # bmp = ExpandedIcon.GetBitmap() # foldIcons.Add(bmp) # bmp = CollapsedIcon.GetBitmap() # foldIcons.Add(bmp) # # # set initial size # if foldIcons: # assert foldIcons.GetImageCount() > 1 # iconWidth, iconHeight = foldIcons.GetSize(0) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick) self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnterLeave) self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseEnterLeave)
def __init__(self, parent, id = wx.ID_ANY, pos=(-1,-1), caption="", foldIcons=None, cbstyle=DEFAULT_CAPTION_STYLE, pin_bits=pin_bits): wx.Window.__init__(self, parent, id, pos=pos, size=(-1,cbstyle['HEIGHT']), style=wx.NO_BORDER) self.style = cbstyle self.parent = parent self.caption = caption self.foldIcons = foldIcons self.buttons = [] self._inactive_pin_bitmap = BitmapFromBits(pin_bits, 16, 16, ColourFromStyle(self.style['INACTIVE_PIN_COLOUR'])) self._active_pin_bitmap = BitmapFromBits(pin_bits, 16, 16, ColourFromStyle(self.style['ACTIVE_PIN_COLOUR'])) #self.pinButtonRect = (0,0,0,0) self.buttons.append(CaptionButton(self._active_pin_bitmap, self._inactive_pin_bitmap, show_fcn=lambda : self.style['HAS_PIN'] and self.parent.foldable, active_fcn=lambda : self.parent.pinnedOpen, onclick=lambda : self.parent.TogglePin())) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)
def __init__(self, parent, id=-1): wx.Window.__init__(self, parent, id, size=(16, 16)) self.bmR = BitmapFromBits(r_arrow, 16, 16, ColourFromStyle('BLACK')) self.bmD = BitmapFromBits(d_arrow, 16, 16, ColourFromStyle('BLACK')) self.folded = True self.Bind(wx.EVT_PAINT, self.OnPaint)
class CaptionBar(wx.Window): def __init__(self, parent, id=wx.ID_ANY, pos=(-1, -1), caption="", foldIcons=None, cbstyle=DEFAULT_CAPTION_STYLE): wx.Window.__init__(self, parent, id, pos=pos, size=(-1, cbstyle['HEIGHT']), style=wx.NO_BORDER) self.style = cbstyle self.parent = parent self.caption = caption self.foldIcons = foldIcons self._inactive_pin_bitmap = BitmapFromBits( pin_bits, 16, 16, ColourFromStyle(self.style['INACTIVE_PIN_COLOUR'])) self._active_pin_bitmap = BitmapFromBits( pin_bits, 16, 16, ColourFromStyle(self.style['ACTIVE_PIN_COLOUR'])) self.pinButtonRect = (0, 0, 0, 0) # if foldIcons is None: # foldIcons = wx.ImageList(16, 16) # # bmp = ExpandedIcon.GetBitmap() # foldIcons.Add(bmp) # bmp = CollapsedIcon.GetBitmap() # foldIcons.Add(bmp) # # # set initial size # if foldIcons: # assert foldIcons.GetImageCount() > 1 # iconWidth, iconHeight = foldIcons.GetSize(0) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick) self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnterLeave) self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseEnterLeave) # self.Bind(wx.EVT_CHAR, self.OnChar) def OnPaint(self, event): dc = wx.PaintDC(self) gc = wx.GraphicsContext.Create(dc) gc.PushState() wndRect = self.GetRect() # vertical = self.IsVertical() #self.FillCaptionBackground(dc) #barHeight = self.style['HEIGHT'] #gc.DrawRectangle(0,0, self.style['HEIGHT'],50,50,5) col_1 = ColourFromStyle(self.style['BACKGROUND_COLOUR_1']) col_2 = ColourFromStyle(self.style['BACKGROUND_COLOUR_2']) brush = gc.CreateLinearGradientBrush(0, 0, 0, self.style['HEIGHT'], col_1, col_2) gc.SetBrush(brush) gc.DrawRectangle(*wndRect) font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) #print font.GetFaceName(), font.GetPointSize() if 'FONT_WEIGHT' in self.style.keys(): font.SetWeight(self.style['FONT_WEIGHT']) if 'FONT_SIZE' in self.style.keys(): font.SetPointSize(self.style['FONT_SIZE']) fc = ColourFromStyle(self.style['FONT_COLOUR']) gc.SetFont(font, fc) w, h = gc.GetTextExtent(self.caption) y0 = self.style['HEIGHT'] / 2. - h / 2. gc.DrawText(self.caption, self.style['CAPTION_INDENT'], y0) h = self._active_pin_bitmap.GetHeight() w = self._active_pin_bitmap.GetWidth() y0 = self.style['HEIGHT'] / 2. - h / 2. #print wndRect[2] self.pinButtonRect = (wndRect[2] - h - y0, y0, w, h) if self.parent.foldable: if self.parent.pinnedOpen: gc.DrawBitmap(self._active_pin_bitmap, *self.pinButtonRect) else: gc.DrawBitmap(self._inactive_pin_bitmap, *self.pinButtonRect) if self.parent.folded and self.parent.foldable: self.DrawEllipses(gc) gc.PopState() def DrawEllipses(self, gc): gc.SetBrush(wx.Brush(ColourFromStyle(self.style['ELLIPSES_COLOUR']))) path = gc.CreatePath() path.AddCircle(0, 0, self.style['ELLIPSES_RADIUS']) path.AddCircle(3 * self.style['ELLIPSES_RADIUS'], 0, self.style['ELLIPSES_RADIUS']) path.AddCircle(6 * self.style['ELLIPSES_RADIUS'], 0, self.style['ELLIPSES_RADIUS']) gc.PushState() gc.Translate(self.pinButtonRect[0], self.pinButtonRect[1] + self.pinButtonRect[3]) bx = path.GetBox() gc.Translate(-bx[2], -bx[3]) gc.FillPath(path) gc.PopState() def OnLeftClick(self, event): if wx.Rect(*self.pinButtonRect).Inside(event.GetPosition()): self.parent.TogglePin() def OnSize(self, event): rect = self.GetRect() self.RefreshRect(rect) def OnMouseEnterLeave(self, event): #event.ResumePropagation(2) #print event.ShouldPropagate() #print 'mev' event.SetEventObject(self.parent) event.ResumePropagation(2) event.Skip()