mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-30 23:47:27 +03:00 
			
		
		
		
	Cast handle to int
This commit is contained in:
		
							parent
							
								
									a60736381e
								
							
						
					
					
						commit
						8a086edbe9
					
				|  | @ -60,6 +60,18 @@ class TestImageWinDib: | ||||||
|         with pytest.raises(ValueError): |         with pytest.raises(ValueError): | ||||||
|             ImageWin.Dib(mode) |             ImageWin.Dib(mode) | ||||||
| 
 | 
 | ||||||
|  |     def test_dib_hwnd(self) -> None: | ||||||
|  |         mode = "RGBA" | ||||||
|  |         size = (128, 128) | ||||||
|  |         wnd = 0 | ||||||
|  | 
 | ||||||
|  |         dib = ImageWin.Dib(mode, size) | ||||||
|  |         hwnd = ImageWin.HWND(wnd) | ||||||
|  | 
 | ||||||
|  |         dib.expose(hwnd) | ||||||
|  |         dib.draw(hwnd, (0, 0) + size) | ||||||
|  |         assert isinstance(dib.query_palette(hwnd), int) | ||||||
|  | 
 | ||||||
|     def test_dib_paste(self) -> None: |     def test_dib_paste(self) -> None: | ||||||
|         # Arrange |         # Arrange | ||||||
|         im = hopper() |         im = hopper() | ||||||
|  |  | ||||||
|  | @ -98,14 +98,15 @@ class Dib: | ||||||
|                        HDC or HWND instance.  In PythonWin, you can use |                        HDC or HWND instance.  In PythonWin, you can use | ||||||
|                        ``CDC.GetHandleAttrib()`` to get a suitable handle. |                        ``CDC.GetHandleAttrib()`` to get a suitable handle. | ||||||
|         """ |         """ | ||||||
|  |         handle_int = int(handle) | ||||||
|         if isinstance(handle, HWND): |         if isinstance(handle, HWND): | ||||||
|             dc = self.image.getdc(handle) |             dc = self.image.getdc(handle_int) | ||||||
|             try: |             try: | ||||||
|                 self.image.expose(dc) |                 self.image.expose(dc) | ||||||
|             finally: |             finally: | ||||||
|                 self.image.releasedc(handle, dc) |                 self.image.releasedc(handle_int, dc) | ||||||
|         else: |         else: | ||||||
|             self.image.expose(handle) |             self.image.expose(handle_int) | ||||||
| 
 | 
 | ||||||
|     def draw( |     def draw( | ||||||
|         self, |         self, | ||||||
|  | @ -124,14 +125,15 @@ class Dib: | ||||||
|         """ |         """ | ||||||
|         if src is None: |         if src is None: | ||||||
|             src = (0, 0) + self.size |             src = (0, 0) + self.size | ||||||
|  |         handle_int = int(handle) | ||||||
|         if isinstance(handle, HWND): |         if isinstance(handle, HWND): | ||||||
|             dc = self.image.getdc(handle) |             dc = self.image.getdc(handle_int) | ||||||
|             try: |             try: | ||||||
|                 self.image.draw(dc, dst, src) |                 self.image.draw(dc, dst, src) | ||||||
|             finally: |             finally: | ||||||
|                 self.image.releasedc(handle, dc) |                 self.image.releasedc(handle_int, dc) | ||||||
|         else: |         else: | ||||||
|             self.image.draw(handle, dst, src) |             self.image.draw(handle_int, dst, src) | ||||||
| 
 | 
 | ||||||
|     def query_palette(self, handle: int | HDC | HWND) -> int: |     def query_palette(self, handle: int | HDC | HWND) -> int: | ||||||
|         """ |         """ | ||||||
|  | @ -148,14 +150,15 @@ class Dib: | ||||||
|         :return: The number of entries that were changed (if one or more entries, |         :return: The number of entries that were changed (if one or more entries, | ||||||
|                  this indicates that the image should be redrawn). |                  this indicates that the image should be redrawn). | ||||||
|         """ |         """ | ||||||
|  |         handle_int = int(handle) | ||||||
|         if isinstance(handle, HWND): |         if isinstance(handle, HWND): | ||||||
|             handle = self.image.getdc(handle) |             handle = self.image.getdc(handle_int) | ||||||
|             try: |             try: | ||||||
|                 result = self.image.query_palette(handle) |                 result = self.image.query_palette(handle) | ||||||
|             finally: |             finally: | ||||||
|                 self.image.releasedc(handle, handle) |                 self.image.releasedc(handle, handle) | ||||||
|         else: |         else: | ||||||
|             result = self.image.query_palette(handle) |             result = self.image.query_palette(handle_int) | ||||||
|         return result |         return result | ||||||
| 
 | 
 | ||||||
|     def paste( |     def paste( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user