RPC Callback to render a view and obtain the rendered image.
(self, options)
| 435 | # Internal function since the reply[image] is not |
| 436 | # JSON(serializable) it can not be an RPC one |
| 437 | def stillRender(self, options): |
| 438 | """ |
| 439 | RPC Callback to render a view and obtain the rendered image. |
| 440 | """ |
| 441 | beginTime = int(round(time.time() * 1000)) |
| 442 | view = self.getView(options["view"]) |
| 443 | size = view.GetSize()[0:2] |
| 444 | resize = size != options.get("size", size) |
| 445 | if resize: |
| 446 | size = options["size"] |
| 447 | if size[0] > 10 and size[1] > 10: |
| 448 | view.SetSize(size) |
| 449 | t = 0 |
| 450 | if options and "mtime" in options: |
| 451 | t = options["mtime"] |
| 452 | quality = 100 |
| 453 | if options and "quality" in options: |
| 454 | quality = options["quality"] |
| 455 | localTime = 0 |
| 456 | if options and "localTime" in options: |
| 457 | localTime = options["localTime"] |
| 458 | reply = {} |
| 459 | app = self.getApplication() |
| 460 | if t == 0: |
| 461 | app.InvalidateCache(view) |
| 462 | if self.decode: |
| 463 | stillRender = app.StillRenderToString |
| 464 | else: |
| 465 | stillRender = app.StillRenderToBuffer |
| 466 | reply_image = stillRender(view, t, quality) |
| 467 | |
| 468 | # Check that we are getting image size we have set if not wait until we |
| 469 | # do. The render call will set the actual window size. |
| 470 | tries = 10 |
| 471 | while resize and list(view.GetSize()) != size and size != [0, 0] and tries > 0: |
| 472 | app.InvalidateCache(view) |
| 473 | reply_image = stillRender(view, t, quality) |
| 474 | tries -= 1 |
| 475 | |
| 476 | if ( |
| 477 | not resize |
| 478 | and options |
| 479 | and ("clearCache" in options) |
| 480 | and options["clearCache"] |
| 481 | ): |
| 482 | app.InvalidateCache(view) |
| 483 | reply_image = stillRender(view, t, quality) |
| 484 | |
| 485 | reply["stale"] = app.GetHasImagesBeingProcessed(view) |
| 486 | reply["mtime"] = app.GetLastStillRenderToMTime() |
| 487 | reply["size"] = view.GetSize()[0:2] |
| 488 | reply["memsize"] = reply_image.GetDataSize() if reply_image else 0 |
| 489 | reply["format"] = "jpeg;base64" if self.decode else "jpeg" |
| 490 | reply["global_id"] = str(self.getGlobalId(view)) |
| 491 | reply["localTime"] = localTime |
| 492 | if self.decode: |
| 493 | reply["image"] = reply_image |
| 494 | else: |
no test coverage detected