30
30
# The default tab setting for a Text widget, in average-width characters.
31
31
TK_TABWIDTH_DEFAULT = 8
32
32
_py_version = ' (%s)' % platform .python_version ()
33
+ darwin = sys .platform == 'darwin'
33
34
34
35
def _sphinx_version ():
35
36
"Format sys.version_info to produce the Sphinx version string used to install the chm docs"
@@ -49,7 +50,7 @@ class EditorWindow(object):
49
50
from idlelib .undo import UndoDelegator
50
51
from idlelib .iomenu import IOBinding , encoding
51
52
from idlelib import mainmenu
52
- from tkinter import Toplevel
53
+ from tkinter import Toplevel , EventType
53
54
from idlelib .statusbar import MultiStatusBar
54
55
from idlelib .autocomplete import AutoComplete
55
56
from idlelib .autoexpand import AutoExpand
@@ -147,6 +148,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
147
148
else :
148
149
# Elsewhere, use right-click for popup menus.
149
150
text .bind ("<3>" ,self .right_menu_event )
151
+ text .bind ('<MouseWheel>' , self .mousescroll )
152
+ text .bind ('<Button-4>' , self .mousescroll )
153
+ text .bind ('<Button-5>' , self .mousescroll )
150
154
text .bind ("<<cut>>" , self .cut )
151
155
text .bind ("<<copy>>" , self .copy )
152
156
text .bind ("<<paste>>" , self .paste )
@@ -193,7 +197,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
193
197
text .bind ("<<open-turtle-demo>>" , self .open_turtle_demo )
194
198
195
199
self .set_status_bar ()
196
- vbar ['command' ] = text . yview
200
+ vbar ['command' ] = self . handle_yview
197
201
vbar .pack (side = RIGHT , fill = Y )
198
202
text ['yscrollcommand' ] = vbar .set
199
203
text ['font' ] = idleConf .GetFont (self .root , 'main' , 'EditorWindow' )
@@ -441,6 +445,27 @@ def postwindowsmenu(self):
441
445
menu .delete (self .wmenu_end + 1 , end )
442
446
windows .add_windows_to_menu (menu )
443
447
448
+ def handle_yview (self , event , * args ):
449
+ "Handle scrollbar."
450
+ if event == 'moveto' :
451
+ fraction = float (args [0 ])
452
+ lines = (round (self .getlineno ('end' ) * fraction ) -
453
+ self .getlineno ('@0,0' ))
454
+ event = 'scroll'
455
+ args = (lines , 'units' )
456
+ self .text .yview (event , * args )
457
+ return 'break'
458
+
459
+ def mousescroll (self , event ):
460
+ "Handle scroll wheel."
461
+ up = {EventType .MouseWheel : event .delta >= 0 == darwin ,
462
+ EventType .Button : event .num == 4 }
463
+ lines = 5
464
+ if up [event .type ]:
465
+ lines = - lines
466
+ self .text .yview_scroll (lines , 'units' )
467
+ return 'break'
468
+
444
469
rmenu = None
445
470
446
471
def right_menu_event (self , event ):
0 commit comments