]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FloatBar.py
Script updates
[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
83def runTest(frame, nb, log):
b4f1aaad
RD
84 if wx.Platform == "__WXMAC__":
85 dlg = wx.MessageDialog(
86 frame, 'FloatBar does not work well on this platform.',
87 'Sorry', wx.OK | wx.ICON_INFORMATION
88 )
89 dlg.ShowModal()
90 dlg.Destroy()
91 else:
92 win = TestFloatBar(frame, log)
93 frame.otherWin = win
94 win.Show(True)
f0261a72
RD
95
96#---------------------------------------------------------------------------
97
98overview = """\
33785d9f 99FloatBar is a subclass of wx.ToolBar, implemented in Python, which
1fded56b 100can be detached from its frame.
f0261a72 101
1fded56b
RD
102Drag the toolbar with the mouse to make it float, and drag it back, or
103close it to make the toolbar return to its original position.
f0261a72 104
f0261a72
RD
105"""
106
1fded56b
RD
107if __name__ == '__main__':
108 import sys,os
109 import run
110 run.main(['', os.path.basename(sys.argv[0])])
111
112
113
f0261a72
RD
114
115
116
117
118
119
120
121
122
123