Skip to content

Commit dcefcd2

Browse files
authored
[Bug] Resolution scale. #12 (#13)
* [minor] resolve scaling bug for windows * [feature] remove and add minimize maximize buttons * [minor] change name of maximize and minimize options * [minor] change name of caption mode
1 parent 4e1a829 commit dcefcd2

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

pypulse/Window/app.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ def __init__(self, *args, **kwargs):
1414
def OnInit(self):
1515
frame = BrowserFrame(url=f"localhost:{Vars.INTERNAL_HTTP_SERVER_PORT}",
1616
title=self.kwargs['title'],
17-
icon=self.kwargs['icon_path'],
18-
size=(self.kwargs.get('window_size_x'),
19-
self.kwargs.get('window_size_y')),
17+
icon=self.kwargs.get('icon_path'),
18+
size=(self.kwargs['window_size_x'],
19+
self.kwargs['window_size_y']),
2020
debug=self.kwargs.get('debug'),
2121
log_file=self.kwargs.get('debug_file_name'),
22-
border_less=self.kwargs.get('border_less'))
22+
border_less=self.kwargs.get('border_less'),
23+
caption = self.kwargs.get('titlebar_caption'),
24+
maximize = self.kwargs.get('titlebar_no_button_maximize'),
25+
minimize = self.kwargs.get('titlebar_no_button_minimize'))
2326

2427
log(LogTypes.SUCCESS, 'CEF initialized')
2528
print()

pypulse/Window/cef.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from enum import Enum
44
from platform import system
55

6+
if system() == "Windows":
7+
import ctypes
8+
69
from cefpython3 import cefpython
710

811

@@ -46,13 +49,15 @@ def __browser(self):
4649
self.event(Event.BROWSER_BEFORE)
4750
self.instance = cefpython.CreateBrowserSync(*self.args,
4851
**self.kwargs)
52+
4953
self.event(Event.BROWSER_AFTER)
5054

5155
def __initialize(self):
5256
self.event(Event.INITIALIZING)
5357
cefpython.Initialize(self.config)
5458

5559
if self.os == 'Windows':
60+
ctypes.windll.shcore.SetProcessDpiAwareness(0)
5661
cefpython.DpiAware.EnableHighDpiSupport()
5762

5863
def open(self):
@@ -106,7 +111,7 @@ class Handler:
106111
def OnGotFocus(self, browser):
107112
if system() == 'Linux':
108113
browser.SetFocus(True)
109-
114+
110115
def event(self, type: Event) -> None:
111116
"""
112117
Event handler for CEF.

pypulse/Window/frames.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ def __init__(self,
4545
icon: str = None,
4646
debug: bool = False,
4747
log_file: bool = None,
48-
border_less: bool = True) -> None:
48+
border_less: bool = True,
49+
maximize: bool = None,
50+
minimize: bool = None,
51+
caption = None) -> None:
52+
4953
self.title = title
5054
self.icon = icon
5155
self.url = url
@@ -58,29 +62,39 @@ def __init__(self,
5862
if log_file:
5963
self.browser.config['log_file'] = log_file
6064

61-
self.width, self.height = scale_window_size_for_high_dpi(self.browser.os,
62-
self.width,
63-
self.height)
65+
self.adapt_width, self.adapt_height = scale_window_size_for_high_dpi(self.browser.os,
66+
self.width,
67+
self.height)
6468

6569
wx.Frame.__init__(
6670
self,
6771
parent=None,
6872
id=wx.ID_ANY,
6973

7074
title=title,
71-
size=(self.width, self.height),
7275
)
76+
width, height = self.FromDIP(wx.Size(self.width, self.height))
77+
self.SetClientSize(width, height)
78+
79+
style = wx.DEFAULT_FRAME_STYLE
80+
if maximize:
81+
style = style & (~wx.MAXIMIZE_BOX)
82+
83+
if minimize:
84+
style = style & (~wx.MINIMIZE_BOX)
85+
86+
self.SetWindowStyle(style)
87+
88+
if caption:
89+
self.SetWindowStyle(wx.CAPTION)
7390

7491
if border_less:
7592
self.SetWindowStyle(wx.NO_BORDER)
7693

7794
if self.browser.os == 'Linux':
7895
cefpython.WindowUtils.InstallX11ErrorHandlers()
7996

80-
self.panel = wx.Panel(self, size=(
81-
self.width, self.height), pos=(0, 32))
82-
83-
width, height = self.panel.GetClientSize().Get()
97+
self.panel = wx.Panel(self)
8498
self.browser.window.SetAsChild(self.panel.GetHandle(),
8599
[0, 0, width, height])
86100

@@ -95,10 +109,8 @@ def __init__(self,
95109

96110
log(LogTypes.SUCCESS, 'Window added')
97111

98-
99-
100112
self.browser.open()
101-
os.system('clear' if self.browser.os != 'Windows' else 'cls')
113+
# os.system('clear' if self.browser.os != 'Windows' else 'cls')
102114

103115
log(LogTypes.INFO, 'Browser open')
104116

pypulse/Window/logger.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class Colors:
88
RESET = '\033[0m'
99

10+
BOLD = '\033[1m'
11+
1012
BRIGHT_CYAN = '\033[96m'
1113
BRIGHT_BLUE = '\033[94m'
1214
BRIGHT_GREEN = '\033[92m'
@@ -19,6 +21,7 @@ class LogTypes(Enum):
1921
LOADING = 'LOADING'
2022
SUCCESS = 'SUCCESS'
2123
WARNING = 'WARNING'
24+
DEBUG = 'DEBUG'
2225

2326

2427
def log(type: LogTypes, message: str, **settings):
@@ -35,6 +38,9 @@ def log(type: LogTypes, message: str, **settings):
3538

3639
elif type is LogTypes.WARNING:
3740
prefix += f' {Colors.BRIGHT_RED}WARNING '
41+
42+
elif type is LogTypes.DEBUG:
43+
prefix += f' {Colors.BOLD}DEBUG '
3844

3945
message_color = Colors.RESET
4046

0 commit comments

Comments
 (0)