def __init__(self, *args): GtkGLExtVTKRenderWindowBase.__init__(self) self._CurrentRenderer = None self._CurrentCamera = None self._CurrentZoom = 1.0 self._CurrentLight = None self._ViewportCenterX = 0 self._ViewportCenterY = 0 self._Picker = vtkCellPicker() self._PickedAssembly = None self._PickedProperty = vtkProperty() self._PickedProperty.SetColor(1, 0, 0) self._PrePickedProperty = None self._OldFocus = None # these record the previous mouse position self._LastX = 0 self._LastY = 0
def __init__(self, parent, ID, *args, **kw): """Default class constructor. @param parent: parent window @param ID: window id @param **kw: wxPython keywords (position, size, style) plus the 'stereo' keyword """ # miscellaneous protected variables self._CurrentRenderer = None self._CurrentCamera = None self._CurrentZoom = 1.0 self._CurrentLight = None self._ViewportCenterX = 0 self._ViewportCenterY = 0 self._Picker = vtkCellPicker() self._PickedActor = None self._PickedProperty = vtkProperty() self._PickedProperty.SetColor(1,0,0) self._PrePickedProperty = None # these record the previous mouse position self._LastX = 0 self._LastY = 0 # the current interaction mode (Rotate, Pan, Zoom, etc) self._Mode = None self._ActiveButton = None # private attributes self.__OldFocus = None # used by the LOD actors self._DesiredUpdateRate = 15 self._StillUpdateRate = 0.0001 # First do special handling of some keywords: # stereo, position, size, width, height, style try: stereo = bool(kw['stereo']) del kw['stereo'] except KeyError: stereo = False try: position = kw['position'] del kw['position'] except KeyError: position = wx.DefaultPosition try: size = kw['size'] del kw['size'] except KeyError: try: size = parent.GetSize() except AttributeError: size = wx.DefaultSize # wx.WANTS_CHARS says to give us e.g. TAB # wx.NO_FULL_REPAINT_ON_RESIZE cuts down resize flicker under GTK style = wx.WANTS_CHARS | wx.NO_FULL_REPAINT_ON_RESIZE try: style = style | kw['style'] del kw['style'] except KeyError: pass # the enclosing frame must be shown under GTK or the windows # don't connect together properly l = [] p = parent while p: # make a list of all parents l.append(p) p = p.GetParent() l.reverse() # sort list into descending order for p in l: p.Show(1) # initialize the wx.Window if baseClass.__name__ == 'GLCanvas': # Set the doublebuffer attribute of the GL canvas. baseClass.__init__(self, parent, ID, pos=position, size=size, style=style, attribList=[wx.glcanvas.WX_GL_DOUBLEBUFFER]) else: baseClass.__init__(self, parent, ID, pos=position, size=size, style=style) # create the RenderWindow and initialize it self._RenderWindow = vtkRenderWindow() self._RenderWindow.SetSize(size.width, size.height) if stereo: self._RenderWindow.StereoCapableWindowOn() self._RenderWindow.SetStereoTypeToCrystalEyes() self.__handle = None # refresh window by doing a Render self.Bind(wx.EVT_PAINT, self.OnPaint) # turn off background erase to reduce flicker self.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None) # Bind the events to the event converters self.Bind(wx.EVT_RIGHT_DOWN, self._OnButtonDown) self.Bind(wx.EVT_LEFT_DOWN, self._OnButtonDown) self.Bind(wx.EVT_MIDDLE_DOWN, self._OnButtonDown) self.Bind(wx.EVT_RIGHT_UP, self._OnButtonUp) self.Bind(wx.EVT_LEFT_UP, self._OnButtonUp) self.Bind(wx.EVT_MIDDLE_UP, self._OnButtonUp) self.Bind(wx.EVT_MOTION, self.OnMotion) self.Bind(wx.EVT_ENTER_WINDOW, self._OnEnterWindow) self.Bind(wx.EVT_LEAVE_WINDOW, self._OnLeaveWindow) self.Bind(wx.EVT_CHAR, self.OnChar) # If we use EVT_KEY_DOWN instead of EVT_CHAR, capital versions # of all characters are always returned. EVT_CHAR also performs # other necessary keyboard-dependent translations. self.Bind(wx.EVT_CHAR, self.OnKeyDown) self.Bind(wx.EVT_KEY_UP, self.OnKeyUp) self.Bind(wx.EVT_SIZE, self._OnSize) self.Bind(wx.EVT_MOVE, self.OnMove) self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
def __init__(self, master, cnf={}, **kw): """ Constructor. Keyword arguments: rw -- Use passed render window instead of creating a new one. stereo -- If True, generate a stereo-capable window. Defaults to False. focus_on_enter -- If True, use a focus-follows-mouse mode. Defaults to False where the widget will use a click-to-focus mode. """ # load the necessary extensions into tk vtkLoadPythonTkWidgets(master.tk) try: # check to see if a render window was specified renderWindow = kw['rw'] except KeyError: renderWindow = vtkRenderWindow() try: # was a stereo rendering context requested? if kw['stereo']: renderWindow.StereoCapableWindowOn() del kw['stereo'] except KeyError: pass # check if focus should follow mouse if kw.get('focus_on_enter'): self._FocusOnEnter = 1 del kw['focus_on_enter'] else: self._FocusOnEnter = 0 kw['rw'] = renderWindow.GetAddressAsString("vtkRenderWindow") tkinter.Widget.__init__(self, master, 'vtkTkRenderWidget', cnf, kw) self._CurrentRenderer = None self._CurrentCamera = None self._CurrentZoom = 1.0 self._CurrentLight = None self._ViewportCenterX = 0 self._ViewportCenterY = 0 self._Picker = vtkCellPicker() self._PickedAssembly = None self._PickedProperty = vtkProperty() self._PickedProperty.SetColor(1,0,0) self._PrePickedProperty = None self._OldFocus = None # used by the LOD actors self._DesiredUpdateRate = 15 self._StillUpdateRate = 0.0001 # these record the previous mouse position self._LastX = 0 self._LastY = 0 # private attributes self.__InExpose = 0 # create the Tk bindings self.BindTkRenderWidget()