From 75f833dc7b4563d2579c77c68332d8a53da0bc43 Mon Sep 17 00:00:00 2001 From: Andrea Gavana Date: Sun, 15 Jul 2012 14:29:13 +0000 Subject: [PATCH] Phoenix: - Phoenix-port of `wx.lib.statbmp.py`, with unittest and documentation; - Small modifications to `wx.lib.stattext.py` docstrings. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72099 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- unittests/test_lib_statbmp.py | 26 ++++++++ wx/lib/statbmp.py | 121 ++++++++++++++++++++++++++++++++-- wx/lib/stattext.py | 24 +++---- 3 files changed, 154 insertions(+), 17 deletions(-) create mode 100644 unittests/test_lib_statbmp.py diff --git a/unittests/test_lib_statbmp.py b/unittests/test_lib_statbmp.py new file mode 100644 index 00000000..9137a1e9 --- /dev/null +++ b/unittests/test_lib_statbmp.py @@ -0,0 +1,26 @@ +import imp_unittest, unittest +import wtc +import wx +import wx.lib.statbmp + +#--------------------------------------------------------------------------- + +class lib_statbmp_Tests(wtc.WidgetTestCase): + + def test_lib_statbmp1(self): + pnl = wx.Panel(self.frame) + bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (32, 32)) + w = wx.lib.statbmp.GenStaticBitmap(pnl, -1, bitmap=bmp, pos=(10,10)) + bs1 = w.GetEffectiveMinSize() + + bmp2 = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (64, 64)) + w.SetBitmap(bmp2) + bs2 = w.GetEffectiveMinSize() + + self.assertEqual(w.GetBitmap(), bmp2) + self.assertTrue(bs2.height > bs1.height) + +#--------------------------------------------------------------------------- + +if __name__ == '__main__': + unittest.main() diff --git a/wx/lib/statbmp.py b/wx/lib/statbmp.py index 3585446e..d08afdff 100644 --- a/wx/lib/statbmp.py +++ b/wx/lib/statbmp.py @@ -8,22 +8,87 @@ # RCS-ID: $Id$ # Copyright: (c) 2004 by Total Control Software # Licence: wxWindows license +# Tags: phoenix-port, unittest, documented #---------------------------------------------------------------------- +""" +:class:`GenStaticBitmap` is a generic implementation of :class:`StaticBitmap`. + + +Description +=========== + +:class:`GenStaticBitmap` is a generic implementation of :class:`StaticBitmap`. + +Some of the platforms supported by wxPython (most notably GTK), do not consider +:class:`StaticBitmap` as a separate widget; instead, the bitmap is just drawn on its +parent window. This essentially bars the use of almost all mouse events (such as +detection of mouse motions, mouse clicks and so on). + +Using :class:`GenStaticBitmap` will overcome all the problems described above, as it +is a generic widget and a real window on its own. + + +Usage +===== + +Sample usage:: + + import wx + import wx.lib.statbmp as SB + + app = wx.App(0) + + frame = wx.Frame(None, -1, "wx.lib.statbmp Test") + panel = wx.Panel(frame) + + bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16)) + st1 = SB.GenStaticBitmap(panel, -1, bmp, (20, 10)) + + bmp = wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_OTHER, (32, 32)) + st2 = SB.GenStaticBitmap(panel, -1, bmp, (20, 60)) + + frame.Show() + app.MainLoop() + + +""" + import wx #---------------------------------------------------------------------- -class GenStaticBitmap(wx.PyControl): +class GenStaticBitmap(wx.Control): + """ :class:`GenStaticBitmap` is a generic implementation of :class:`StaticBitmap`. """ + labelDelta = 1 def __init__(self, parent, ID, bitmap, pos = wx.DefaultPosition, size = wx.DefaultSize, style = 0, name = "genstatbmp"): + """ + Default class constructor. + + :param `parent`: parent window, must not be ``None``; + :param integer `ID`: window identifier. A value of -1 indicates a default value; + :param Bitmap `bitmap`: the static bitmap used in the control; + :param `pos`: the control position. A value of (-1, -1) indicates a default position, + chosen by either the windowing system or wxPython, depending on platform; + :param `size`: the control size. A value of (-1, -1) indicates a default size, + chosen by either the windowing system or wxPython, depending on platform; + :param integer `style`: the underlying :class:`Control` style; + :param string `name`: the widget name. + + :type parent: :class:`Window` + :type pos: tuple or :class:`Point` + :type size: tuple or :class:`Size` + """ + if not style & wx.BORDER_MASK: style = style | wx.BORDER_NONE - wx.PyControl.__init__(self, parent, ID, pos, size, style, + + wx.Control.__init__(self, parent, ID, pos, size, style, wx.DefaultValidator, name) self._bitmap = bitmap self.InheritAttributes() @@ -34,33 +99,60 @@ class GenStaticBitmap(wx.PyControl): def SetBitmap(self, bitmap): + """ + Sets the bitmap label. + + :param Bitmap `bitmap`: the new bitmap. + + .. seealso:: :meth:`GetBitmap` + """ + self._bitmap = bitmap self.SetInitialSize( (bitmap.GetWidth(), bitmap.GetHeight()) ) self.Refresh() def GetBitmap(self): + """ + Returns the bitmap currently used in the control. + + :rtype: Bitmap + + .. seealso:: :meth:`SetBitmap` + """ + return self._bitmap def DoGetBestSize(self): """ - Overridden base class virtual. Determines the best size of the - control based on the bitmap size. + Overridden base class virtual. Determines the best size of + the control based on the label size and the current font. + + .. note:: Overridden from :class:`Control`. """ + return wx.Size(self._bitmap.GetWidth(), self._bitmap.GetHeight()) def AcceptsFocus(self): - """Overridden base class virtual.""" + """ + Can this window be given focus by mouse click? + + .. note:: Overridden from :class:`Control`. + """ + return False def GetDefaultAttributes(self): """ Overridden base class virtual. By default we should use - the same font/colour attributes as the native StaticBitmap. + the same font/colour attributes as the native :class:`StaticBitmap`. + + .. note:: Overridden from :class:`Control`. """ + return wx.StaticBitmap.GetClassDefaultAttributes() @@ -68,17 +160,34 @@ class GenStaticBitmap(wx.PyControl): """ Overridden base class virtual. If the parent has non-default colours then we want this control to inherit them. + + .. note:: Overridden from :class:`Control`. """ + return True def OnPaint(self, event): + """ + Handles the ``wx.EVT_PAINT`` for :class:`GenStaticBitmap`. + + :param `event`: a :class:`PaintEvent` event to be processed. + """ + dc = wx.PaintDC(self) if self._bitmap: dc.DrawBitmap(self._bitmap, 0, 0, True) def OnEraseBackground(self, event): + """ + Handles the ``wx.EVT_ERASE_BACKGROUND`` event for :class:`GenStaticBitmap`. + + :param `event`: a :class:`EraseEvent` event to be processed. + + .. note:: This is intentionally empty to reduce flicker. + """ + pass diff --git a/wx/lib/stattext.py b/wx/lib/stattext.py index 3b37d09a..88a741f7 100644 --- a/wx/lib/stattext.py +++ b/wx/lib/stattext.py @@ -155,7 +155,7 @@ class GenStaticText(wx.Control): Overridden base class virtual. Determines the best size of the control based on the label size and the current font. - :note: Overridden from :class:`Control`. + .. note:: Overridden from :class:`Control`. """ label = self.GetLabel() @@ -187,10 +187,10 @@ class GenStaticText(wx.Control): :returns: ``True`` if the window has been enabled or disabled, ``False`` if nothing was done, i.e. if the window had already been in the specified state. - :note: Note that when a parent window is disabled, all of its children are disabled as - well and they are reenabled again when the parent is. + .. note:: Note that when a parent window is disabled, all of its children are disabled as + well and they are reenabled again when the parent is. - :note: Overridden from :class:`Control`. + .. note:: Overridden from :class:`Control`. """ retVal = wx.Control.Enable(self, enable) @@ -206,9 +206,9 @@ class GenStaticText(wx.Control): :returns: ``True`` if the window has been disabled, ``False`` if it had been already disabled before the call to this function. - :note: This is functionally equivalent of calling :meth:`~Control.Enable` with a ``False`` flag. + .. note:: This is functionally equivalent of calling :meth:`~Control.Enable` with a ``False`` flag. - :note: Overridden from :class:`Control`. + .. note:: Overridden from :class:`Control`. """ retVal = wx.Control.Disable(self) @@ -221,7 +221,7 @@ class GenStaticText(wx.Control): """ Can this window be given focus by mouse click? - :note: Overridden from :class:`Control`. + .. note:: Overridden from :class:`Control`. """ return False @@ -230,10 +230,11 @@ class GenStaticText(wx.Control): def GetDefaultAttributes(self): """ Overridden base class virtual. By default we should use - the same font/colour attributes as the native StaticText. + the same font/colour attributes as the native :class:`StaticText`. - :note: Overridden from :class:`Control`. + .. note:: Overridden from :class:`Control`. """ + return wx.StaticText.GetClassDefaultAttributes() @@ -242,8 +243,9 @@ class GenStaticText(wx.Control): Overridden base class virtual. If the parent has non-default colours then we want this control to inherit them. - :note: Overridden from :class:`Control`. + .. note:: Overridden from :class:`Control`. """ + return True @@ -301,7 +303,7 @@ class GenStaticText(wx.Control): :param `event`: a :class:`EraseEvent` event to be processed. - :note: This is intentionally empty to reduce flicker. + .. note:: This is intentionally empty to reduce flicker. """ pass