1
###############################################################################
2
# Name: ed_basewin.py #
3
# Purpose: Common window base class(es) #
4
# Author: Cody Precord <cprecord@editra.org> #
5
# Copyright: (c) 2011 Cody Precord <staff@editra.org> #
6
# License: wxWindows License #
7
###############################################################################
10
This module provides base classes for windows and dialogs to be used within
15
__author__ = "Cody Precord <cprecord@editra.org>"
16
__svnid__ = "$Id: ed_basewin.py 67857 2011-06-05 00:16:24Z CJP $"
17
__revision__ = "$Revision: 67857 $"
19
#--------------------------------------------------------------------------#
28
#--------------------------------------------------------------------------#
30
def FindMainWindow(window):
31
"""Find the MainWindow of the given window
32
@return: MainWindow or None
36
"""Check if the given window is a main window"""
37
return getattr(win, '__name__', '') == 'MainWindow'
41
# else start looking up the parent hierarchy
42
tlw = window.GetTopLevelParent()
45
elif hasattr(tlw, 'GetParent'):
52
#--------------------------------------------------------------------------#
54
class EdBaseDialog(eclib.ECBaseDlg):
55
"""Editra Dialog Base Class"""
56
def __init__(self, parent, id=wx.ID_ANY, title=u"",
57
pos=wx.DefaultPosition, size=wx.DefaultSize,
58
style=wx.DEFAULT_DIALOG_STYLE, name=u"EdBaseDialog"):
59
super(EdBaseDialog, self).__init__(parent, id, title, pos,
62
#--------------------------------------------------------------------------#
64
class EdBaseFrame(wx.Frame):
65
"""Editra Frame Base Class"""
66
def __init__(self, parent, id=wx.ID_ANY, title=u"",
67
pos=wx.DefaultPosition, size=wx.DefaultSize,
68
style=wx.DEFAULT_FRAME_STYLE, name=u"EdBaseFrame"):
69
super(EdBaseFrame, self).__init__(parent, id, title, pos,
73
util.SetWindowIcon(self)
76
wx.GetApp().RegisterWindow(repr(self), self)
79
self.Bind(wx.EVT_CLOSE, self.OnClose)
81
def OnClose(self, event):
82
"""Handle frame closure event"""
83
wx.GetApp().UnRegisterWindow(repr(self))
86
#--------------------------------------------------------------------------#
88
class EdBaseCtrlBox(eclib.ControlBox):
89
"""ControlBox base class to be used by all common components"""
90
def __init__(self, parent):
91
super(EdBaseCtrlBox, self).__init__(parent)
93
ed_msg.Subscribe(self._OnFontChange, ed_msg.EDMSG_DSP_FONT)
94
self.Bind(wx.EVT_WINDOW_DESTROY, self._OnDestroy)
96
def _OnDestroy(self, evt):
97
if self and evt.GetEventObject is self:
98
ed_msg.Unsubscribe(self._OnFontChange)
100
def _OnFontChange(self, msg):
104
if isinstance(font, wx.Font):
105
for pos in (wx.TOP, wx.BOTTOM, wx.LEFT, wx.RIGHT):
106
cbar = self.GetControlBar(pos)
108
for child in cbar.GetChildren():
111
def AddPlateButton(self, lbl=u"", bmp=-1,
112
align=wx.ALIGN_LEFT, cbarpos=wx.TOP):
113
"""Add an eclib.PlateButton to the ControlBar specified by
115
@keyword lbl: Button Label
116
@keyword bmp: Bitmap or EditraArtProvider ID
117
@keyword align: button alignment
118
@keyword cbarpos: ControlBar position
119
@return: PlateButton instance
122
ctrlbar = self.GetControlBar(cbarpos)
123
assert ctrlbar is not None, "No ControlBar at cbarpos"
124
if not isinstance(bmp, wx.Bitmap):
125
assert isinstance(bmp, int)
126
bmp = wx.ArtProvider.GetBitmap(str(bmp), wx.ART_MENU)
127
if bmp.IsNull() or not bmp.IsOk():
129
btn = eclib.PlateButton(ctrlbar, wx.ID_ANY, lbl, bmp,
130
style=eclib.PB_STYLE_NOBG)
131
ctrlbar.AddControl(btn, align)
134
def CreateControlBar(self, pos=wx.TOP):
135
"""Override for CreateControlBar to automatically set the
136
flat non-gradient version of the control under GTK.
139
cbar = super(EdBaseCtrlBox, self).CreateControlBar(pos)
140
if wx.Platform == '__WXGTK__':
141
cbar.SetWindowStyle(eclib.CTRLBAR_STYLE_DEFAULT)