Commit bc7ac485 authored by carlosperate's avatar carlosperate

Adding platform awareness to wxPython gui code

parent 55ea4e30
#!/usr/bin/env python2
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Embedding CEF browser in a wxPython window to launch Ardublockly.
......@@ -45,6 +45,7 @@ __file__ = sys.argv[0]
g_applicationSettings = None
g_browserSettings = None
g_ardutag = "[ardublockly] "
g_platform_os = None
# Which method to use for message loop processing.
# EVT_IDLE - wx application has priority
......@@ -123,7 +124,13 @@ class MainFrame(wx.Frame):
def GetHandleForBrowser(self):
if self.mainPanel:
if g_platform_os == "linux":
return self.mainPanel.GetGtkWidget()
else:
return self.mainPanel.GetHandle()
else:
if g_platform_os == "linux":
return self.GetGtkWidget()
else:
return self.GetHandle()
......@@ -136,8 +143,9 @@ class MainFrame(wx.Frame):
size = (1250, 768)
# This is an optional code to enable High DPI support.
if "auto_zooming" in g_applicationSettings \
and g_applicationSettings["auto_zooming"] == "system_dpi":
if (g_platform_os == "win") \
and ("auto_zooming" in g_applicationSettings) \
and (g_applicationSettings["auto_zooming"] == "system_dpi"):
# This utility function will adjust width/height using
# OS DPI settings. For 800/600 with Win7 DPI settings
# being set to "Larger 150%" will return 1200/900.
......@@ -254,9 +262,11 @@ class MainFrame(wx.Frame):
self.menubar.SetBarHeight()
def OnSetFocus(self, event):
if g_platform_os != "linux":
cefpython.WindowUtils.OnSetFocus(self.GetHandleForBrowser(), 0, 0, 0)
def OnSize(self, event):
if g_platform_os != "linux":
cefpython.WindowUtils.OnSize(self.GetHandleForBrowser(), 0, 0, 0)
def OnClose(self, event):
......@@ -801,6 +811,7 @@ def cef_init():
# Larger 150% = 144 DPI = 2.0 zoom level
# Custom 75% = 72 DPI = -1.0 zoom level
#g_applicationSettings["auto_zooming"] = "system_dpi"
if g_platform_os == "win":
print(g_ardutag + "Calling SetProcessDpiAware")
cefpython.DpiAware.SetProcessDpiAware()
......@@ -833,12 +844,29 @@ def launch_server(server_root):
else:
root_location = os.path.dirname(os.path.realpath(sys.argv[0]))
thread = threading.Thread(
target=start_server, kwargs={"document_root": root_location})
target=start_server, kwargs={"document_root":root_location})
print("\n======= Starting Server =======")
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):
detect_os()
print(g_ardutag + "OS: %s" % g_platform_os)
print(g_ardutag + "Python version: %s" % platform.python_version())
print(g_ardutag + "wx.version: %s" % wx.version())
print(g_ardutag + "cefpython GetModuleDirectory: %s" % cefpython.GetModuleDirectory())
......
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