Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
bc7ac485
Commit
bc7ac485
authored
May 27, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding platform awareness to wxPython gui code
parent
55ea4e30
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
10 deletions
+38
-10
start_cef.py
start_cef.py
+38
-10
No files found.
start_cef.py
View file @
bc7ac485
#!/usr/bin/env python2
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
# Embedding CEF browser in a wxPython window to launch Ardublockly.
# Embedding CEF browser in a wxPython window to launch Ardublockly.
...
@@ -45,6 +45,7 @@ __file__ = sys.argv[0]
...
@@ -45,6 +45,7 @@ __file__ = sys.argv[0]
g_applicationSettings
=
None
g_applicationSettings
=
None
g_browserSettings
=
None
g_browserSettings
=
None
g_ardutag
=
"[ardublockly] "
g_ardutag
=
"[ardublockly] "
g_platform_os
=
None
# Which method to use for message loop processing.
# Which method to use for message loop processing.
# EVT_IDLE - wx application has priority
# EVT_IDLE - wx application has priority
...
@@ -123,9 +124,15 @@ class MainFrame(wx.Frame):
...
@@ -123,9 +124,15 @@ class MainFrame(wx.Frame):
def
GetHandleForBrowser
(
self
):
def
GetHandleForBrowser
(
self
):
if
self
.
mainPanel
:
if
self
.
mainPanel
:
return
self
.
mainPanel
.
GetHandle
()
if
g_platform_os
==
"linux"
:
return
self
.
mainPanel
.
GetGtkWidget
()
else
:
return
self
.
mainPanel
.
GetHandle
()
else
:
else
:
return
self
.
GetHandle
()
if
g_platform_os
==
"linux"
:
return
self
.
GetGtkWidget
()
else
:
return
self
.
GetHandle
()
def
__init__
(
self
,
url
=
None
,
popup
=
False
):
def
__init__
(
self
,
url
=
None
,
popup
=
False
):
if
popup
:
if
popup
:
...
@@ -136,8 +143,9 @@ class MainFrame(wx.Frame):
...
@@ -136,8 +143,9 @@ class MainFrame(wx.Frame):
size
=
(
1250
,
768
)
size
=
(
1250
,
768
)
# This is an optional code to enable High DPI support.
# This is an optional code to enable High DPI support.
if
"auto_zooming"
in
g_applicationSettings
\
if
(
g_platform_os
==
"win"
)
\
and
g_applicationSettings
[
"auto_zooming"
]
==
"system_dpi"
:
and
(
"auto_zooming"
in
g_applicationSettings
)
\
and
(
g_applicationSettings
[
"auto_zooming"
]
==
"system_dpi"
):
# This utility function will adjust width/height using
# This utility function will adjust width/height using
# OS DPI settings. For 800/600 with Win7 DPI settings
# OS DPI settings. For 800/600 with Win7 DPI settings
# being set to "Larger 150%" will return 1200/900.
# being set to "Larger 150%" will return 1200/900.
...
@@ -254,10 +262,12 @@ class MainFrame(wx.Frame):
...
@@ -254,10 +262,12 @@ class MainFrame(wx.Frame):
self
.
menubar
.
SetBarHeight
()
self
.
menubar
.
SetBarHeight
()
def
OnSetFocus
(
self
,
event
):
def
OnSetFocus
(
self
,
event
):
cefpython
.
WindowUtils
.
OnSetFocus
(
self
.
GetHandleForBrowser
(),
0
,
0
,
0
)
if
g_platform_os
!=
"linux"
:
cefpython
.
WindowUtils
.
OnSetFocus
(
self
.
GetHandleForBrowser
(),
0
,
0
,
0
)
def
OnSize
(
self
,
event
):
def
OnSize
(
self
,
event
):
cefpython
.
WindowUtils
.
OnSize
(
self
.
GetHandleForBrowser
(),
0
,
0
,
0
)
if
g_platform_os
!=
"linux"
:
cefpython
.
WindowUtils
.
OnSize
(
self
.
GetHandleForBrowser
(),
0
,
0
,
0
)
def
OnClose
(
self
,
event
):
def
OnClose
(
self
,
event
):
# Remove all CEF browser references so that browser is closed
# Remove all CEF browser references so that browser is closed
...
@@ -801,8 +811,9 @@ def cef_init():
...
@@ -801,8 +811,9 @@ def cef_init():
# Larger 150% = 144 DPI = 2.0 zoom level
# Larger 150% = 144 DPI = 2.0 zoom level
# Custom 75% = 72 DPI = -1.0 zoom level
# Custom 75% = 72 DPI = -1.0 zoom level
#g_applicationSettings["auto_zooming"] = "system_dpi"
#g_applicationSettings["auto_zooming"] = "system_dpi"
print
(
g_ardutag
+
"Calling SetProcessDpiAware"
)
if
g_platform_os
==
"win"
:
cefpython
.
DpiAware
.
SetProcessDpiAware
()
print
(
g_ardutag
+
"Calling SetProcessDpiAware"
)
cefpython
.
DpiAware
.
SetProcessDpiAware
()
# Command line switches set programmatically
# Command line switches set programmatically
# https://code.google.com/p/cefpython/wiki/CommandLineSwitches
# https://code.google.com/p/cefpython/wiki/CommandLineSwitches
...
@@ -833,12 +844,29 @@ def launch_server(server_root):
...
@@ -833,12 +844,29 @@ def launch_server(server_root):
else
:
else
:
root_location
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
sys
.
argv
[
0
]))
root_location
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
sys
.
argv
[
0
]))
thread
=
threading
.
Thread
(
thread
=
threading
.
Thread
(
target
=
start_server
,
kwargs
=
{
"document_root"
:
root_location
})
target
=
start_server
,
kwargs
=
{
"document_root"
:
root_location
})
print
(
"
\n
======= Starting Server ======="
)
print
(
"
\n
======= Starting Server ======="
)
thread
.
start
()
thread
.
start
()
def
detect_os
():
"""
Detects the Operating System and sets a global variable to target OS
specific features to the right platform.
Options for g_platform_os are: win, lin, mac
"""
global
g_platform_os
if
os
.
name
==
"nt"
:
g_platform_os
=
"win"
elif
os
.
name
==
"posix"
:
g_platform_os
=
"linux"
elif
os
.
name
==
"mac"
:
g_platform_os
=
"mac"
def
main
(
argv
):
def
main
(
argv
):
detect_os
()
print
(
g_ardutag
+
"OS: %s"
%
g_platform_os
)
print
(
g_ardutag
+
"Python version: %s"
%
platform
.
python_version
())
print
(
g_ardutag
+
"Python version: %s"
%
platform
.
python_version
())
print
(
g_ardutag
+
"wx.version: %s"
%
wx
.
version
())
print
(
g_ardutag
+
"wx.version: %s"
%
wx
.
version
())
print
(
g_ardutag
+
"cefpython GetModuleDirectory: %s"
%
cefpython
.
GetModuleDirectory
())
print
(
g_ardutag
+
"cefpython GetModuleDirectory: %s"
%
cefpython
.
GetModuleDirectory
())
...
...
Write
Preview
Markdown
is supported
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