Skip to content

Commit 4df5552

Browse files
committed
Updated Linux examples to work within a package.
Added LICENSE.txt to binaries. Added support for package: setup.py and __init__.py created.
1 parent cd04e7a commit 4df5552

7 files changed

Lines changed: 138 additions & 10 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Copyright (c) 2012-2013 Czarek Tomczak. Portions Copyright
2+
(c) 2008-2013 Marshall A.Greenblatt, 2006-2009 Google Inc.
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with
6+
or without modification, are permitted provided that the
7+
following conditions are met:
8+
9+
* Redistributions of source code must retain the above
10+
copyright notice, this list of conditions and the
11+
following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above
14+
copyright notice, this list of conditions and the
15+
following disclaimer in the documentation and/or other
16+
materials provided with the distribution.
17+
18+
* Neither the name of Google Inc. nor the name Chromium
19+
Embedded Framework nor the name of CEF Python nor the
20+
names of its contributors may be used to endorse or
21+
promote products derived from this software without
22+
specific prior written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cefpython/cef1/linux/binaries/pygtk_.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
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
1011
# Import local module
1112
ctypes.CDLL(libcef_so, ctypes.RTLD_GLOBAL)
1213
if 0x02070000 <= sys.hexversion < 0x03000000:
1314
import cefpython_py27 as cefpython
1415
else:
1516
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
1620
else:
21+
CEFPYTHON_PACKAGE = True
1722
# Import from package
1823
from cefpython1 import cefpython
24+
# cefpython.locales_dir and cefpython.resources_dir are already
25+
# defined when importing cefpython from a package.
1926

2027
import pygtk
2128
pygtk.require('2.0')
@@ -44,13 +51,24 @@ def GetApplicationPath(file=None):
4451
return path
4552
return str(file)
4653

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+
4759
def ExceptHook(type, value, traceObject):
4860
import traceback, os, time
4961
# This hook does the following: in case of exception display it,
5062
# write to error.log, shutdown CEF and exit application.
5163
error = "\n".join(traceback.format_exception(type, value, traceObject))
52-
with open(GetApplicationPath("error.log"), "a") as file:
53-
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
64+
try:
65+
with open(GetApplicationPath("error.log"), "a") as file:
66+
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
67+
except:
68+
# If this is an example run from
69+
# /usr/local/lib/python2.7/dist-packages/cefpython1/examples/
70+
# then we do not have permission to write to that directory.
71+
pass
5472
print("\n"+error+"\n")
5573
cefpython.QuitMessageLoop()
5674
cefpython.Shutdown()
@@ -159,15 +177,20 @@ def OnExit(self, widget, data=None):
159177

160178
sys.excepthook = ExceptHook
161179
cefpython.g_debug = True
162-
cefpython.g_debugFile = GetApplicationPath("debug.log")
180+
if not CEFPYTHON_PACKAGE:
181+
# No permission to write files when running examples/ from a package.
182+
cefpython.g_debugFile = GetApplicationPath("debug.log")
163183
settings = {
164184
"log_severity": cefpython.LOGSEVERITY_INFO,
165185
"log_file": GetApplicationPath("debug.log"),
166186
"release_dcheck_enabled": True, # Enable only when debugging.
167187
# This directories must be set on Linux
168-
"locales_dir_path": GetApplicationPath("locales"),
169-
"resources_dir_path": GetApplicationPath()
188+
"locales_dir_path": cefpython.locales_dir,
189+
"resources_dir_path": cefpython.resources_dir
170190
}
191+
if CEFPYTHON_PACKAGE:
192+
# No permission to write files when running examples/ from a package.
193+
settings["log_file"] = ""
171194
cefpython.Initialize(settings)
172195

173196
gobject.threads_init() # timer for messageloop

cefpython/cef1/linux/binaries/wxpython.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
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
1011
# Import local module
1112
ctypes.CDLL(libcef_so, ctypes.RTLD_GLOBAL)
1213
if 0x02070000 <= sys.hexversion < 0x03000000:
1314
import cefpython_py27 as cefpython
1415
else:
1516
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
1620
else:
21+
CEFPYTHON_PACKAGE = True
1722
# Import from package
1823
from cefpython1 import cefpython
24+
# cefpython.locales_dir and cefpython.resources_dir are already
25+
# defined when importing cefpython from a package.
1926

2027
import wx
2128
import time
@@ -51,13 +58,24 @@ def GetApplicationPath(file=None):
5158
return path
5259
return str(file)
5360

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+
5466
def ExceptHook(type, value, traceObject):
5567
import traceback, os, time
5668
# This hook does the following: in case of exception display it,
5769
# write to error.log, shutdown CEF and exit application.
5870
error = "\n".join(traceback.format_exception(type, value, traceObject))
59-
with open(GetApplicationPath("error.log"), "a") as file:
60-
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
71+
try:
72+
with open(GetApplicationPath("error.log"), "a") as file:
73+
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
74+
except:
75+
# If this is an example run from
76+
# /usr/local/lib/python2.7/dist-packages/cefpython1/examples/
77+
# then we do not have permission to write to that directory.
78+
pass
6179
print("\n"+error+"\n")
6280
cefpython.QuitMessageLoop()
6381
cefpython.Shutdown()
@@ -159,15 +177,20 @@ def OnExit(self):
159177
if __name__ == '__main__':
160178
sys.excepthook = ExceptHook
161179
cefpython.g_debug = True
162-
cefpython.g_debugFile = GetApplicationPath("debug.log")
180+
if not CEFPYTHON_PACKAGE:
181+
# No permission to write files when running examples/ from a package.
182+
cefpython.g_debugFile = GetApplicationPath("debug.log")
163183
settings = {
164184
"log_severity": cefpython.LOGSEVERITY_INFO,
165185
"log_file": GetApplicationPath("debug.log"),
166186
"release_dcheck_enabled": True, # Enable only when debugging.
167187
# This directories must be set on Linux
168-
"locales_dir_path": GetApplicationPath("locales"),
169-
"resources_dir_path": GetApplicationPath()
188+
"locales_dir_path": cefpython.locales_dir,
189+
"resources_dir_path": cefpython.resources_dir
170190
}
191+
if CEFPYTHON_PACKAGE:
192+
# No permission to write files when running examples/ from a package.
193+
settings["log_file"] = ""
171194
cefpython.Initialize(settings)
172195

173196
print('wx.version=%s' % wx.version())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cefpython_setup
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1. To install CEF Python 1 type:
2+
3+
sudo python setup.py install
4+
5+
2. Go to /usr/local/lib/python2.7/dist-packages/cefpython1/examples/
6+
and run some examples:
7+
8+
python wxpython.py
9+
python pygtk_.py
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import ctypes, os
2+
libcef_so = os.path.join(os.path.dirname(os.path.abspath(__file__)), "libcef.so")
3+
ctypes.CDLL(libcef_so, ctypes.RTLD_GLOBAL)
4+
5+
import sys
6+
if 0x02070000 <= sys.hexversion < 0x03000000:
7+
from . import cefpython_py27 as cefpython
8+
else:
9+
raise Exception("Unsupported python version: " + sys.version)
10+
11+
cefpython.locales_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "locales")
12+
cefpython.resources_dir = os.path.dirname(os.path.abspath(__file__))
13+
14+
__version__ = "v53"
15+
__author__ = "CEF Python authors"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from distutils.core import setup
2+
3+
setup(
4+
name='CEF Python 1',
5+
version='v53',
6+
description='Python bindings for the Chromium Embedded Framework',
7+
license='BSD 3-Clause',
8+
author='Czarek Tomczak',
9+
author_email='czarek.tomczak@gmail.com',
10+
url='http://code.google.com/p/cefpython/',
11+
packages=['cefpython1'],
12+
package_data={'cefpython1': [
13+
'examples/*.py',
14+
'examples/*.html',
15+
'locales/*.pak',
16+
'*.txt',
17+
'cefclient',
18+
'*.so',
19+
'*.pak'
20+
]}
21+
)

0 commit comments

Comments
 (0)