]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FloatBar.py
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 their 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()
36 new_bmp
= wx
.ArtProvider
.GetBitmap(wx
.ART_NEW
, wx
.ART_TOOLBAR
, tsize
)
37 open_bmp
= wx
.ArtProvider
.GetBitmap(wx
.ART_FILE_OPEN
, wx
.ART_TOOLBAR
, tsize
)
38 copy_bmp
= wx
.ArtProvider
.GetBitmap(wx
.ART_COPY
, wx
.ART_TOOLBAR
, tsize
)
39 paste_bmp
= wx
.ArtProvider
.GetBitmap(wx
.ART_PASTE
, wx
.ART_TOOLBAR
, tsize
)
41 tb
.AddSimpleTool(10, new_bmp
, "New", "Long help for 'New'")
42 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=10)
43 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=10)
45 tb
.AddSimpleTool(20, open_bmp
, "Open")
46 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=20)
47 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=20)
50 tb
.AddSimpleTool(30, copy_bmp
, "Copy")
51 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=30)
52 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=30)
54 tb
.AddSimpleTool(40, paste_bmp
, "Paste")
55 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=40)
56 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=40)
60 tb
.AddCheckTool(60, images
.getTog1Bitmap(), images
.getTog2Bitmap())
61 self
.Bind(wx
.EVT_TOOL
, self
.OnToolClick
, id=60)
62 self
.Bind(wx
.EVT_TOOL_RCLICKED
, self
.OnToolRClick
, id=60)
67 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
70 def OnCloseWindow(self
, event
):
73 def OnToolClick(self
, event
):
74 self
.log
.WriteText("tool %s clicked\n" % event
.GetId())
76 if event
.GetId() == 60:
77 print event
.GetExtraLong(), event
.IsChecked(), event
.GetInt(), self
.tb
.GetToolState(60)
79 if event
.GetExtraLong():
82 self
.tb
.SetTitle("Floating!")
84 def OnToolRClick(self
, event
):
85 self
.log
.WriteText("tool %s right-clicked\n" % event
.GetId())
87 #---------------------------------------------------------------------------
89 class TestPanel(wx
.Panel
):
90 def __init__(self
, parent
, log
):
92 wx
.Panel
.__init
__(self
, parent
, -1)
94 b
= wx
.Button(self
, -1, "Show the FloatBar sample", (50,50))
95 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
98 def OnButton(self
, evt
):
99 if wx
.Platform
== "__WXMAC__":
100 dlg
= wx
.MessageDialog(
101 self
, 'FloatBar does not work well on this platform.',
102 'Sorry', wx
.OK | wx
.ICON_WARNING
107 win
= TestFloatBar(self
, self
.log
)
111 #---------------------------------------------------------------------------
114 def runTest(frame
, nb
, log
):
115 win
= TestPanel(nb
, log
)
118 #---------------------------------------------------------------------------
121 FloatBar is a subclass of wx.ToolBar, implemented in Python, which
122 can be detached from its frame.
124 Drag the toolbar with the mouse to make it float, and drag it back, or
125 close it to make the toolbar return to its original position.
129 if __name__
== '__main__':
132 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])