Changeset 152:f0701a18628a for src
- Timestamp:
- 05/05/12 11:40:28 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/acft.py
r150 r152 202 202 "Block time: " + 203 203 util.getTimeIntervalString(blockLength)) 204 bookedFlight = self._flight.bookedFlight205 # FIXME: translate the ICAO into an airport name206 fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT,207 "Flight plan closed. Welcome to %s" % \208 (bookedFlight.arrivalICAO,),209 5)210 204 211 205 def prepareFlare(self): -
src/mlx/fs.py
r134 r152 64 64 self.daemon = True 65 65 66 def add(self, messageType, text, duration ):66 def add(self, messageType, text, duration, disconnect): 67 67 """Add the given message to the requested messages.""" 68 68 with self._requestCondition: 69 self._messages.append((messageType, text, duration)) 69 self._messages.append((messageType, text, duration, 70 disconnect)) 70 71 self._requestCondition.notify() 71 72 … … 80 81 """Perform the thread's operation.""" 81 82 while True: 82 (messageType, text, duration ) = (None, None, None)83 (messageType, text, duration, disconnect) = (None, None, None, None) 83 84 with self._requestCondition: 84 85 now = time.time() … … 96 97 97 98 if self._messages: 98 (messageType, text, duration) = self._messages[0] 99 (messageType, text, 100 duration, disconnect) = self._messages[0] 99 101 del self._messages[0] 100 102 101 103 if text is not None: 102 self._sendMessage(messageType, text, duration )103 104 def _sendMessage(self, messageType, text, duration ):104 self._sendMessage(messageType, text, duration, disconnect) 105 106 def _sendMessage(self, messageType, text, duration, disconnect): 105 107 """Send the message and setup the next message time.""" 106 108 messageLevel = self._config.getMessageTypeLevel(messageType) … … 110 112 if (messageLevel==const.MESSAGELEVEL_FS or \ 111 113 messageLevel==const.MESSAGELEVEL_BOTH): 112 self._simulator.sendMessage("[MLX] " + text, duration = duration) 114 if disconnect: 115 self._simulator.disconnect("[MLX] " + text, 116 duration = duration) 117 else: 118 self._simulator.sendMessage("[MLX] " + text, 119 duration = duration) 120 elif disconnecte: 121 self._simulator.disconnect() 113 122 self._nextMessageTime = time.time() + duration 114 123 … … 129 138 #------------------------------------------------------------------------------- 130 139 131 def sendMessage(messageType, text, duration = 3 ):140 def sendMessage(messageType, text, duration = 3, disconnect = False): 132 141 """Send the given message of the given type into the simulator and/or play 133 142 a corresponding sound.""" 134 143 global _messageThread 135 144 if _messageThread is not None: 136 _messageThread.add(messageType, text, duration )145 _messageThread.add(messageType, text, duration, disconnect) 137 146 138 147 #------------------------------------------------------------------------------- -
src/mlx/fsuipc.py
r148 r152 245 245 """ 246 246 with self._requestCondition: 247 self._requests.append(Handler.Request(True, data, callback, extra)) 247 request = Handler.Request(True, data, callback, extra) 248 #print "fsuipc.Handler.requestWrite", request 249 self._requests.append(request) 248 250 self._requestCondition.notify() 249 251 … … 371 373 timeout = self._periodicRequests[0].nextFire - time.time() 372 374 373 if timeout is not None and timeout <= 0.0: 375 if self._requests or \ 376 (timeout is not None and timeout <= 0.0): 374 377 return 375 378 … … 378 381 def _disconnect(self): 379 382 """Disconnect from the flight simulator.""" 383 print "fsuipc.Handler._disconnect" 380 384 if self._connected: 381 385 pyuipc.close() … … 394 398 whole processing the request and reconnecting.""" 395 399 self._requestCondition.release() 400 401 #print "fsuipc.Handler._processRequest", request 396 402 397 403 needReconnect = False … … 531 537 self._flareStart = None 532 538 self._flareStartFS = None 533 539 534 540 self._latin1decoder = codecs.getdecoder("iso-8859-1") 535 541 … … 600 606 self._flareRequestID = None 601 607 602 def sendMessage(self, message, duration = 3): 608 def sendMessage(self, message, duration = 3, 609 _disconnect = False): 603 610 """Send a message to the pilot via the simulator. 604 611 … … 613 620 (0x32fa, 'h', duration)] 614 621 615 self._handler.requestWrite(data, self._handleMessageSent) 622 #if _disconnect: 623 # print "fsuipc.Simulator.sendMessage(disconnect)", message 624 625 self._handler.requestWrite(data, self._handleMessageSent, 626 extra = _disconnect) 616 627 617 628 def getFuel(self, tanks, callback): … … 655 666 self._nextSyncTime = -1 656 667 657 def disconnect(self ):668 def disconnect(self, closingMessage = None, duration = 3): 658 669 """Disconnect from the simulator.""" 659 670 assert not self._monitoringRequested 671 672 print "fsuipc.Simulator.disconnect", closingMessage, duration 660 673 661 674 self._stopNormal() 662 self._handler.disconnect() 675 if closingMessage is None: 676 self._handler.disconnect() 677 else: 678 self.sendMessage(closingMessage, duration = duration, 679 _disconnect = True) 663 680 664 681 def _startDefaultNormal(self): … … 874 891 callback(dow, payload, zfw, grossWeight) 875 892 876 def _handleMessageSent(self, success, extra):893 def _handleMessageSent(self, success, disconnect): 877 894 """Callback for a message sending request.""" 878 pass 895 #print "fsuipc.Simulator._handleMessageSent", disconnect 896 if disconnect: 897 self._handler.disconnect() 879 898 880 899 def _handleFuelRetrieved(self, data, callback): -
src/mlx/gui/gui.py
r151 r152 399 399 self._logView.get_buffer().set_text("") 400 400 401 def _disconnect(self ):401 def _disconnect(self, closingMessage = None, duration = 3): 402 402 """Disconnect from the simulator if connected.""" 403 403 self.stopMonitoring() 404 404 405 405 if self._connected: 406 self._flight.simulator.disconnect() 406 if closingMessage is None: 407 self._flight.simulator.disconnect() 408 else: 409 fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT, 410 closingMessage, duration, 411 disconnect = True) 407 412 self._connected = False 408 413 … … 455 460 self._wizard.setStage(stage) 456 461 if stage==const.STAGE_END: 457 # FIXME: perhaps a more elegant method, e.g.458 # the simulator should provide a function disconnect459 # with a final message460 gobject.timeout_add(1000, self._disconnect)462 self._disconnect(closingMessage = 463 "Flight plan closed. Welcome to %s" % \ 464 (self.bookedFlight.arrivalICAO,), 465 duration = 5) 461 466 462 467 def setRating(self, rating):
Note:
See TracChangeset
for help on using the changeset viewer.