Changeset 1076:5a7bb93c337d for src/mlx
- Timestamp:
- 02/14/23 14:30:51 (22 months ago)
- Branch:
- python3
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r1075 r1076 25 25 import re 26 26 import webbrowser 27 import urllib.request, urllib.error, urllib.parse 28 from lxml import etree 29 from io import StringIO 30 import lxml.html 31 import certifi 27 32 28 33 #----------------------------------------------------------------------------- … … 3207 3212 } 3208 3213 3214 _resultQueryInterval = 2000 3215 3216 _waitTimeout = 2 * 60.0 3217 3209 3218 @staticmethod 3210 3219 def getHTMLFilePath(): … … 3234 3243 xscale = 0.0, yscale = 0.0) 3235 3244 3236 table = Gtk.Table( 9, 3)3245 table = Gtk.Table(6, 3) 3237 3246 table.set_row_spacings(4) 3238 3247 table.set_col_spacings(16) … … 3241 3250 self.setMainWidget(alignment) 3242 3251 3243 label = Gtk.Label(xstr("simbrief_username")) 3244 label.set_use_underline(True) 3245 label.set_alignment(0.0, 0.5) 3246 table.attach(label, 0, 1, 0, 1) 3247 3248 self._userName = Gtk.Entry() 3249 self._userName.set_width_chars(16) 3250 self._userName.connect("changed", 3251 lambda button: self._updateForwardButton()) 3252 self._userName.set_tooltip_text(xstr("simbrief_username_tooltip")) 3253 table.attach(self._userName, 1, 2, 0, 1) 3254 label.set_mnemonic_widget(self._userName) 3255 3256 label = Gtk.Label(xstr("simbrief_password")) 3257 label.set_use_underline(True) 3258 label.set_alignment(0.0, 0.5) 3259 table.attach(label, 0, 1, 1, 2) 3260 3261 self._password = Gtk.Entry() 3262 self._password.set_visibility(False) 3263 self._password.connect("changed", 3264 lambda button: self._updateForwardButton()) 3265 self._password.set_tooltip_text(xstr("simbrief_password_tooltip")) 3266 table.attach(self._password, 1, 2, 1, 2) 3267 label.set_mnemonic_widget(self._password) 3268 3269 self._rememberButton = Gtk.CheckButton(xstr("simbrief_remember_password")) 3270 self._rememberButton.set_use_underline(True) 3271 self._rememberButton.set_tooltip_text(xstr("simbrief_remember_tooltip")) 3272 table.attach(self._rememberButton, 1, 2, 2, 3, ypadding = 8) 3252 3253 row = 0 3254 3255 # label = Gtk.Label(xstr("simbrief_username")) 3256 # label.set_use_underline(True) 3257 # label.set_alignment(0.0, 0.5) 3258 # table.attach(label, 0, 1, row, row+1) 3259 3260 # self._userName = Gtk.Entry() 3261 # self._userName.set_width_chars(16) 3262 # self._userName.connect("changed", 3263 # lambda button: self._updateForwardButton()) 3264 # self._userName.set_tooltip_text(xstr("simbrief_username_tooltip")) 3265 # table.attach(self._userName, 1, 2, row, row+1) 3266 # label.set_mnemonic_widget(self._userName) 3267 # row += 1 3268 3269 # label = Gtk.Label(xstr("simbrief_password")) 3270 # label.set_use_underline(True) 3271 # label.set_alignment(0.0, 0.5) 3272 # table.attach(label, 0, 1, row, row+1) 3273 3274 # self._password = Gtk.Entry() 3275 # self._password.set_visibility(False) 3276 # self._password.connect("changed", 3277 # lambda button: self._updateForwardButton()) 3278 # self._password.set_tooltip_text(xstr("simbrief_password_tooltip")) 3279 # table.attach(self._password, 1, 2, row, row+1) 3280 # label.set_mnemonic_widget(self._password) 3281 # row += 1 3282 3283 # self._rememberButton = Gtk.CheckButton(xstr("simbrief_remember_password")) 3284 # self._rememberButton.set_use_underline(True) 3285 # self._rememberButton.set_tooltip_text(xstr("simbrief_remember_tooltip")) 3286 # table.attach(self._rememberButton, 1, 2, row, row+1, ypadding = 8) 3287 # row += 1 3273 3288 3274 3289 label = Gtk.Label(xstr("simbrief_extra_fuel")) 3275 3290 label.set_use_underline(True) 3276 3291 label.set_alignment(0.0, 0.5) 3277 table.attach(label, 0, 1, 3, 4)3292 table.attach(label, 0, 1, row, row+1) 3278 3293 3279 3294 self._extraFuel = IntegerEntry(defaultValue = 0) 3280 3295 self._extraFuel.set_width_chars(6) 3281 3296 self._extraFuel.set_tooltip_text(xstr("simbrief_extra_fuel_tooltip")) 3282 table.attach(self._extraFuel, 1, 2, 3, 4)3297 table.attach(self._extraFuel, 1, 2, row, row+1) 3283 3298 label.set_mnemonic_widget(self._extraFuel) 3284 3299 3285 table.attach(Gtk.Label("kg"), 2, 3, 3, 4) 3300 table.attach(Gtk.Label("kg"), 2, 3, row, row+1) 3301 row += 1 3286 3302 3287 3303 label = Gtk.Label(xstr("simbrief_takeoff_runway")) 3288 3304 label.set_use_underline(True) 3289 3305 label.set_alignment(0.0, 0.5) 3290 table.attach(label, 0, 1, 4, 5)3306 table.attach(label, 0, 1, row, row+1) 3291 3307 3292 3308 self._takeoffRunway = Gtk.Entry() … … 3294 3310 self._takeoffRunway.set_tooltip_text(xstr("simbrief_takeoff_runway_tooltip")) 3295 3311 self._takeoffRunway.connect("changed", self._upperChanged) 3296 table.attach(self._takeoffRunway, 1, 2, 4, 5)3312 table.attach(self._takeoffRunway, 1, 2, row, row+1) 3297 3313 label.set_mnemonic_widget(self._takeoffRunway) 3314 row += 1 3298 3315 3299 3316 label = Gtk.Label(xstr("simbrief_landing_runway")) 3300 3317 label.set_use_underline(True) 3301 3318 label.set_alignment(0.0, 0.5) 3302 table.attach(label, 0, 1, 5, 6)3319 table.attach(label, 0, 1, row, row+1) 3303 3320 3304 3321 self._landingRunway = Gtk.Entry() 3305 3322 self._landingRunway.set_width_chars(10) 3306 self._landingRunway.set_tooltip_text(xstr("simbrief_ takeoff_runway_tooltip"))3323 self._landingRunway.set_tooltip_text(xstr("simbrief_landing_runway_tooltip")) 3307 3324 self._landingRunway.connect("changed", self._upperChanged) 3308 table.attach(self._landingRunway, 1, 2, 5, 6)3325 table.attach(self._landingRunway, 1, 2, row, row+1) 3309 3326 label.set_mnemonic_widget(self._landingRunway) 3327 row += 1 3310 3328 3311 3329 label = Gtk.Label(xstr("simbrief_climb_profile")) 3312 3330 label.set_use_underline(True) 3313 3331 label.set_alignment(0.0, 0.5) 3314 table.attach(label, 0, 1, 6, 7)3332 table.attach(label, 0, 1, row, row+1) 3315 3333 3316 3334 self._climbProfile = Gtk.ComboBox() … … 3319 3337 self._climbProfile.add_attribute(renderer, "text", 0) 3320 3338 self._climbProfile.set_tooltip_text(xstr("simbrief_climb_profile_tooltip")) 3321 table.attach(self._climbProfile, 1, 2, 6, 7)3339 table.attach(self._climbProfile, 1, 2, row, row+1) 3322 3340 label.set_mnemonic_widget(self._climbProfile) 3341 row += 1 3323 3342 3324 3343 label = Gtk.Label(xstr("simbrief_cruise_profile")) 3325 3344 label.set_use_underline(True) 3326 3345 label.set_alignment(0.0, 0.5) 3327 table.attach(label, 0, 1, 7, 8)3346 table.attach(label, 0, 1, row, row+1) 3328 3347 3329 3348 self._cruiseProfile = Gtk.ComboBox() … … 3332 3351 self._cruiseProfile.add_attribute(renderer, "text", 0) 3333 3352 self._cruiseProfile.set_tooltip_text(xstr("simbrief_cruise_profile_tooltip")) 3334 table.attach(self._cruiseProfile, 1, 2, 7, 8)3353 table.attach(self._cruiseProfile, 1, 2, row, row+1) 3335 3354 label.set_mnemonic_widget(self._cruiseProfile) 3355 row += 1 3336 3356 3337 3357 label = Gtk.Label(xstr("simbrief_descent_profile")) 3338 3358 label.set_use_underline(True) 3339 3359 label.set_alignment(0.0, 0.5) 3340 table.attach(label, 0, 1, 8, 9)3360 table.attach(label, 0, 1, row, row+1) 3341 3361 3342 3362 self._descentProfile = Gtk.ComboBox() … … 3345 3365 self._descentProfile.add_attribute(renderer, "text", 0) 3346 3366 self._descentProfile.set_tooltip_text(xstr("simbrief_descent_profile_tooltip")) 3347 table.attach(self._descentProfile, 1, 2, 8, 9)3367 table.attach(self._descentProfile, 1, 2, row, row+1) 3348 3368 label.set_mnemonic_widget(self._descentProfile) 3349 3369 … … 3352 3372 self._backButton = self.addPreviousButton(clicked = self._backClicked) 3353 3373 self._button = self.addNextButton(clicked = self._forwardClicked) 3374 3375 self._resultTimestamp = None 3354 3376 3355 3377 def activate(self): … … 3357 3379 config = self._wizard.gui.config 3358 3380 3359 self._userName.set_text(config.simBriefUserName)3360 self._userName.set_sensitive(True)3361 3362 self._password.set_text(config.simBriefPassword)3363 self._password.set_sensitive(True)3364 3365 self._rememberButton.set_active(config.rememberSimBriefPassword)3366 self._rememberButton.set_sensitive(True)3381 # self._userName.set_text(config.simBriefUserName) 3382 # self._userName.set_sensitive(True) 3383 3384 # self._password.set_text(config.simBriefPassword) 3385 # self._password.set_sensitive(True) 3386 3387 # self._rememberButton.set_active(config.rememberSimBriefPassword) 3388 # self._rememberButton.set_sensitive(True) 3367 3389 3368 3390 self._extraFuel.set_int(0) … … 3392 3414 self._descentProfile.set_active(0) 3393 3415 3416 self._resultTimestamp = None 3417 self._waitEnd = None 3418 3394 3419 self._updateForwardButton() 3395 3420 3396 3421 def _updateForwardButton(self): 3397 3422 """Update the sensitivity of the forward button.""" 3398 self._button.set_sensitive(len(self._userName.get_text())>0 and 3399 len(self._password.get_text())>0) 3423 self._button.set_sensitive(True) 3424 # self._button.set_sensitive(len(self._userName.get_text())>0 and 3425 # len(self._password.get_text())>0) 3400 3426 3401 3427 def _backClicked(self, button): … … 3407 3433 self._wizard.nextPage() 3408 3434 else: 3409 config = self._wizard.gui.config 3410 3411 config.simBriefUserName = self._userName.get_text() 3412 3413 rememberPassword = self._rememberButton.get_active() 3414 config.simBriefPassword = \ 3415 self._password.get_text() if rememberPassword else "" 3416 config.rememberSimBriefPassword = rememberPassword 3417 3418 config.save() 3419 3420 plan = self._getPlan() 3421 print("plan:", plan) 3422 3423 takeoffRunway = self._takeoffRunway.get_text() 3424 if takeoffRunway: 3425 self._wizard.takeoffRunway = takeoffRunway 3426 3427 landingRunway = self._landingRunway.get_text() 3428 if landingRunway: 3429 self._wizard.landingRunway = landingRunway 3430 3431 self._userName.set_sensitive(False) 3432 self._password.set_sensitive(False) 3433 self._rememberButton.set_sensitive(False) 3434 self._extraFuel.set_sensitive(False) 3435 self._takeoffRunway.set_sensitive(False) 3436 self._landingRunway.set_sensitive(False) 3437 3438 self._climbProfile.set_sensitive(False) 3439 self._cruiseProfile.set_sensitive(False) 3440 self._descentProfile.set_sensitive(False) 3441 3442 self._wizard.gui.beginBusy(xstr("simbrief_calling")) 3443 3444 cef.callSimBrief(plan, 3445 self._getCredentials, 3446 self._simBriefProgress, 3447 SimBriefSetupPage.getHTMLFilePath()) 3448 3449 startSound(const.SOUND_NOTAM) 3450 3451 def _getCredentials(self, count): 3452 """Get the credentials. 3453 3454 If count is 0, the user name and password entered into the setup page 3455 are returned. Otherwise a dialog box is displayed informing the user of 3456 invalid credentials and requesting another set of them.""" 3457 print("_getCredentials", count) 3458 if count==0: 3459 return (self._userName.get_text(), self._password.get_text()) 3460 else: 3461 gui = self._wizard.gui 3462 config = gui.config 3463 3464 dialog = SimBriefCredentialsDialog(gui, 3465 config.simBriefUserName, 3466 config.simBriefPassword, 3467 config.rememberSimBriefPassword) 3468 response = dialog.run() 3469 3470 if response==Gtk.ResponseType.OK: 3471 userName = dialog.userName 3472 self._userName.set_text(userName) 3473 password = dialog.password 3474 self._password.set_text(password) 3475 rememberPassword = dialog.rememberPassword 3476 3477 config.simBriefUserName = userName 3478 3479 config.simBriefPassword = \ 3480 password if rememberPassword else "" 3481 config.rememberSimBriefPassword = rememberPassword 3482 3483 config.save() 3484 3485 return (userName, password) 3486 else: 3487 return (None, None) 3488 3489 def _simBriefProgress(self, progress, result, flightInfo): 3490 """The real SimBrief progress handler.""" 3491 print("_simBriefProgress", progress, result, flightInfo) 3492 if result==cef.SIMBRIEF_RESULT_NONE: 3493 message = SimBriefSetupPage.progress2Message.get(progress, 3494 "simbrief_progress_unknown") 3495 self._wizard.gui.updateBusyState(xstr(message)) 3496 else: 3497 self._wizard.gui.endBusy() 3498 3499 if result==cef.SIMBRIEF_RESULT_OK: 3500 self._wizard.departureMETARChanged(flightInfo["orig_metar"], 3501 self) 3502 self._wizard.arrivalMETARChanged(flightInfo["dest_metar"], self) 3503 self._wizard.nextPage() 3504 else: 3505 message = SimBriefSetupPage.result2Message.get(result, 3506 "simbrief_result_unknown") 3507 dialog = Gtk.MessageDialog(parent = self._wizard.gui.mainWindow, 3508 type = Gtk.MessageType.ERROR, 3509 message_format = 3510 xstr(message) + "\n"+ 3511 xstr("simbrief_cancelled")) 3512 3513 dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK) 3514 dialog.set_title(WINDOW_TITLE_BASE) 3515 secondary = xstr("flightsel_save_failed_sec") 3516 dialog.format_secondary_markup(secondary) 3517 dialog.run() 3518 dialog.hide() 3519 3520 self._wizard.usingSimBrief = False 3521 self._wizard.jumpPage("fuel", fromPageShift = 1) 3522 3523 def _getPlan(self): 3435 # config = self._wizard.gui.config 3436 3437 # config.simBriefUserName = self._userName.get_text() 3438 3439 # rememberPassword = self._rememberButton.get_active() 3440 # config.simBriefPassword = \ 3441 # self._password.get_text() if rememberPassword else "" 3442 # config.rememberSimBriefPassword = rememberPassword 3443 3444 # config.save() 3445 3446 self._wizard.gui.simulator.requestTime(self._handleTime) 3447 3448 def _handleTime(self, simulatorNow): 3449 """Handle the result of a time retrieval.""" 3450 GObject.idle_add(self._processTime, simulatorNow) 3451 3452 def _processTime(self, simulatorNow): 3453 """Process the given time.""" 3454 plan = self._getPlan(simulatorNow) 3455 print("plan:", plan) 3456 3457 takeoffRunway = self._takeoffRunway.get_text() 3458 if takeoffRunway: 3459 self._wizard.takeoffRunway = takeoffRunway 3460 3461 landingRunway = self._landingRunway.get_text() 3462 if landingRunway: 3463 self._wizard.landingRunway = landingRunway 3464 3465 # self._userName.set_sensitive(False) 3466 # self._password.set_sensitive(False) 3467 # self._rememberButton.set_sensitive(False) 3468 self._extraFuel.set_sensitive(False) 3469 self._takeoffRunway.set_sensitive(False) 3470 self._landingRunway.set_sensitive(False) 3471 3472 self._climbProfile.set_sensitive(False) 3473 self._cruiseProfile.set_sensitive(False) 3474 self._descentProfile.set_sensitive(False) 3475 3476 self._wizard.gui.beginBusy(xstr("simbrief_calling")) 3477 3478 url = MAVA_BASE_URL + "/simbrief_form.php?" + \ 3479 urllib.parse.urlencode(plan) 3480 print("url:", url) 3481 3482 # GObject.idle_add(self._resultsAvailable, 3483 # { "orig_metar": "LDZA...", 3484 # "dest_metar": "LHBP..." }) 3485 # return 3486 3487 webbrowser.open(url = url, new = 1) 3488 3489 # cef.callSimBrief(plan, 3490 # self._getCredentials, 3491 # self._simBriefProgress, 3492 # SimBriefSetupPage.getHTMLFilePath()) 3493 3494 startSound(const.SOUND_NOTAM) 3495 3496 self._waitEnd = time.time() + SimBriefSetupPage._waitTimeout 3497 GObject.timeout_add(SimBriefSetupPage._resultQueryInterval, 3498 lambda: self._wizard.gui.webHandler. \ 3499 getSimBriefResult(self._resultCallback, 3500 self._resultTimestamp)) 3501 3502 # def _getCredentials(self, count): 3503 # """Get the credentials. 3504 3505 # If count is 0, the user name and password entered into the setup page 3506 # are returned. Otherwise a dialog box is displayed informing the user of 3507 # invalid credentials and requesting another set of them.""" 3508 # print("_getCredentials", count) 3509 # if count==0: 3510 # return (self._userName.get_text(), self._password.get_text()) 3511 # else: 3512 # gui = self._wizard.gui 3513 # config = gui.config 3514 3515 # dialog = SimBriefCredentialsDialog(gui, 3516 # config.simBriefUserName, 3517 # config.simBriefPassword, 3518 # config.rememberSimBriefPassword) 3519 # response = dialog.run() 3520 3521 # if response==Gtk.ResponseType.OK: 3522 # userName = dialog.userName 3523 # self._userName.set_text(userName) 3524 # password = dialog.password 3525 # self._password.set_text(password) 3526 # rememberPassword = dialog.rememberPassword 3527 3528 # config.simBriefUserName = userName 3529 3530 # config.simBriefPassword = \ 3531 # password if rememberPassword else "" 3532 # config.rememberSimBriefPassword = rememberPassword 3533 3534 # config.save() 3535 3536 # return (userName, password) 3537 # else: 3538 # return (None, None) 3539 3540 # def _simBriefProgress(self, progress, result, flightInfo): 3541 # """The real SimBrief progress handler.""" 3542 # print("_simBriefProgress", progress, result, flightInfo) 3543 # if result==cef.SIMBRIEF_RESULT_NONE: 3544 # message = SimBriefSetupPage.progress2Message.get(progress, 3545 # "simbrief_progress_unknown") 3546 # self._wizard.gui.updateBusyState(xstr(message)) 3547 # else: 3548 # self._wizard.gui.endBusy() 3549 3550 # if result==cef.SIMBRIEF_RESULT_OK: 3551 # self._wizard.departureMETARChanged(flightInfo["orig_metar"], 3552 # self) 3553 # self._wizard.arrivalMETARChanged(flightInfo["dest_metar"], self) 3554 # self._wizard.nextPage() 3555 # else: 3556 # message = SimBriefSetupPage.result2Message.get(result, 3557 # "simbrief_result_unknown") 3558 # dialog = Gtk.MessageDialog(parent = self._wizard.gui.mainWindow, 3559 # type = Gtk.MessageType.ERROR, 3560 # message_format = 3561 # xstr(message) + "\n"+ 3562 # xstr("simbrief_cancelled")) 3563 3564 # dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK) 3565 # dialog.set_title(WINDOW_TITLE_BASE) 3566 # secondary = xstr("flightsel_save_failed_sec") 3567 # dialog.format_secondary_markup(secondary) 3568 # dialog.run() 3569 # dialog.hide() 3570 3571 # self._wizard.usingSimBrief = False 3572 # self._wizard.jumpPage("fuel", fromPageShift = 1) 3573 3574 def _getPlan(self, simulatorNow): 3524 3575 """Get the flight plan data for SimBrief.""" 3576 print("timestamp:", simulatorNow) 3577 3578 self._resultTimestamp = now = int(time.time()) 3579 3525 3580 plan = { 3526 3581 "airline": "MAH", … … 3531 3586 "taxiout": "10", 3532 3587 "taxiin": "10", 3533 "civalue": "AUTO" 3588 "civalue": "AUTO", 3589 "lang": "hun" if getLanguage().lower()=="hu" else "eng", 3590 "sessionID": self._wizard._loginResult.sessionID, 3591 "timestamp": now 3534 3592 } 3535 3593 … … 3547 3605 plan["dest"] = bookedFlight.arrivalICAO 3548 3606 plan["reg"] = bookedFlight.tailNumber 3549 plan["fin"] = bookedFlight.tailNumber[3:]3550 3607 plan["pax"] = str(bookedFlight.numPassengers) 3551 3608 3552 3609 departureTime = bookedFlight.departureTime 3553 plan["date"] = "%d%s%d" % (departureTime.day, 3554 SimBriefSetupPage.monthNum2Name[departureTime.month-1], 3555 departureTime.year%100) 3556 plan["deph"] = str(departureTime.hour) 3557 plan["depm"] = str(departureTime.minute) 3610 print("departureTime", departureTime) 3611 3612 tm = time.gmtime(simulatorNow) 3613 diffMinutes = (departureTime.hour - tm.tm_hour)*60 + \ 3614 departureTime.minute - tm.tm_min 3615 while diffMinutes<0: 3616 diffMinutes += 24*60 3617 3618 realDepartureTime = datetime.datetime.utcnow() 3619 realDepartureTime += datetime.timedelta(minutes = diffMinutes) 3620 3621 plan["date"] = "%02d%s%02d" % (realDepartureTime.day, 3622 SimBriefSetupPage.monthNum2Name[realDepartureTime.month-1], 3623 realDepartureTime.year%100) 3624 plan["deph"] = str(realDepartureTime.hour) 3625 plan["depm"] = str(realDepartureTime.minute) 3558 3626 3559 3627 arrivalTime = bookedFlight.arrivalTime 3560 plan["steh"] = str(arrivalTime.hour) 3561 plan["stem"] = str(arrivalTime.minute) 3628 blockMinutes = (arrivalTime.hour - departureTime.hour)*60 + \ 3629 arrivalTime.minute - departureTime.minute 3630 while blockMinutes<0: 3631 blockMinutes += 24*60 3632 plan["steh"] = str(blockMinutes//60) 3633 plan["stem"] = str(blockMinutes%60) 3562 3634 3563 3635 plan["manualzfw"] = str(wizard.zfw / 1000.0) … … 3582 3654 return plan 3583 3655 3656 def _resultCallback(self, returned, result): 3657 """Callback for the SimBrief result query.""" 3658 GObject.idle_add(self._handleResult, returned, result) 3659 3660 def _handleResult(self, returned, result): 3661 """Handle an RPC query result.""" 3662 print("_handleResult", returned, result) 3663 if result.result and result.result.get("result"): 3664 link = result.result.get("result") 3665 if link=="<failed>": 3666 self._wizard.gui.endBusy() 3667 3668 self._finishWithError() 3669 else: 3670 link ="https://www.simbrief.com/ofp/flightplans/xml/" + link + ".xml" 3671 3672 thread = threading.Thread(target = self._getResults, args = (link,)) 3673 thread.daemon = True 3674 thread.start() 3675 3676 elif time.time() >= self._waitEnd: 3677 self._wizard.gui.endBusy() 3678 3679 self._finishWithError() 3680 else: 3681 GObject.timeout_add(SimBriefSetupPage._resultQueryInterval, 3682 lambda: self._wizard.gui.webHandler. \ 3683 getSimBriefResult(self._resultCallback, 3684 self._resultTimestamp)) 3685 3584 3686 def _upperChanged(self, entry, arg = None): 3585 3687 """Called when the value of some entry widget has changed and the value 3586 3688 should be converted to uppercase.""" 3587 3689 entry.set_text(entry.get_text().upper()) 3690 3691 def _getResults(self, link): 3692 """Get the result from the given link.""" 3693 ## Holds analysis data to be used 3694 flightInfo = {} 3695 try: 3696 availableInfo = {} 3697 3698 # Obtaining the xml 3699 response = urllib.request.urlopen(link, 3700 cafile = certifi.where()) 3701 content = etree.iterparse(response) 3702 3703 for (action, element) in content: 3704 # Processing tags that occur multiple times 3705 if element.tag == "weather": 3706 weatherElementList = list(element) 3707 for weatherElement in weatherElementList: 3708 flightInfo[weatherElement.tag] = weatherElement.text 3709 else: 3710 availableInfo[element.tag] = element.text 3711 3712 # Processing plan_html 3713 ## Obtaining chart links 3714 imageLinks = [] 3715 for imageLinkElement in lxml.html.find_class(availableInfo["plan_html"], 3716 "ofpmaplink"): 3717 for imageLink in imageLinkElement.iterlinks(): 3718 if imageLink[1] == 'src': 3719 imageLinks.append(imageLink[2]) 3720 flightInfo["image_links"] = imageLinks 3721 print((sorted(availableInfo.keys()))) 3722 htmlFilePath = SimBriefSetupPage.getHTMLFilePath() 3723 with open(htmlFilePath, 'w') as f: 3724 f.write(availableInfo["plan_html"]) 3725 except Exception as e: 3726 print("_getResults", e) 3727 3728 GObject.idle_add(self._resultsAvailable, flightInfo) 3729 3730 def _resultsAvailable(self, flightInfo): 3731 """Called from the result retrieval thread when the result is 3732 available.""" 3733 print("_resultsAvailable") 3734 self._wizard.gui.endBusy() 3735 3736 if flightInfo: 3737 self._wizard.departureMETARChanged(flightInfo["orig_metar"], 3738 self) 3739 self._wizard.arrivalMETARChanged(flightInfo["dest_metar"], self) 3740 self._wizard.nextPage() 3741 else: 3742 self._finishWithError() 3743 3744 def _finishWithError(self): 3745 """Display an error dialog, and when it is accepted, cancel 3746 SimBrief briefing and jump to the fuel page.""" 3747 dialog = Gtk.MessageDialog(parent = self._wizard.gui.mainWindow, 3748 type = Gtk.MessageType.ERROR, 3749 message_format = 3750 xstr("simbrief_result_error_other") + "\n"+ 3751 xstr("simbrief_cancelled")) 3752 3753 dialog.add_button(xstr("button_ok"), Gtk.ResponseType.OK) 3754 dialog.set_title(WINDOW_TITLE_BASE) 3755 secondary = xstr("flightsel_save_failed_sec") 3756 dialog.format_secondary_markup(secondary) 3757 dialog.run() 3758 dialog.hide() 3759 3760 self._wizard.usingSimBrief = False 3761 self._wizard.jumpPage("fuel", fromPageShift = 1) 3762 3763 3588 3764 3589 3765 #----------------------------------------------------------------------------- … … 3626 3802 self._button.set_use_stock(False) 3627 3803 3628 def activate(self):3629 """ Activate the SimBrief flight plan page"""3804 def prepareShow(self): 3805 """Prepare the page for showing (again).""" 3630 3806 if self._browser is None: 3631 3807 self._startBrowser() 3632 3808 else: 3633 3809 self._browser.Reload() 3810 3811 def prepareHide(self): 3812 """Prepare the page for hiding.""" 3813 if os.name!="nt": 3814 self._browser.CloseBrowser(False) 3634 3815 3635 3816 def grabDefault(self): … … 3661 3842 self._container = cef.getContainer() 3662 3843 self._alignment.add(self._container) 3844 else: 3845 self._container.show() 3663 3846 3664 3847 url = "file://" + SimBriefSetupPage.getHTMLFilePath() … … 3670 3853 def _invalidateBrowser(self): 3671 3854 """Invalidate the browser (and associated stuff).""" 3672 self._alignment.remove(self._container) 3673 self._container = None 3855 self._container.hide() 3674 3856 self._browser = None 3675 3857
Note:
See TracChangeset
for help on using the changeset viewer.