]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FloatBar.py
wx.EventLoop is now implemented for wxMac.
[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 their 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 tsize = (16,16)
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)
40
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)
44
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)
48
49 tb.AddSeparator()
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)
53
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)
57
58 tb.AddSeparator()
59
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)
63
64 tb.Realize()
65
66 self.tb = tb
67 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
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())
75
76 if event.GetId() == 60:
77 print event.GetExtraLong(), event.IsChecked(), event.GetInt(), self.tb.GetToolState(60)
78
79 if event.GetExtraLong():
80 self.tb.SetTitle("")
81 else:
82 self.tb.SetTitle("Floating!")
83
84 def OnToolRClick(self, event):
85 self.log.WriteText("tool %s right-clicked\n" % event.GetId())
86
87 #---------------------------------------------------------------------------
88
89 class 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.',
102 'Sorry', wx.OK | wx.ICON_WARNING
103 )
104 dlg.ShowModal()
105 dlg.Destroy()
106 else:
107 win = TestFloatBar(self, self.log)
108 win.Show(True)
109
110
111 #---------------------------------------------------------------------------
112
113
114 def runTest(frame, nb, log):
115 win = TestPanel(nb, log)
116 return win
117
118 #---------------------------------------------------------------------------
119
120 overview = """\
121 FloatBar is a subclass of wx.ToolBar, implemented in Python, which
122 can be detached from its frame.
123
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.
126
127 """
128
129 if __name__ == '__main__':
130 import sys,os
131 import run
132 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
133
134
135
136
137
138
139
140
141
142
143
144
145