Skip to content

Commit

Permalink
Use ctypes instead of pywin32 to get screen DPI
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyroberts committed Oct 20, 2020
1 parent 1a5f8a0 commit 5ec8a69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions pyxll_jupyter/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
from .browser import Browser
from .qtimports import QWidget, QVBoxLayout
import subprocess

try:
import win32gui, win32ui
_have_win32ui = True
except ImportError:
_have_win32ui = False
import ctypes


class JupyterQtWidget(QWidget):
Expand All @@ -23,16 +18,16 @@ def __init__(self, parent=None, scale=None, initial_path=None):
self.proc = None

# Get the scale from the window DPI
if scale is None and _have_win32ui:
if scale is None:
LOGPIXELSX = 88
hwnd = self.winId()
if isinstance(hwnd, str):
hwnd = int(hwnd, 16 if hwnd.startswith("0x") else 10)
screen = win32gui.GetDC(hwnd)
screen = ctypes.windll.user32.GetDC(hwnd)
try:
scale = win32ui.GetDeviceCaps(screen, LOGPIXELSX) / 96.0
scale = ctypes.windll.gdi32.GetDeviceCaps(screen, LOGPIXELSX) / 96.0
finally:
win32gui.ReleaseDC(hwnd, screen)
ctypes.windll.user32.ReleaseDC(hwnd, screen)

# Create the browser widget
self.browser = Browser(self, scale=scale)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name="pyxll_jupyter",
description="Adds Jupyter notebooks to Microsoft Excel using PyXLL.",
version="0.1.5",
version="0.1.6",
packages=find_packages(),
include_package_data=True,
package_data={
Expand Down

0 comments on commit 5ec8a69

Please sign in to comment.