zooui.objects.mediaobjects.svgmediaobject module¶
SVG objects to be displayed in the ZUI.
- class zooui.objects.mediaobjects.svgmediaobject.SVGMediaObject(media_id, scene)[source]¶
Bases:
MediaObject- Constructor :
SVGMediaObject(media_id, scene)
- Parameters :
media_id : str scene : Scene
SVGMediaObject(media_id, scene) –> None
SVGMediaObject objects are used to represent SVG images that can be rendered in the ZUI.
- Constructor :
SVGMediaObject(media_id, scene)
- Parameters :
media_id : str (can be file path or cache hash starting with
'svg_') scene : Scene
SVGMediaObject(media_id, scene) –> None
Initialize a new SVGMediaObject from the SVG file identified by media_id, and the parent Scene referenced by scene.
Creates a QSvgRenderer and attempts to load the SVG file. Raises LoadError if the SVG file cannot be parsed.
Stores the default width and height of the SVG image for rendering calculations.
- __get_svg_load_path(media_id)¶
Get the file path to load SVG from, handling cache hashes.
- Parameters:
media_id – Either a file path or cache hash (starting with
'svg_')- Returns:
File path to load
- transparent = True¶
- 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)
- MAX_EMBEDDED_SVG_SIZE_BYTES = 1048576¶
- render(painter, mode)[source]¶
- Method :
SVGMediaObject.render(painter, mode)
- Parameters :
painter : QPainter mode : int
SVGMediaObject.render(painter, mode) –> None
Render the SVG image using the given painter and render mode.
Note: Size visibility is checked by the scene via is_size_visible().
- is_size_visible(mode)[source]¶
SVG-specific size visibility check.
Returns False if SVG is too small or too large to be visible, otherwise returns super().is_size_visible(mode).
- property onscreen_size¶
- Property:
SVGMediaObject.onscreen_size
- Parameters :
None
SVGMediaObject.onscreen_size –> Tuple[float, float]
Return the on-screen size of the SVG image.
Multiplies the SVG’s native width and height by the current scale factor. The scale factor is derived from the combined scene and object zoom levels.
Uses caching to avoid recalculating size on every access.
- property is_modified¶
Check if SVG has been modified.
- property original_file_path¶
Get original file path if SVG was loaded from file.
- get_svg_content()[source]¶
Get current SVG content with caching. Returns None if content cannot be retrieved.
See Also¶
zooui/objects/mediaobjects/mediaobject - Base MediaObject class
zooui/windows/dialogwindows/modifysvginputdialog - Dialog for modifying SVG objects
zooui/windows/dialogwindows/svgpickerinputdialog - Dialog for selecting new SVG objects
../../usageinstructions/svgfeatures - User guide for SVG features