]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/FloatBar.py
Added wrappers for wx.MediaCtrl
[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 class TestPanel(wx.Panel):
84 def __init__(self, parent, log):
85 self.log = log
86 wx.Panel.__init__(self, parent, -1)
87
88 b = wx.Button(self, -1, "Show the FloatBar sample", (50,50))
89 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
90
91
92 def OnButton(self, evt):
93 if wx.Platform == "__WXMAC__":
94 dlg = wx.MessageDialog(
95 self, 'FloatBar does not work well on this platform.',
96 'Sorry', wx.OK | wx.ICON_WARNING
97 )
98 dlg.ShowModal()
99 dlg.Destroy()
100 else:
101 win = TestFloatBar(self, self.log)
102 win.Show(True)
103
104
105 #---------------------------------------------------------------------------
106
107
108 def runTest(frame, nb, log):
109 win = TestPanel(nb, log)
110 return win
111
112 #---------------------------------------------------------------------------
113
114 overview = """\
115 FloatBar is a subclass of wx.ToolBar, implemented in Python, which
116 can be detached from its frame.
117
118 Drag the toolbar with the mouse to make it float, and drag it back, or
119 close it to make the toolbar return to its original position.
120
121 """
122
123 if __name__ == '__main__':
124 import sys,os
125 import run
126 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
127
128
129
130
131
132
133
134
135
136
137
138
139