Beispiel #1
0
class GLWidgetPlugin(GLPluginBase):
    """A GL plugin that sends user events to one or more Klamp't widgets"""
    def __init__(self):
        GLPluginBase.__init__(self)
        self.klamptwidgetbutton = 2
        self.klamptwidgetmaster = WidgetSet()
        self.klamptwidgetdragging = False

    def addWidget(self, widget):
        self.klamptwidgetmaster.add(widget)

    def display(self):
        self.klamptwidgetmaster.drawGL(self.viewport())
        return False

    def keyboardfunc(self, c, x, y):
        self.klamptwidgetmaster.keypress(c)
        return False

    def keyboardupfunc(self, c, x, y):
        return False

    def specialfunc(self, c, x, y):
        self.klamptwidgetmaster.keypress(c)
        return False

    def specialupfunc(self, c, x, y):
        return False

    def mousefunc(self, button, state, x, y):
        if button == self.klamptwidgetbutton:
            if state == 0:  #down
                if self.klamptwidgetmaster.beginDrag(x, self.height - y,
                                                     self.viewport()):
                    self.klamptwidgetdragging = True
            else:
                if self.klamptwidgetdragging:
                    self.klamptwidgetmaster.endDrag()
                self.klamptwidgetdragging = False
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        return False

    def motionfunc(self, x, y, dx, dy):
        if self.klamptwidgetdragging:
            self.klamptwidgetmaster.drag(dx, -dy, self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        else:
            self.klamptwidgetmaster.hover(x, self.height - y, self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
        return False

    def idlefunc(self):
        self.klamptwidgetmaster.idle()
        return True
Beispiel #2
0
class GLWidgetPlugin(GLPluginBase):
    """A GL plugin that sends user events to one or more Klamp't widgets"""    
    def __init__(self):
        GLPluginBase.__init__(self)
        self.klamptwidgetbutton = 2
        self.klamptwidgetmaster = WidgetSet()
        self.klamptwidgetdragging = False
    def addWidget(self,widget):
        self.klamptwidgetmaster.add(widget)
    def display(self):
        self.klamptwidgetmaster.drawGL(self.viewport())
    def keyboardfunc(self,c,x,y):
        self.klamptwidgetmaster.keypress(c)
        return False
    def keyboardupfunc(self,c,x,y):
        return False
    def specialfunc(self,c,x,y):
        self.klamptwidgetmaster.keypress(c)
        return False
    def specialupfunc(self,c,x,y):
        return False
    def mousefunc(self,button,state,x,y):
        if button == self.klamptwidgetbutton:
            if state == 0:  #down
                if self.klamptwidgetmaster.beginDrag(x,self.height-y,self.viewport()):
                    self.klamptwidgetdragging = True
            else:
                if self.klamptwidgetdragging:
                    self.klamptwidgetmaster.endDrag()
                self.klamptwidgetdragging = False
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        return False
    def motionfunc(self,x,y,dx,dy):
        if self.klamptwidgetdragging:
            self.klamptwidgetmaster.drag(dx,-dy,self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        else:
            self.klamptwidgetmaster.hover(x,self.height-y,self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
        return False
    def idlefunc(self):
        self.klamptwidgetmaster.idle()
        return True
class _VisualEditorBase:
    #A base class for editing resources.

    def __init__(self, name, value, description, world):
        self.name = name
        self.value = value
        self.description = description
        self.world = world
        self.qtwidget = None
        self.width = 100
        self.height = 100
        self.klamptwidgetbutton = 2
        self.klamptwidgetmaster = WidgetSet()
        self.klamptwidgetdragging = False
        #refresh appearances for new OpenGL context
        #for i in range(world.numIDs()):
        #    world.appearance(i).refresh()
    def addWidget(self, widget):
        self.klamptwidgetmaster.add(widget)

    def instructions(self):
        return None

    def display(self):
        if self.world: self.world.drawGL()
        self.klamptwidgetmaster.drawGL(self.viewport())

    def display_screen(self):
        glDisable(GL_LIGHTING)
        glColor3f(0, 0, 0)
        h = 30
        """
        if self.instructions() != None:
            glRasterPos(20,h)
            gldraw.glutBitmapString(GLUT_BITMAP_HELVETICA_12,"Instructions: "+self.instructions())
            h += 20
        if self.description != None:
            glRasterPos(20,h)
            gldraw.glutBitmapString(GLUT_BITMAP_HELVETICA_12,"Description: "+self.description)
            h += 20
        glRasterPos(20,h)
        gldraw.glutBitmapString(GLUT_BITMAP_HELVETICA_12,"Press 'x' to exit without saving, 'q' to save+exit")
        """

    def viewport(self):
        return self.qtwidget.viewport()

    def idlesleep(self, seconds):
        self.qtwidget.idlesleep(seconds)

    def refresh(self):
        self.qtwidget.refresh()

    def click_ray(self, x, y):
        return self.qtwidget.click_ray(x, y)

    def initialize(self):
        return False

    def reshapefunc(self, w, h):
        self.width, self.height = w, h
        return False

    def keyboardfunc(self, c, x, y):
        self.klamptwidgetmaster.keypress(c)
        return False

    def keyboardupfunc(self, c, x, y):
        return False

    def specialfunc(self, c, x, y):
        self.klamptwidgetmaster.keypress(c)
        return False

    def specialupfunc(self, c, x, y):
        return False

    def mousefunc(self, button, state, x, y):
        if button == self.klamptwidgetbutton:
            if state == 0:  #down
                if self.klamptwidgetmaster.beginDrag(x, self.height - y,
                                                     self.viewport()):
                    self.klamptwidgetdragging = True
            else:
                if self.klamptwidgetdragging:
                    self.klamptwidgetmaster.endDrag()
                self.klamptwidgetdragging = False
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        return False

    def motionfunc(self, x, y, dx, dy):
        if self.klamptwidgetdragging:
            self.klamptwidgetmaster.drag(dx, -dy, self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        else:
            self.klamptwidgetmaster.hover(x, self.height - y, self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
        return False

    def idlefunc(self):
        self.klamptwidgetmaster.idle()
        return True
Beispiel #4
0
class GLWidgetProgram(GLRealtimeProgram):
    """A base class for using widgets.  Right-clicks are passed onto widgets.
    
    Subclasses should call self.widgetMaster.add() upon initializiation to
    add widgets to the program.
    """
    def __init__(self,world,name="My GL Widget Program"):
        GLRealtimeProgram.__init__(self,name)
        self.world = world
        self.widgetMaster = WidgetSet()
        self.widgetButton = 2  #right-clicks are sent to widget
        self.draggingWidget = False
        self.verbose = 0

    def display(self):
        #Put your display handler here
        """
        #the next few lines draw everything but the robot
        for i in xrange(self.world.numTerrains()):
            self.world.terrain(i).drawGL()
        for i in xrange(self.world.numRigidObjects()):
            self.world.rigidObject(i).drawGL()
        for i in xrange(1,self.world.numRobots()):
            self.world.robot(i).drawGL()
        #TEMP: the widget master will draw the robot if a RobotPoseWidget
        #is added... but what if there is no such widget?
        """
        self.world.drawGL()
        self.widgetMaster.drawGL(self.viewport())

    def idle(self):
        self.widgetMaster.idle()
        if self.widgetMaster.wantsRedraw():
            self.refresh()

    def mousefunc(self,button,state,x,y):
        if self.verbose: print "mouse",button,state,x,y
        if button==self.widgetButton:
            if state==0:
                if self.widgetMaster.beginDrag(x,self.height-y,self.viewport()):
                    self.draggingWidget = True
            else:
                if self.draggingWidget:
                    self.widgetMaster.endDrag()
                    self.draggingWidget = False
            if self.widgetMaster.wantsRedraw():
                self.refresh()
            self.lastx,self.lasty = x,y
            return
        GLRealtimeProgram.mousefunc(self,button,state,x,y)

    def motionfunc(self,x,y,dx,dy):
        if self.draggingWidget:
            self.widgetMaster.drag(dx,-dy,self.viewport())
            if self.widgetMaster.wantsRedraw():
                self.refresh()
        else:
            res = self.widgetMaster.hover(x,self.height-y,self.viewport())
            if self.widgetMaster.wantsRedraw():
                self.refresh()
            GLRealtimeProgram.motionfunc(self,x,y,dx,dy)

    def specialfunc(self,c,x,y):
        #Put your keyboard special character handler here
        if self.verbose: print c,"pressed"
        self.widgetMaster.keypress(c)
        self.refresh()

    def keyboardfunc(self,c,x,y):
        #Put your keyboard handler here
        #the current example toggles simulation / movie mode
        if self.verbose: print c,"pressed"
        self.widgetMaster.keypress(c)
        self.refresh()
class _VisualEditorBase:
    #A base class for editing resources.
    
    def __init__(self,name,value,description,world):
        self.name = name
        self.value = value
        self.description = description
        self.world = world
        self.qtwidget = None
        self.width = 100
        self.height = 100
        self.klamptwidgetbutton = 2
        self.klamptwidgetmaster = WidgetSet()
        self.klamptwidgetdragging = False
        #refresh appearances for new OpenGL context
        #for i in xrange(world.numIDs()):
        #    world.appearance(i).refresh()
    def addWidget(self,widget):
        self.klamptwidgetmaster.add(widget)
    def instructions(self):
        return None
    def display(self):
        if self.world: self.world.drawGL()
        self.klamptwidgetmaster.drawGL(self.viewport())
    def display_screen(self):
        glDisable(GL_LIGHTING)
        glColor3f(0,0,0)
        h = 30
        """
        if self.instructions() != None:
            glRasterPos(20,h)
            gldraw.glutBitmapString(GLUT_BITMAP_HELVETICA_12,"Instructions: "+self.instructions())
            h += 20
        if self.description != None:
            glRasterPos(20,h)
            gldraw.glutBitmapString(GLUT_BITMAP_HELVETICA_12,"Description: "+self.description)
            h += 20
        glRasterPos(20,h)
        gldraw.glutBitmapString(GLUT_BITMAP_HELVETICA_12,"Press 'x' to exit without saving, 'q' to save+exit")
        """
    def viewport(self):
        return self.qtwidget.viewport()
    def idlesleep(self,seconds):
        self.qtwidget.idlesleep(seconds)
    def refresh(self):
        self.qtwidget.refresh()
    def click_ray(self,x,y):
        return self.qtwidget.click_ray(x,y)
    def initialize(self):
        return False
    def reshapefunc(self,w,h):
        self.width,self.height = w,h
        return False
    def keyboardfunc(self,c,x,y):
        self.klamptwidgetmaster.keypress(c)
        return False
    def keyboardupfunc(self,c,x,y):
        return False
    def specialfunc(self,c,x,y):
        self.klamptwidgetmaster.keypress(c)
        return False
    def specialupfunc(self,c,x,y):
        return False
    def mousefunc(self,button,state,x,y):
        if button == self.klamptwidgetbutton:
            if state == 0:  #down
                if self.klamptwidgetmaster.beginDrag(x,self.height-y,self.viewport()):
                    self.klamptwidgetdragging = True
            else:
                if self.klamptwidgetdragging:
                    self.klamptwidgetmaster.endDrag()
                self.klamptwidgetdragging = False
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        return False
    def motionfunc(self,x,y,dx,dy):
        if self.klamptwidgetdragging:
            self.klamptwidgetmaster.drag(dx,-dy,self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
            return True
        else:
            self.klamptwidgetmaster.hover(x,self.height-y,self.viewport())
            if self.klamptwidgetmaster.wantsRedraw():
                self.refresh()
        return False
    def idlefunc(self):
        self.klamptwidgetmaster.idle()
        return True
Beispiel #6
0
class GLWidgetProgram(GLRealtimeProgram):
    """A base class for using widgets.  Right-clicks are passed onto widgets.
    
    Subclasses should call self.widgetMaster.add() upon initializiation to
    add widgets to the program.
    """

    def __init__(self, world, name="My GL Widget Program"):
        GLRealtimeProgram.__init__(self, name)
        self.world = world
        self.widgetMaster = WidgetSet()
        self.widgetButton = 2  # right-clicks are sent to widget
        self.draggingWidget = False
        self.verbose = 0

    def display(self):
        # Put your display handler here
        """
        #the next few lines draw everything but the robot
        for i in xrange(self.world.numTerrains()):
            self.world.terrain(i).drawGL()
        for i in xrange(self.world.numRigidObjects()):
            self.world.rigidObject(i).drawGL()
        for i in xrange(1,self.world.numRobots()):
            self.world.robot(i).drawGL()
        #TEMP: the widget master will draw the robot if a RobotPoseWidget
        #is added... but what if there is no such widget?
        """
        self.world.drawGL()
        self.widgetMaster.drawGL(self.viewport())

    def idle(self):
        self.widgetMaster.idle()
        if self.widgetMaster.wantsRedraw():
            self.refresh()

    def mousefunc(self, button, state, x, y):
        if self.verbose:
            print "mouse", button, state, x, y
        if button == self.widgetButton:
            if state == 0:
                if self.widgetMaster.beginDrag(x, self.height - y, self.viewport()):
                    self.draggingWidget = True
            else:
                if self.draggingWidget:
                    self.widgetMaster.endDrag()
                    self.draggingWidget = False
            if self.widgetMaster.wantsRedraw():
                self.refresh()
            self.lastx, self.lasty = x, y
            return
        GLRealtimeProgram.mousefunc(self, button, state, x, y)

    def motionfunc(self, x, y, dx, dy):
        if self.draggingWidget:
            self.widgetMaster.drag(dx, -dy, self.viewport())
            if self.widgetMaster.wantsRedraw():
                self.refresh()
        else:
            res = self.widgetMaster.hover(x, self.height - y, self.viewport())
            if self.widgetMaster.wantsRedraw():
                self.refresh()
            GLRealtimeProgram.motionfunc(self, x, y, dx, dy)

    def specialfunc(self, c, x, y):
        # Put your keyboard special character handler here
        if self.verbose:
            print c, "pressed"
        self.widgetMaster.keypress(c)
        self.refresh()

    def keyboardfunc(self, c, x, y):
        # Put your keyboard handler here
        # the current example toggles simulation / movie mode
        if self.verbose:
            print c, "pressed"
        self.widgetMaster.keypress(c)
        self.refresh()