Example #1
0
    def __init__(self, parent, ID, title, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE):
        self.parent = parent
        import graphcanvas
        import graphcontext
        import config
        from pathhelper import resFile

        self.cursor2D = None
        self.timer = None
        # Load XML resources.
        self.xmlres = xrc.XmlResource(resFile("gluskap.xrc"))

        # Before we set up the frame, parse command line arguments.
        (self.cmdline_options, self.cmdline_args) = cmdline_opts()

        # Parse Port number
        try:
            portnum = int(self.cmdline_options.portnum)
        except:
            print "Port number needs to be a number. Using default: 12001."
            portnum = 12001

        if self.cmdline_options.highlight:
            config.current['global:highlight'] = True

        # Two-stage creation from an XRC frame.
        pre = wx.PreFrame()
        self.xmlres.LoadOnFrame(pre, parent, "NetcliWindow")
        self.PostCreate(pre)

        # Bind the onClose handler
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        # Bind the handlers for the interface widgets.
        XRCCTRL(self, 'RenderFPS').Bind(wx.EVT_SPINCTRL, self.OnSetFPS)
        XRCCTRL(self, 'RenderFPS').Bind(wx.EVT_TEXT, self.OnSetFPS)
        XRCCTRL(self, 'ButtonRender').Bind(wx.EVT_BUTTON, self.OnRenderOne)
        XRCCTRL(self, 'OptionEye').Bind(wx.EVT_CHOICE, self.OnEyeChoice)
        XRCCTRL(self, 'OptionFilter').Bind(wx.EVT_CHOICE, self.OnFilterChoice)

        # Bind the exit button to OnClose.
        XRCCTRL(self, 'wxID_EXIT').Bind(wx.EVT_BUTTON, self.OnClose)

        self.size = size
        self.pos = pos

        # The ContextList is all the graphs currently open
        # This will be overwritten...
        self.contexts = graphcontext.ContextList(parent=self)

        # The GraphCanvas is the GLCanvas the graph gets drawn on
        self.canvas = graphcanvas.GraphCanvas(self)

        self.xmlres.AttachUnknownControl("GLCanvas", self.canvas, self)

        self.CreateStatusBar(1)
        self.SetStatusText("Initializing...", 0)

        #wx.Image_AddHandler(wx.ICOHandler())
        log = wx.LogNull()
        self.icon = wx.Icon(resFile("GLuskap.ico"), wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)
        del log

        # Set up behaviour for when we successfully connect to the
        # remote display.
        import remoteobjs

        def deliver(x):
            self.contexts = x
            x.parent = self
            self.SetStatusText("Connected to remote context manager.", 0)

        self.handler = remoteobjs.Handler(reactor, deliver)

        factory = MyPBClientFactory()

        def onConnect():
            factory.getRootObject(
            ).addCallback(self.handler.getmaker
            ).addErrback(self.handler.error
            )
            wx.CallAfter(self.GoFullscreen)
            ConnectedNow()

        def onConnectFailed(reason):
            """
	    wx.CallAfter(wx.MessageBox,
		message = "GLuskap@%s:%d could not be contacted (%s)" % (
		    self.cmdline_options.remote_peer,
                    portnum,
		    reason.getErrorMessage(),
		),
		caption = 'Sorry',
		style = wx.ICON_ERROR,
	    )
            """
            wx.CallAfter(self.SetStatusText, "Connection to remote GLuskap failed... Trying again.")
            if isinstance(self.timer, wx.Timer):
                self.timer.Stop()
            self.timer = wx.Timer(owner=self)
            self.delay = 5000.0
            self.Bind(wx.EVT_TIMER, Connect)
            self.timer.Start(milliseconds=self.delay, oneShot=True)

        def OnConnectionLost(event):
            if isinstance(self.timer, wx.Timer):
                self.timer.Stop()
            self.contexts.active = None
            self.ShowFullScreen(False)
            self.canvas.Refresh()
            wx.CallAfter(self.SetStatusText, "Connection to remote GLuskap lost... Attempting to reconnect.")
            wx.SafeYield()
            Connect(None)

        def Connect(event):
            print "Trying to connect..."
            reactor.connectTCP(self.cmdline_options.remote_peer, portnum, factory)

        factory.setConnectionMadeHandler(onConnect)
        factory.setConnectionLost(OnConnectionLost)
        factory.setConnectionFailedHandler(onConnectFailed)

        Connect(None)
        reactor.interleave(wx.CallAfter)

        def ConnectedNow():
            # Start a timer that will refresh the GraphCanvas at 20fps.
            self.timer = wx.Timer(owner=self)
            self.fps = 20
            self.timer.Start(milliseconds=1000.0 / self.fps, oneShot=False)
            self.Bind(wx.EVT_TIMER, self.OnTick)
Example #2
0
    def __init__(self, parent, ID, title, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE):
        self.parent = parent
        import tabbar, sidebar, mainmenu, graphcanvas, graphcontext
        import inputmanager
        from pathhelper import resFile

        wx.Frame.__init__(self, parent, ID, title, pos, size, style)

        # Before we set up the frame, parse command line arguments.
        (self.cmdline_options, self.cmdline_args) = cmdline_opts()

        # set the side by side 3D to False
        config.current['global:sideBySide3D']=False

        #Check Always highlight:
        if self.cmdline_options.alwaysHighlight:
            config.current['global:highlight'] = True

        # Set up anaglyph mode if requested
        if self.cmdline_options.anaglyph:
            config.current['global:enable-anaglyph'] = True
            #	    config.current['default:show-plane'] = False
            #	    config.current['default:plane-color'] = (0.0, 0.0, 0.0)
            config.current['default:background-color'] = (0.0, 0.0, 0.0)

        # Set up jitter control if specified
        if self.cmdline_options.jitter == 175.0:
            pass
        else:
            config.current['global:jitter'] = self.cmdline_options.jitter

        # Bind the onClose handler to prompt for saving before
        # app close
        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.size = size
        self.pos = pos
        # Set Up Joystick
        try:
            self.js = wx.Joystick(0)
            if self.js.GetNumberJoysticks() > 0:
                self.haveJoystick = True
                print "Joystick Detected."
                self.xJoystickRotation = 0
                self.yJoystickRotation = 0
                self.JoystickB2 = False
                self.JoystickB4 = False
                self.pov = self.js.GetRudderMax()
            else:
                self.haveJoystick = False
        except NotImplementedError:
            print "wxJoystick not available."
            self.haveJoystick = False

        # Load Sounds:
        self.sound = EvtSounds()
        # Load Cursors:
        self.cursor2D = Cursor2D()

        # Load XML resources.
        self.xmlres = xrc.XmlResource(resFile("gluskap.xrc"))

        self.menu = mainmenu.MainMenu(self)

        # The ContextList is all the graphs currently open
        # The InteractiveCanvas is the GLCanvas the graph gets drawn on
        self.contexts = graphcontext.ContextList(parent=self)
        self.canvas = graphcanvas.InteractiveCanvas(parent=self, stereo=self.cmdline_options.stereo)

        # The Sidebar and Tabbar
        self.sidebar = sidebar.Sidebar(self)
        self.tabbar = tabbar.TabBar(self)

        boxGraphTabs = wx.BoxSizer(wx.VERTICAL)
        boxGraphTabs.Add(self.canvas, 1, wx.EXPAND)
        boxGraphTabs.Add(self.tabbar, 0, wx.EXPAND)

        boxAllControls = wx.BoxSizer(wx.HORIZONTAL)
        boxAllControls.Add(boxGraphTabs, 3, wx.EXPAND)
        boxAllControls.Add(self.sidebar, 1, wx.EXPAND)
        self.SetSizer(boxAllControls)
        self.SetAutoLayout(True)

        self.CreateStatusBar(1)
        self.SetStatusText("Welcome to GLuskap", 0)

        #this lines causes memory leeks. REmoving it seems to make everything better
        #it might be needed somewheres... but who knows?
        #wx.Image_AddHandler(wx.ICOHandler())

        log = wx.LogNull()
        self.icon = wx.Icon(resFile("GLuskap.ico"), wx.BITMAP_TYPE_ICO)
        self.SetIcon(self.icon)
        del log

        self.menuBar = wx.MenuBar()
        self.menuBar.Append(self.menu.mnuFile, "&File")
        self.menuBar.Append(self.menu.mnuEdit, "&Edit")
        self.menuBar.Append(self.menu.mnuView, "&View")
        self.menuBar.Append(self.menu.mnuTools, "&Tools")
        self.menuBar.Append(self.menu.mnuHelp, "&Help")
        self.SetMenuBar(self.menuBar)

        def startingFiles():
            if len(self.cmdline_args) > 0:
                for f in self.cmdline_args:
                    self.menu._FileOpen(filename=f)
            else:
                self.menu._FileNew()

        wx.CallAfter(startingFiles)

        # Start the reactor - only if twisted is available.
        if havetwisted:
            try:
                print "Converting", self.cmdline_options.portnum
                realport = int(self.cmdline_options.portnum)
            except:
                print "Port number needs to be a number."
                realport = 12001
            self.port = reactor.listenTCP(realport, pb.PBServerFactory(ContextServer(self.contexts)))
            reactor.interleave(wx.CallAfter)

        # Start a timer that will refresh the GraphCanvas.
        self.timer = wx.Timer(owner=self)
        self.fps = config.current['global:render-fps']
        XRCCTRL(self.sidebar, "CameraRenderFPS").SetValue(self.fps)
        self.timer.Start(milliseconds=1000.0 / self.fps, oneShot=False)
        self.Bind(wx.EVT_TIMER, self.OnTick)

        # Initialize the Animator
        from animate import Animator

        self.animator = Animator(parent=self)

        # Initialize the Input Manager - we need it for the Flock
        # and/or the Wanda
        self.inputmgr = inputmanager.InputManager(self, self.contexts)

        # Initialize flock control
        if self.cmdline_options.useFlock:
            import flock

            # Try to use the port as an integer (0-based indexing
            # for pySerial) - if not, pass it as a string
            try:
                port = int(self.cmdline_options.flockPort)
            except ValueError:
                port = self.cmdline_options.flockPort
            self.FOB = flock.FlockControl(port=port, nbirds=2, reportrate=4)

            def next():
                print "Flock init succeeded."
                # HEMI_FWD
                # HEMI_AFT
                # HEMI_UPPER
                # HEMI_LOWER
                self.FOB.SendCmd(flock.CMD_HEMISPHERE + flock.HEMI_UPPER)
                #		self.FOB.SendCmd(flock.CMD_HEMISPHERE+flock.HEMI_FWD)

                #XXX# untested!
                #XXX# self.FOB.SetLineFreq(50)

                # Bird 1: Wanda tracker (map to cursor)
                self.FOB.birds[0].SetReportFormat(flock.CMD_POSITION_MATRIX)
                self.FOB.birds[0].SetHandlers(position=self.inputmgr.cursorInputPos,
                                              matrix=self.inputmgr.cursorInputRot)
                # Bird 2: Headtracker
                self.FOB.birds[1].SetReportFormat(flock.CMD_POSITION_MATRIX)
                self.FOB.birds[1].SetHandlers(position=self.inputmgr.trackerInputPos)
                self.FOB.Start()
                wx.CallAfter(self.FOB.Update, 50)

            def fail():
                print "Flock init failed."
                config.current['global:flock'] = False

            self.FOB.Prestart(onSuccess=next, onFailure=fail)
        else:
            self.FOB = None

        # Initialize wanda control
        if self.cmdline_options.useWanda:
            import flock

            # Try to use the port as an integer (0-based indexing
            # for pySerial) - if not, pass it as a string
            try:
                port = int(self.cmdline_options.wandaPort)
            except ValueError:
                port = self.cmdline_options.wandaPort
            self.Wanda = flock.WandaControl(port=port)

            def printArgs(*args, **kwargs):
                print "args:", args, "kwargs:", kwargs

            #	    self.Wanda.SetHandlers(movement=printArgs,leftbutton=printArgs,rightbutton=printArgs,midbutton=printArgs)
            self.Wanda.SetHandlers(movement=self.inputmgr.wandaInput2D,
                                   leftbutton=self.inputmgr.wandaButtonLeft,
                                   rightbutton=self.inputmgr.wandaButtonRight,
                                   midbutton=self.inputmgr.wandaButtonMid)
            wx.CallAfter(self.Wanda.Update, 50)


        # Always call ContextList.setActive; that way menu disabling/enabling
        # happens properly.
        self.contexts.setActive(-1)