ed_book.py
3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
###############################################################################
# Name: ed_book.py #
# Purpose: Editra notebook base class #
# Author: Cody Precord <cprecord@editra.org> #
# Copyright: (c) 2011 Cody Precord <staff@editra.org> #
# License: wxWindows License #
###############################################################################
"""
Base class for the main tab controls
@summary: Tabbed book control base classes
"""
__author__ = "Cody Precord <cprecord@editra.org>"
__svnid__ = "$Id: ed_book.py 69245 2011-09-30 17:52:23Z CJP $"
__revision__ = "$Revision: 69245 $"
#-----------------------------------------------------------------------------#
# Imports
import wx
# Editra Imports
import extern.aui as aui
import ed_msg
from profiler import Profile_Get
#-----------------------------------------------------------------------------#
class EdBaseBook(aui.AuiNotebook):
"""Base notebook control"""
def __init__(self, parent, style=0):
style |= self.GetBaseStyles()
super(EdBaseBook, self).__init__(parent, agwStyle=style)
if wx.Platform == '__WXGTK__':
self.SetArtProvider(GtkTabArt())
# Setup
self.UpdateFontSetting()
font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
font.PointSize += 2
self.NavigatorProps.Font = font
self.NavigatorProps.MinSize = wx.Size(300, 250)
self.SetSashDClickUnsplit(True)
# Message Handlers
ed_msg.Subscribe(self.OnUpdateFont, ed_msg.EDMSG_DSP_FONT)
# Event Handlers
self.Bind(wx.EVT_WINDOW_DESTROY, self._OnDestroy, self)
def _OnDestroy(self, evt):
"""Unsubscribe message handlers on delete"""
if self and evt.GetEventObject() is self:
ed_msg.Unsubscribe(self.OnUpdateFont)
evt.Skip()
@staticmethod
def GetBaseStyles():
"""Get the common base style flags
@return: bitmask
"""
style = aui.AUI_NB_NO_TAB_FOCUS
if wx.Platform == '__WXMAC__':
style |= aui.AUI_NB_CLOSE_ON_TAB_LEFT
return style
def OnUpdateFont(self, msg):
"""Update the font settings for the control in response to
user settings change.
"""
if self:
self.UpdateFontSetting()
def SetPageBitmap(self, pg, bmp):
"""Set a tabs bitmap
@param pg: page index
@param bmp: Bitmap
@note: no action if user prefs have turned off bmp
"""
if not self.UseIcons():
bmp = wx.NullBitmap
super(EdBaseBook, self).SetPageBitmap(pg, bmp)
def UpdateFontSetting(self):
"""Update font setting using latest profile data"""
font = Profile_Get('FONT3', 'font', None)
if font:
self.SetFont(font)
def UseIcons(self):
"""Is the book using tab icons?"""
bUseIcons = Profile_Get('TABICONS', default=True)
return bUseIcons
#-----------------------------------------------------------------------------#
class GtkTabArt(aui.VC71TabArt):
"""Simple tab art with no gradients"""
def __init__(self):
super(GtkTabArt, self).__init__()
def DrawBackground(self, dc, wnd, rect):
"""
Draws the tab area background.
:param `dc`: a `wx.DC` device context;
:param `wnd`: a `wx.Window` instance object;
:param `rect`: the tab control rectangle.
"""
self._buttonRect = wx.Rect()
# draw background
r = wx.Rect(rect.x, rect.y, rect.width+2, rect.height)
# draw base lines
dc.SetPen(self._border_pen)
dc.SetBrush(self._base_colour_brush)
dc.DrawRectangleRect(r)