Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Quick commit(s) before 1.1 #29

Merged
merged 6 commits into from Apr 13, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/networkaccessmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

from PyQt4.QtGui import QDesktopServices
from PyQt4.QtCore import SIGNAL, QString, qDebug, qWarning
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkDiskCache
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkDiskCache, \
QNetworkRequest

class NetworkAccessManager(QNetworkAccessManager):
def __init__(self, diskCacheEnabled, parent = None):
Expand Down Expand Up @@ -55,6 +56,9 @@ def createRequest(self, op, req, outgoingData):
def handleFinished(self, reply):
qDebug('HTTP/1.1 Response')
qDebug(QString('URL %s' % reply.url().toString()))
code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute).toString()
if code:
qDebug('Status code: %s' % code)

headerPairs = reply.rawHeaderPairs()
for pair in headerPairs:
Expand Down
16 changes: 8 additions & 8 deletions python/phantom.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
QRect, SIGNAL, SLOT, QTimer, QUrl, QFileInfo, \
QDir, QSize, QSizeF, QTime, QEventLoop, qDebug
from PyQt4.QtGui import QPalette, QDesktopServices, qApp, QPrinter, \
QImage, QPainter, QRegion, QApplication
QImage, QPainter, QRegion, QApplication, qRgba
from PyQt4.QtWebKit import QWebSettings, QWebPage
from PyQt4.QtNetwork import QNetworkProxy, QNetworkProxyFactory

Expand All @@ -49,14 +49,14 @@ def __init__(self, args, parent = None):
self.m_page = WebPage(self)
self.m_clipRect = QRect()
# setup the values from args
self.m_script = QString.fromUtf8(args.script[0].read())
self.m_scriptFile = args.script[0].name
self.m_args = args.script[1:]
self.m_script = QString.fromUtf8(args.script.read())
self.m_scriptFile = args.script.name
self.m_args = args.script_args
self.m_upload_file = args.upload_file
autoLoadImages = False if args.load_images == 'no' else True
pluginsEnabled = True if args.load_plugins == 'yes' else False

args.script[0].close()
args.script.close()

palette = self.m_page.palette()
palette.setBrush(QPalette.Base, Qt.transparent)
Expand Down Expand Up @@ -200,7 +200,7 @@ def clipRect(self, size):
top = int(size[QString('top')])
left = int(size[QString('left')])

if w > 0 and h > 0:
if w >= 0 and h >= 0:
self.m_clipRect = QRect(left, top, w, h)

@pyqtProperty('QString')
Expand Down Expand Up @@ -287,8 +287,8 @@ def render(self, fileName):
if pageSize == '':
return False

image = QImage(bufferSize, QImage.Format_ARGB32_Premultiplied)
image.fill(Qt.transparent)
image = QImage(bufferSize, QImage.Format_ARGB32)
image.fill(qRgba(255, 255, 255, 0))
p = QPainter(image)

p.setRenderHint(QPainter.Antialiasing, True)
Expand Down
36 changes: 31 additions & 5 deletions python/pyphantomjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
if __name__ == '__main__':
# Handle all command-line options
p = argParser()
args = p.parse_args()
arg_data = p.parse_known_args(sys.argv[1:])
args = arg_data[0]
args.script_args = arg_data[1]

# register an alternative Message Handler
messageHandler = MessageHandler(args.verbose)
Expand All @@ -48,7 +50,31 @@
if len(item_buffer) == 0:
p.print_help()
sys.exit(1)
args.script = args.upload_file[i:]

# this is a bug workaround for argparse.
# if you call parse_known_args, and you
# have an --option script arg, the args
# get jumbled up, and it's inconsistent
#
# we're just going to check for -- and
# swap it all back to the right order
if args.script_args:
for i in range(len(args.upload_file)):
if not args.upload_file[i].count('='):
# insert the arg after --option
args.script_args.insert(1, args.script)
# insert value args before --option
if args.upload_file[i+1:]:
arg_buffer = args.upload_file[i+1:]
arg_buffer.reverse()
for val in arg_buffer:
args.script_args.insert(0, val)
args.script = args.upload_file[i]
break
else:
args.script = args.upload_file[i]
args.script_args = args.upload_file[i+1:]

break
item_buffer[QString(item[0])] = QString(item[1])
for tag in item_buffer:
Expand All @@ -63,14 +89,14 @@
sys.exit(1)
args.proxy = item

if len(args.script) == 0:
if not args.script:
p.print_help()
sys.exit(1)

try:
args.script[0] = open(args.script[0])
args.script = open(args.script)
except IOError as (errno, stderr):
qFatal(str(stderr) + ': \'%s\'' % args.script[0])
qFatal(str(stderr) + ': \'%s\'' % args.script)

app = QApplication(sys.argv)

Expand Down
2 changes: 1 addition & 1 deletion python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def argParser():
formatter_class=argparse.RawTextHelpFormatter
)

parser.add_argument('script', metavar='script.[js|coffee]', nargs='*',
parser.add_argument('script', metavar='script.[js|coffee]', nargs='?',
help='The script to execute, and any args to pass to it'
)
parser.add_argument('--load-images', default='yes',
Expand Down
4 changes: 4 additions & 0 deletions src/networkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ void NetworkAccessManager::handleFinished(QNetworkReply *reply)
{
qDebug() << "HTTP/1.1 Response";
qDebug() << "URL" << qPrintable(reply->url().toString());
QString code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
if (!code.isEmpty()) {
qDebug() << "Status code:" << qPrintable(code);
}
QList<QNetworkReply::RawHeaderPair> headerPairs = reply->rawHeaderPairs();
foreach ( QNetworkReply::RawHeaderPair pair, headerPairs ) {
qDebug() << pair.first << "=" << pair.second;
Expand Down
2 changes: 1 addition & 1 deletion src/phantom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void Phantom::setClipRect(const QVariantMap &size)
int top = size.value("top").toInt();
int left = size.value("left").toInt();

if (w > 0 && h > 0)
if (w >= 0 && h >= 0)
m_clipRect = QRect(left, top, w, h);
}

Expand Down