Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
cefpython/cefpython/cef1/windows/binaries/pyside.py at cefpython31 · elmalla/cefpython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
elmalla
/
cefpython
Public
forked from
cztomczak/cefpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
cefpython31
Breadcrumbs
cefpython
/
cefpython
/
cef1
/
windows
/
binaries
/
pyside.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
184 lines (159 loc) · 6.52 KB
cefpython31
Breadcrumbs
cefpython
/
cefpython
/
cef1
/
windows
/
binaries
/
pyside.py
Copy path
Top
File metadata and controls
Code
Blame
184 lines (159 loc) · 6.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# An example of embedding CEF Python in PySide application.
import
platform
if
platform
.
architecture
()[
0
]
!=
"32bit"
:
raise
Exception
(
"Only 32bit architecture is supported"
)
import
os
,
sys
libcef_dll
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'libcef.dll'
)
if
os
.
path
.
exists
(
libcef_dll
):
# Import the local module.
if
0x02070000
<=
sys
.
hexversion
<
0x03000000
:
import
cefpython_py27
as
cefpython
elif
0x03000000
<=
sys
.
hexversion
<
0x04000000
:
import
cefpython_py32
as
cefpython
else
:
raise
Exception
(
"Unsupported python version: %s"
%
sys
.
version
)
else
:
# Import the package.
from
cefpython1
import
cefpython
import
PySide
from
PySide
import
QtGui
from
PySide
import
QtCore
import
ctypes
def
GetApplicationPath
(
file
=
None
):
import
re
,
os
# If file is None return current directory without trailing slash.
if
file
is
None
:
file
=
""
# Only when relative path.
if
not
file
.
startswith
(
"/"
)
and
not
file
.
startswith
(
"
\\
"
)
and
(
not
re
.
search
(
r"^[\w-]+:"
,
file
)):
if
hasattr
(
sys
,
"frozen"
):
path
=
os
.
path
.
dirname
(
sys
.
executable
)
elif
"__file__"
in
globals
():
path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
else
:
path
=
os
.
getcwd
()
path
=
path
+
os
.
sep
+
file
path
=
re
.
sub
(
r"[/\\]+"
,
re
.
escape
(
os
.
sep
),
path
)
path
=
re
.
sub
(
r"[/\\]+$"
,
""
,
path
)
return
path
return
str
(
file
)
def
ExceptHook
(
excType
,
excValue
,
traceObject
):
import
traceback
,
os
,
time
,
codecs
# This hook does the following: in case of exception write it to
# the "error.log" file, display it to the console, shutdown CEF
# and exit application immediately by ignoring "finally" (_exit()).
errorMsg
=
"
\n
"
.
join
(
traceback
.
format_exception
(
excType
,
excValue
,
traceObject
))
errorFile
=
GetApplicationPath
(
"error.log"
)
try
:
appEncoding
=
cefpython
.
g_applicationSettings
[
"string_encoding"
]
except
:
appEncoding
=
"utf-8"
if
type
(
errorMsg
)
==
bytes
:
errorMsg
=
errorMsg
.
decode
(
encoding
=
appEncoding
,
errors
=
"replace"
)
try
:
with
codecs
.
open
(
errorFile
,
mode
=
"a"
,
encoding
=
appEncoding
)
as
fp
:
fp
.
write
(
"
\n
[%s] %s
\n
"
%
(
time
.
strftime
(
"%Y-%m-%d %H:%M:%S"
),
errorMsg
))
except
:
print
(
"cefpython: WARNING: failed writing to error file: %s"
%
(
errorFile
))
# Convert error message to ascii before printing, otherwise
# you may get error like this:
# | UnicodeEncodeError: 'charmap' codec can't encode characters
errorMsg
=
errorMsg
.
encode
(
"ascii"
,
errors
=
"replace"
)
errorMsg
=
errorMsg
.
decode
(
"ascii"
,
errors
=
"replace"
)
print
(
"
\n
"
+
errorMsg
+
"
\n
"
)
cefpython
.
QuitMessageLoop
()
cefpython
.
Shutdown
()
os
.
_exit
(
1
)
class
MainWindow
(
QtGui
.
QMainWindow
):
mainFrame
=
None
def
__init__
(
self
):
super
(
MainWindow
,
self
).
__init__
(
None
)
self
.
createMenu
()
self
.
mainFrame
=
MainFrame
(
self
)
self
.
setCentralWidget
(
self
.
mainFrame
)
self
.
resize
(
600
,
480
)
self
.
setWindowTitle
(
'PySide example'
)
self
.
setFocusPolicy
(
QtCore
.
Qt
.
StrongFocus
)
def
createMenu
(
self
):
menubar
=
self
.
menuBar
()
filemenu
=
menubar
.
addMenu
(
"&File"
)
filemenu
.
addAction
(
QtGui
.
QAction
(
"Open"
,
self
))
filemenu
.
addAction
(
QtGui
.
QAction
(
"Exit"
,
self
))
aboutmenu
=
menubar
.
addMenu
(
"&About"
)
def
focusInEvent
(
self
,
event
):
cefpython
.
WindowUtils
.
OnSetFocus
(
int
(
self
.
centralWidget
().
winIdFixed
()),
0
,
0
,
0
)
def
closeEvent
(
self
,
event
):
self
.
mainFrame
.
browser
.
CloseBrowser
()
class
MainFrame
(
QtGui
.
QWidget
):
browser
=
None
def
__init__
(
self
,
parent
=
None
):
super
(
MainFrame
,
self
).
__init__
(
parent
)
windowInfo
=
cefpython
.
WindowInfo
()
windowInfo
.
SetAsChild
(
int
(
self
.
winIdFixed
()))
self
.
browser
=
cefpython
.
CreateBrowserSync
(
windowInfo
,
browserSettings
=
{},
navigateUrl
=
GetApplicationPath
(
"cefsimple.html"
))
self
.
show
()
def
winIdFixed
(
self
):
# PySide bug: QWidget.winId() returns <PyCObject object at 0x02FD8788>,
# there is no easy way to convert it to int.
try
:
return
int
(
self
.
winId
())
except
:
if
sys
.
version_info
[
0
]
==
2
:
ctypes
.
pythonapi
.
PyCObject_AsVoidPtr
.
restype
=
ctypes
.
c_void_p
ctypes
.
pythonapi
.
PyCObject_AsVoidPtr
.
argtypes
=
[
ctypes
.
py_object
]
return
ctypes
.
pythonapi
.
PyCObject_AsVoidPtr
(
self
.
winId
())
elif
sys
.
version_info
[
0
]
==
3
:
ctypes
.
pythonapi
.
PyCapsule_GetPointer
.
restype
=
ctypes
.
c_void_p
ctypes
.
pythonapi
.
PyCapsule_GetPointer
.
argtypes
=
[
ctypes
.
py_object
]
return
ctypes
.
pythonapi
.
PyCapsule_GetPointer
(
self
.
winId
(),
None
)
def
moveEvent
(
self
,
event
):
cefpython
.
WindowUtils
.
OnSize
(
int
(
self
.
winIdFixed
()),
0
,
0
,
0
)
def
resizeEvent
(
self
,
event
):
cefpython
.
WindowUtils
.
OnSize
(
int
(
self
.
winIdFixed
()),
0
,
0
,
0
)
class
CefApplication
(
QtGui
.
QApplication
):
timer
=
None
def
__init__
(
self
,
args
):
super
(
CefApplication
,
self
).
__init__
(
args
)
self
.
createTimer
()
def
createTimer
(
self
):
self
.
timer
=
QtCore
.
QTimer
()
self
.
timer
.
timeout
.
connect
(
self
.
onTimer
)
self
.
timer
.
start
(
10
)
def
onTimer
(
self
):
# The proper way of doing message loop should be:
# 1. In createTimer() call self.timer.start(0)
# 2. In onTimer() call MessageLoopWork() only when
# QtGui.QApplication.instance()->hasPendingEvents() returns False.
# But... there is a bug in Qt, hasPendingEvents() returns always true.
cefpython
.
MessageLoopWork
()
def
stopTimer
(
self
):
# Stop the timer after Qt message loop ended, calls to MessageLoopWork()
# should not happen anymore.
self
.
timer
.
stop
()
if
__name__
==
'__main__'
:
print
(
"PySide version: %s"
%
PySide
.
__version__
)
print
(
"QtCore version: %s"
%
QtCore
.
__version__
)
sys
.
excepthook
=
ExceptHook
settings
=
{
"log_severity"
:
cefpython
.
LOGSEVERITY_INFO
,
"log_file"
:
GetApplicationPath
(
"debug.log"
),
"release_dcheck_enabled"
:
True
# Enable only when debugging.
}
cefpython
.
Initialize
(
settings
)
app
=
CefApplication
(
sys
.
argv
)
mainWindow
=
MainWindow
()
mainWindow
.
show
()
app
.
exec_
()
app
.
stopTimer
()
# Need to destroy QApplication(), otherwise Shutdown() fails.
# Unset main window also just to be safe.
del
mainWindow
del
app
cefpython
.
Shutdown
()
You can’t perform that action at this time.