]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/FloatBar.py
The great wxVScrolledWindow refactoring: allow using it both horizontal and
[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
90e572f1 5# wx.ToolBar, but everyone else has to take their 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
6c75a4cf 35 tsize = (16,16)
406011a8 36 new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
6c75a4cf
RD
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)
40
41 tb.AddSimpleTool(10, new_bmp, "New", "Long help for 'New'")
8fa876ca
RD
42 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
43 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)
f0261a72 44
6c75a4cf 45 tb.AddSimpleTool(20, open_bmp, "Open")
8fa876ca
RD
46 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
47 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)
f0261a72
RD
48
49 tb.AddSeparator()
6c75a4cf 50 tb.AddSimpleTool(30, copy_bmp, "Copy")
8fa876ca
RD
51 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
52 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30)
f0261a72 53
6c75a4cf 54 tb.AddSimpleTool(40, paste_bmp, "Paste")
8fa876ca
RD
55 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
56 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40)
f0261a72
RD
57
58 tb.AddSeparator()
59
70a357c2 60 tb.AddCheckTool(60, images.getTog1Bitmap(), images.getTog2Bitmap())
8fa876ca
RD
61 self.Bind(wx.EVT_TOOL, self.OnToolClick, id=60)
62 self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=60)
63
f0261a72 64 tb.Realize()
944930d5
RD
65
66 self.tb = tb
8fa876ca 67 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
f0261a72
RD
68
69
70 def OnCloseWindow(self, event):
71 self.Destroy()
72
73 def OnToolClick(self, event):
74 self.log.WriteText("tool %s clicked\n" % event.GetId())
8fa876ca 75
944930d5 76 if event.GetId() == 60:
33785d9f 77 print event.GetExtraLong(), event.IsChecked(), event.GetInt(), self.tb.GetToolState(60)
8fa876ca 78
944930d5
RD
79 if event.GetExtraLong():
80 self.tb.SetTitle("")
81 else:
82 self.tb.SetTitle("Floating!")
f0261a72
RD
83
84 def OnToolRClick(self, event):
85 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
f0261a72
RD
86
87#---------------------------------------------------------------------------
88
34a544a6
RD
89class TestPanel(wx.Panel):
90 def __init__(self, parent, log):
91 self.log = log
92 wx.Panel.__init__(self, parent, -1)
93
94 b = wx.Button(self, -1, "Show the FloatBar sample", (50,50))
95 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
96
97
98 def OnButton(self, evt):
99 if wx.Platform == "__WXMAC__":
100 dlg = wx.MessageDialog(
101 self, 'FloatBar does not work well on this platform.',
c4ef95da 102 'Sorry', wx.OK | wx.ICON_WARNING
34a544a6
RD
103 )
104 dlg.ShowModal()
105 dlg.Destroy()
106 else:
107 win = TestFloatBar(self, self.log)
108 win.Show(True)
109
110
111#---------------------------------------------------------------------------
112
113
f0261a72 114def runTest(frame, nb, log):
34a544a6
RD
115 win = TestPanel(nb, log)
116 return win
f0261a72
RD
117
118#---------------------------------------------------------------------------
119
120overview = """\
33785d9f 121FloatBar is a subclass of wx.ToolBar, implemented in Python, which
1fded56b 122can be detached from its frame.
f0261a72 123
1fded56b
RD
124Drag the toolbar with the mouse to make it float, and drag it back, or
125close it to make the toolbar return to its original position.
f0261a72 126
f0261a72
RD
127"""
128
1fded56b
RD
129if __name__ == '__main__':
130 import sys,os
131 import run
8eca4fef 132 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
1fded56b
RD
133
134
135
f0261a72
RD
136
137
138
139
140
141
142
143
144
145