WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Modifying Vizinfo to Support Re-parenting Tip (https://forum.worldviz.com/showthread.php?t=1757)

Gladsomebeast 12-16-2008 05:34 PM

Modifying Vizinfo to Support Re-parenting Tip
 
Flexible graphical user interfaces (GUIs) components often have a common parent node for global positioning and scale. Vizard's vizinfo module does not allow setting of vizinfo menus' parent, so one cannot incorporate them into GUI components. The following article describes how to fix the issue by adding a setParent method to a subclass of vizinfo's Info class.

http://vizworkshop.com/articles/vizinfo_reparenting.html


Here is the module that adds a setParent method to the Info class:

Code:

import viz
import vizinfo

def add(text, textsize=1.0, **kw):
        return ParentableVizInfo(text, textsize, **kw)
       
class ParentableVizInfo(vizinfo.Info):
        def __init__(self, text, textsize, parent=viz.SCREEN, scene=viz.MainScene, **kw):
                vizinfo.Info.__init__(self, text, textsize, **kw)                       
                self.setParent(newParent=parent, newScene=scene)
                if parent != viz.SCREEN:
                        #remove initial offset so info in in center of parent node, not [.95, .95, 0]
                        self.translate([0,0,0])
                       
        def setParent(self, newParent=viz.SCREEN, newScene=viz.MainScene):
                self._group.parent(newParent, newScene)
               
               
if __name__ == '__main__':
        viz.go()
        SIM_SCENE = viz.Scene2
        viz.scene(SIM_SCENE)
        node = viz.addGroup(parent=viz.SCREEN, pos=[.5, .5, 0], scene=SIM_SCENE)
        add('test asdafasdf', parent=node, scene=SIM_SCENE)



All times are GMT -7. The time now is 05:24 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC