]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FloatBar.py
7e603aa9f59843f447cd06bdd4e12a16d48590b0
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.
14 class TestFloatBar(wx
.Frame
):
15 def __init__(self
, parent
, log
):
17 self
, parent
, -1, 'Test ToolBar', wx
.DefaultPosition
, (500, 300)
22 win
= wx
.Window(self
, -1)
23 win
.SetBackgroundColour("WHITE")
25 win
, -1, "Drag the toolbar to float it,\n"
26 "Toggle the last tool to remove\nthe title.", (15,15)
29 tb
= wx
.lib
.floatbar
.FloatBar(self
, -1)
32 tb
.SetTitle("Floating!")
33 self
.CreateStatusBar()
35 tb
.AddSimpleTool(10, images
.getNewBitmap(), "New", "Long help for 'New'")
36 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=10)
37 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=10)
39 tb
.AddSimpleTool(20, images
.getOpenBitmap(), "Open")
40 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=20)
41 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=20)
44 tb
.AddSimpleTool(30, images
.getCopyBitmap(), "Copy")
45 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=30)
46 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=30)
48 tb
.AddSimpleTool(40, images
.getPasteBitmap(), "Paste")
49 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=40)
50 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=40)
54 tb
.AddCheckTool(60, images
.getTog1Bitmap(), images
.getTog2Bitmap())
55 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=60)
56 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=60)
61 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
64 def OnCloseWindow(self
, event
):
67 def OnToolClick(self
, event
):
68 self
.log
.WriteText("tool %s clicked\n" % event
.GetId())
70 if event
.GetId() == 60:
71 print event
.GetExtraLong(), event
.IsChecked(), event
.GetInt(), self
.tb
.GetToolState(60)
73 if event
.GetExtraLong():
76 self
.tb
.SetTitle("Floating!")
78 def OnToolRClick(self
, event
):
79 self
.log
.WriteText("tool %s right-clicked\n" % event
.GetId())
81 #---------------------------------------------------------------------------
83 class TestPanel(wx
.Panel
):
84 def __init__(self
, parent
, log
):
86 wx
.Panel
.__init
__(self
, parent
, -1)
88 b
= wx
.Button(self
, -1, "Show the FloatBar sample", (50,50))
89 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
92 def OnButton(self
, evt
):
93 if wx
.Platform
== "__WXMAC__":
94 dlg
= wx
.MessageDialog(
95 self
, 'FloatBar does not work well on this platform.',
96 'Sorry', wx
.OK | wx
.ICON_WARNING
101 win
= TestFloatBar(self
, self
.log
)
105 #---------------------------------------------------------------------------
108 def runTest(frame
, nb
, log
):
109 win
= TestPanel(nb
, log
)
112 #---------------------------------------------------------------------------
115 FloatBar is a subclass of wx.ToolBar, implemented in Python, which
116 can be detached from its frame.
118 Drag the toolbar with the mouse to make it float, and drag it back, or
119 close it to make the toolbar return to its original position.
123 if __name__
== '__main__':
126 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])