Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d43ffc9

Browse files
committed
Issue #21933: Make Control-Mousewhell only change font size and not also scroll.
Original patch by Serhiy Storchaka.
1 parent be74668 commit d43ffc9

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

Lib/turtledemo/__main__.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
2020
The demo viewer windows can be resized. The divider between text
2121
and canvas can be moved by grabbing it with the mouse. The text font
22-
size can be changed from the menu and with Control/Command- '-'/'+'.
23-
It can also be changed on most systems with Control-mousewheel.
22+
size can be changed from the menu and with Control/Command '-'/'+'.
23+
It can also be changed on most systems with Control-mousewheel
24+
when the mouse is over the text.
2425
2526
Press START button to start the demo.
2627
Stop execution by pressing the STOP button.
@@ -210,10 +211,19 @@ def makeTextFrame(self, root):
210211
self.hbar = hbar = Scrollbar(text_frame, name='hbar', orient=HORIZONTAL)
211212
hbar['command'] = text.xview
212213
hbar.pack(side=BOTTOM, fill=X)
213-
214-
text['font'] = tuple(txtfont)
215214
text['yscrollcommand'] = vbar.set
216215
text['xscrollcommand'] = hbar.set
216+
217+
text['font'] = tuple(txtfont)
218+
shortcut = 'Command' if darwin else 'Control'
219+
text.bind_all('<%s-minus>' % shortcut, self.decrease_size)
220+
text.bind_all('<%s-underscore>' % shortcut, self.decrease_size)
221+
text.bind_all('<%s-equal>' % shortcut, self.increase_size)
222+
text.bind_all('<%s-plus>' % shortcut, self.increase_size)
223+
text.bind('<Control-MouseWheel>', self.update_mousewheel)
224+
text.bind('<Control-Button-4>', self.increase_size)
225+
text.bind('<Control-Button-5>', self.decrease_size)
226+
217227
text.pack(side=LEFT, fill=BOTH, expand=1)
218228
return text_frame
219229

@@ -224,7 +234,7 @@ def makeGraphFrame(self, root):
224234
turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas(
225235
root, 800, 600, self.canvwidth, self.canvheight)
226236
canvas.adjustScrolls()
227-
self.makeBindings(canvas._rootwindow)
237+
canvas._rootwindow.bind('<Configure>', self.onResize)
228238
canvas._canvas['borderwidth'] = 0
229239

230240
self.screen = _s_ = turtle.Screen()
@@ -233,34 +243,26 @@ def makeGraphFrame(self, root):
233243
turtle.RawTurtle.screens = [_s_]
234244
return canvas
235245

236-
def makeBindings(self, widget):
237-
widget.bind('<Configure>', self.onResize)
238-
239-
shortcut = 'Command' if darwin else 'Control'
240-
widget.bind_all('<%s-minus>' % shortcut, self.decrease_size)
241-
widget.bind_all('<%s-underscore>' % shortcut, self.decrease_size)
242-
widget.bind_all('<%s-equal>' % shortcut, self.increase_size)
243-
widget.bind_all('<%s-plus>' % shortcut, self.increase_size)
244-
widget.bind_all('<Control-MouseWheel>', self.update_mousewheel)
245-
widget.bind('<Control-Button-4>', self.increase_size)
246-
widget.bind('<Control-Button-5>', self.decrease_size)
247-
248246
def set_txtsize(self, size):
249247
txtfont[1] = size
250248
self.text['font'] = tuple(txtfont)
251249
self.output_lbl['text'] = 'Font size %d' % size
252250

253251
def decrease_size(self, dummy=None):
254252
self.set_txtsize(max(txtfont[1] - 1, MINIMUM_FONT_SIZE))
253+
return 'break'
255254

256255
def increase_size(self, dummy=None):
257256
self.set_txtsize(min(txtfont[1] + 1, MAXIMUM_FONT_SIZE))
257+
return 'break'
258258

259259
def update_mousewheel(self, event):
260260
# For wheel up, event.delte = 120 on Windows, -1 on darwin.
261261
# X-11 sends Control-Button-4 event instead.
262-
(self.decrease_size() if (event.delta < 0 and not darwin)
263-
else self.increase_size())
262+
if (event.delta < 0) == (not darwin):
263+
return self.decrease_size()
264+
else:
265+
return self.increase_size()
264266

265267
def configGUI(self, start, stop, clear, txt="", color="blue"):
266268
self.start_btn.config(state=start,

0 commit comments

Comments
 (0)