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
3d5dffe5
Commit
3d5dffe5
authored
Jun 01, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CEF GUI: Fixed issue with running thread on exit.
parent
13fb6c14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
39 deletions
+40
-39
start_cef.py
start_cef.py
+40
-39
No files found.
start_cef.py
View file @
3d5dffe5
...
@@ -62,7 +62,7 @@ USE_EVT_IDLE = False # If False then Timer will be used
...
@@ -62,7 +62,7 @@ USE_EVT_IDLE = False # If False then Timer will be used
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
def
GetApplicationPath
(
file
=
None
):
def
GetApplicationPath
(
file
_
=
None
):
# On Windows after downloading file and calling Browser.GoForward(),
# On Windows after downloading file and calling Browser.GoForward(),
# current working directory is set to %UserProfile%.
# current working directory is set to %UserProfile%.
# Calling os.path.dirname(os.path.realpath(__file__))
# Calling os.path.dirname(os.path.realpath(__file__))
...
@@ -77,45 +77,45 @@ def GetApplicationPath(file=None):
...
@@ -77,45 +77,45 @@ def GetApplicationPath(file=None):
dir
=
os
.
getcwd
()
dir
=
os
.
getcwd
()
GetApplicationPath
.
dir
=
dir
GetApplicationPath
.
dir
=
dir
# If file is None return current directory without trailing slash.
# If file is None return current directory without trailing slash.
if
file
is
None
:
if
file
_
is
None
:
file
=
""
file
_
=
""
# Only when relative path.
# Only when relative path.
if
not
file
.
startswith
(
"/"
)
and
not
file
.
startswith
(
"
\\
"
)
and
(
if
not
file
_
.
startswith
(
"/"
)
and
not
file_
.
startswith
(
"
\\
"
)
and
(
not
re
.
search
(
r"^[\w-]+:"
,
file
)):
not
re
.
search
(
r"^[\w-]+:"
,
file
_
)):
path
=
GetApplicationPath
.
dir
+
os
.
sep
+
file
path
=
GetApplicationPath
.
dir
+
os
.
sep
+
file
_
if
g_platform_os
==
"windows"
:
if
g_platform_os
==
"windows"
:
path
=
re
.
sub
(
r"[/\\]+"
,
re
.
escape
(
os
.
sep
),
path
)
path
=
re
.
sub
(
r"[/\\]+"
,
re
.
escape
(
os
.
sep
),
path
)
path
=
re
.
sub
(
r"[/\\]+$"
,
""
,
path
)
path
=
re
.
sub
(
r"[/\\]+$"
,
""
,
path
)
return
path
return
path
return
str
(
file
)
return
str
(
file
_
)
def
ExceptHook
(
excType
,
excValue
,
traceObject
):
def
ExceptHook
(
excType
,
excValue
,
traceObject
):
# This hook does the following: in case of exception write it to
# This hook does the following: in case of exception write it to
# the "error.log" file, display it to the console, shutdown CEF
# the "error.log" file, display it to the console, shutdown CEF
# and exit application immediately by ignoring "finally" (os._exit()).
# and exit application immediately by ignoring "finally" (os._exit()).
error
Msg
=
"
\n
"
.
join
(
traceback
.
format_exception
(
excType
,
excValue
,
error
_msg
=
"
\n
"
.
join
(
traceback
.
format_exception
(
traceObject
))
excType
,
excValue
,
traceObject
))
error
F
ile
=
GetApplicationPath
(
"cef_error.log"
)
error
_f
ile
=
GetApplicationPath
(
"cef_error.log"
)
try
:
try
:
app
E
ncoding
=
cefpython
.
g_applicationSettings
[
"string_encoding"
]
app
_e
ncoding
=
cefpython
.
g_applicationSettings
[
"string_encoding"
]
except
:
except
:
app
E
ncoding
=
"utf-8"
app
_e
ncoding
=
"utf-8"
if
type
(
error
M
sg
)
==
bytes
:
if
type
(
error
_m
sg
)
==
bytes
:
error
Msg
=
errorMsg
.
decode
(
encoding
=
appE
ncoding
,
errors
=
"replace"
)
error
_msg
=
error_msg
.
decode
(
encoding
=
app_e
ncoding
,
errors
=
"replace"
)
try
:
try
:
with
codecs
.
open
(
error
File
,
mode
=
"a"
,
encoding
=
appE
ncoding
)
as
fp
:
with
codecs
.
open
(
error
_file
,
mode
=
"a"
,
encoding
=
app_e
ncoding
)
as
fp
:
fp
.
write
(
"
\n
[%s] %s
\n
"
%
(
fp
.
write
(
"
\n
[%s] %s
\n
"
%
(
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
),
error
M
sg
))
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
),
error
_m
sg
))
except
:
except
:
print
(
g_ardutag
+
"WARNING: failed writing to error file: %s"
%
(
print
(
g_ardutag
+
"WARNING: failed writing to error file: %s"
%
(
errorF
ile
))
error_f
ile
))
# Convert error message to ascii before printing, otherwise
# Convert error message to ascii before printing, otherwise
# you may get error like this:
# you may get error like this:
# | UnicodeEncodeError: 'charmap' codec can't encode characters
# | UnicodeEncodeError: 'charmap' codec can't encode characters
error
Msg
=
errorM
sg
.
encode
(
"ascii"
,
errors
=
"replace"
)
error
_msg
=
error_m
sg
.
encode
(
"ascii"
,
errors
=
"replace"
)
error
Msg
=
errorM
sg
.
decode
(
"ascii"
,
errors
=
"replace"
)
error
_msg
=
error_m
sg
.
decode
(
"ascii"
,
errors
=
"replace"
)
print
(
"
\n
"
+
error
M
sg
+
"
\n
"
)
print
(
"
\n
"
+
error
_m
sg
+
"
\n
"
)
cefpython
.
QuitMessageLoop
()
cefpython
.
QuitMessageLoop
()
cefpython
.
Shutdown
()
cefpython
.
Shutdown
()
os
.
_exit
(
1
)
os
.
_exit
(
1
)
...
@@ -172,20 +172,20 @@ class MainFrame(wx.Frame):
...
@@ -172,20 +172,20 @@ class MainFrame(wx.Frame):
# Global client callbacks must be set before browser is created.
# Global client callbacks must be set before browser is created.
self
.
clientHandler
=
ClientHandler
()
self
.
clientHandler
=
ClientHandler
()
cefpython
.
SetGlobalClientCallback
(
"OnCertificateError"
,
cefpython
.
SetGlobalClientCallback
(
"OnCertificateError"
,
self
.
clientHandler
.
_OnCertificateError
)
self
.
clientHandler
.
_OnCertificateError
)
cefpython
.
SetGlobalClientCallback
(
"OnBeforePluginLoad"
,
cefpython
.
SetGlobalClientCallback
(
"OnBeforePluginLoad"
,
self
.
clientHandler
.
_OnBeforePluginLoad
)
self
.
clientHandler
.
_OnBeforePluginLoad
)
cefpython
.
SetGlobalClientCallback
(
"OnAfterCreated"
,
cefpython
.
SetGlobalClientCallback
(
"OnAfterCreated"
,
self
.
clientHandler
.
_OnAfterCreated
)
self
.
clientHandler
.
_OnAfterCreated
)
windowInfo
=
cefpython
.
WindowInfo
()
windowInfo
=
cefpython
.
WindowInfo
()
(
width
,
height
)
=
self
.
mainPanel
.
GetClientSizeTuple
()
(
width
,
height
)
=
self
.
mainPanel
.
GetClientSizeTuple
()
windowInfo
.
SetAsChild
(
self
.
GetHandleForBrowser
(),
windowInfo
.
SetAsChild
(
self
.
GetHandleForBrowser
(),
[
0
,
0
,
width
,
height
])
[
0
,
0
,
width
,
height
])
self
.
browser
=
cefpython
.
CreateBrowserSync
(
self
.
browser
=
cefpython
.
CreateBrowserSync
(
windowInfo
,
windowInfo
,
browserSettings
=
g_browserSettings
,
browserSettings
=
g_browserSettings
,
navigateUrl
=
url
)
navigateUrl
=
url
)
self
.
clientHandler
.
mainBrowser
=
self
.
browser
self
.
clientHandler
.
mainBrowser
=
self
.
browser
self
.
browser
.
SetClientHandler
(
self
.
clientHandler
)
self
.
browser
.
SetClientHandler
(
self
.
clientHandler
)
...
@@ -209,7 +209,7 @@ class MainFrame(wx.Frame):
...
@@ -209,7 +209,7 @@ class MainFrame(wx.Frame):
self
.
Bind
(
wx
.
EVT_CLOSE
,
self
.
OnClose
)
self
.
Bind
(
wx
.
EVT_CLOSE
,
self
.
OnClose
)
if
USE_EVT_IDLE
and
not
popup
:
if
USE_EVT_IDLE
and
not
popup
:
# Bind EVT_IDLE only for the main application frame.
# Bind EVT_IDLE only for the main application frame.
print
(
g_ardutag
+
\
print
(
g_ardutag
+
"Using EVT_IDLE to execute the CEF message loop work"
)
"Using EVT_IDLE to execute the CEF message loop work"
)
self
.
Bind
(
wx
.
EVT_IDLE
,
self
.
OnIdle
)
self
.
Bind
(
wx
.
EVT_IDLE
,
self
.
OnIdle
)
...
@@ -670,8 +670,8 @@ class ClientHandler:
...
@@ -670,8 +670,8 @@ class ClientHandler:
# ** This callback is executed on the IO thread **
# ** This callback is executed on the IO thread **
# Empty place-holders: popupFeatures, client.
# Empty place-holders: popupFeatures, client.
def
OnBeforePopup
(
self
,
browser
,
frame
,
targetUrl
,
targetFrameName
,
def
OnBeforePopup
(
self
,
browser
,
frame
,
targetUrl
,
targetFrameName
,
popupFeatures
,
windowInfo
,
client
,
browserSettings
,
popupFeatures
,
windowInfo
,
client
,
browserSettings
,
noJavascriptAccess
):
noJavascriptAccess
):
print
(
g_ardutag
+
"LifespanHandler::OnBeforePopup()"
)
print
(
g_ardutag
+
"LifespanHandler::OnBeforePopup()"
)
print
(
" targetUrl = %s"
%
targetUrl
)
print
(
" targetUrl = %s"
%
targetUrl
)
...
@@ -720,8 +720,8 @@ class ClientHandler:
...
@@ -720,8 +720,8 @@ class ClientHandler:
# JavascriptDialogHandler
# JavascriptDialogHandler
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def
OnJavascriptDialog
(
self
,
browser
,
originUrl
,
acceptLang
,
dialogType
,
def
OnJavascriptDialog
(
self
,
browser
,
originUrl
,
acceptLang
,
dialogType
,
messageText
,
defaultPromptText
,
callback
,
messageText
,
defaultPromptText
,
callback
,
suppressMessage
):
suppressMessage
):
print
(
g_ardutag
+
"JavascriptDialogHandler::OnJavascriptDialog()"
)
print
(
g_ardutag
+
"JavascriptDialogHandler::OnJavascriptDialog()"
)
print
(
" originUrl="
+
originUrl
)
print
(
" originUrl="
+
originUrl
)
print
(
" acceptLang="
+
acceptLang
)
print
(
" acceptLang="
+
acceptLang
)
...
@@ -819,7 +819,7 @@ def cef_init():
...
@@ -819,7 +819,7 @@ def cef_init():
"log_severity"
:
cefpython
.
LOGSEVERITY_INFO
,
"log_severity"
:
cefpython
.
LOGSEVERITY_INFO
,
"release_dcheck_enabled"
:
False
,
"release_dcheck_enabled"
:
False
,
"remote_debugging_port"
:
0
,
"remote_debugging_port"
:
0
,
"unique_request_context_per_browser"
:
True
,
"unique_request_context_per_browser"
:
True
,
"auto_zooming"
:
"system_dpi"
"auto_zooming"
:
"system_dpi"
}
}
...
@@ -827,12 +827,12 @@ def cef_init():
...
@@ -827,12 +827,12 @@ def cef_init():
# "resources_dir_path" must be set on Mac, "locales_dir_path" not.
# "resources_dir_path" must be set on Mac, "locales_dir_path" not.
if
g_platform_os
==
"mac"
:
if
g_platform_os
==
"mac"
:
g_applicationSettings
[
"resources_dir_path"
]
=
\
g_applicationSettings
[
"resources_dir_path"
]
=
\
cefpython
.
GetModuleDirectory
()
+
os
.
sep
+
"Resources"
cefpython
.
GetModuleDirectory
()
+
os
.
sep
+
"Resources"
else
:
else
:
g_applicationSettings
[
"resources_dir_path"
]
=
\
g_applicationSettings
[
"resources_dir_path"
]
=
\
cefpython
.
GetModuleDirectory
()
cefpython
.
GetModuleDirectory
()
g_applicationSettings
[
"locales_dir_path"
]
=
\
g_applicationSettings
[
"locales_dir_path"
]
=
\
cefpython
.
GetModuleDirectory
()
+
os
.
sep
+
"locales"
cefpython
.
GetModuleDirectory
()
+
os
.
sep
+
"locales"
# High DPI support is available only on Windows.
# High DPI support is available only on Windows.
# Example values for auto_zooming are:
# Example values for auto_zooming are:
...
@@ -860,15 +860,15 @@ def cef_init():
...
@@ -860,15 +860,15 @@ def cef_init():
# On Win/Linux you only specify the ApplicationSettings.locales_dir_path.
# On Win/Linux you only specify the ApplicationSettings.locales_dir_path.
if
g_platform_os
==
"mac"
:
if
g_platform_os
==
"mac"
:
g_commandLineSwitches
[
"locale_pak"
]
=
cefpython
.
GetModuleDirectory
()
+
\
g_commandLineSwitches
[
"locale_pak"
]
=
cefpython
.
GetModuleDirectory
()
+
\
"/Resources/en.lproj/locale.pak"
"/Resources/en.lproj/locale.pak"
cefpython
.
Initialize
(
g_applicationSettings
,
g_commandLineSwitches
)
cefpython
.
Initialize
(
g_applicationSettings
,
g_commandLineSwitches
)
def
splash_screen
():
def
splash_screen
():
import
wx.lib.agw.advancedsplash
as
AS
import
wx.lib.agw.advancedsplash
as
AS
image
P
ath
=
"ardublockly/img/ardublockly_splash.png"
image
_p
ath
=
"ardublockly/img/ardublockly_splash.png"
bitmap
=
wx
.
Bitmap
(
image
P
ath
,
wx
.
BITMAP_TYPE_PNG
)
bitmap
=
wx
.
Bitmap
(
image
_p
ath
,
wx
.
BITMAP_TYPE_PNG
)
shadow
=
wx
.
WHITE
shadow
=
wx
.
WHITE
splash
=
AS
.
AdvancedSplash
(
splash
=
AS
.
AdvancedSplash
(
None
,
bitmap
=
bitmap
,
timeout
=
5000
,
shadowcolour
=
shadow
,
None
,
bitmap
=
bitmap
,
timeout
=
5000
,
shadowcolour
=
shadow
,
...
@@ -883,7 +883,8 @@ def launch_server(server_root):
...
@@ -883,7 +883,8 @@ 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
})
thread
.
daemon
=
True
print
(
"
\n
======= Starting Server ======="
)
print
(
"
\n
======= Starting Server ======="
)
thread
.
start
()
thread
.
start
()
...
...
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