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

Source Code for Module pallavi.plugins.SameIndent

 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  '''This plugin ensures that when a newline is entered, it 
22  has the same amount of whitespace as the previous line. This 
23  is a fake form of auto-indent, but it doesn't know about adding 
24  indentation when the next line should be indented another level. 
25   
26  Unless otherwise bound, Shift+Enter will ignore this effect. 
27   
28  This plugin listens for the following events: 
29  TextViewAdded 
30          To set up the keylistener on the indicated textview''' 
31  from pallavi import EventActionManager 
32  import wx 
33   
34   
35 -def setup():
36 eventBus.AddListener("TextViewAdded", TextViewAdded) 37 for view in pallavi.views: 38 for textview in view.textViews.values(): 39 TextViewAdded(None, textview)
40
41 -def TextViewAdded(eventName, textview):
42 textview.Bind(wx.EVT_KEY_DOWN, KeyDown)
43
44 -def KeyDown(event):
45 if event.GetKeyCode() == 13: #Enter Key 46 if not ((event.AltDown() or event.ControlDown() or event.ShiftDown())): 47 tv = pallavi.focusedView.focusedTextView 48 lineNo = tv.GetCurrentLine() 49 indentpos = tv.GetLineIndentPosition(lineNo) 50 line = tv.GetLine(lineNo) 51 linestartpos = tv.PositionFromLine(lineNo) 52 indentString = line[0:indentpos-linestartpos] 53 tv.AddText("\n%s" %indentString) 54 eventBus.QueueEvent("KeyStroke", event.GetKeyCode()) 55 else: 56 event.Skip() 57 else: 58 event.Skip()
59