zooui.objects.mediaobjects.tiledmediaobject module

Tiled media to be displayed in the ZUI.

class zooui.objects.mediaobjects.tiledmediaobject.TiledMediaObject(media_id, scene, autofit=True, deferred=False)[source]

Bases: MediaObject

Constructor :

TiledMediaObject(media_id, scene, autofit)

Parameters :

media_id : str scene : Scene autofit : bool

TiledMediaObject(media_id, scene, autofit) –> None

TileMedia object wraps given media_id in MediaObject type, (calling converter if necessary) so that it can be rendered in the ZUI.

If autofit is True, then once the media has loaded it will be fitted to the area occupied by the placeholder.

Supported formats: - PDF files (.pdf) via PDFConverter - PPM files (.ppm) used directly - Image files (JPG, PNG, GIF, TIFF, etc.) via VipsConverter

For any acceptable filetype the adequate converter gets called. The converter returns a ppm image file on which we can run the tiler on.

Constructor :

TiledMediaObject(media_id, scene, autofit, deferred)

Parameters :

media_id : str scene : Scene autofit : bool (default=True) deferred : bool (default=False)

TiledMediaObject(media_id, scene, autofit, deferred) –> None

Initialize a new TiledMediaObject from the media identified by media_id, the parent Scene referenced by scene, and optionally autofit behavior.

If autofit is True, once the media has loaded it will be fitted to the area occupied by the placeholder.

If deferred is True, conversion and tiling setup is skipped — the caller is responsible for initiating those operations. This is used by PdfMediaObject to manage multi-page PDFs.

Sets up conversion and tiling infrastructure based on the media file type. Initializes caching variables for tileblocks and rendering optimization.

transparent = False
Constructor:

MediaObject(media_id, scene)

Parameters :

media_id[‘string’], scene[‘Scene’]

Media_object(media_id, scene) –> PhysicalObject

MediaObject objects are used to represent media that can be rendered in the ZUI.

Screen view it’s fixed unless user change mainwindow size on the screen. Both scene and MediaObjects have their own reference systems so that zooms can be applied bot to Scene and Mediaobject indipendently trough their reference system transformation.

You can think about it as fixed window looking at a scene that can strecth or shrink beneath it, with this stretch or shrink always having it’s origin at the Scene center for scene zoom and MediaObject center for the mediobject zoom as at the same time individual mediaobject can also strecth or shrink. The fixed window can then move on the 2d plane bringing objects into view.

World:

 --------------------------------------->
|   Scene
|  @ ------------------------------+--->
|  |  ViewPort        MediaObj     |
|  |  (Screen View)   *-------+--> |
|  |                  |   &   |    |
|  |               %  +-------"    |
|  |                  |            |
|  |                  ∨            |
|  |                               |
|  +-------------------------------#
|  |
|  ∨
∨

Legend:

(All attributes are relative to screen view)
* -> MediaObject.topleft()
" -> MediaObject.bottomright()
& -> MediaObject.center()
# -> Scene.viewport_size()
% -> Scene.center()
@ -> Scene.origin()

MediaObject topleft coordinates relative to screen view are given by:

MediaObject.topleft[0-1] = self._scene.origin[0-1] + self.pos[0-1] * (2 ** self._scene.zoomlevel)

Where self.pos[0-1] it’s MediaObject position relative to Scene reference system wich get’s scaled by math.exp2() of scene zoom level

MediaObject centre coordinates relative to screen view are given firstly by calculating image center coordinates relative to Scene reference coordinates:

C_s[0-1] = self.pos[0-1] + self._centre[0-1] * math.exp2(self._z)

Where self._centre[0-1] are center coordinates relative to the mediaobject frame of reference and self._z it’s MediaObject reference frame scaling (zoom).

Take note that self.pos[0-1] dosen’t get to be scaled by self._z as that position it’s relative to Scene reference frame.

Then we can calculate MediaObject centre coordinates relative to screen view as:

MediaObject.centre[0-1] = self._scene.origin[0] + C_s[0-1] * math.exp2(self._scene.zoomlevel)
default_size = (256, 256)
tempcache = 5
_reset_for_page(new_media_id)[source]
Method :

_reset_for_page(new_media_id)

Parameters :

new_media_id : str

_reset_for_page(new_media_id) –> None

Reset internal state and switch to a different media_id for page navigation. Invalidates all cached tileblocks, then starts loading the root tile for the new media_id.

Dimension data (width, height, aspect_ratio, maxtilelevel) is kept from the previous page so that the bounding box for autofit is computed correctly during the transition.

Used by PdfMediaObject when changing pages.

property __progress
Property:

__progress

Parameters :

None

__progress –> float

Calculate and return the current loading progress as a float between 0.0 and 1.0.

If only tiler is active, returns tiler progress. If only converter is active, returns half of converter progress. If both are active, returns average of both progresses.

__pixpos2rowcol(pixpos, tilescale)
Method :

__pixpos2rowcol(pixpos, tilescale)

Parameters :

pixpos : Tuple[float, float] tilescale : float

__pixpos2rowcol(pixpos, tilescale) –> Tuple[int, int]

Convert the on-screen pixel position to a (row,col) tile position.

__rowcol_bound(tilelevel)
Method :

__rowcol_bound(tilelevel)

Parameters :

tilelevel : int

__rowcol_bound(tilelevel) –> Tuple[int, int]

Return the maximum row and column for the given tilelevel.

__render_tileblock(tileblock_id, mode)
Method :

__render_tileblock(tileblock_id, mode)

Parameters :

tileblock_id : Tuple[int, int, int, int, int] mode : int

__render_tileblock(tileblock_id, mode) –> QImage

Render, cache, and return the tileblock given the unique tileblock_id and render mode.

Precondition: mode is equal to either RenderMode.Draft or RenderMode.HighQuality

__render_media(painter, mode)
Method :

__render_media(painter, mode)

Parameters :

painter : QPainter mode : int

__render_media(painter, mode) –> None

Render the media using the given painter and render mode.

Precondition: mode is equal to one of the constants defined in RenderMode

Note: Size visibility is checked by the scene via is_size_visible().

__render_placeholder(painter)
Method :

__render_placeholder(painter)

Parameters :

painter : QPainter

__render_placeholder(painter) –> None

Render a placeholder indicating that the image is still loading, using the given painter.

_try_load()[source]
Method :

_try_load()

Parameters :

None

_try_load() –> None

Try to load the (0,0,0) tile from the TileManager.

__run_tiler()
Method :

__run_tiler()

Parameters :

None

__run_tiler() –> None

Run the tiler (after checking that there is an image to run the tiler on).

render(painter, mode)[source]
Method :

TiledMediaObject.render(painter, mode)

Parameters :

painter : QPainter mode : int

TiledMediaObject.render(painter, mode) –> None

Render the tiled media using the given painter and rendering mode.

If the media is loaded, renders the actual media content. Otherwise, renders a placeholder showing loading progress.

Handles tiler initialization if converter has finished but tiler hasn’t started yet.

Precondition: mode is equal to one of the constants defined in RenderMode

is_size_visible(mode)[source]

Tiled image size visibility check.

Returns False if image is too small (<= 1 pixel), otherwise returns super().is_size_visible(mode).

property onscreen_size
Property:

TiledMediaObject.onscreen_size

Parameters :

None

TiledMediaObject.onscreen_size –> Tuple[float, float]

Return the on-screen size of the tiled media.

Calculates the width and height based on aspect ratio if available, otherwise uses the actual width and height scaled by zoom levels.

Returns (0,0) if the media dimensions are not yet known.