1
# -*- coding: UTF-8 -*-
3
# Copyright (C) 2007-2008 www.stani.be
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see http://www.gnu.org/licenses/
21
from compatible import GCDC, FONT_SIZE
29
paint_color = wx.Colour(60, 60, 60) # ,200)
30
paint_border_color = None
34
def OnEraseBackground(self, event=None, paint_object=None):
35
paint_object = event.GetEventObject()
36
if not paint_object.IsShown():
40
_dc = wx.ClientDC(paint_object)
41
rect = paint_object.GetUpdateRegion().GetBox()
42
_dc.SetClippingRect(rect)
45
# Calculate text extents.
46
paint_message = self.GetPaintMessage()
48
tw, th = self.GetClientSize()
49
cw, ch = tw - MARGIN, th - MARGIN
50
font_size = FONT_SIZE + 1
51
while (tw >= cw or th >= ch) and font_size > 5:
53
font = wx.Font(font_size, wx.FONTFAMILY_SWISS,
54
wx.FONTSTYLE_NORMAL, wx.FONTSTYLE_NORMAL,
55
encoding=wx.FONTENCODING_SYSTEM)
57
tw, th = dc.GetTextExtent(paint_message)
64
ew, eh = paint_object.GetSize()
67
lw, lh = self._paint_logo.GetSize()
68
lx, ly = (ew - lw) / 2, (eh - lh + 2 * thd) / 2
69
dc.DrawBitmap(self._paint_logo, lx, ly, True)
72
lx, ly = ew / 2, eh / 2
73
# Check if text is necessary too.
76
# Draw rounded rectangle.
78
rx, ry = (ew - twd) / 2, ly - 2 * thd
80
rx, ry = (ew - twd) / 2, (eh - thd) / 2
81
rect = wx.Rect(rx, ry, twd, thd)
82
if self.paint_border_color:
83
penclr = self.paint_border_color
85
penclr = self.paint_color
86
dc.SetPen(wx.Pen(penclr))
87
dc.SetBrush(wx.Brush(self.paint_color))
88
dc.DrawRoundedRectangleRect(rect, self.paint_radius)
90
dc.SetTextForeground(paint_object.GetBackgroundColour())
91
dc.DrawText(paint_message, rx + td, ry + td)
93
def EnableBackgroundPainting(self, object, state=True, color=wx.WHITE):
96
self._paint_logo = graphics.bitmap(self.paint_logo)
97
object.SetBackgroundColour(color)
98
object.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
100
object.Unbind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
102
def GetPaintMessage(self):
103
return self.paint_message
109
sys.path.extend(['..'])
112
class TestFrame(Mixin, wx.Frame):
113
paint_message = 'hello world'
114
paint_logo = images.LOGO
116
class TestApp(wx.App):
118
wx.InitAllImageHandlers()
119
frame = TestFrame(None, -1, "Test", size=(600, 400))
120
frame.EnableBackgroundPainting(frame) # ,color=(245,245,255))
121
self.SetTopWindow(frame)
128
if __name__ == '__main__':