Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adamn/python-webkit2png
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: morty/python-webkit2png
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Sep 1, 2010

  1. Unverified

    No user is associated with the committer email.
    Copy the full SHA
    115efff View commit details

Commits on Sep 2, 2010

  1. Unverified

    No user is associated with the committer email.
    Copy the full SHA
    31ff4fd View commit details

Commits on Apr 12, 2011

  1. Unverified

    No user is associated with the committer email.
    Copy the full SHA
    71be405 View commit details
  2. Added missing selfs.

    morty committed Apr 12, 2011

    Unverified

    No user is associated with the committer email.
    Copy the full SHA
    b7b9554 View commit details
  3. Small fix.

    morty committed Apr 12, 2011

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d80f09f View commit details
Showing with 37 additions and 3 deletions.
  1. +1 −0 setup.py
  2. +1 −0 webkit2png.egg-info/SOURCES.txt
  3. +1 −1 webkit2png.egg-info/top_level.txt
  4. +34 −2 webkit2png.py
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
author_email = 'roland at dau-sicher de',
packages = find_packages(),
package_dir = {'webkit2png': 'webkit2png'},
py_modules = ['webkit2png'],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
1 change: 1 addition & 0 deletions webkit2png.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
setup.py
webkit2png.py
webkit2png.egg-info/PKG-INFO
webkit2png.egg-info/SOURCES.txt
webkit2png.egg-info/dependency_links.txt
2 changes: 1 addition & 1 deletion webkit2png.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@

webkit2png
36 changes: 34 additions & 2 deletions webkit2png.py
Original file line number Diff line number Diff line change
@@ -115,11 +115,15 @@ def __init__(self,**kwargs):
self.scaleToWidth = kwargs.get('scaleToWidth', 0)
self.scaleToHeight = kwargs.get('scaleToHeight', 0)
self.scaleRatio = kwargs.get('scaleRatio', 'keep')
self.scaleTransform = kwargs.get('scaleTransform', 'fast')
# Set this to true if you want to capture flash.
# Not that your desktop must be large enough for
# fitting the whole window.
self.grabWholeWindow = kwargs.get('grabWholeWindow', False)

self.ignoreAlerts = kwargs.get('ignoreAlerts', False)
self.ignoreConfirms = kwargs.get('ignoreConfirms', False)
self.ignoreConsoleMessages = kwargs.get('ignoreConsoleMessages', False)

# Set some default options for QWebPage
self.qWebSettings = {
@@ -164,6 +168,28 @@ def render_to_bytes(self, url):
image.save(qBuffer, format)
return qBuffer.buffer().data()

class ConfigurableWebPage(QWebPage):
def __init__(self, parent=None, ignoreAlerts=False, ignoreConfirms=False, ignoreConsoleMessages=False):
super(ConfigurableWebPage, self).__init__(parent)
self.ignoreAlerts = ignoreAlerts
self.ignoreConfirms = ignoreConfirms
self.ignoreConsoleMessages = ignoreConsoleMessages

def javaScriptAlert(self, frame, msg):
if not self.ignoreAlerts:
return super(ConfigurableWebPage, self).javaScriptAlert(frame, msg)

def javaScriptConfirm(self, frame, msg):
if not self.ignoreConfirms:
return super(ConfigurableWebPage, self).javaScriptConfirm(frame, msg)
else:
return False

def javaScriptConsoleMessage(self, message, lineNumber, sourceID):
if not self.ignoreConsoleMessages:
return super(ConfigurableWebPage, self).javaScriptConsoleMessage(message, lineNumber, sourceID)


class _WebkitRendererHelper(QObject):
"""This helper class is doing the real work. It is required to
allow WebkitRenderer.render() to be called "asynchronously"
@@ -182,7 +208,7 @@ def __init__(self, parent):
setattr(self,key,value)

# Create and connect required PyQt4 objects
self._page = QWebPage()
self._page = ConfigurableWebPage(None, self.ignoreAlerts, self.ignoreConfirms, self.ignoreConsoleMessages)
self._view = QWebView()
self._view.setPage(self._page)
self._window = QMainWindow()
@@ -301,7 +327,13 @@ def _post_process_image(self, qImage):
ratio = Qt.KeepAspectRatioByExpanding
else: # 'ignore'
ratio = Qt.IgnoreAspectRatio
qImage = qImage.scaled(self.scaleToWidth, self.scaleToHeight, ratio)

if self.scaleTransform == 'smooth':
transform = Qt.SmoothTransformation
else:
transform = Qt.FastTransformation

qImage = qImage.scaled(self.scaleToWidth, self.scaleToHeight, ratio, transform)
if self.scaleRatio == 'crop':
qImage = qImage.copy(0, 0, self.scaleToWidth, self.scaleToHeight)
return qImage