]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FloatBar.py
#include "wx/settings.h" for wxSystemSettings
[wxWidgets.git] / wxPython / demo / FloatBar.py
1 #
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.
6 #
7
8 import wx
9 import wx.lib.floatbar
10
11 import images
12
13
14 class TestFloatBar(wx.Frame):
15 def __init__(self, parent, log):
16 wx.Frame.__init__(
17 self, parent, -1, 'Test ToolBar', wx.DefaultPosition, (500, 300)
18 )
19
20 self.log = log
21
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 )
28
29 tb = wx.lib.floatbar.FloatBar(self, -1)
30 self.SetToolBar(tb)
31 tb.SetFloatable(1)
32 tb.SetTitle("Floating!")
33 self.CreateStatusBar()
34
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)
38
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)
42
43 tb.AddSeparator()
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)
47
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)
51
52 tb.AddSeparator()
53
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)
57
58 tb.Realize()
59
60 self.tb = tb
61 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
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())
69
70 if event.GetId() == 60:
71 print event.GetExtraLong(), event.IsChecked(), event.GetInt(), self.tb.GetToolState(60)
72
73 if event.GetExtraLong():
74 self.tb.SetTitle("")
75 else:
76 self.tb.SetTitle("Floating!")
77
78 def OnToolRClick(self, event):
79 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
80
81 #---------------------------------------------------------------------------
82
83 def runTest(frame, nb, log):
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)
95
96 #---------------------------------------------------------------------------
97
98 overview = """\
99 FloatBar is a subclass of wx.ToolBar, implemented in Python, which
100 can be detached from its frame.
101
102 Drag the toolbar with the mouse to make it float, and drag it back, or
103 close it to make the toolbar return to its original position.
104
105 """
106
107 if __name__ == '__main__':
108 import sys,os
109 import run
110 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
111
112
113
114
115
116
117
118
119
120
121
122
123