File size: 6,785 Bytes
d12bc25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# The default keyboard etc configuration file for Pythonwin.
#
# The format of this file is very similar to a Windows INI file.
# Sections are identified with [Section] lines, but comments
# use the standatd Python # character.  Depending on the section,
# lines may not be in the standard "key=value" format.

# NOTE:  You should not need to modify this file.
# Simply create a new .CFG file, and add an entry:
# [General]
# BasedOn = Default
#
# and add your customisations.  Then select your new configuration 
# from the Pythonwin View/Options/Editor dialog.
# This way you get to add your own customisations,
# but still take advantage of changes to the default
# configuration in new releases.

# See IDLE.cfg for an example extension configuration.
#
##########################################################################

[IDLE Extensions]

# The list of IDLE extensions to load.  The extensions
# AutoIndent, AutoFormat and possibly others are
# "built-in", so do not need specifying.

FormatParagraph
CallTips


[Keys]

# The list of _default_ key definitions.  
#  See [Keys:Interactive] and [Keys:Editor] below for further defs.

#Events of the format <<event-name>> 
# are events defined in IDLE extensions.

Alt+Q             = <<format-paragraph>>

Ctrl+W            = ViewWhitespace
Ctrl+Shift+8      = ViewWhitespace # The MSVC default key def.

Ctrl+Shift+F      = ViewFixedFont

# Auto-complete, call-tips, etc.
Alt+/             = <<expand-word>>
Ctrl+Space   = <<expand-word>>
(           = <<paren-open>>
)           = <<paren-close>>
Up                = <<check-calltip-cancel>>
Down              = <<check-calltip-cancel>>
Left              = <<check-calltip-cancel>>
Right             = <<check-calltip-cancel>>
.                 = KeyDot

# Debugger - These are the MSVC default keys, for want of a better choice.
F9                = DbgBreakpointToggle
F5                = DbgGo
Shift+F5          = DbgClose
F11               = DbgStep
F10               = DbgStepOver
Shift+F11         = DbgStepOut

Ctrl+F3           = AutoFindNext


[Keys:Editor]
# Key bindings specific to the editor
F2                = GotoNextBookmark
Ctrl+F2           = ToggleBookmark
Ctrl+G            = GotoLine

Alt+I             = ShowInteractiveWindow
Alt-B             = AddBanner # A sample Event defined in this file.

# Block operations
Alt+3             = <<comment-region>>
Shift+Alt+3       = <<uncomment-region>>
Alt+4             = <<uncomment-region>> # IDLE default.
Alt+5             = <<tabify-region>>
Alt+6             = <<untabify-region>>

# Tabs and other indent features
Back              = <<smart-backspace>>
Ctrl+T            = <<toggle-tabs>>
Alt+U             = <<change-indentwidth>>
Enter             = EnterKey
Tab               = TabKey
Shift-Tab         = <<dedent-region>>

# Folding
Add               = FoldExpand
Alt+Add           = FoldExpandAll
Shift+Add         = FoldExpandSecondLevel
Subtract          = FoldCollapse
Alt+Subtract      = FoldCollapseAll
Shift+Subtract    = FoldCollapseSecondLevel
Multiply          = FoldTopLevel

[Keys:Interactive]
# Key bindings specific to the interactive window.
# History for the interactive window
Ctrl+Up           = <<history-previous>>
Ctrl+Down         = <<history-next>>
Enter             = ProcessEnter
Ctrl+Enter        = ProcessEnter
Shift+Enter       = ProcessEnter
Esc               = ProcessEsc
Alt+I             = WindowBack # Toggle back to previous window.
Home              = InteractiveHome # A sample Event defined in this file.
Shift+Home        = InteractiveHomeExtend # A sample Event defined in this file.

# When docked, the Ctrl+Tab and Shift+Ctrl+Tab keys dont work as expected.
Ctrl+Tab          = MDINext
Ctrl+Shift+Tab    = MDIPrev

[Extensions]
# Python event handlers specific to this config file.
# All functions not starting with an "_" are assumed
# to be events, and take 2 params:
# * editor_window is the same object passed to IDLE
#   extensions.  editor_window.text is a text widget
#   that conforms to the Tk text widget interface.
# * event is the event being fired.  Will always be None
#   in the current implementation.

# Simply by defining these functions, they are available as
# events.
# Note that we bind keystrokes to these events in the various
# [Keys] sections.

# Add a simple file/class/function simple banner
def AddBanner(editor_window, event):

	text = editor_window.text
	big_line = "#" * 70
	banner = "%s\n## \n## \n## \n%s\n" % (big_line, big_line)

	# Insert at the start of the current line.
	pos = text.index("insert linestart")

	text.undo_block_start() # Allow action to be undone as a single unit.
	text.insert(pos, banner)
	text.undo_block_stop()

	# Now set the insert point to the middle of the banner.
	line, col = [int(s) for s in pos.split(".")]
	text.mark_set("insert", "%d.1 lineend" % (line+2, ) )


# Here is a sample event bound to the "Home" key in the
# interactive window
def InteractiveHome(editor_window, event):
	return _DoInteractiveHome(editor_window.text, 0)

def InteractiveHomeExtend(editor_window, event):
	return _DoInteractiveHome(editor_window.text, 1)

def _DoInteractiveHome(text, extend):
	import sys
	# If Scintilla has an autocomplete window open, then let Scintilla handle it.
	if text.edit.SCIAutoCActive():
		return 1
	of_interest = "insert linestart + %d c" % len(sys.ps1)
	if not text.compare("insert", "==", of_interest) and \
	   text.get("insert linestart", of_interest) in [sys.ps1, sys.ps2]: # Not sys.ps? line
		end = of_interest
	else:
		end = "insert linestart"

	if extend: start = "insert"
	else: start = end
	text.tag_add("sel", start, end)

# From Niki Spahie
def AutoFindNext(editor_window, event):
    "find selected text or word under cursor"

    from pywin.scintilla import find
    from pywin.scintilla import scintillacon

    try:
        sci = editor_window.edit
        word = sci.GetSelText()
        if word:
            find.lastSearch.findText = word
            find.lastSearch.sel = sci.GetSel()
        else:
            pos = sci.SendScintilla( scintillacon.SCI_GETCURRENTPOS )
            start = sci.SendScintilla( scintillacon.SCI_WORDSTARTPOSITION, pos, 1 )
            end = sci.SendScintilla( scintillacon.SCI_WORDENDPOSITION, pos, 1 )
            word = sci.GetTextRange( start, end )
            if word:
                find.lastSearch.findText = word
                find.lastSearch.sel = (start,end)
    except Exception:
        import traceback
        traceback.print_exc()
    find.FindNext()


# A couple of generic events.
def Beep(editor_window, event):
	editor_window.text.beep()

def DoNothing(editor_window, event):
	pass

def ContinueEvent(editor_window, event):
	# Almost an "unbind" - allows Pythonwin/MFC to handle the keystroke
	return 1