Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Code for Analabs
RST Evaluation
Commits
a17373d6
Commit
a17373d6
authored
Nov 18, 2021
by
Michael Rudolf
Browse files
Removed DPI Awareness
parent
dc35bd03
Changes
1
Hide whitespace changes
Inline
Side-by-side
rstevaluation/rstevaluation/mainGUI.py
View file @
a17373d6
...
...
@@ -162,65 +162,6 @@ class RST_pick_GUI(tk.Tk):
self
.
button_start
.
grid
(
column
=
0
,
row
=
7
,
columnspan
=
3
,
sticky
=
'w'
)
self
.
button_start
.
bind
(
'<ButtonRelease-1>'
,
self
.
start_processing
)
self
.
make_dpi_aware
()
def
get_HWND_dpi
(
self
):
"""Detects high dpi displays and rescales gui in Windows
Adapted from the user 'dingles at stack-overflow"""
if
os
.
name
==
"nt"
:
from
ctypes
import
pointer
,
windll
,
wintypes
try
:
windll
.
shcore
.
SetProcessDpiAwareness
(
1
)
except
Exception
:
print
(
'High-DPI scaling failed'
)
pass
# this will fail on Win Server and maybe early Windows
DPI100pc
=
96
# DPI 96 is 100% scaling
DPI_type
=
0
# MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2
winH
=
wintypes
.
HWND
(
self
.
winfo_id
())
monitorhandle
=
windll
.
user32
.
MonitorFromWindow
(
winH
,
wintypes
.
DWORD
(
2
))
# MONITOR_DEFAULTTONEAREST = 2
X
=
wintypes
.
UINT
()
Y
=
wintypes
.
UINT
()
try
:
windll
.
shcore
.
GetDpiForMonitor
(
monitorhandle
,
DPI_type
,
pointer
(
X
),
pointer
(
Y
))
return
X
.
value
,
Y
.
value
,
(
X
.
value
+
Y
.
value
)
/
(
2
*
DPI100pc
)
except
Exception
:
print
(
'Assuming standard dpi scaling.'
)
return
96
,
96
,
1
# Assume standard Windows DPI & scaling
else
:
return
None
,
None
,
1
# What to do for other OSs?
def
make_dpi_aware
(
self
):
"""Adapted from the user 'dingles at stack-overflow"""
def
TkGeometryScale
(
s
,
cvtfunc
):
# format "WxH+X+Y"
patt
=
r
"(?P<W>\d+)x(?P<H>\d+)\+(?P<X>\d+)\+(?P<Y>\d+)"
R
=
re
.
compile
(
patt
).
search
(
s
)
G
=
str
(
cvtfunc
(
R
.
group
(
"W"
)))
+
"x"
G
+=
str
(
cvtfunc
(
R
.
group
(
"H"
)))
+
"+"
G
+=
str
(
cvtfunc
(
R
.
group
(
"X"
)))
+
"+"
G
+=
str
(
cvtfunc
(
R
.
group
(
"Y"
)))
return
G
self
.
DPI_X
,
self
.
DPI_Y
,
self
.
DPI_scaling
=
self
.
get_HWND_dpi
()
self
.
TkScale
=
lambda
v
:
int
(
float
(
v
)
*
self
.
DPI_scaling
)
self
.
TkGeometryScale
=
lambda
s
:
TkGeometryScale
(
s
,
self
.
TkScale
)
def
resize_all_elements
(
self
):
"""
Resizes all elements according to the DPI scaling of the window
(WIP)
-----
"""
pass
def
plot_window
(
self
,
event
):
"""Shows a plot window"""
plot_win
=
tk
.
Toplevel
(
self
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment