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

Source Code for Module pallavi.plugins.Statusbar

 1  # Copyright (c) 2007 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  ''' 
22  This plugin provides a simple statusbar. It monitors the current line and 
23  column number and allows general status messages to be sent via the 
24  eventaction mechanism (this would allow the statusbar to be replaced 
25  by another plugin without interfering 
26   
27  This plugin provides the following action: 
28  SetStatusMessage message 
29          Set the status bar's status message. 
30           
31  This plugin listens for the following events: 
32  Keystroke 
33  TextViewFocused 
34          To update the line and column number 
35  TextViewAdded 
36          Sets up a mouse click listener on a textview when it has been added to the view. 
37  ViewCreated 
38          Sets up a mouse click listener and status bar on each new view 
39  ''' 
40   
41  from pallavi import EventActionManager 
42  import wx 
43   
44 -def setup():
45 '''Setup the statusbar, event listeners, and action to allow other plugins to set 46 status messages''' 47 eventBus.AddListener("KeyStroke", UpdateCursorPos) 48 eventBus.AddListener("TextViewFocused", UpdateCursorPos) 49 eventBus.AddListener("ViewCreated", NewView) 50 eventBus.AddListener("TextViewAdded", TextViewAdded) 51 actions.AddAction(EventActionManager.Action("SetStatusMessage", SetStatusMessage)) 52 for view in pallavi.views: 53 NewView(None, view)
54 55
56 -def NewView(name, view=None):
57 '''Called when a new view is created -- add a statusbar to that view''' 58 for textview in view.textViews: 59 TextViewAdded(None, pallavi.focusedView.textViews[textview]) 60 statusbar = wx.StatusBar(pallavi.focusedView, wx.ID_ANY) 61 statusbar.SetFieldsCount(2) 62 statusbar.SetStatusWidths([-1, 120]) 63 view.SetStatusBar(statusbar) 64 statusbar.SetStatusText("", 0) 65 statusbar.SetStatusText("", 1)
66
67 -def TextViewAdded(eventname, textview):
68 '''Responds to the textviewadded event. Should not be called directly''' 69 textview.Bind(wx.EVT_LEFT_DOWN, UpdateCursorPos)
70
71 -def SetStatusMessage(data):
72 '''Set the status message to a particular string, data. This can be called 73 directly if necessary, but its better to invoke the SetStatusMessage action instead''' 74 statusbar = pallavi.focusedView.GetStatusBar() 75 if statusbar: 76 statusbar.SetStatusText(data, 0) 77 wx.CallLater(4000, statusbar.SetStatusText, "", 0)
78
79 -def UpdateCursorPos(name, data=None):
80 '''Update the area of the statusbar that indicates the current line and column number. 81 This function is automatically called when the mouse relocates the cursor, a new 82 textview is focused, or a keypress moves the cursor.''' 83 # Hack to use as a mouse listener too 84 if type(name) == wx.MouseEvent: 85 name.Skip() 86 87 tv = pallavi.focusedView.focusedTextView 88 col = tv.GetColumn(tv.GetCurrentPos()) 89 line = tv.GetCurrentLine() 90 statusbar = pallavi.focusedView.GetStatusBar() 91 if statusbar: statusbar.SetStatusText("line %d col %d" %(line, col), 1)
92