1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 '''Simple Toolbar with built-in actions. Eventually, I suppose it should
22 be fully customizable, but I'm not even using this thing, so if somebody
23 likes toolbars they can hack this plugin and send me the new version.
24
25 This plugin invokes the following actions:
26 NewFile
27 OpenFile
28 SaveActive
29 When a toolbar icon is clicked.'''
30
31 from pallavi import EventActionManager
32 import wx
33 import sys
34
35 size=(16, 16)
38
40 "Called whenever a new textview is created"
41 toolbar = wx.ToolBar(view, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)
42 toolbar.SetToolBitmapSize(size)
43
44 BindAction(toolbar, "NewFile", view)
45 BindAction(toolbar, "OpenFile", view)
46 BindAction(toolbar, "SaveActive", view)
47 toolbar.AddSeparator()
48
49 bm = wx.ArtProvider.GetBitmap
50 BindFunction(toolbar, bm(wx.ART_UNDO), "Undo", "Undo last action", lambda x:pallavi.focusedView.focusedTextView.Undo(), view)
51 BindFunction(toolbar, bm(wx.ART_REDO), "Redo", "Redo last action", lambda x:pallavi.focusedView.focusedTextView.Redo(), view)
52 toolbar.AddSeparator()
53 BindFunction(toolbar, bm(wx.ART_CUT), "Cut", "Cut selected text", lambda x:pallavi.focusedView.focusedTextView.Cut(), view)
54 BindFunction(toolbar, bm(wx.ART_COPY), "Copy", "Copy selected text", lambda x:pallavi.focusedView.focusedTextView.Copy(), view)
55 BindFunction(toolbar, bm(wx.ART_PASTE), "Paste", "Paste text from clipboard", lambda x:pallavi.focusedView.focusedTextView.Paste(), view)
56 view.dockmanager.AddPane(toolbar, wx.aui.AuiPaneInfo().Caption("Toolbar").ToolbarPane().Top().LeftDockable(False).RightDockable(False))
57 view.dockmanager.Update()
58
60 '''Convenience method to make the actions bound in the setup method
61 more readable. Toolbar is the toolbar to add to, action is the
62 id of a Pallavi Action to add. The action should have an icon set.'''
63 icon = actions[action].icon
64 text = actions[action].label
65 tooltip = actions[action].description
66 BindFunction(toolbar, icon, text, tooltip, lambda x:actions.Invoke(action), view)
67
68 -def BindFunction(toolbar, icon, text, tooltip, function, view):
69 '''Bind a function to a specific menu action. Toolbar is the toolbar
70 to bind to. Icon is the icon to bind. Text and tooltip are short and
71 long helps. Function is the function to bind.'''
72 tool = toolbar.AddSimpleTool(wx.ID_ANY, icon, text, tooltip)
73 view.Bind(wx.EVT_TOOL, function, tool)
74