Here is a very basic SegmentedButton Class that one can pass size and
segment arguments. It will return the buttons (2, 3, or 4) on a
PyPanel that can be inserted into an AUI Toolbar as a control. It uses
the Generic Buttons. It does not yet deal with events or labels. This
is just a "proof of concept" thing.
I am not very swift on making hand drawn buttons that could appear to
overlap (the 5th button in the center). That would be very nice and
somewhat unique. There are many possibilities with button arrangements
such as this. I know some of you guys (and gals) could make some very
compact, functional, and attractive controls (hint, hint).
Tim
ps. If the code below is wrapped, here it is as well,
http://www.BibleAnalyzer.com/files/segTest.py
···
-------------------------------
import wx
import wx.lib.buttons as buttons
class SegmentButton(wx.PyPanel):
def __init__(self, parent, id=wx.ID_ANY, size = (32, 32), segments
= 4):
wx.PyPanel.__init__(self, parent, id)
segSize = (size[0] /2, size[0] /2) # 4 segments
if segments == 3:
segSize = (size[0], size[0] /3.33)
if segments == 2:
segSize = (size[0], size[0] /2)
segList = []
for seg, num in enumerate(range(segments)):
b = buttons.GenButton(self, -1, str(num), size =
(segSize[0], segSize[1]))
segList.append(b)
gsRows = (2, 2) # 4 segments
if segments == 3:
gsRows = (3, 1)
elif segments == 2:
gsRows = (2, 1)
gs = wx.GridSizer(gsRows[0], gsRows[1])
for b in segList:
gs.Add(b, 0, wx.EXPAND)
self.SetSizer(gs)
class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, style =
wx.DEFAULT_FRAME_STYLE)
panel = wx.Panel(self, -1)
segButton = SegmentButton(panel, size = (48, 48), segments =
4)
self.SetTitle('Segment Button Demo')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(segButton, 0, wx.ALL, 30)
panel.SetSizer(sizer)
self.Layout()
class MyApp(wx.App):
def OnInit(self):
Demo = TestFrame(None)
Demo.Show()
return 1
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()