home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from gui import skin as skincore
- from gui.uberwidgets.UberButton import UberButton
- from gui.uberwidgets.UberEvents import DragStart, TabNotifiedEvent
- from gui.textutil import default_font
- from gui.windowfx import ApplySmokeAndMirrors
- import wx
- import sys
- from util import do
- from util import Delegate, debug_property
- from common import pref, profile, prefprop
- from gui import skin
- from gui.skin.skinobjects import Margins
- from logging import getLogger
- log = getLogger('tab')
- from wx import EmptyBitmap, MemoryDC, Point, Size, Rect, ImageFromBitmap, WHITE_BRUSH, TRANSPARENT_PEN, BitmapFromImage, BLACK, Point, NullBitmap, RectS, ClientDC, EmptyBitmap, MemoryDC, Rect, PaintDC, BufferedPaintDC, GetMousePosition, ALIGN_LEFT, ALIGN_CENTER_VERTICAL, GetTopLevelParent, Mask, Point
-
- class MultiTab(object):
-
- def __init__(self, tabs):
- self.tabwidth = max((lambda .0: for tab in .0:
- tab.Size.width)(tabs))
- self.tabheight = tabs[0].Size.height
- self.Size = Size(self.tabwidth + 14 * len(tabs), self.tabheight + 14 * len(tabs))
- self.tabs = tabs
-
-
- def OnPaint(self, otherdc, otherwindow):
- size = self.Size
- bitmap = EmptyBitmap(*size)
- mdc = MemoryDC()
- tab = self.tabs[0].states[self.tabs[0].mode][0].GetBitmap(Size(self.tabwidth, self.tabheight))
- tab = ImageFromBitmap(tab)
- tab.ConvertAlphaToMask()
- tab = BitmapFromImage(tab)
- mdc.SelectObject(tab)
- mdc.Brush = WHITE_BRUSH
- mdc.Pen = TRANSPARENT_PEN
- mdc.DrawRectangle(0, 0, self.tabwidth, self.tabheight)
- mdc.SelectObject(bitmap)
- for i, tabobj in enumerate(self.tabs):
- s = 14 * i
- rect = Rect(s, s, self.tabwidth, self.tabheight)
- mdc.DrawBitmap(tab, s, s, True)
- tabobj.OnPaint(forcedrect = rect, otherdc = otherdc)
-
- mdc.SelectObject(NullBitmap)
- bitmap.SetMask(Mask(bitmap, BLACK))
- ApplySmokeAndMirrors(otherwindow, bitmap)
-
-
-
- class NotifiedTimer(wx.Timer):
-
- def __init__(self, tab):
- wx.Timer.__init__(self)
- self.drawnotified = False
- self.tab = tab
- self.click = 0
-
-
- def Start(self):
- self.click = 0
- if not self.IsRunning():
- wx.Timer.Start(self, pref('tabs.notify_duration', 1000))
-
-
-
- def Notify(self):
- self.drawnotified = not (self.drawnotified)
- self.RefreshTab()
- self.click += 1
- if self.click >= pref('tabs.notify_count', 10):
- self.drawnotified = True
- wx.Timer.Stop(self)
-
-
-
- def Stop(self):
- self.drawnotified = False
- self.RefreshTab()
- wx.Timer.Stop(self)
-
-
- def RefreshTab(self):
- if not wx.IsDestroyed(self.tab):
- self.tab.Refresh()
-
-
-
- from gui.uberwidgets import UberWidget
-
- class Tab(wx.Window, UberWidget):
- NORMAL = 0
- ACTIVE = 1
- HOVER = 2
- ACTIVE_HOVER = 3
- NOTIFIED = 4
-
- def __init__(self, parent, page, _id = -1, skinkey = ''):
- wx.Window.__init__(self, parent, id = _id)
- self.Show(False)
- self.events = [
- (wx.EVT_PAINT, self.OnPaint),
- (wx.EVT_ERASE_BACKGROUND, (lambda e: pass)),
- (wx.EVT_ENTER_WINDOW, self.OnMouseEnter),
- (wx.EVT_LEAVE_WINDOW, self.OnMouseLeave),
- (wx.EVT_RIGHT_DOWN, self.OnRightDown),
- (wx.EVT_LEFT_DOWN, self.OnLeftDown),
- (wx.EVT_MIDDLE_UP, self.OnMidUp),
- (wx.EVT_LEFT_UP, self.OnLeftUp),
- (wx.EVT_BUTTON, self.OnButton),
- (wx.EVT_MOTION, self.OnMotion),
- (wx.EVT_CLOSE, self.OnClose),
- (wx.EVT_SIZE, self.OnSize)]
- (do,)((lambda .0: for event, method in .0:
- self.Bind(event, method))(self.events))
- if sys.DEV and not isinstance(page.name, unicode):
- msg = ('please only use unicode for labels: %r', page.name)
- if pref('errors.nonunicode_buddy_names', type = bool, default = False):
- raise TypeError(msg)
- else:
- log.warning(msg)
-
- self.page = page
- self.page.tab = self
- if sys.DEV and not isinstance(page.title, unicode):
- msg = ('please only use unicode for labels: %r', page.title)
- if pref('errors.nonunicode_buddy_names', type = bool, default = False):
- raise TypeError(msg)
- else:
- log.warning(msg)
-
- self.label1 = self.page.title
- self.row = None
- self.notified = page.notified
- self.drawnotified = NotifiedTimer(self)
- self.focus = False
- self.alignment = wx.ALIGN_LEFT
- self._active = False
- self.clickage = False
- self.OnActive = Delegate()
- self.fontcolors = ([
- None] * 5, [
- None] * 5)
- self.states = ([
- None] * 5, [
- None] * 5)
- self.state = 0
- self.mode = pref('tabs.side_tabs', False)
- self.SetSkinKey(skinkey, True)
- self.mark = None
- self.bufferbitmap = None
- self.previewtabs = None
- if self.notified:
- self.drawnotified.Start()
-
- profile.prefs.link('tabs.style', self.OnPrefChange, False)
- profile.prefs.link('tabs.flip', self.OnPrefChange, False)
- profile.prefs.link('tabs.max_width', self.OnPrefChange, False)
-
-
- def OnPrefChange(self, val):
- self.Calcumalate()
-
-
- def UpdateSkin(self):
- key = self.skinkey
-
- s = lambda k, default = sentinel, mode = (0,): skin.get('%s%s.%s' % ('side' * mode, key, k), default)
- self.mode = pref('tabs.side_tabs', False)
- self.maxtabwidth = s('maxwidth', pref('tabs.max_width', 100))
- padd = s('padding', (lambda : Point(0, 0)))
- marg = s('margins', (lambda : Margins([
- 0,
- 0,
- 0,
- 0])))
- icsz = s('iconsize', 16)
- font = s('font', (lambda : default_font()))
- spad = s('padding', padd, 1)
- smar = s('margins', marg, 1)
- sico = s('iconsize', icsz, 1)
- sfnt = s('font', font, 1)
- self.padding = (padd, spad)
- self.margins = (marg, smar)
- self.iconsize = (icsz, sico)
- self.font = (font, sfnt)
- states = self.states
- states[0][0] = s('backgrounds.normal')
- states[0][1] = s('backgrounds.active')
- states[0][2] = s('backgrounds.hover', states[0][0])
- states[0][3] = s('backgrounds.activehover', states[0][2])
- states[0][4] = s('backgrounds.notify', states[0][0])
- states[1][0] = s('backgrounds.normal', states[0][0], 1)
- states[1][1] = s('backgrounds.active', states[0][1], 1)
- states[1][2] = s('backgrounds.hover', states[0][2], 1)
- states[1][3] = s('backgrounds.activehover', states[0][3], 1)
- states[1][4] = s('backgrounds.notify', states[0][4], 1)
- fc = self.fontcolors
- fc[0][0] = s('fontcolors.normal', BLACK)
- fc[0][1] = s('fontcolors.active', BLACK)
- fc[0][2] = s('fontcolors.hover', fc[0][0])
- fc[0][3] = s('fontcolors.activehover', fc[0][2])
- fc[0][4] = s('fontcolors.notify', fc[0][0])
- fc[1][0] = s('fontcolors.normal', fc[0][0], 1)
- fc[1][1] = s('fontcolors.active', fc[0][1], 1)
- fc[1][2] = s('fontcolors.hover', fc[1][0], 1)
- fc[1][3] = s('fontcolors.activehover', fc[1][2], 1)
- fc[1][4] = s('fontcolors.notify', fc[1][0], 1)
- if pref('tabs.style', 2) and not hasattr(self, 'closebutton'):
- self.GenCloseButton()
-
- if hasattr(self, 'closebutton'):
- self.closebutton.SetSkinKey(self.Parent.closebuttonskin)
- self.closebutton.SetIcon(self.Parent.closeicon)
-
- self.Calcumalate()
- self.Refresh(False)
-
-
- def UpdateMode(self):
- self.mode = pref('tabs.side_tabs', False)
- self.closebutton.SetSkinKey(self.Parent.closebuttonskin, True)
- self.closebutton.SetIcon(self.Parent.closeicon)
- self.Calcumalate()
- self.Refresh(False)
-
-
- def OnSize(self, event):
- self.Refresh(False)
-
-
- def __repr__(self):
- return '<Tab %r>' % self.label1
-
-
- def GenCloseButton(self):
- self.closebutton = UberButton(self, skin = self.Parent.closebuttonskin, icon = self.Parent.closeicon, size = (self.iconsize[self.mode], self.iconsize[self.mode]))
- if pref('tabs.style', 2) == 2:
- self.closebutton.Show(False)
-
-
-
- def Icon(self):
- return self.page.Icon.Resized(self.iconsize[self.mode]).WXB
-
- Icon = debug_property(Icon)
-
- def Calcumalate(self):
- dc = ClientDC(self)
- dc.Font = self.font[self.mode]
- xpad = self.padding[self.mode].x
- xcurser = xpad + self.margins[self.mode].left
- ypad = self.padding[self.mode].y
- flip = pref('tabs.flip', False)
- style = pref('tabs.style', 2)
- icon = self.Icon
- iconsize = self.iconsize[self.mode]
- label1 = self.label1
- if isinstance(label1, str):
- label1 = label1.decode('fuzzy utf8')
-
- txtwh = dc.GetTextExtent(label1)[0]
- ycurser = self.txtht = dc.Font.Height
- if (icon or style) and ycurser < iconsize:
- ycurser = iconsize
-
- ycurser += 2 * ypad + self.margins[self.mode].y
- if not flip:
- self.iconcurser = Point(xcurser, (ycurser - self.margins[self.mode].y) / 2 + self.margins[self.mode].top - iconsize / 2)
-
- if (style == 2 or not flip or style == 1) and flip:
- self.closebutton.Size = Size(iconsize, iconsize)
- if not self.iconcurser:
- pass
- self.buttoncurser = Point(xcurser, (ycurser - self.margins[self.mode].y) / 2 + self.margins[self.mode].top - iconsize / 2)
-
- if not icon or not flip:
- if (style == 2 or not flip or style == 1) and flip:
- xcurser += iconsize + xpad
-
- self.label1curser = Point(xcurser, (ycurser - self.margins[self.mode].y) / 2 + self.margins[self.mode].top - self.txtht / 2)
- xcurser += txtwh + xpad
- if not icon or flip:
- if (style == 1 or not flip or style == 2) and flip:
- xcurser += iconsize + xpad
-
- xcurser += self.margins[self.mode].right
- maxwidth = self.maxtabwidth
- if maxwidth and maxwidth < xcurser:
- xcurser = maxwidth
-
- self.gensize = (xcurser, ycurser)
- self.SetMinSize(self.gensize)
- if style == 1 and style == 2:
- pass
- self.closebutton.Show(self.Rect.Contains(self.Parent.ScreenToClient(GetMousePosition())))
- print 'calced tab size for', repr(self.label1), 'at', self.gensize, ' / ', self.Size
-
-
- def OnPaint(self, event = None, forcedrect = None, otherdc = None, otherwindow = None):
- size = None if forcedrect else self.Size
- if not forcedrect:
- pass
- rect = RectS(size)
- iconsize = self.iconsize[self.mode]
- cliptangle = self.Rect
- (sx, sy) = self.Rect.Position
- (sw, sh) = size
- ph = self.Parent.Size.height - 16
- sidetabs = pref('tabs.side_tabs', False)
- style = pref('tabs.style', 2)
- flip = pref('tabs.flip', False)
- if sidetabs and event and sy + sh > ph:
- cliptangle = Rect(sx, sy, sw, ph - sy)
- cdc = PaintDC(self)
- cdc.SetClippingRegion(0, 0, cliptangle.width, cliptangle.height)
- buffer = EmptyBitmap(*self.Size)
- dc = MemoryDC()
- dc.SelectObject(buffer)
- else:
- cdc = None
- if not otherdc:
- pass
- dc = BufferedPaintDC(self)
- state = None if not (self.active) and self.notified and self.drawnotified.drawnotified else self.state
- bg = None[self.states[self.mode] if event else 0]
- bg.Draw(dc, rect)
- if event or otherwindow:
- if not otherwindow:
- pass
- ApplySmokeAndMirrors(self, bg.GetBitmap(rect.Size))
-
- icon = self.Icon
- iconoffsetx = (iconsize - icon.Size.width) // 2
- iconoffsety = (iconsize - icon.Size.height) // 2
- xpad = self.padding[self.mode].x
- if icon and flip:
- self.iconcurser = Point(size.width - (iconsize + xpad + self.margins[self.mode].right), (size.height - self.margins[self.mode].y) / 2 + self.margins[self.mode].top - iconsize // 2)
-
- if (style == 1 or not flip or style == 2) and flip:
- self.buttoncurser = Point(size.width - (iconsize + xpad + self.margins[self.mode].right), (size.height - self.margins[self.mode].y) / 2 + self.margins[self.mode].top - iconsize // 2)
-
- if icon:
- if style != 2 or not (self.focus) or not event:
- dc.DrawBitmap(icon, rect.x + self.iconcurser.x + iconoffsetx, rect.y + self.iconcurser.y + iconoffsety, True)
-
- filled = xpad + self.margins[self.mode].x
- if style:
- filled += self.closebutton.Size.width + xpad
-
- if icon and style != 2:
- filled += iconsize + xpad
-
- dc.SetFont(self.font[self.mode])
- dc.SetTextForeground(self.fontcolors[self.mode][state])
- txtrct = Rect(rect.x + self.label1curser.x, rect.y + self.label1curser.y, size.width - filled - xpad, self.txtht)
- dc.DrawTruncatedText(self.label1, txtrct, alignment = ALIGN_LEFT | ALIGN_CENTER_VERTICAL)
- if event:
- if style:
- self.closebutton.SetPosition(self.buttoncurser)
-
- if cdc:
- dc.SelectObject(NullBitmap)
- cdc.DrawBitmap(buffer, 0, 0, True)
-
-
-
-
- def GetActive(self):
-
- try:
- return self._active
- except AttributeError:
- return False
-
-
-
- def SetActive(self, switch = None):
- self._active = None if switch is None else switch
- if self._active:
- self.state = None if self.focus else Tab.ACTIVE
- self.page.Display()
- elif self.focus:
- pass
-
- self.state = Tab.NORMAL
- win = GetTopLevelParent(self)
- page = self.page
- icon = page.icon
- title = None if page.window_title is not None else page.title
- if title is not None:
- win.Title = title
-
- win.SetFrameIcon(icon)
- self.SetNotify(False)
- self.OnActive()
- if self.Parent.side_tabs:
- self.Parent.ReVgenerate()
- else:
- self.Parent.Regenerate()
- self.Refresh(False)
-
- active = property(GetActive, SetActive)
- left_down_activates = prefprop('messaging.tabs.left_down_activates', False)
-
- def OnLeftDown(self, event):
- if hasattr(self, 'closebutton') and self.closebutton.hovered:
- self.closebutton.OnLeftDown(event)
- else:
- self.mark = event.Position
- if self.left_down_activates:
- self.active = True
-
- event.Skip()
-
-
- def OnLeftUp(self, event):
- self.mark = None
- if not self.focus and event.LeftIsDown():
- if self.focus:
- self.active = True
-
- self.OnMouseEnter(event)
- self.OnMotion(event)
-
- event.Skip()
-
-
- def OnMidUp(self, event):
- self.CloseTab()
-
-
- def OnRightDown(self, event):
- pass
-
-
- def OnMouseEnter(self, event):
- cliptangle = RectS(self.Size)
- sy = self.Rect.y
- (sw, sh) = cliptangle.Size
- ph = self.Parent.Size.height - 16
- if sy + sh > ph and pref('tabs.side_tabs', False):
- cliptangle = Rect(0, 0, sw, ph - sy)
-
- if cliptangle.Contains(event.Position):
- if not self.HasCapture():
- self.CaptureMouse()
-
- if not event.LeftIsDown():
- self.focus = True
- self.state = None if not self.active else 3
- if pref('tabs.style', 2) == 2:
- self.closebutton.Show(True)
-
- self.Refresh(False)
-
-
-
-
- def OnMouseLeave(self, event = None):
- cliptangle = RectS(self.Size)
- sy = self.Rect.y
- (sw, sh) = self.Size
- ph = self.Parent.Size.height - 16
- if sy + sh > ph and pref('tabs.side_tabs', False):
- cliptangle = Rect(0, 0, sw, ph - sy)
-
- if not hasattr(self, 'closebutton') and not event or not self.closebutton.Rect.Contains(event.Position) or not cliptangle.Contains(event.Position):
- while self.HasCapture():
- self.ReleaseMouse()
- if not (self.Parent.dragorigin) and event and self.focus and event.LeftIsDown():
- pass
- None if not (self.closebutton) or not (self.closebutton.hovered) else not (self.closebutton.hovered)
- if self.focus:
- self.focus = False
- self.state = None if self._active else 0
- if pref('tabs.style', 2) == 2:
- self.closebutton.Show(False)
-
-
-
- self.mark = None
- self.Refresh(False)
-
-
- def OnMotion(self, event):
- if not self.focus and event.LeftIsDown():
- self.OnMouseEnter(event)
-
- position = self.Parent.ScreenToClient(self.ClientToScreen(event.Position))
- mouseisin = self.Rect.Contains(position)
- if mouseisin and event.LeftIsDown() and self.Manager.source:
- self.Parent.DragCalc(self.Parent.ScreenToClient(GetMousePosition()))
- elif mouseisin and self.mark:
- if abs(event.Position.x - self.mark.x) > 5 or abs(event.Position.y - self.mark.y) > 5:
- self.OnMouseLeave(event)
- elif self.HasCapture() and mouseisin and hasattr(self, 'closebutton'):
- if self.closebutton.Rect.Contains(event.Position):
- self.closebutton.OnMouseIn(event)
- elif self.closebutton.hovered:
- self.closebutton.OnMouseOut(event)
-
- elif self.HasCapture() and not mouseisin:
- self.OnMouseLeave(event)
-
-
-
- def Notebook(self):
- return self.GrandParent
-
- Notebook = property(Notebook)
-
- def Manager(self):
- return self.Notebook.manager
-
- Manager = property(Manager)
-
- def OnButton(self, event = None):
- while self.closebutton.HasCapture():
- self.closebutton.ReleaseMouse()
- wx.CallAfter(self.Close)
- wx.CallAfter(self.page.Close)
-
- CloseTab = OnButton
-
- def OnClose(self, event = None):
- self.SetEvtHandlerEnabled(False)
- while self.HasCapture():
- self.ReleaseMouse()
- if self.active:
- self.Parent.SetNextActive(self)
-
- if self in self.Parent:
- self.Parent.Remove(self)
-
- if self.previewtabs:
- self.previewtabs.Stop()
- self.previewtabs = None
-
- if self.closebutton is not None and not wx.IsDestroyed(self.closebutton):
- self.closebutton.Close()
- self.closebutton = None
-
- if not wx.IsDestroyed(self):
- self.Show(False)
- self.Destroy()
-
- return True
-
-
- def SetLabel(self, label1 = None, windowtitle = None):
- if label1 and label1 != self.label1:
- self.label1 = label1
- self.Calcumalate()
- if not self.Parent.side_tabs:
- self.Parent.Regenerate()
-
-
-
-
- def GetIcon(self):
- icon = self.page.icon
- return None if icon is not None else None
-
- Icon = property(GetIcon)
-
- def SetNotify(self, switch):
- log.info('%r SetNotify(%r)', self, switch)
- self.notified = switch
- if switch:
- self.drawnotified.Start()
- else:
- self.drawnotified.Stop()
- self.Parent.UpdateNotify()
- self.page.notified = switch
- self.Top.ProcessEvent(TabNotifiedEvent(tab = self))
-
-
-