~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/ed_basewin.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2012-01-07 13:59:25 UTC
  • mfrom: (1.1.9) (5.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120107135925-2601miy9ullcon9j
Tags: 2.8.12.1-6ubuntu1
* Resync from Debian, changes that were kept:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control: Build-dep on libxt-dev for mediactrl.
  - Patches
    + fix-bashism-in-example
* Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to python-wxversion
  to guarantee upgrade ordering when moving from pycentral to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
###############################################################################
 
8
 
 
9
"""
 
10
This module provides base classes for windows and dialogs to be used within
 
11
Editra.
 
12
 
 
13
"""
 
14
 
 
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 $"
 
18
 
 
19
#--------------------------------------------------------------------------#
 
20
# Imports
 
21
import wx
 
22
 
 
23
# Local Imports
 
24
import ed_msg
 
25
import eclib
 
26
import util
 
27
 
 
28
#--------------------------------------------------------------------------#
 
29
 
 
30
def FindMainWindow(window):
 
31
        """Find the MainWindow of the given window
 
32
        @return: MainWindow or None
 
33
 
 
34
        """
 
35
        def IsMainWin(win):
 
36
            """Check if the given window is a main window"""
 
37
            return getattr(win, '__name__', '') == 'MainWindow'
 
38
 
 
39
        if IsMainWin(window):
 
40
            return window
 
41
        # else start looking up the parent hierarchy
 
42
        tlw = window.GetTopLevelParent()
 
43
        if IsMainWin(tlw):
 
44
            return tlw
 
45
        elif hasattr(tlw, 'GetParent'):
 
46
            tlw = tlw.GetParent()
 
47
            if IsMainWin(tlw):
 
48
                return tlw
 
49
 
 
50
        return None
 
51
 
 
52
#--------------------------------------------------------------------------#
 
53
 
 
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,
 
60
                                           size, style, name)
 
61
 
 
62
#--------------------------------------------------------------------------#
 
63
 
 
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,
 
70
                                          size, style, name)
 
71
 
 
72
        # Setup
 
73
        util.SetWindowIcon(self)
 
74
 
 
75
        # Register with App
 
76
        wx.GetApp().RegisterWindow(repr(self), self)
 
77
 
 
78
        # Event Handlers
 
79
        self.Bind(wx.EVT_CLOSE, self.OnClose)
 
80
 
 
81
    def OnClose(self, event):
 
82
        """Handle frame closure event"""
 
83
        wx.GetApp().UnRegisterWindow(repr(self))
 
84
        event.Skip()
 
85
 
 
86
#--------------------------------------------------------------------------#
 
87
 
 
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)
 
92
 
 
93
        ed_msg.Subscribe(self._OnFontChange, ed_msg.EDMSG_DSP_FONT)
 
94
        self.Bind(wx.EVT_WINDOW_DESTROY, self._OnDestroy)
 
95
 
 
96
    def _OnDestroy(self, evt):
 
97
        if self and evt.GetEventObject is self:
 
98
            ed_msg.Unsubscribe(self._OnFontChange)
 
99
 
 
100
    def _OnFontChange(self, msg):
 
101
        if not self:
 
102
            return
 
103
        font = msg.GetData()
 
104
        if isinstance(font, wx.Font):
 
105
            for pos in (wx.TOP, wx.BOTTOM, wx.LEFT, wx.RIGHT):
 
106
                cbar = self.GetControlBar(pos)
 
107
                if cbar:
 
108
                    for child in cbar.GetChildren():
 
109
                        child.SetFont(font)
 
110
 
 
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
 
114
        cbarpos.
 
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
 
120
 
 
121
        """
 
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():
 
128
            bmp = None
 
129
        btn = eclib.PlateButton(ctrlbar, wx.ID_ANY, lbl, bmp,
 
130
                                style=eclib.PB_STYLE_NOBG)
 
131
        ctrlbar.AddControl(btn, align)
 
132
        return btn
 
133
 
 
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.
 
137
 
 
138
        """
 
139
        cbar = super(EdBaseCtrlBox, self).CreateControlBar(pos)
 
140
        if wx.Platform == '__WXGTK__':
 
141
            cbar.SetWindowStyle(eclib.CTRLBAR_STYLE_DEFAULT)
 
142
        return cbar