Package pallavi :: Package plugins :: Module SimpleToolbar
[hide private]
[frames] | no frames]

Source Code for Module pallavi.plugins.SimpleToolbar

 1  # Copyright (c) 2006 Dusty Phillips 
 2   
 3  # Permission is hereby granted, free of charge, to any person obtaining a 
 4  # copy of this software and associated documentation files (the "Software"), 
 5  # to deal in the Software without restriction, including without limitation 
 6  # the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 7  # and/or sell copies of the Software, and to permit persons to whom the 
 8  # Software is furnished to do so, subject to the following conditions: 
 9   
10  # The above copyright notice and this permission notice shall be included in 
11  # all copies or substantial portions of the Software. 
12   
13  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
14  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
15  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
16  # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
17  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
18  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
19  # DEALINGS IN THE SOFTWARE. 
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) 
36 -def setup():
37 eventBus.AddListener("ViewCreated", NewView)
38
39 -def NewView(name, view):
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
59 -def BindAction(toolbar, action, view):
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