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 -*- # -*- 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,7 +124,13 @@ class MainFrame(wx.Frame): ...@@ -123,7 +124,13 @@ class MainFrame(wx.Frame):
def GetHandleForBrowser(self): def GetHandleForBrowser(self):
if self.mainPanel: if self.mainPanel:
if g_platform_os == "linux":
return self.mainPanel.GetGtkWidget()
else:
return self.mainPanel.GetHandle() return self.mainPanel.GetHandle()
else:
if g_platform_os == "linux":
return self.GetGtkWidget()
else: else:
return self.GetHandle() return self.GetHandle()
...@@ -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,9 +262,11 @@ class MainFrame(wx.Frame): ...@@ -254,9 +262,11 @@ class MainFrame(wx.Frame):
self.menubar.SetBarHeight() self.menubar.SetBarHeight()
def OnSetFocus(self, event): def OnSetFocus(self, event):
if g_platform_os != "linux":
cefpython.WindowUtils.OnSetFocus(self.GetHandleForBrowser(), 0, 0, 0) cefpython.WindowUtils.OnSetFocus(self.GetHandleForBrowser(), 0, 0, 0)
def OnSize(self, event): def OnSize(self, event):
if g_platform_os != "linux":
cefpython.WindowUtils.OnSize(self.GetHandleForBrowser(), 0, 0, 0) cefpython.WindowUtils.OnSize(self.GetHandleForBrowser(), 0, 0, 0)
def OnClose(self, event): def OnClose(self, event):
...@@ -801,6 +811,7 @@ def cef_init(): ...@@ -801,6 +811,7 @@ 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"
if g_platform_os == "win":
print(g_ardutag + "Calling SetProcessDpiAware") print(g_ardutag + "Calling SetProcessDpiAware")
cefpython.DpiAware.SetProcessDpiAware() cefpython.DpiAware.SetProcessDpiAware()
...@@ -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())
......
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