diff -r 6eab274d3e34 Lib/idlelib/ZoomInOut.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/ZoomInOut.py Mon May 13 16:32:15 2013 +0200 @@ -0,0 +1,76 @@ +# ZoomInOut extension +# Press to zoom in and to zoom out + + +def cursor(func): + """Decorator function for handling yview""" + def f(self, event): + if self._zero_pause: + self.pause_at_default() + return "break" + line, top, bot = self.store_cursor(event) + func(self) + self.restore_cursor(line, top, bot) + return f + + +class ZoomInOut: + + menudefs = [ + ('windows', [ + ('Zoom In', '<>'), + ('Zoom Out', '<>') + ]) + ] + + def __init__(self, editwin): + self.editwin = editwin + self.text = editwin.text + self._zero_pause = False + + @cursor + def zoom_in_event(self): + self._zoom(offset=1) + + @cursor + def zoom_out_event(self): + self._zoom(offset=-1) + + def _zoom(self, offset): + fontname, fontsize, fontwidth = self.get_font() + new_fontsize = int(fontsize) + offset + if 7 < new_fontsize < 22: + self.text.configure(font=(fontname, new_fontsize, fontwidth)) + + def get_font(self): + font = self.text.configure('font')[-1] + if isinstance(font, str): + font = self.text.tk.split(font) + return font + + def store_cursor(self, event): + x, y = event.x, event.y + coords = self.text.index('@%d,%d' % (x,y)) + line = int(coords.split('.')[0]) + top, bot = self.editwin.getwindowlines() + return line, top, bot + + def restore_cursor(self, line, top, bot): + new_top, new_bot = self.editwin.getwindowlines() + new_h = max(new_bot-new_top-1, 1) + + h = max(bot - top, 1) + ratio = (line - top) / (1.0 * h) + top2 = int(line - new_h * ratio) + self.text.yview('%i.%i' % (max(top2, 0), 0)) + + def control_release(self, event=None): + self._zero_pause = False + + def pause_at_default(self, event=None): + self._zero_pause = True + if self._pause_id: + self.text.after_cancel(self._pause_id) + def unpause(): + self._zero_pause = False + self._pause_id = self.text.after(250, unpause) diff -r 6eab274d3e34 Lib/idlelib/config-extensions.def --- a/Lib/idlelib/config-extensions.def Sun May 12 23:08:28 2013 -0500 +++ b/Lib/idlelib/config-extensions.def Mon May 13 16:32:15 2013 +0200 @@ -44,6 +44,12 @@ [ZoomHeight_cfgBindings] zoom-height= +[ZoomInOut] +enable=1 +[ZoomInOut_cfgBindings] +zoom-in= +zoom-out= + [ScriptBinding] enable=1 enable_shell=0