Changeset 67:6a8ed0857638 for src/mlx
- Timestamp:
- 04/09/12 07:22:16 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r65 r67 109 109 if self._defaultButton is not None: 110 110 self._defaultButton.grab_default() 111 112 def reset(self): 113 """Reset the page if the wizard is reset.""" 114 pass 111 115 112 116 #----------------------------------------------------------------------------- … … 871 875 def _handleNOTAMs(self, returned, result): 872 876 """Handle the NOTAMs.""" 873 self._wizard.gui.endBusy()874 877 if returned: 875 878 self._wizard._departureNOTAMs = result.departureNOTAMs 876 879 self._wizard._arrivalNOTAMs = result.arrivalNOTAMs 877 880 else: 881 self._wizard._departureNOTAMs = None 882 self._wizard._arrivalNOTAMs = None 883 884 bookedFlight = self._wizard._bookedFlight 885 self._wizard.gui.beginBusy("Downloading METARs...") 886 self._wizard.gui.webHandler.getMETARs(self._metarsCallback, 887 [bookedFlight.departureICAO, 888 bookedFlight.arrivalICAO]) 889 890 def _metarsCallback(self, returned, result): 891 """Callback for the METARs.""" 892 gobject.idle_add(self._handleMETARs, returned, result) 893 894 def _handleMETARs(self, returned, result): 895 """Handle the METARs.""" 896 self._wizard._departureMETAR = None 897 self._wizard._arrivalMETAR = None 898 bookedFlight = self._wizard._bookedFlight 899 if returned: 900 if bookedFlight.departureICAO in result.metars: 901 self._wizard._departureMETAR = result.metars[bookedFlight.departureICAO] 902 if bookedFlight.arrivalICAO in result.metars: 903 self._wizard._arrivalMETAR = result.metars[bookedFlight.arrivalICAO] 904 905 self._wizard.gui.endBusy() 878 906 self._wizard.nextPage() 879 907 880 908 #----------------------------------------------------------------------------- 881 909 882 class NOTAMPage(Page): 883 """Page for the NOTAMs.""" 884 def __init__(self, wizard): 885 help = "Read carefully the NOTAMs below." 886 887 super(NOTAMPage, self).__init__(wizard, "NOTAMs", help) 910 class BriefingPage(Page): 911 """Page for the briefing.""" 912 def __init__(self, wizard, departure): 913 """Construct the briefing page.""" 914 self._departure = departure 915 self._activated = False 916 917 title = "Briefing (%d/2): %s airport" % (1 if departure else 2, 918 "departure" if departure 919 else "arrival") 920 921 help = "Read carefully the NOTAMs and METAR below." 922 923 super(BriefingPage, self).__init__(wizard, title, help) 888 924 889 925 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5, … … 894 930 self.setMainWidget(alignment) 895 931 896 self._ departureNOTAMsFrame = gtk.Frame()897 self._ departureNOTAMsFrame.set_label("LHBP NOTAMs")932 self._notamsFrame = gtk.Frame() 933 self._notamsFrame.set_label("LHBP NOTAMs") 898 934 scrolledWindow = gtk.ScrolledWindow() 899 scrolledWindow.set_size_request(-1, 80) 900 self._departureNOTAMs = gtk.TextView() 901 self._departureNOTAMs.set_wrap_mode(gtk.WrapMode.WORD if pygobject else 902 gtk.WRAP_WORD) 903 scrolledWindow.add(self._departureNOTAMs) 904 self._departureNOTAMsFrame.add(scrolledWindow) 905 mainBox.pack_start(self._departureNOTAMsFrame, True, True, 4) 906 907 self._arrivalNOTAMsFrame = gtk.Frame() 908 self._arrivalNOTAMsFrame.set_label("LIRF NOTAMs") 935 scrolledWindow.set_size_request(-1, 128) 936 self._notams = gtk.TextView() 937 self._notams.set_editable(False) 938 self._notams.set_accepts_tab(False) 939 self._notams.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD) 940 scrolledWindow.add(self._notams) 941 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0, 942 xscale = 1.0, yscale = 1.0) 943 alignment.set_padding(padding_top = 4, padding_bottom = 0, 944 padding_left = 0, padding_right = 0) 945 alignment.add(scrolledWindow) 946 self._notamsFrame.add(alignment) 947 mainBox.pack_start(self._notamsFrame, True, True, 4) 948 949 self._metarFrame = gtk.Frame() 950 self._metarFrame.set_label("LHBP METAR") 909 951 scrolledWindow = gtk.ScrolledWindow() 910 scrolledWindow.set_size_request(-1, 80) 911 self._arrivalNOTAMs = gtk.TextView() 912 self._arrivalNOTAMs.set_wrap_mode(gtk.WrapMode.WORD if pygobject else 913 gtk.WRAP_WORD) 914 scrolledWindow.add(self._arrivalNOTAMs) 915 self._arrivalNOTAMsFrame.add(scrolledWindow) 916 mainBox.pack_start(self._arrivalNOTAMsFrame, True, True, 4) 917 918 # metarBox = gtk.HBox() 919 920 # departureMETARFrame = gtk.Frame() 921 # departureMETARFrame.set_label("LHBP METAR") 922 # scrolledWindow = gtk.ScrolledWindow() 923 # self._departureMETAR = gtk.TextView() 924 # scrolledWindow.add(self._departureMETAR) 925 # departureMETARFrame.add(scrolledWindow) 926 # metarBox.pack_start(departureMETARFrame, True, True, 4) 927 928 # arrivalMETARFrame = gtk.Frame() 929 # arrivalMETARFrame.set_label("EPWA METAR") 930 # scrolledWindow = gtk.ScrolledWindow() 931 # self._arrivalMETAR = gtk.TextView() 932 # scrolledWindow.add(self._arrivalMETAR) 933 # arrivalMETARFrame.add(scrolledWindow) 934 # metarBox.pack_start(arrivalMETARFrame, True, True, 4) 935 936 # mainBox.pack_start(metarBox, True, True, 4) 952 scrolledWindow.set_size_request(-1, 32) 953 self._metar = gtk.TextView() 954 self._metar.set_editable(False) 955 self._metar.set_accepts_tab(False) 956 self._metar.set_wrap_mode(gtk.WrapMode.WORD if pygobject else gtk.WRAP_WORD) 957 scrolledWindow.add(self._metar) 958 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0, 959 xscale = 1.0, yscale = 1.0) 960 alignment.set_padding(padding_top = 4, padding_bottom = 0, 961 padding_left = 0, padding_right = 0) 962 alignment.add(scrolledWindow) 963 self._metarFrame.add(alignment) 964 mainBox.pack_start(self._metarFrame, True, True, 4) 937 965 938 966 self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True) … … 942 970 def activate(self): 943 971 """Activate the page.""" 944 bookedFlight = self._wizard._bookedFlight 945 self._setupNOTAMs(self._departureNOTAMsFrame, self._departureNOTAMs, 946 bookedFlight.departureICAO, self._wizard._departureNOTAMs) 947 self._setupNOTAMs(self._arrivalNOTAMsFrame, self._arrivalNOTAMs, 948 bookedFlight.arrivalICAO, self._wizard._arrivalNOTAMs) 949 950 def _setupNOTAMs(self, frame, textView, icao, notams): 951 """Setup the NOTAMs.""" 952 frame.set_label(icao + " NOTAMs") 953 buffer = textView.get_buffer() 954 if notams is None: 955 buffer.set_text("Could not download NOTAMs") 972 if self._activated: 973 if not self._departure: 974 self._button.set_label(gtk.STOCK_GO_FORWARD) 975 self._button.set_use_stock(True) 956 976 else: 957 s = "" 958 for notam in notams: 959 s += str(notam.begin) 960 if notam.end is not None: 961 s += " - " + str(notam.end) 962 elif notam.permanent: 963 s += " - PERMANENT" 964 s += "\n" 965 if notam.repeatCycle: 966 s += "Repeat cycle: " + notam.repeatCycle + "\n" 967 s += notam.notice + "\n" 968 s += "-------------------- * --------------------\n" 969 buffer.set_text(s) 970 971 def _forwardClicked(self): 977 if not self._departure: 978 self._button.set_label("I have read the briefing and am ready to fly!") 979 self._button.set_use_stock(False) 980 981 bookedFlight = self._wizard._bookedFlight 982 983 icao = bookedFlight.departureICAO if self._departure \ 984 else bookedFlight.arrivalICAO 985 notams = self._wizard._departureNOTAMs if self._departure \ 986 else self._wizard._arrivalNOTAMs 987 metar = self._wizard._departureMETAR if self._departure \ 988 else self._wizard._arrivalMETAR 989 990 self._notamsFrame.set_label(icao + " NOTAMs") 991 buffer = self._notams.get_buffer() 992 if notams is None: 993 buffer.set_text("Could not download NOTAMs") 994 else: 995 s = "" 996 for notam in notams: 997 s += str(notam.begin) 998 if notam.end is not None: 999 s += " - " + str(notam.end) 1000 elif notam.permanent: 1001 s += " - PERMANENT" 1002 s += "\n" 1003 if notam.repeatCycle: 1004 s += "Repeat cycle: " + notam.repeatCycle + "\n" 1005 s += notam.notice + "\n" 1006 s += "-------------------- * --------------------\n" 1007 buffer.set_text(s) 1008 1009 self._metarFrame.set_label(icao + " METAR") 1010 buffer = self._metar.get_buffer() 1011 if metar is None: 1012 buffer.set_text("Could not download METAR") 1013 else: 1014 buffer.set_text(metar) 1015 1016 self._activated = True 1017 1018 def reset(self): 1019 """Reset the page if the wizard is reset.""" 1020 super(BriefingPage, self).reset() 1021 self._activated = False 1022 1023 def _forwardClicked(self, button): 972 1024 """Called when the forward button is clicked.""" 1025 self._wizard.nextPage() 973 1026 974 1027 #----------------------------------------------------------------------------- … … 992 1045 self._pages.append(TimePage(self)) 993 1046 self._pages.append(RoutePage(self)) 994 self._pages.append(NOTAMPage(self)) 995 1047 self._pages.append(BriefingPage(self, True)) 1048 self._pages.append(BriefingPage(self, False)) 1049 996 1050 maxWidth = 0 997 1051 maxHeight = 0 … … 1064 1118 self._route = None 1065 1119 self._departureNOTAMs = None 1120 self._departureMETAR = None 1066 1121 self._arrivalNOTAMs = None 1122 self._arrivalMETAR = None 1123 1124 for page in self._pages: 1125 page.reset() 1067 1126 1068 1127 self.setCurrentPage(0) -
src/mlx/web.py
r66 r67 13 13 import datetime 14 14 import codecs 15 import re16 15 import xml.sax 17 16 … … 452 451 """Get the METARs from the NOAA website for certain airport ICAOs.""" 453 452 454 # Regular expression matching a METAR line455 metarLine = re.compile("^[A-Z0-9]{4} ")456 457 453 def __init__(self, callback, airports): 458 454 """Construct the request for the given airports."""
Note:
See TracChangeset
for help on using the changeset viewer.