Changeset 70:64fb5caf4cad for src/mlx
- Timestamp:
- 04/09/12 08:55:12 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r69 r70 75 75 padding_left = 16, padding_right = 16) 76 76 77 self._buttonBox = gtk.HButtonBox() 77 self._buttonBox = gtk.HBox() 78 self._buttonBox.set_homogeneous(False) 78 79 self._defaultButton = None 79 80 buttonAlignment.add(self._buttonBox) … … 82 83 83 84 self._wizard = wizard 85 86 self._finalized = False 87 self._fromPage = None 84 88 85 89 def setMainWidget(self, widget): … … 92 96 Return the button object created.""" 93 97 button = gtk.Button(label) 94 self._buttonBox. add(button)98 self._buttonBox.pack_start(button, False, False, 4) 95 99 button.set_use_underline(True) 96 100 if default: … … 105 109 pass 106 110 111 def finalize(self): 112 """Called when the page is finalized.""" 113 pass 114 107 115 def grabDefault(self): 108 116 """If the page has a default button, make it the default one.""" … … 112 120 def reset(self): 113 121 """Reset the page if the wizard is reset.""" 114 pass 122 self._finalized = False 123 self._fromPage = None 124 125 def goBack(self): 126 """Go to the page we were invoked from.""" 127 assert self._fromPage is not None 128 129 self._wizard.setCurrentPage(self._fromPage, finalize = False) 115 130 116 131 #----------------------------------------------------------------------------- … … 192 207 def _loginClicked(self, button): 193 208 """Called when the login button was clicked.""" 194 self._wizard.gui.beginBusy("Logging in...") 195 self._wizard.gui.webHandler.login(self._loginResultCallback, 196 self._pilotID.get_text(), 197 self._password.get_text()) 209 self._loginButton.set_sensitive(False) 210 gui = self._wizard.gui 211 gui.beginBusy("Logging in...") 212 gui.webHandler.login(self._loginResultCallback, 213 self._pilotID.get_text(), 214 self._password.get_text()) 198 215 199 216 def _loginResultCallback(self, returned, result): … … 204 221 """Handle the login result.""" 205 222 self._wizard.gui.endBusy() 223 self._loginButton.set_sensitive(True) 206 224 if returned: 207 225 if result.loggedIn: … … 290 308 self._button.connect("clicked", self._forwardClicked) 291 309 292 self._activated = False293 294 310 def activate(self): 295 311 """Fill the flight list.""" 296 if not self._activated: 297 for flight in self._wizard.loginResult.flights: 298 self._listStore.append([str(flight.departureTime), 299 flight.callsign, 300 flight.departureICAO, 301 flight.arrivalICAO]) 302 self._activated = True 312 self._flightList.set_sensitive(True) 313 self._listStore.clear() 314 for flight in self._wizard.loginResult.flights: 315 self._listStore.append([str(flight.departureTime), 316 flight.callsign, 317 flight.departureICAO, 318 flight.arrivalICAO]) 319 320 def finalize(self): 321 """Finalize the page.""" 322 self._flightList.set_sensitive(False) 303 323 304 324 def _selectionChanged(self, selection): … … 308 328 def _forwardClicked(self, button): 309 329 """Called when the forward button was clicked.""" 310 selection = self._flightList.get_selection() 311 (listStore, iter) = selection.get_selected() 312 path = listStore.get_path(iter) 313 [index] = path.get_indices() if pygobject else path 314 315 flight = self._wizard.loginResult.flights[index] 316 self._wizard._bookedFlight = flight 317 318 self._updateDepartureGate() 330 if self._finalized: 331 self._wizard.jumpPage(self._nextDistance, finalize = False) 332 else: 333 selection = self._flightList.get_selection() 334 (listStore, iter) = selection.get_selected() 335 path = listStore.get_path(iter) 336 [index] = path.get_indices() if pygobject else path 337 338 flight = self._wizard.loginResult.flights[index] 339 self._wizard._bookedFlight = flight 340 341 self._updateDepartureGate() 319 342 320 343 def _updateDepartureGate(self): … … 324 347 self._wizard._getFleet(self._fleetRetrieved) 325 348 else: 349 self._nextDistance = 2 326 350 self._wizard.jumpPage(2) 327 351 … … 329 353 """Called when the fleet has been retrieved.""" 330 354 if fleet is None: 355 self._nextDistance = 2 331 356 self._wizard.jumpPage(2) 332 357 else: 333 358 plane = fleet[self._wizard._bookedFlight.tailNumber] 334 359 if plane is None: 360 self._nextDistance = 2 335 361 self._wizard.jumpPage(2) 336 337 if plane.gateNumber is not None and \ 338 not fleet.isGateConflicting(plane): 362 elif plane.gateNumber is not None and \ 363 not fleet.isGateConflicting(plane): 339 364 self._wizard._departureGate = plane.gateNumber 365 self._nextDistance = 2 340 366 self._wizard.jumpPage(2) 341 367 else: 368 self._nextDistance = 1 342 369 self._wizard.nextPage() 343 370 … … 391 418 """Fill the gate list.""" 392 419 self._listStore.clear() 420 self._gateList.set_sensitive(True) 393 421 occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers() 394 422 for gateNumber in const.lhbpGateNumbers: … … 396 424 self._listStore.append([gateNumber]) 397 425 426 def finalize(self): 427 """Finalize the page.""" 428 self._gateList.set_sensitive(False) 429 398 430 def _selectionChanged(self, selection): 399 431 """Called when the selection is changed.""" … … 402 434 def _forwardClicked(self, button): 403 435 """Called when the forward button is clicked.""" 404 selection = self._gateList.get_selection() 405 (listStore, iter) = selection.get_selected() 406 (gateNumber,) = listStore.get(iter, 0) 407 408 self._wizard._departureGate = gateNumber 409 410 #self._wizard._updatePlane(self._planeUpdated, 411 # self._wizard._bookedFlight.tailNumber, 412 # const.PLANE_HOME, 413 # gateNumber) 436 if not self._finalized: 437 selection = self._gateList.get_selection() 438 (listStore, iter) = selection.get_selected() 439 (gateNumber,) = listStore.get(iter, 0) 440 441 self._wizard._departureGate = gateNumber 442 443 #self._wizard._updatePlane(self._planeUpdated, 444 # self._wizard._bookedFlight.tailNumber, 445 # const.PLANE_HOME, 446 # gateNumber) 447 414 448 self._wizard.nextPage() 415 449 … … 482 516 table.attach(labelAlignment, 1, 2, 1, 2) 483 517 518 button = self.addButton(gtk.STOCK_GO_BACK) 519 button.set_use_stock(True) 520 button.connect("clicked", self._backClicked) 521 484 522 self._button = self.addButton("_Connect", default = True) 485 523 self._button.set_use_underline(True) 486 self._ button.connect("clicked", self._connectClicked)524 self._clickedID = self._button.connect("clicked", self._connectClicked) 487 525 488 526 def activate(self): 489 527 """Setup the departure information.""" 528 self._button.set_label("_Connect") 529 self._button.set_use_underline(True) 530 self._button.disconnect(self._clickedID) 531 self._clickedID = self._button.connect("clicked", self._connectClicked) 532 490 533 icao = self._wizard._bookedFlight.departureICAO 491 534 self._departureICAO.set_markup("<b>" + icao + "</b>") … … 495 538 self._departureGate.set_markup(gate) 496 539 540 def finalize(self): 541 """Finalize the page.""" 542 self._button.set_label(gtk.STOCK_GO_FORWARD) 543 self._button.set_use_stock(True) 544 self._button.disconnect(self._clickedID) 545 self._clickedID = self._button.connect("clicked", self._forwardClicked) 546 547 def _backClicked(self, button): 548 """Called when the Back button is pressed.""" 549 self.goBack() 550 497 551 def _connectClicked(self, button): 498 552 """Called when the Connect button is pressed.""" 499 553 self._wizard._connectSimulator() 554 555 def _forwardClicked(self, button): 556 """Called when the Forward button is pressed.""" 557 self._wizard.nextPage() 500 558 501 559 #----------------------------------------------------------------------------- … … 589 647 table.attach(gtk.Label("kg"), 2, 3, 5, 6) 590 648 591 button = gtk.Button("_ZFW from FS:")592 button.set_use_underline(True)593 button.connect("clicked", self._zfwRequested)594 table.attach( button, 0, 1, 6, 7)649 self._zfwButton = gtk.Button("_ZFW from FS:") 650 self._zfwButton.set_use_underline(True) 651 self._zfwButton.connect("clicked", self._zfwRequested) 652 table.attach(self._zfwButton, 0, 1, 6, 7) 595 653 596 654 self._simulatorZFW = gtk.Label("-") … … 601 659 602 660 table.attach(gtk.Label("kg"), 2, 3, 6, 7) 661 662 self._backButton = self.addButton(gtk.STOCK_GO_BACK) 663 self._backButton.set_use_stock(True) 664 self._backButton.connect("clicked", self._backClicked) 603 665 604 666 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True) … … 614 676 self._cargoWeightValue = bookedFlight.cargoWeight 615 677 self._cargoWeight.set_text(str(bookedFlight.cargoWeight)) 678 self._cargoWeight.set_sensitive(True) 616 679 self._mailWeight.set_text(str(bookedFlight.mailWeight)) 680 self._zfwButton.set_sensitive(True) 617 681 self._updateCalculatedZFW() 682 683 def finalize(self): 684 """Finalize the payload page.""" 685 self._cargoWeight.set_sensitive(False) 686 self._zfwButton.set_sensitive(False) 618 687 619 688 def _calculateZFW(self): … … 653 722 def _zfwRequested(self, button): 654 723 """Called when the ZFW is requested from the simulator.""" 655 self._wizard.gui.beginBusy("Querying ZFW...") 656 self._wizard.gui.simulator.requestZFW(self._handleZFW) 724 self._zfwButton.set_sensitive(False) 725 self._backButton.set_sensitive(False) 726 self._button.set_sensitive(False) 727 gui = self._wizard.gui 728 gui.beginBusy("Querying ZFW...") 729 gui.simulator.requestZFW(self._handleZFW) 657 730 658 731 def _handleZFW(self, zfw): … … 663 736 """Process the given ZFW value received from the simulator.""" 664 737 self._wizard.gui.endBusy() 738 self._zfwButton.set_sensitive(True) 739 self._backButton.set_sensitive(True) 740 self._button.set_sensitive(True) 665 741 self._simulatorZFWValue = zfw 666 742 self._simulatorZFW.set_text("%.0f" % (zfw,)) … … 669 745 def _forwardClicked(self, button): 670 746 """Called when the forward button is clicked.""" 671 self._wizard._zfw = self._calculateZFW() 747 if not self._finalized: 748 self._wizard._zfw = self._calculateZFW() 672 749 self._wizard.nextPage() 750 751 def _backClicked(self, button): 752 """Called when the Back button is pressed.""" 753 self.goBack() 673 754 674 755 #----------------------------------------------------------------------------- … … 710 791 table.attach(self._arrival, 1, 2, 1, 2) 711 792 712 button = gtk.Button("_Time from FS:")713 button.set_use_underline(True)714 button.connect("clicked", self._timeRequested)715 table.attach( button, 0, 1, 2, 3)793 self._timeButton = gtk.Button("_Time from FS:") 794 self._timeButton.set_use_underline(True) 795 self._timeButton.connect("clicked", self._timeRequested) 796 table.attach(self._timeButton, 0, 1, 2, 3) 716 797 717 798 self._simulatorTime = gtk.Label("-") … … 719 800 table.attach(self._simulatorTime, 1, 2, 2, 3) 720 801 802 self._backButton = self.addButton(gtk.STOCK_GO_BACK) 803 self._backButton.set_use_stock(True) 804 self._backButton.connect("clicked", self._backClicked) 805 721 806 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True) 722 807 self._button.set_use_stock(True) … … 725 810 def activate(self): 726 811 """Activate the page.""" 812 self._timeButton.set_sensitive(True) 727 813 bookedFlight = self._wizard._bookedFlight 728 814 self._departure.set_text(str(bookedFlight.departureTime.time())) 729 815 self._arrival.set_text(str(bookedFlight.arrivalTime.time())) 730 816 817 def finalize(self): 818 """Finalize the page.""" 819 self._timeButton.set_sensitive(False) 820 731 821 def _timeRequested(self, button): 732 822 """Request the time from the simulator.""" 823 self._timeButton.set_sensitive(False) 824 self._backButton.set_sensitive(False) 825 self._button.set_sensitive(False) 733 826 self._wizard.gui.beginBusy("Querying time...") 734 827 self._wizard.gui.simulator.requestTime(self._handleTime) … … 741 834 """Process the given time.""" 742 835 self._wizard.gui.endBusy() 836 self._timeButton.set_sensitive(True) 837 self._backButton.set_sensitive(True) 838 self._button.set_sensitive(True) 743 839 tm = time.gmtime(timestamp) 744 840 t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec) … … 761 857 self._departure.set_markup(markupBegin + str(dt) + markupEnd) 762 858 859 def _backClicked(self, button): 860 """Called when the Back button is pressed.""" 861 self.goBack() 862 763 863 def _forwardClicked(self, button): 764 864 """Called when the forward button is clicked.""" … … 834 934 mainBox.pack_start(routeBox, True, True, 8) 835 935 936 self._backButton = self.addButton(gtk.STOCK_GO_BACK) 937 self._backButton.set_use_stock(True) 938 self._backButton.connect("clicked", self._backClicked) 939 836 940 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True) 837 941 self._button.set_use_stock(True) … … 840 944 def activate(self): 841 945 """Setup the route from the booked flight.""" 946 self._route.set_sensitive(True) 947 self._cruiseLevel.set_sensitive(True) 842 948 self._route.get_buffer().set_text(self._wizard._bookedFlight.route) 843 949 self._updateForwardButton() 950 951 def finalize(self): 952 """Finalize the page.""" 953 self._route.set_sensitive(False) 954 self._cruiseLevel.set_sensitive(False) 844 955 845 956 def _getRoute(self): … … 862 973 self._updateForwardButton() 863 974 975 def _backClicked(self, button): 976 """Called when the Back button is pressed.""" 977 self.goBack() 978 864 979 def _forwardClicked(self, button): 865 980 """Called when the Forward button is clicked.""" 866 self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100 867 self._wizard._route = self._getRoute() 868 869 bookedFlight = self._wizard._bookedFlight 870 self._wizard.gui.beginBusy("Downloading NOTAMs...") 871 self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback, 872 bookedFlight.departureICAO, 873 bookedFlight.arrivalICAO) 981 if self._finalized: 982 self._wizard.nextPage() 983 else: 984 self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100 985 self._wizard._route = self._getRoute() 986 987 self._backButton.set_sensitive(False) 988 self._button.set_sensitive(False) 989 self._cruiseLevel.set_sensitive(False) 990 self._route.set_sensitive(False) 991 992 bookedFlight = self._wizard._bookedFlight 993 self._wizard.gui.beginBusy("Downloading NOTAMs...") 994 self._wizard.gui.webHandler.getNOTAMs(self._notamsCallback, 995 bookedFlight.departureICAO, 996 bookedFlight.arrivalICAO) 874 997 875 998 def _notamsCallback(self, returned, result): … … 908 1031 909 1032 self._wizard.gui.endBusy() 1033 self._backButton.set_sensitive(True) 1034 self._button.set_sensitive(True) 910 1035 self._wizard.nextPage() 911 1036 … … 917 1042 """Construct the briefing page.""" 918 1043 self._departure = departure 919 self._activated = False920 1044 921 1045 title = "Briefing (%d/2): %s" % (1 if departure else 2, … … 976 1100 mainBox.pack_start(self._metarFrame, True, True, 4) 977 1101 1102 button = self.addButton(gtk.STOCK_GO_BACK) 1103 button.set_use_stock(True) 1104 button.connect("clicked", self._backClicked) 1105 978 1106 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True) 979 1107 self._button.set_use_stock(True) … … 982 1110 def activate(self): 983 1111 """Activate the page.""" 984 if self._activated: 985 if not self._departure: 986 self._button.set_label(gtk.STOCK_GO_FORWARD) 987 self._button.set_use_stock(True) 1112 if not self._departure: 1113 self._button.set_label("I have read the briefing and am ready to fly!") 1114 self._button.set_use_stock(False) 1115 1116 bookedFlight = self._wizard._bookedFlight 1117 1118 icao = bookedFlight.departureICAO if self._departure \ 1119 else bookedFlight.arrivalICAO 1120 notams = self._wizard._departureNOTAMs if self._departure \ 1121 else self._wizard._arrivalNOTAMs 1122 metar = self._wizard._departureMETAR if self._departure \ 1123 else self._wizard._arrivalMETAR 1124 1125 self._notamsFrame.set_label(icao + " NOTAMs") 1126 buffer = self._notams.get_buffer() 1127 if notams is None: 1128 buffer.set_text("Could not download NOTAMs") 988 1129 else: 989 if not self._departure: 990 self._button.set_label("I have read the briefing and am ready to fly!") 991 self._button.set_use_stock(False) 992 993 bookedFlight = self._wizard._bookedFlight 994 995 icao = bookedFlight.departureICAO if self._departure \ 996 else bookedFlight.arrivalICAO 997 notams = self._wizard._departureNOTAMs if self._departure \ 998 else self._wizard._arrivalNOTAMs 999 metar = self._wizard._departureMETAR if self._departure \ 1000 else self._wizard._arrivalMETAR 1001 1002 self._notamsFrame.set_label(icao + " NOTAMs") 1003 buffer = self._notams.get_buffer() 1004 if notams is None: 1005 buffer.set_text("Could not download NOTAMs") 1006 else: 1007 s = "" 1008 for notam in notams: 1009 s += str(notam.begin) 1010 if notam.end is not None: 1011 s += " - " + str(notam.end) 1012 elif notam.permanent: 1013 s += " - PERMANENT" 1014 s += "\n" 1015 if notam.repeatCycle: 1016 s += "Repeat cycle: " + notam.repeatCycle + "\n" 1017 s += notam.notice + "\n" 1018 s += "-------------------- * --------------------\n" 1019 buffer.set_text(s) 1020 1021 self._metarFrame.set_label(icao + " METAR") 1022 buffer = self._metar.get_buffer() 1023 if metar is None: 1024 buffer.set_text("Could not download METAR") 1025 else: 1026 buffer.set_text(metar) 1027 1028 self._activated = True 1029 1030 def reset(self): 1031 """Reset the page if the wizard is reset.""" 1032 super(BriefingPage, self).reset() 1033 self._activated = False 1034 1130 s = "" 1131 for notam in notams: 1132 s += str(notam.begin) 1133 if notam.end is not None: 1134 s += " - " + str(notam.end) 1135 elif notam.permanent: 1136 s += " - PERMANENT" 1137 s += "\n" 1138 if notam.repeatCycle: 1139 s += "Repeat cycle: " + notam.repeatCycle + "\n" 1140 s += notam.notice + "\n" 1141 s += "-------------------- * --------------------\n" 1142 buffer.set_text(s) 1143 1144 self._metarFrame.set_label(icao + " METAR") 1145 buffer = self._metar.get_buffer() 1146 if metar is None: 1147 buffer.set_text("Could not download METAR") 1148 else: 1149 buffer.set_text(metar) 1150 1151 def finalize(self): 1152 """Finalize the page.""" 1153 if not self._departure: 1154 self._button.set_use_stock(True) 1155 self._button.set_label(gtk.STOCK_GO_FORWARD) 1156 1157 def _backClicked(self, button): 1158 """Called when the Back button is pressed.""" 1159 self.goBack() 1160 1035 1161 def _forwardClicked(self, button): 1036 1162 """Called when the forward button is clicked.""" 1037 self._wizard.nextPage() 1163 if not self._departure: 1164 if not self._finalized: 1165 self._wizard.gui.startMonitoring() 1166 self.finalize() 1167 self._finalized = True 1168 else: 1169 self._wizard.nextPage() 1038 1170 1039 1171 #----------------------------------------------------------------------------- … … 1080 1212 return self._loginResult 1081 1213 1082 def setCurrentPage(self, index ):1214 def setCurrentPage(self, index, finalize = False): 1083 1215 """Set the current page to the one with the given index.""" 1084 1216 assert index < len(self._pages) 1085 1086 if self._currentPage is not None: 1087 self.remove(self._pages[self._currentPage]) 1217 1218 fromPage = self._currentPage 1219 if fromPage is not None: 1220 page = self._pages[fromPage] 1221 if finalize and not page._finalized: 1222 page.finalize() 1223 page._finalized = True 1224 self.remove(page) 1088 1225 1089 1226 self._currentPage = index 1090 self.add(self._pages[index]) 1091 self._pages[index].activate() 1227 page = self._pages[index] 1228 self.add(page) 1229 if page._fromPage is None: 1230 page._fromPage = fromPage 1231 page.activate() 1232 self.grabDefault() 1092 1233 self.show_all() 1093 1234 1094 def nextPage(self ):1235 def nextPage(self, finalize = True): 1095 1236 """Go to the next page.""" 1096 self.jumpPage(1 )1097 1098 def jumpPage(self, count ):1237 self.jumpPage(1, finalize) 1238 1239 def jumpPage(self, count, finalize = True): 1099 1240 """Go to the page which is 'count' pages after the current one.""" 1100 self.setCurrentPage(self._currentPage + count) 1101 self.grabDefault() 1241 self.setCurrentPage(self._currentPage + count, finalize = finalize) 1102 1242 1103 1243 def grabDefault(self): -
src/mlx/gui/gui.py
r59 r70 394 394 self._flight.zfw = self._zfwSpinButton.get_value_as_int() 395 395 396 self._simulator.startMonitoring() 397 self._monitoring = True 396 self.startMonitoring() 398 397 else: 399 398 self.resetFlightStatus() … … 408 407 409 408 self._statusbar.updateConnection(self._connecting, self._connected) 409 410 def startMonitoring(self): 411 """Start monitoring.""" 412 self._simulator.startMonitoring() 413 self._monitoring = True 414 415 def stopMonitoring(self): 416 """Stop monitoring.""" 417 self._simulator.stoptMonitoring() 418 self._monitoring = False 410 419 411 420 def _buildSetupFrame(self): -
src/mlx/gui/statusbar.py
r59 r70 62 62 63 63 self._ratingLabel = gtk.Label() 64 self._ratingLabel.set_width_chars(1 0)64 self._ratingLabel.set_width_chars(12) 65 65 self._ratingLabel.set_tooltip_text("The flight rating") 66 66 self._ratingLabel.set_alignment(0.0, 0.5) … … 85 85 """Update the busy state.""" 86 86 self._busyLabel.set_text("" if message is None else message) 87 87 88 88 def _drawConnState(self, connStateArea, eventOrContext): 89 89 """Draw the connection state."""
Note:
See TracChangeset
for help on using the changeset viewer.