Skip to content

Commit 26ef07f

Browse files
committed
Fix DPI display
1 parent cc6e55a commit 26ef07f

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

addon/globalPlugins/objectTree.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# objectViewer add-on for NVDA
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING.txt for more details.
4-
# Copyright (C) 2024 hwf1324 <1398969445@qq.com>
4+
# Copyright (C) 2024-2025 hwf1324 <1398969445@qq.com>
55

66
import api
77
import config
@@ -39,19 +39,15 @@ def extractSmallHICON(pszPath: str) -> shellapi.HICON:
3939

4040
psfi = SHFILEINFO()
4141
uFlags = SHGFI_ICON | SHGFI_SMALLICON
42-
shellapi.shell32.SHGetFileInfoW(
43-
pszPath,
44-
0,
45-
shellapi.byref(psfi),
46-
shellapi.sizeof(psfi),
47-
uFlags
48-
)
42+
shellapi.shell32.SHGetFileInfoW(pszPath, 0, shellapi.byref(psfi), shellapi.sizeof(psfi), uFlags)
4943

5044
return psfi.hIcon
5145

5246

5347
def cleanupHICON(hicon: shellapi.HICON) -> None:
5448
shellapi.windll.user32.DestroyIcon(hicon)
49+
50+
5551
# -----------------------------------------------------------------------------
5652

5753

@@ -67,16 +63,17 @@ def createIconFromPath(path: str) -> wx.Icon:
6763

6864
class NVDAObjectTree(wx.TreeCtrl):
6965
def __init__(
70-
self,
71-
parent,
72-
simpleReviewMode: bool = config.conf["reviewCursor"]["simpleReviewMode"],
73-
*args,
74-
**kw,
66+
self,
67+
parent,
68+
simpleReviewMode: bool = config.conf["reviewCursor"]["simpleReviewMode"],
69+
*args,
70+
**kw,
7571
):
7672
super().__init__(parent, *args, **kw)
7773
self.simpleReviewMode = simpleReviewMode
7874
rootNVDAObject: NVDAObject = api.getDesktopObject()
79-
il = wx.ImageList(16, 16)
75+
imageDPISize: int = int(16 * self.GetDPIScaleFactor())
76+
il = wx.ImageList(imageDPISize, imageDPISize)
8077
self.AssignImageList(il)
8178
self.il = il
8279
root: wx.TreeItemId = self.AddRoot(self.getObjectDisplayText(rootNVDAObject), data=rootNVDAObject)

addon/globalPlugins/viewerFrame.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# objectViewer add-on for NVDA
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING.txt for more details.
4-
# Copyright (C) 2024 hwf1324 <1398969445@qq.com>
4+
# Copyright (C) 2024-2025 hwf1324 <1398969445@qq.com>
55

66
import sys
77

@@ -15,18 +15,13 @@
1515
from .objectTree import NVDAObjectTree
1616

1717

18-
class ObjectViewerFrame(wx.Frame):
19-
def __init__(
20-
self,
21-
parent,
22-
namespace
23-
):
18+
class ObjectViewerFrame(DpiScalingHelperMixinWithoutInit, wx.Frame):
19+
def __init__(self, parent, namespace):
2420
super().__init__(
2521
parent,
2622
wx.ID_ANY,
2723
# Translators: The title of the Object Viewer frame.
2824
_("Object Viewer"),
29-
size=(850, 700),
3025
style=wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP,
3126
)
3227

@@ -64,27 +59,31 @@ def __init__(
6459
splitterSizer.Add(self.treeContentsSizer, proportion=1, flag=wx.EXPAND)
6560
splitterSizer.Add(self.propertieContentsSizer.sizer, proportion=1, flag=wx.EXPAND)
6661
self.panelContentsSizer.Add(splitterSizer, proportion=1, flag=wx.EXPAND)
67-
self.panelContentsSizer.Add(self.crust, flag=wx.EXPAND)
62+
self.panelContentsSizer.Add(self.crust, proportion=1, flag=wx.EXPAND)
6863

6964
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.onSelectionChanged, self.objectTree)
7065

7166
self.makeMenuBar()
7267

73-
self.CenterOnScreen()
68+
# setting the size must be done after the parent is constructed.
69+
self.SetMinSize(self.scaleSize(self.MIN_SIZE))
70+
self.SetSize(self.scaleSize(self.INITIAL_SIZE))
71+
# the size has changed, so recenter on the screen
72+
self.CentreOnScreen()
73+
74+
INITIAL_SIZE = (800, 480)
75+
MIN_SIZE = (470, 240)
7476

7577
def createCrust(self, namespace):
7678
import buildVersion
79+
7780
introText = _(
7881
f"Python {sys.version.split()[0]} on {sys.platform}, NVDA {buildVersion.version}\n"
7982
"NOTE: The 'obj' variable refers to the NVDA object selected in the tree."
8083
)
8184

8285
crust = wx.py.crust.Crust(
83-
self.panel,
84-
size=(-1, 200),
85-
locals=namespace,
86-
intro=introText,
87-
showInterpIntro=False
86+
self.panel, size=(-1, 200), locals=namespace, intro=introText, showInterpIntro=False
8887
)
8988
crust.shell.SetBufferedDraw(False)
9089
crust.filling.text.SetBufferedDraw(False)
@@ -96,13 +95,11 @@ def makeMenuBar(self):
9695
treeMenu: wx.Menu = wx.Menu()
9796
menu_addTreeNotesMode: wx.Menu = wx.Menu()
9897
self.addTreeNotesChildrenMode: wx.MenuItem = menu_addTreeNotesMode.AppendRadioItem(
99-
wx.ID_ANY,
100-
_("children")
98+
wx.ID_ANY, _("children")
10199
)
102100
self.addTreeNotesChildrenMode.Check(config.conf["objectViewer"]["addTreeNotesMode"] == "children")
103101
self.addTreeNotesIteratorMode: wx.MenuItem = menu_addTreeNotesMode.AppendRadioItem(
104-
wx.ID_ANY,
105-
_("iterator")
102+
wx.ID_ANY, _("iterator")
106103
)
107104
self.addTreeNotesIteratorMode.Check(config.conf["objectViewer"]["addTreeNotesMode"] == "iterator")
108105
self.Bind(wx.EVT_MENU, self.onToggleAddTreeNotesMode, self.addTreeNotesChildrenMode)

0 commit comments

Comments
 (0)