]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FloatBar.py
Fixes for the stubbed version so it will compile
[wxWidgets.git] / wxPython / demo / FloatBar.py
CommitLineData
8fa876ca 1#
95bfd958
RD
2# Please note that wx.lib.floatbar is not formally supported as
3# part of wxPython. If it works, fine. If not, unfortunate.
4# GTK users can use the wx.TB_DOCKABLE flag with a regular
5# wx.ToolBar, but everyone else has to take thier chances.
33785d9f 6#
f0261a72 7
8fa876ca 8import wx
33785d9f 9import wx.lib.floatbar
96bfd053 10
8fa876ca 11import images
96bfd053 12
8fa876ca
RD
13
14class TestFloatBar(wx.Frame):
f0261a72 15 def __init__(self, parent, log):
8fa876ca
RD
16 wx.Frame.__init__(
17 self, parent, -1, 'Test ToolBar', wx.DefaultPosition, (500, 300)
18 )
19
f0261a72
RD
20 self.log = log
21
8fa876ca
RD
22 win = wx.Window(self, -1)
23 win.SetBackgroundColour("WHITE")
24 wx.StaticText(
25 win, -1, "Drag the toolbar to float it,\n"
26 "Toggle the last tool to remove\nthe title.", (15,15)
27 )
f0261a72 28
33785d9f 29 tb = wx.lib.floatbar.FloatBar(self, -1)
f0261a72
RD
30 self.SetToolBar(tb)
31 tb.SetFloatable(1)
32 tb.SetTitle("Floating!")
33 self.CreateStatusBar()
96bfd053 34
70a357c2 35 tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help for 'New'")
8fa876ca
RD
36 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
37 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)
f0261a72 38
70a357c2 39 tb.AddSimpleTool(20, images.getOpenBitmap(), "Open")
8fa876ca
RD
40 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
41 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)
f0261a72
RD
42
43 tb.AddSeparator()
70a357c2 44 tb.AddSimpleTool(30, images.getCopyBitmap(), "Copy")
8fa876ca
RD
45 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
46 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30)
f0261a72 47
70a357c2 48 tb.AddSimpleTool(40, images.getPasteBitmap(), "Paste")
8fa876ca
RD
49 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
50 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40)
f0261a72
RD
51
52 tb.AddSeparator()
53
70a357c2 54 tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap())
8fa876ca
RD
55 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=60)
56 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=60)
57
f0261a72 58 tb.Realize()
944930d5
RD
59
60 self.tb = tb
8fa876ca 61 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
f0261a72
RD
62
63
64 def OnCloseWindow(self, event):
65 self.Destroy()
66
67 def OnToolClick(self, event):
68 self.log.WriteText("tool %s clicked\n" % event.GetId())
8fa876ca 69
944930d5 70 if event.GetId() == 60:
33785d9f 71 print event.GetExtraLong(), event.IsChecked(), event.GetInt(), self.tb.GetToolState(60)
8fa876ca 72
944930d5
RD
73 if event.GetExtraLong():
74 self.tb.SetTitle("")
75 else:
76 self.tb.SetTitle("Floating!")
f0261a72
RD
77
78 def OnToolRClick(self, event):
79 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
f0261a72
RD
80
81#---------------------------------------------------------------------------
82
34a544a6
RD
83class TestPanel(wx.Panel):
84 def __init__(self, parent, log):
85 self.log = log
86 wx.Panel.__init__(self, parent, -1)
87
88 b = wx.Button(self, -1, "Show the FloatBar sample", (50,50))
89 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
90
91
92 def OnButton(self, evt):
93 if wx.Platform == "__WXMAC__":
94 dlg = wx.MessageDialog(
95 self, 'FloatBar does not work well on this platform.',
c4ef95da 96 'Sorry', wx.OK | wx.ICON_WARNING
34a544a6
RD
97 )
98 dlg.ShowModal()
99 dlg.Destroy()
100 else:
101 win = TestFloatBar(self, self.log)
102 win.Show(True)
103
104
105#---------------------------------------------------------------------------
106
107
f0261a72 108def runTest(frame, nb, log):
34a544a6
RD
109 win = TestPanel(nb, log)
110 return win
f0261a72
RD
111
112#---------------------------------------------------------------------------
113
114overview = """\
33785d9f 115FloatBar is a subclass of wx.ToolBar, implemented in Python, which
1fded56b 116can be detached from its frame.
f0261a72 117
1fded56b
RD
118Drag the toolbar with the mouse to make it float, and drag it back, or
119close it to make the toolbar return to its original position.
f0261a72 120
f0261a72
RD
121"""
122
1fded56b
RD
123if __name__ == '__main__':
124 import sys,os
125 import run
8eca4fef 126 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b
RD
127
128
129
f0261a72
RD
130
131
132
133
134
135
136
137
138
139