Skip to content

Commit 623e26a

Browse files
committed
Fixed cefpython.GetModuleDirectory() invalid windows slashes
in the path. Fixed setup syntax error. Updated cefpython_py27 module. Updated wxpython.py and pygtk_.py examples - minor improvements. Updated package __init__.py there is no more need to use locales_dir or resources_dir, use instead GetModuleDirectory().
1 parent ac9514a commit 623e26a

5 files changed

Lines changed: 32 additions & 62 deletions

File tree

cefpython/!linux_todo.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

cefpython/cef1/linux/binaries/pygtk_.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@
77
import ctypes, os, sys
88
libcef_so = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libcef.so')
99
if os.path.exists(libcef_so):
10-
CEFPYTHON_PACKAGE = False
1110
# Import local module
1211
ctypes.CDLL(libcef_so, ctypes.RTLD_GLOBAL)
1312
if 0x02070000 <= sys.hexversion < 0x03000000:
1413
import cefpython_py27 as cefpython
1514
else:
1615
raise Exception("Unsupported python version: %s" % sys.version)
17-
# These dirs will be set after GetApplicationPath() is defined.
18-
cefpython.locales_dir = None
19-
cefpython.resources_dir = None
2016
else:
21-
CEFPYTHON_PACKAGE = True
2217
# Import from package
2318
from cefpython1 import cefpython
24-
# cefpython.locales_dir and cefpython.resources_dir are already
25-
# defined when importing cefpython from a package.
2619

2720
import pygtk
2821
pygtk.require('2.0')
@@ -51,24 +44,21 @@ def GetApplicationPath(file=None):
5144
return path
5245
return str(file)
5346

54-
if not CEFPYTHON_PACKAGE:
55-
# Set these only when importing a local module.
56-
cefpython.locales_dir = GetApplicationPath("locales")
57-
cefpython.resources_dir = GetApplicationPath()
58-
5947
def ExceptHook(type, value, traceObject):
6048
import traceback, os, time
6149
# This hook does the following: in case of exception display it,
6250
# write to error.log, shutdown CEF and exit application.
6351
error = "\n".join(traceback.format_exception(type, value, traceObject))
52+
error_file = GetApplicationPath("error.log")
6453
try:
65-
with open(GetApplicationPath("error.log"), "a") as file:
54+
with open(error_file, "a") as file:
6655
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
6756
except:
6857
# If this is an example run from
6958
# /usr/local/lib/python2.7/dist-packages/cefpython1/examples/
70-
# then we do not have permission to write to that directory.
71-
pass
59+
# then we might have not permission to write to that directory.
60+
print("cefpython: WARNING: failed writing to error file: %s" % (
61+
error_file))
7262
print("\n"+error+"\n")
7363
cefpython.QuitMessageLoop()
7464
cefpython.Shutdown()
@@ -177,20 +167,15 @@ def OnExit(self, widget, data=None):
177167

178168
sys.excepthook = ExceptHook
179169
cefpython.g_debug = True
180-
if not CEFPYTHON_PACKAGE:
181-
# No permission to write files when running examples/ from a package.
182-
cefpython.g_debugFile = GetApplicationPath("debug.log")
170+
cefpython.g_debugFile = GetApplicationPath("debug.log")
183171
settings = {
184172
"log_severity": cefpython.LOGSEVERITY_INFO,
185173
"log_file": GetApplicationPath("debug.log"),
186174
"release_dcheck_enabled": True, # Enable only when debugging.
187175
# This directories must be set on Linux
188-
"locales_dir_path": cefpython.locales_dir,
189-
"resources_dir_path": cefpython.resources_dir
176+
"locales_dir_path": cefpython.GetModuleDirectory()+"/locales",
177+
"resources_dir_path": cefpython.GetModuleDirectory()
190178
}
191-
if CEFPYTHON_PACKAGE:
192-
# No permission to write files when running examples/ from a package.
193-
settings["log_file"] = ""
194179
cefpython.Initialize(settings)
195180

196181
gobject.threads_init() # timer for messageloop

cefpython/cef1/linux/binaries/wxpython.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@
77
import ctypes, os, sys
88
libcef_so = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libcef.so')
99
if os.path.exists(libcef_so):
10-
CEFPYTHON_PACKAGE = False
1110
# Import local module
1211
ctypes.CDLL(libcef_so, ctypes.RTLD_GLOBAL)
1312
if 0x02070000 <= sys.hexversion < 0x03000000:
1413
import cefpython_py27 as cefpython
1514
else:
1615
raise Exception("Unsupported python version: %s" % sys.version)
17-
# These dirs will be set after GetApplicationPath() is defined.
18-
cefpython.locales_dir = None
19-
cefpython.resources_dir = None
2016
else:
21-
CEFPYTHON_PACKAGE = True
2217
# Import from package
2318
from cefpython1 import cefpython
24-
# cefpython.locales_dir and cefpython.resources_dir are already
25-
# defined when importing cefpython from a package.
2619

2720
import wx
2821
import time
@@ -58,24 +51,21 @@ def GetApplicationPath(file=None):
5851
return path
5952
return str(file)
6053

61-
if not CEFPYTHON_PACKAGE:
62-
# Set these only when importing a local module.
63-
cefpython.locales_dir = GetApplicationPath("locales")
64-
cefpython.resources_dir = GetApplicationPath()
65-
6654
def ExceptHook(type, value, traceObject):
6755
import traceback, os, time
6856
# This hook does the following: in case of exception display it,
6957
# write to error.log, shutdown CEF and exit application.
7058
error = "\n".join(traceback.format_exception(type, value, traceObject))
59+
error_file = GetApplicationPath("error.log")
7160
try:
72-
with open(GetApplicationPath("error.log"), "a") as file:
61+
with open(error_file, "a") as file:
7362
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
7463
except:
7564
# If this is an example run from
7665
# /usr/local/lib/python2.7/dist-packages/cefpython1/examples/
77-
# then we do not have permission to write to that directory.
78-
pass
66+
# then we might have not permission to write to that directory.
67+
print("cefpython: WARNING: failed writing to error file: %s" % (
68+
error_file))
7969
print("\n"+error+"\n")
8070
cefpython.QuitMessageLoop()
8171
cefpython.Shutdown()
@@ -177,20 +167,15 @@ def OnExit(self):
177167
if __name__ == '__main__':
178168
sys.excepthook = ExceptHook
179169
cefpython.g_debug = True
180-
if not CEFPYTHON_PACKAGE:
181-
# No permission to write files when running examples/ from a package.
182-
cefpython.g_debugFile = GetApplicationPath("debug.log")
170+
cefpython.g_debugFile = GetApplicationPath("debug.log")
183171
settings = {
184172
"log_severity": cefpython.LOGSEVERITY_INFO,
185173
"log_file": GetApplicationPath("debug.log"),
186174
"release_dcheck_enabled": True, # Enable only when debugging.
187175
# This directories must be set on Linux
188-
"locales_dir_path": cefpython.locales_dir,
189-
"resources_dir_path": cefpython.resources_dir
176+
"locales_dir_path": cefpython.GetModuleDirectory()+"/locales",
177+
"resources_dir_path": cefpython.GetModuleDirectory()
190178
}
191-
if CEFPYTHON_PACKAGE:
192-
# No permission to write files when running examples/ from a package.
193-
settings["log_file"] = ""
194179
cefpython.Initialize(settings)
195180

196181
print('wx.version=%s' % wx.version())

cefpython/cef1/linux/setup/setup.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ def CompileTimeConstants():
6060
'cpp_utils'
6161
],
6262

63-
"""
64-
Loading libcef.so will only work when running scripts from the same
65-
directory that libcef.so resides in when you put "./" in here.
66-
runtime_library_dirs=[
67-
'./'
68-
],
69-
"""
63+
# Loading libcef.so will only work when running scripts from the same
64+
# directory that libcef.so resides in when you put "./" in here.
65+
# runtime_library_dirs=[
66+
# './'
67+
#],
7068

7169
# /EHsc - using STL string, multimap and others that use C++ exceptions.
7270
extra_compile_args=[],

cefpython/utils.pyx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ cpdef object Debug(str msg):
1515
msg = "cefpython: "+str(msg)
1616
print(msg)
1717
if g_debugFile:
18-
with open(g_debugFile, "a") as file:
19-
file.write(msg+"\n")
18+
try:
19+
with open(g_debugFile, "a") as file:
20+
file.write(msg+"\n")
21+
except:
22+
print("cefpython: WARNING: failed writing to debug file: %s" % (
23+
g_debugFile))
24+
2025

2126
cpdef str GetSystemError():
2227
IF UNAME_SYSNAME == "Windows":
@@ -57,6 +62,9 @@ cpdef str GetModuleDirectory():
5762
path = os.path.dirname(os.path.realpath(__file__))
5863
else:
5964
path = os.getcwd()
60-
path = re.sub(r"[/\\]+", re.escape(os.sep), path)
65+
if platform.system() == "Windows":
66+
# On linux this regexp would give:
67+
# "\/home\/czarek\/cefpython\/cefpython\/cef1\/linux\/binaries"
68+
path = re.sub(r"[/\\]+", re.escape(os.sep), path)
6169
path = re.sub(r"[/\\]+$", "", path)
6270
return str(path)

0 commit comments

Comments
 (0)