308 if accepted: |
308 if accepted: |
309 request.accept() |
309 request.accept() |
310 else: |
310 else: |
311 request.reject() |
311 request.reject() |
312 |
312 |
313 def printPage(self, printer): |
313 def execPrintPage(self, printer, timeout=1000): |
314 """ |
314 """ |
315 Public method to print the current page. |
315 Public method to execute a synchronous print. |
316 |
|
317 Note: This is just a wrapper around QWebEnginePage.print() to ensure |
|
318 the printer object is available until the print job finished. |
|
319 |
316 |
320 @param printer reference to the printer object |
317 @param printer reference to the printer object |
321 @type QPrinter |
318 @type QPrinter |
322 """ |
319 @param timeout timeout value in milliseconds |
323 self.__printer = printer |
320 @type int |
324 self.print(self.__printer, self.__printFinished) |
321 @return flag indicating a successful print job |
325 |
322 @rtype bool |
326 def __printFinished(self, ok): |
323 """ |
327 """ |
324 loop = QEventLoop() |
328 Private method called when the print job finished. |
325 resultDict = {"res": None} |
329 |
326 QTimer.singleShot(timeout, loop.quit) |
330 @param ok flag indicating a successful print |
327 |
331 @type bool |
328 def printCallback(res, resDict=resultDict): |
332 """ |
329 if loop and loop.isRunning(): |
333 self.__printer = None |
330 resDict["res"] = res |
|
331 loop.quit() |
|
332 |
|
333 self.print(printer, printCallback) |
|
334 |
|
335 loop.exec_() |
|
336 return resultDict["res"] |
334 |
337 |
335 ############################################## |
338 ############################################## |
336 ## Methods below deal with JavaScript messages |
339 ## Methods below deal with JavaScript messages |
337 ############################################## |
340 ############################################## |
338 |
341 |