gh-77578: IDLE Help - let users control font size by csabella · Pull Request #6665 · python/cpython (original) (raw)
We started with this code, extracted from turtledemo.main.
# Menu bindings (which we might use for context menu)
menu.add_command(label="Decrease (C-'-')", command=self.decrease_size,
font=menufont)
menu.add_command(label="Increase (C-'+')", command=self.increase_size,
font=menufont)
# Key/mouse bindings
text.bind_all('<%s-minus>' % shortcut, self.decrease_size)
text.bind_all('<%s-underscore>' % shortcut, self.decrease_size)
text.bind_all('<%s-equal>' % shortcut, self.increase_size)
text.bind_all('<%s-plus>' % shortcut, self.increase_size)
text.bind('<Control-MouseWheel>', self.update_mousewheel)
text.bind('<Control-Button-4>', self.increase_size)
text.bind('<Control-Button-5>', self.decrease_size)
# Event/action functions
darwin = sys.platform == 'darwin'
def set_txtsize(self, size):
txtfont[1] = size
self.text['font'] = tuple(txtfont)
self.output_lbl['text'] = 'Font size %d' % size
def decrease_size(self, dummy=None):
self.set_txtsize(max(txtfont[1] - 1, MINIMUM_FONT_SIZE))
return 'break'
def increase_size(self, dummy=None):
self.set_txtsize(min(txtfont[1] + 1, MAXIMUM_FONT_SIZE))
return 'break'
def update_mousewheel(self, event):
# For wheel up, event.delta = 120 on Windows, -1 on darwin.
# X-11 sends Control-Button-4 event instead.
if (event.delta < 0) == (not darwin):
return self.decrease_size()
else:
return self.increase_size()
As far as I know, menu, keyboard, and mouse methods work on all three major systems. There are no pseudoevents. To the extent possible, the meaning of actions is determined by their bindings.
Note: the code above is extracted from 4 different locations. This is the first time I have looked at it altogether.
At my request, Cheryl combined and consolidated the functions into one zoom handler. At Tal's request, she partly undid what I had requested. Zoom() has been separated into multiple functions again. However, I prefer the original code to the result. If we don't agree on reverting to the original design, lets discuss.