mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-31500: IDLE: Scale default fonts on HiDPI displays. (#3639)
This commit is contained in:
		
							parent
							
								
									3d1e2ab584
								
							
						
					
					
						commit
						a96c96f5da
					
				
					 4 changed files with 20 additions and 0 deletions
				
			
		|  | @ -113,8 +113,10 @@ def canonize(self, filename): | ||||||
| 
 | 
 | ||||||
| def _test(): | def _test(): | ||||||
|     from idlelib.editor import fixwordbreaks |     from idlelib.editor import fixwordbreaks | ||||||
|  |     from idlelib.run import fix_scaling | ||||||
|     import sys |     import sys | ||||||
|     root = Tk() |     root = Tk() | ||||||
|  |     fix_scaling(root) | ||||||
|     fixwordbreaks(root) |     fixwordbreaks(root) | ||||||
|     root.withdraw() |     root.withdraw() | ||||||
|     flist = FileList(root) |     flist = FileList(root) | ||||||
|  |  | ||||||
|  | @ -12,6 +12,8 @@ | ||||||
| if TkVersion < 8.5: | if TkVersion < 8.5: | ||||||
|     root = Tk()  # otherwise create root in main |     root = Tk()  # otherwise create root in main | ||||||
|     root.withdraw() |     root.withdraw() | ||||||
|  |     from idlelib.run import fix_scaling | ||||||
|  |     fix_scaling(root) | ||||||
|     tkMessageBox.showerror("Idle Cannot Start", |     tkMessageBox.showerror("Idle Cannot Start", | ||||||
|             "Idle requires tcl/tk 8.5+, not %s." % TkVersion, |             "Idle requires tcl/tk 8.5+, not %s." % TkVersion, | ||||||
|             parent=root) |             parent=root) | ||||||
|  | @ -1457,6 +1459,8 @@ def main(): | ||||||
|         NoDefaultRoot() |         NoDefaultRoot() | ||||||
|     root = Tk(className="Idle") |     root = Tk(className="Idle") | ||||||
|     root.withdraw() |     root.withdraw() | ||||||
|  |     from idlelib.run import fix_scaling | ||||||
|  |     fix_scaling(root) | ||||||
| 
 | 
 | ||||||
|     # set application icon |     # set application icon | ||||||
|     icondir = os.path.join(os.path.dirname(__file__), 'Icons') |     icondir = os.path.join(os.path.dirname(__file__), 'Icons') | ||||||
|  |  | ||||||
|  | @ -184,6 +184,7 @@ def show_socket_error(err, address): | ||||||
|     import tkinter |     import tkinter | ||||||
|     from tkinter.messagebox import showerror |     from tkinter.messagebox import showerror | ||||||
|     root = tkinter.Tk() |     root = tkinter.Tk() | ||||||
|  |     fix_scaling(root) | ||||||
|     root.withdraw() |     root.withdraw() | ||||||
|     msg = f"IDLE's subprocess can't connect to {address[0]}:{address[1]}.\n"\ |     msg = f"IDLE's subprocess can't connect to {address[0]}:{address[1]}.\n"\ | ||||||
|           f"Fatal OSError #{err.errno}: {err.strerror}.\n"\ |           f"Fatal OSError #{err.errno}: {err.strerror}.\n"\ | ||||||
|  | @ -277,6 +278,18 @@ def exit(): | ||||||
|     sys.exit(0) |     sys.exit(0) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def fix_scaling(root): | ||||||
|  |     """Scale fonts on HiDPI displays.""" | ||||||
|  |     import tkinter.font | ||||||
|  |     scaling = float(root.tk.call('tk', 'scaling')) | ||||||
|  |     if scaling > 1.4: | ||||||
|  |         for name in tkinter.font.names(root): | ||||||
|  |             font = tkinter.font.Font(root=root, name=name, exists=True) | ||||||
|  |             size = int(font['size']) | ||||||
|  |             if size < 0: | ||||||
|  |                 font['size'] = round(-0.75*size) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class MyRPCServer(rpc.RPCServer): | class MyRPCServer(rpc.RPCServer): | ||||||
| 
 | 
 | ||||||
|     def handle_error(self, request, client_address): |     def handle_error(self, request, client_address): | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | Default fonts now are scaled on HiDPI displays. | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka