diff --git a/wrp.py b/wrp.py index c984dc6..7cba619 100755 --- a/wrp.py +++ b/wrp.py @@ -210,18 +210,45 @@ if sys.platform == "linux" or sys.platform == "linux2": httpout = WebkitRenderer.httpout + frame = self._view.page().currentFrame() + web_url = frame.url().toString() + # Write URL map httpout.write("\n" - "\n\n" - "\"webrender\"\n" - "\n" % (__version__, WebkitRenderer.req_jpg)) - frame = self._view.page().currentFrame() + % (__version__)) + httpout.write("\n" + % (WebkitRenderer.req_url, web_url)) + httpout.write("WRP%s:%s\n\n" + % (__version__, web_url)) + + if ISMAP == "true": + httpout.write("" + "\"wrp-render\"\n" + "\n" % (WebkitRenderer.req_map, WebkitRenderer.req_jpg)) + mapfile = StringIO.StringIO() + mapfile.write("default %s\n" % (web_url)) + else: + httpout.write("\"wrp-render\"\n" + "\n" % (WebkitRenderer.req_jpg)) + for x in frame.findAllElements('a'): - value = x.attribute('href') + turl = QUrl(web_url).resolved(QUrl(x.attribute('href'))).toString() xmin, ymin, xmax, ymax = x.geometry().getCoords() - httpout.write("\"%s\"" - "\n" % (xmin, ymin, xmax, ymax, value, value)) - httpout.write("\n\n\n") + if ISMAP == "true": + mapfile.write("rect %s %i,%i %i,%i\n" % (turl, xmin, ymin, xmax, ymax)) + else: + httpout.write("\"%s\"\n" + % (xmin, ymin, xmax, ymax, turl, turl)) + + if ISMAP != "true": + httpout.write("\n") + + httpout.write("\n\n") + + if ISMAP == "true": + RENDERS[WebkitRenderer.req_map] = mapfile return image @@ -355,10 +382,10 @@ if sys.platform == "linux" or sys.platform == "linux2": while True: req = REQ.get() WebkitRenderer.httpout = req[0] - rurl = req[1] + WebkitRenderer.req_url = req[1] WebkitRenderer.req_jpg = req[2] WebkitRenderer.req_map = req[3] - if rurl == "http://wrp.stop/": + if WebkitRenderer.req_url == "http://wrp.stop/": print ">>> Terminate Request Received" QApplication.exit(0) break @@ -372,7 +399,7 @@ if sys.platform == "linux" or sys.platform == "linux2": renderer.wait = WAIT renderer.grabWholeWindow = False - image = renderer.render(rurl) + image = renderer.render(WebkitRenderer.req_url) qBuffer = QBuffer() image.save(qBuffer, 'jpg', QUALITY) @@ -606,16 +633,19 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): default_url = re.match(r"\S+\s+(\S+)", line).group(1) elif re.match(r"(\S+)", line).group(1) == "rect": - rect = re.match(r"(\S+)\s+(\S+)\s+(\d+),(\d+)\s+(\d+),(\d+)", line) - min_x = int(rect.group(3)) - min_y = int(rect.group(4)) - max_x = int(rect.group(5)) - max_y = int(rect.group(6)) - if (req_x >= min_x) and \ - (req_x <= max_x) and \ - (req_y >= min_y) and \ - (req_y <= max_y): - goto_url = rect.group(2) + try: + rect = re.match(r"(\S+)\s+(\S+)\s+(\d+),(\d+)\s+(\d+),(\d+)", line) + min_x = int(rect.group(3)) + min_y = int(rect.group(4)) + max_x = int(rect.group(5)) + max_y = int(rect.group(6)) + if (req_x >= min_x) and \ + (req_x <= max_x) and \ + (req_y >= min_y) and \ + (req_y <= max_y): + goto_url = rect.group(2) + except AttributeError: + pass if goto_url == "none": goto_url = default_url