]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxGenBitmapTextButton contrib from Lorne White.
authorRobin Dunn <robin@alldunn.com>
Mon, 3 Sep 2001 23:23:47 +0000 (23:23 +0000)
committerRobin Dunn <robin@alldunn.com>
Mon, 3 Sep 2001 23:23:47 +0000 (23:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11552 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/CHANGES.txt
wxPython/demo/GenericButtons.py
wxPython/wxPython/lib/buttons.py

index 9c3e5c7c8e736a51b58c25c05707bb52cc0facce..956c408a47c64ebfb9001ccf58dd6ee13879ce3d 100644 (file)
@@ -35,6 +35,9 @@ Updated wxColumnSorterMixin to also be able to place sort icons on the
 column headers, and updated the wxListCtrl demo to show it off by
 using wxColumnSorterMixin.
 
+Added wxGenBitmapTextButton contrib from Lorne White.
+
+
 
 
 2.3.1
index e9edfa7bb69f212748b31b3f72d3c01c96680e2b..c11d7a5b8ce3b9054781db9676137cbefc1261c7 100644 (file)
@@ -1,7 +1,6 @@
 
 from wxPython.wx import *
-from wxPython.lib.buttons import wxGenButton, wxGenBitmapButton, \
-                                 wxGenToggleButton, wxGenBitmapToggleButton
+from wxPython.lib.buttons import *
 
 import images
 #----------------------------------------------------------------------
@@ -69,6 +68,19 @@ class TestPanel(wxPanel):
         b.SetToggle(true)
         b.SetBestSize()
 
+        b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", (220, 230), size = (200, 45))
+        EVT_BUTTON(self, b.GetId(), self.OnButton)
+        bmp = images.getBulb1Bitmap()
+        mask = wxMaskColour(bmp, wxBLUE)
+        bmp.SetMask(mask)
+        b.SetBitmapLabel(bmp)
+        bmp = images.getBulb2Bitmap()
+        mask = wxMaskColour(bmp, wxBLUE)
+        bmp.SetMask(mask)
+        b.SetBitmapSelected(bmp)
+        b.SetUseFocusIndicator(false)
+        b.SetBestSize()
+
 
     def OnButton(self, event):
         self.log.WriteText("Button Clicked: %d\n" % event.GetId())
index fb455c86c4b519ed8d1e0a8b484f4f6b131dfcea..d81475dbd684ba10d4ba794be32dc729402d3aef 100644 (file)
@@ -382,9 +382,68 @@ class wxGenBitmapButton(wxGenButton):
         dc.DrawBitmap(bmp, (width-bw)/2+dw, (height-bh)/2+dy, hasMask)
 
 
-
 #----------------------------------------------------------------------
 
+class wxGenBitmapTextButton(wxGenBitmapButton):     # generic bitmapped button with Text Label
+    def __init__(self, parent, ID, bitmap, label,
+                 pos = wxDefaultPosition, size = wxDefaultSize,
+                 style = 0, validator = wxDefaultValidator,
+                 name = "genbutton"):
+        wxGenBitmapButton.__init__(self, parent, ID, bitmap, pos, size, style, validator, name)
+        self.SetLabel(label)
+
+
+    def _GetLabelSize(self):
+        """ used internally """
+        w, h = self.GetTextExtent(self.GetLabel())
+        if not self.bmpLabel:
+            return w, h, true       # if there isn't a bitmap use the size of the text
+
+        w_bmp = self.bmpLabel.GetWidth()+2
+        h_bmp = self.bmpLabel.GetHeight()+2
+        width = w + w_bmp
+        if h_bmp > h:
+            height = h_bmp
+        else:
+            height = h
+        return width, height, true
+
+
+    def DrawLabel(self, dc, width, height, dw=0, dy=0):
+        bmp = self.bmpLabel
+        if bmp != None:     # if the bitmap is used
+            if self.bmpDisabled and not self.IsEnabled():
+                bmp = self.bmpDisabled
+            if self.bmpFocus and self.hasFocus:
+                bmp = self.bmpFocus
+            if self.bmpSelected and not self.up:
+                bmp = self.bmpSelected
+            bw,bh = bmp.GetWidth(), bmp.GetHeight()
+            if not self.up:
+                dw = dy = self.labelDelta
+            hasMask = bmp.GetMask() != None
+        else:
+            bw = bh = 0     # no bitmap -> size is zero
+
+        dc.SetFont(self.GetFont())
+        if self.IsEnabled():
+            dc.SetTextForeground(self.GetForegroundColour())
+        else:
+            dc.SetTextForeground(wxSystemSettings_GetSystemColour(wxSYS_COLOUR_GRAYTEXT))
+
+        label = self.GetLabel()
+        tw, th = dc.GetTextExtent(label)        # size of text
+        if not self.up:
+            dw = dy = self.labelDelta
+
+        pos_x = (width-bw-tw)/2+dw      # adjust for bitmap and text to centre
+        if bmp !=None:
+            dc.DrawBitmap(bmp, pos_x, (height-bh)/2+dy, hasMask)        # draw bitmap if available
+            pos_x = pos_x + 2   # extra spacing from bitmap
+
+        dc.DrawText(label, pos_x + dw+bw, (height-th)/2+dy)             # draw the text
+
+#----------------------------------------------------------------------
 
 class __ToggleMixin:
     def SetToggle(self, flag):
@@ -429,6 +488,8 @@ class wxGenToggleButton(__ToggleMixin, wxGenButton):
 class wxGenBitmapToggleButton(__ToggleMixin, wxGenBitmapButton):
     pass
 
+class wxGenBitmapTextToggleButton(__ToggleMixin, wxGenBitmapTextButton):
+    pass
 #----------------------------------------------------------------------