-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogoPanel.py
121 lines (92 loc) · 3.56 KB
/
LogoPanel.py
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
#!/usr/bin/env python
import wx
import sys
import os
import builtins as __builtin__
import inspect
moduleList = {'osvmGlobals':'globs'}
for k,v in moduleList.items():
print('Loading: %s as %s' % (k,v))
mod = __import__(k, fromlist=[None])
globals()[v] = globals().pop('mod') # Rename module in globals()
####
#print(__name__)
####
# From A. Gavana FlatNoteBook Demo
class LogoPanel(wx.Panel):
def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.CLIP_CHILDREN):
wx.Panel.__init__(self, parent, id, pos, size, style)
self.SetBackgroundColour(wx.WHITE)
imgpath = os.path.join(globs.imgDir, 'sad-smiley.png')
self.bmp = wx.Bitmap(wx.Image(imgpath, wx.BITMAP_TYPE_PNG))
self.bigfont = wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD, False)
self.normalfont = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD, True)
self.smallfont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD, False)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.topTitle = 'No File Detected'
self.midTitle = 'D. Poirot'
self.bottomTitle = '%s %s' % (globs.myName, globs.myVersion)
def setLogoPanelTopTitle(self, title):
self.topTitle = title
def setLogoPanelMidTitle(self, title):
self.midTitle = title
def setLogoPanelBottomTitle(self, title):
self.bottomTitle = title
def OnSize(self, event):
event.Skip()
self.Refresh()
def OnPaint(self, event):
dc = wx.AutoBufferedPaintDC(self)
self.DoDrawing(dc)
def DoDrawing(self, dc):
dc.SetBackground(wx.WHITE_BRUSH)
dc.Clear()
w, h = self.GetClientSize()
bmpW, bmpH = self.bmp.GetWidth(), self.bmp.GetHeight()
xpos, ypos = int((w - bmpW)/2), int((h - bmpH)/2)
dc.DrawBitmap(self.bmp, xpos, ypos, True)
dc.SetFont(self.bigfont)
dc.SetTextForeground(wx.BLUE)
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.SetPen(wx.Pen(wx.BLUE, 2))
tw, th = dc.GetTextExtent(self.topTitle)
xpos = int((w - tw)/2)
ypos = int(h/3)
dc.DrawRoundedRectangle(xpos-5, ypos-3, tw+10, th+6, 3)
dc.DrawText(self.topTitle, xpos, ypos)
dc.SetFont(self.normalfont)
dc.SetTextForeground(wx.RED)
tw, th = dc.GetTextExtent(self.midTitle)
xpos = int((w - tw)/2)
ypos = int(2*h/3)
dc.DrawText(self.midTitle, xpos, ypos)
dc.SetFont(self.smallfont)
tw, th = dc.GetTextExtent(self.bottomTitle)
xpos = int((w - tw)/2)
ypos = int(2*h/3 + 4*th/2)
dc.DrawText(self.bottomTitle, xpos, ypos)
####
def myprint(*args, **kwargs):
"""My custom print() function."""
# Adding new arguments to the print function signature
# is probably a bad idea.
# Instead consider testing if custom argument keywords
# are present in kwargs
__builtin__.print('%s():' % inspect.stack()[1][3], *args, **kwargs)
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
panel = LogoPanel(self)
self.Show()
def main():
# Initialize Globals instance
globs.imgDir = os.path.join(os.getcwd(), 'images')
# Create DemoFrame frame, passing globals instance as parameter
app = wx.App(False)
frame = MyFrame(None, -1, title="Test")
frame.Show()
app.MainLoop()
if __name__ == "__main__":
main()