Created
January 21, 2013 02:01
-
-
Save KelSolaar/4583102 to your computer and use it in GitHub Desktop.
sIBL_GUI - Editor Capture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
from PyQt4.QtCore import * | |
from PyQt4.QtGui import * | |
import foundations.walkers | |
import foundations.common | |
def captureEditorPages(editor, outputDirectory, prefix): | |
viewport = editor.viewport() | |
scrollBar = editor.verticalScrollBar() | |
scrollBar.setValue(0) | |
pages = [] | |
frame = 1 | |
while not scrollBar.maximum() == scrollBar.value(): | |
pixmap = QPixmap(viewport.size()) | |
viewport.render(pixmap) | |
path = os.path.join(outputDirectory, "{0}{1:0>4}.png".format(prefix, frame)) | |
pages.append(path) | |
image = QFile(path) | |
image.open(QIODevice.WriteOnly) | |
pixmap.save(image, "PNG") | |
scrollBar.setValue(scrollBar.value() + scrollBar.pageStep()) | |
frame += 1 | |
return pages | |
def stitchEditorPages(pages, baseOffset): | |
firstPage = foundations.common.getFirstItem(pages) | |
pixmap = QPixmap() | |
pixmap.load(firstPage) | |
width, height = pixmap.size().width(), pixmap.size().height() | |
stichedPixmap = QPixmap(QSize(width, height * len(pages) - (baseOffset * (len(pages) - 1)) + baseOffset / 2)) | |
painter = QPainter(stichedPixmap) | |
painter.drawPixmap(0, 0, pixmap) | |
offset = baseOffset / 2 | |
for i, page in enumerate(pages[1:]): | |
pixmap.load(page) | |
painter.drawPixmap(0, height + (i * height) - offset, pixmap) | |
offset += baseOffset | |
painter.end() | |
image = QFile(os.path.join(os.path.dirname(firstPage), "Stiched.png")) | |
image.open(QIODevice.WriteOnly) | |
stichedPixmap.save(image, "PNG") | |
def printChecker(): | |
counter = 20 | |
increment = 1 | |
for i in range(400): | |
if i % 20 == 0: | |
increment = -increment | |
print "# {0}|-| {1} {2}".format(" " * counter, i, "-" * (i / 10)) | |
counter += increment | |
DIRECTORY = "/Users/kelsolaar/Downloads/temp" | |
PREFIX = "Editor." | |
scriptEditor = componentsManager["factory.scriptEditor"] | |
scriptEditor.setCurrentEditor("/Users/kelsolaar/Documents/Development/sIBL_GUI/sibl_gui/components/core/inspector/inspector.py") | |
editor = scriptEditor.getCurrentEditor() | |
stitchEditorPages(captureEditorPages(editor, DIRECTORY, PREFIX), 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment