Commit 3d5dffe5 authored by carlosperate's avatar carlosperate

CEF GUI: Fixed issue with running thread on exit.

parent 13fb6c14
...@@ -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()).
errorMsg = "\n".join(traceback.format_exception(excType, excValue, error_msg = "\n".join(traceback.format_exception(
traceObject)) excType, excValue, traceObject))
errorFile = GetApplicationPath("cef_error.log") error_file = GetApplicationPath("cef_error.log")
try: try:
appEncoding = cefpython.g_applicationSettings["string_encoding"] app_encoding = cefpython.g_applicationSettings["string_encoding"]
except: except:
appEncoding = "utf-8" app_encoding = "utf-8"
if type(errorMsg) == bytes: if type(error_msg) == bytes:
errorMsg = errorMsg.decode(encoding=appEncoding, errors="replace") error_msg = error_msg.decode(encoding=app_encoding, errors="replace")
try: try:
with codecs.open(errorFile, mode="a", encoding=appEncoding) as fp: with codecs.open(error_file, mode="a", encoding=app_encoding) as fp:
fp.write("\n[%s] %s\n" % ( fp.write("\n[%s] %s\n" % (
time.strftime("%Y-%m-%d %H:%M:%S"), errorMsg)) time.strftime("%Y-%m-%d %H:%M:%S"), error_msg))
except: except:
print(g_ardutag + "WARNING: failed writing to error file: %s" % ( print(g_ardutag + "WARNING: failed writing to error file: %s" % (
errorFile)) error_file))
# 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
errorMsg = errorMsg.encode("ascii", errors="replace") error_msg = error_msg.encode("ascii", errors="replace")
errorMsg = errorMsg.decode("ascii", errors="replace") error_msg = error_msg.decode("ascii", errors="replace")
print("\n"+errorMsg+"\n") print("\n"+error_msg+"\n")
cefpython.QuitMessageLoop() cefpython.QuitMessageLoop()
cefpython.Shutdown() cefpython.Shutdown()
os._exit(1) os._exit(1)
...@@ -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)
...@@ -867,8 +867,8 @@ def cef_init(): ...@@ -867,8 +867,8 @@ def cef_init():
def splash_screen(): def splash_screen():
import wx.lib.agw.advancedsplash as AS import wx.lib.agw.advancedsplash as AS
imagePath = "ardublockly/img/ardublockly_splash.png" image_path = "ardublockly/img/ardublockly_splash.png"
bitmap = wx.Bitmap(imagePath, wx.BITMAP_TYPE_PNG) bitmap = wx.Bitmap(image_path, 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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment