Changeset 151:a2584357ff6c for src/mlx/gui
- Timestamp:
- 05/05/12 11:02:52 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/common.py
r149 r151 46 46 47 47 FILE_CHOOSER_ACTION_SELECT_FOLDER = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER 48 FILE_CHOOSER_ACTION_OPEN = gtk.FILE_CHOOSER_ACTION_OPEN 49 FILE_CHOOSER_ACTION_SAVE = gtk.FILE_CHOOSER_ACTION_SAVE 48 50 49 51 def text2unicode(text): … … 85 87 86 88 FILE_CHOOSER_ACTION_SELECT_FOLDER = gtk.FileChooserAction.SELECT_FOLDER 89 FILE_CHOOSER_ACTION_OPEN = gtk.FileChooserAction.OPEN 90 FILE_CHOOSER_ACTION_SAVE = gtk.FileChooserAction.SAVE 87 91 88 92 import codecs -
src/mlx/gui/flight.py
r146 r151 2187 2187 self._saveButton = self.addButton(xstr("finish_save"), 2188 2188 sensitive = False, 2189 tooltip = xstr("finish_send_tooltip")) 2190 2191 self._sendButton = self.addButton(xstr("finish_send"), default = True, 2189 clicked = self._saveClicked, 2190 tooltip = xstr("finish_save_tooltip")) 2191 self._savePIREPDialog = None 2192 self._lastSavePath = None 2193 2194 self._sendButton = self.addButton(xstr("sendPIREP"), default = True, 2192 2195 sensitive = False, 2193 2196 clicked = self._sendClicked, 2194 tooltip = xstr(" finish_send_tooltip"))2197 tooltip = xstr("sendPIREP_tooltip")) 2195 2198 2196 2199 @property … … 2255 2258 self._gate.get_active()>=0) 2256 2259 2257 #self._saveButton.set_sensitive(sensitive)2260 self._saveButton.set_sensitive(sensitive) 2258 2261 self._sendButton.set_sensitive(sensitive) 2259 2262 … … 2266 2269 self._updateButtons() 2267 2270 2271 def _saveClicked(self, button): 2272 """Called when the Save PIREP button is clicked.""" 2273 gui = self._wizard.gui 2274 2275 bookedFlight = gui.bookedFlight 2276 tm = time.gmtime() 2277 2278 fileName = "%s %s %02d%02d %s-%s.pirep" % \ 2279 (gui.loginResult.pilotID, 2280 str(bookedFlight.departureTime.date()), 2281 tm.tm_hour, tm.tm_min, 2282 bookedFlight.departureICAO, 2283 bookedFlight.arrivalICAO) 2284 2285 dialog = self._getSaveDialog() 2286 2287 if self._lastSavePath is None: 2288 pirepDirectory = gui.config.pirepDirectory 2289 if pirepDirectory is not None: 2290 dialog.set_current_folder(pirepDirectory) 2291 else: 2292 dialog.set_current_folder(os.path.dirname(self._lastSavePath)) 2293 2294 dialog.set_current_name(fileName) 2295 result = dialog.run() 2296 dialog.hide() 2297 2298 if result==RESPONSETYPE_OK: 2299 pirep = PIREP(gui) 2300 2301 self._lastSavePath = dialog.get_filename() 2302 2303 if pirep.save(self._lastSavePath): 2304 type = MESSAGETYPE_INFO 2305 message = xstr("finish_save_done") 2306 secondary = None 2307 else: 2308 type = MESSAGETYPE_ERROR 2309 message = xstr("finish_save_failed") 2310 secondary = xstr("finish_save_failed_sec") 2311 2312 dialog = gtk.MessageDialog(parent = gui.mainWindow, 2313 type = type, message_format = message) 2314 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 2315 dialog.set_title(WINDOW_TITLE_BASE) 2316 if secondary is not None: 2317 dialog.format_secondary_markup(secondary) 2318 2319 dialog.run() 2320 dialog.hide() 2321 2322 def _getSaveDialog(self): 2323 """Get the PIREP saving dialog. 2324 2325 If it does not exist yet, create it.""" 2326 if self._savePIREPDialog is None: 2327 gui = self._wizard.gui 2328 dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " + 2329 xstr("finish_save_title"), 2330 action = FILE_CHOOSER_ACTION_SAVE, 2331 buttons = (gtk.STOCK_CANCEL, 2332 RESPONSETYPE_CANCEL, 2333 gtk.STOCK_OK, RESPONSETYPE_OK), 2334 parent = gui.mainWindow) 2335 dialog.set_modal(True) 2336 dialog.set_do_overwrite_confirmation(True) 2337 2338 filter = gtk.FileFilter() 2339 filter.set_name(xstr("loadPIREP_filter_pireps")) 2340 filter.add_pattern("*.pirep") 2341 dialog.add_filter(filter) 2342 2343 filter = gtk.FileFilter() 2344 filter.set_name(xstr("loadPIREP_filter_all")) 2345 filter.add_pattern("*.*") 2346 dialog.add_filter(filter) 2347 2348 self._savePIREPDialog = dialog 2349 2350 return self._savePIREPDialog 2351 2352 2268 2353 def _sendClicked(self, button): 2269 2354 """Called when the Send button is clicked.""" 2270 2355 pirep = PIREP(self._wizard.gui) 2271 gui = self._wizard.gui 2272 gui.beginBusy(xstr("finish_send_busy")) 2273 gui.webHandler.sendPIREP(self._pirepSentCallback, pirep) 2274 2275 def _pirepSentCallback(self, returned, result): 2276 """Callback for the PIREP sending result.""" 2277 gobject.idle_add(self._handlePIREPSent, returned, result) 2356 self._wizard.gui.sendPIREP(pirep, 2357 callback = self._handlePIREPSent) 2278 2358 2279 2359 def _handlePIREPSent(self, returned, result): 2280 2360 """Callback for the PIREP sending result.""" 2281 self._wizard.gui.endBusy()2282 secondaryMarkup = None2283 type = MESSAGETYPE_ERROR2284 if returned:2285 if result.success:2286 type = MESSAGETYPE_INFO2287 messageFormat = xstr("finish_send_success")2288 secondaryMarkup = xstr("finish_send_success_sec")2289 elif result.alreadyFlown:2290 messageFormat = xstr("finish_send_already")2291 secondaryMarkup = xstr("finish_send_already_sec")2292 elif result.notAvailable:2293 messageFormat = xstr("finish_send_notavail")2294 else:2295 messageFormat = xstr("finish_send_unknown")2296 secondaryMarkup = xstr("finish_send_unknown_sec")2297 else:2298 print "PIREP sending failed", result2299 messageFormat = xstr("finish_send_failed")2300 secondaryMarkup = xstr("finish_send_failed_sec")2301 2302 dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow,2303 type = type, message_format = messageFormat)2304 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK)2305 dialog.set_title(WINDOW_TITLE_BASE)2306 if secondaryMarkup is not None:2307 dialog.format_secondary_markup(secondaryMarkup)2308 2309 dialog.run()2310 dialog.hide()2311 2312 2361 if self._wizard.gui.config.onlineGateSystem and returned and result.success: 2313 2362 bookedFlight = self._wizard.bookedFlight -
src/mlx/gui/gui.py
r148 r151 19 19 import mlx.web as web 20 20 from mlx.i18n import xstr 21 from mlx.pirep import PIREP 21 22 22 23 import time … … 61 62 self._stdioText = "" 62 63 64 self._sendPIREPCallback = None 65 63 66 self.webHandler = web.Handler() 64 67 self.webHandler.start() … … 145 148 self._busyCursor = gdk.Cursor(gdk.CursorType.WATCH if pygobject 146 149 else gdk.WATCH) 150 151 self._loadPIREPDialog = None 152 self._lastLoadedPIREP = None 147 153 148 154 @property … … 730 736 menuBar.append(fileMenuItem) 731 737 738 loadPIREPMenuItem = gtk.ImageMenuItem(gtk.STOCK_OPEN) 739 loadPIREPMenuItem.set_use_stock(True) 740 loadPIREPMenuItem.set_label(xstr("menu_file_loadPIREP")) 741 loadPIREPMenuItem.add_accelerator("activate", accelGroup, 742 ord(xstr("menu_file_loadPIREP_key")), 743 CONTROL_MASK, ACCEL_VISIBLE) 744 loadPIREPMenuItem.connect("activate", self._loadPIREP) 745 fileMenu.append(loadPIREPMenuItem) 746 747 fileMenu.append(gtk.SeparatorMenuItem()) 748 732 749 quitMenuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT) 733 750 quitMenuItem.set_use_stock(True) … … 865 882 else: 866 883 simulator.disableTimeSync() 884 885 def _loadPIREP(self, menuItem): 886 """Load a PIREP for sending.""" 887 dialog = self._getLoadPirepDialog() 888 889 if self._lastLoadedPIREP: 890 dialog.set_current_folder(os.path.dirname(self._lastLoadedPIREP)) 891 else: 892 pirepDirectory = self.config.pirepDirectory 893 if pirepDirectory is not None: 894 dialog.set_current_folder(pirepDirectory) 895 896 result = dialog.run() 897 dialog.hide() 898 899 if result==RESPONSETYPE_OK: 900 self._lastLoadedPIREP = dialog.get_filename() 901 902 pirep = PIREP.load(self._lastLoadedPIREP) 903 if pirep is None: 904 dialog = gtk.MessageDialog(parent = self._mainWindow, 905 type = MESSAGETYPE_ERROR, 906 message_format = xstr("loadPIREP_failed")) 907 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 908 dialog.set_title(WINDOW_TITLE_BASE) 909 dialog.format_secondary_markup(xstr("loadPIREP_failed_sec")) 910 dialog.run() 911 dialog.hide() 912 else: 913 dialog = self._getSendLoadedDialog(pirep) 914 dialog.show_all() 915 result = dialog.run() 916 dialog.hide() 917 918 if result==RESPONSETYPE_OK: 919 self.sendPIREP(pirep) 920 921 def _getLoadPirepDialog(self): 922 """Get the PIREP loading file chooser dialog. 923 924 If it is not created yet, it will be created.""" 925 if self._loadPIREPDialog is None: 926 dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " + 927 xstr("loadPIREP_browser_title"), 928 action = FILE_CHOOSER_ACTION_OPEN, 929 buttons = (gtk.STOCK_CANCEL, 930 RESPONSETYPE_CANCEL, 931 gtk.STOCK_OK, RESPONSETYPE_OK), 932 parent = self._mainWindow) 933 dialog.set_modal(True) 934 935 936 filter = gtk.FileFilter() 937 filter.set_name(xstr("loadPIREP_filter_pireps")) 938 filter.add_pattern("*.pirep") 939 dialog.add_filter(filter) 940 941 filter = gtk.FileFilter() 942 filter.set_name(xstr("loadPIREP_filter_all")) 943 filter.add_pattern("*.*") 944 dialog.add_filter(filter) 945 946 self._loadPIREPDialog = dialog 947 948 return self._loadPIREPDialog 949 950 def _getSendLoadedDialog(self, pirep): 951 """Get a dialog displaying the main information of the flight from the 952 PIREP and providing Cancel and Send buttons.""" 953 dialog = gtk.Dialog(title = WINDOW_TITLE_BASE + " - " + 954 xstr("loadPIREP_send_title"), 955 parent = self._mainWindow, 956 flags = DIALOG_MODAL) 957 958 contentArea = dialog.get_content_area() 959 960 label = gtk.Label(xstr("loadPIREP_send_help")) 961 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5, 962 xscale = 0.0, yscale = 0.0) 963 alignment.set_padding(padding_top = 16, padding_bottom = 0, 964 padding_left = 48, padding_right = 48) 965 alignment.add(label) 966 contentArea.pack_start(alignment, False, False, 8) 967 968 table = gtk.Table(5, 2) 969 tableAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5, 970 xscale = 0.0, yscale = 0.0) 971 tableAlignment.set_padding(padding_top = 0, padding_bottom = 32, 972 padding_left = 48, padding_right = 48) 973 table.set_row_spacings(4) 974 table.set_col_spacings(16) 975 tableAlignment.add(table) 976 contentArea.pack_start(tableAlignment, True, True, 8) 977 978 bookedFlight = pirep.bookedFlight 979 980 label = gtk.Label("<b>" + xstr("loadPIREP_send_flightno") + "</b>") 981 label.set_use_markup(True) 982 labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, 983 xscale = 0.0, yscale = 0.0) 984 labelAlignment.add(label) 985 table.attach(labelAlignment, 0, 1, 0, 1) 986 987 label = gtk.Label(bookedFlight.callsign) 988 labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5, 989 xscale = 0.0, yscale = 0.0) 990 labelAlignment.add(label) 991 table.attach(labelAlignment, 1, 2, 0, 1) 992 993 label = gtk.Label("<b>" + xstr("loadPIREP_send_date") + "</b>") 994 label.set_use_markup(True) 995 labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, 996 xscale = 0.0, yscale = 0.0) 997 labelAlignment.add(label) 998 table.attach(labelAlignment, 0, 1, 1, 2) 999 1000 label = gtk.Label(str(bookedFlight.departureTime.date())) 1001 labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5, 1002 xscale = 0.0, yscale = 0.0) 1003 labelAlignment.add(label) 1004 table.attach(labelAlignment, 1, 2, 1, 2) 1005 1006 label = gtk.Label("<b>" + xstr("loadPIREP_send_from") + "</b>") 1007 label.set_use_markup(True) 1008 labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, 1009 xscale = 0.0, yscale = 0.0) 1010 labelAlignment.add(label) 1011 table.attach(labelAlignment, 0, 1, 2, 3) 1012 1013 label = gtk.Label(bookedFlight.departureICAO) 1014 labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5, 1015 xscale = 0.0, yscale = 0.0) 1016 labelAlignment.add(label) 1017 table.attach(labelAlignment, 1, 2, 2, 3) 1018 1019 label = gtk.Label("<b>" + xstr("loadPIREP_send_to") + "</b>") 1020 label.set_use_markup(True) 1021 labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, 1022 xscale = 0.0, yscale = 0.0) 1023 labelAlignment.add(label) 1024 table.attach(labelAlignment, 0, 1, 3, 4) 1025 1026 label = gtk.Label(bookedFlight.arrivalICAO) 1027 labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5, 1028 xscale = 0.0, yscale = 0.0) 1029 labelAlignment.add(label) 1030 table.attach(labelAlignment, 1, 2, 3, 4) 1031 1032 label = gtk.Label("<b>" + xstr("loadPIREP_send_rating") + "</b>") 1033 label.set_use_markup(True) 1034 labelAlignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, 1035 xscale = 0.0, yscale = 0.0) 1036 labelAlignment.add(label) 1037 table.attach(labelAlignment, 0, 1, 4, 5) 1038 1039 rating = pirep.rating 1040 label = gtk.Label() 1041 if rating<0: 1042 label.set_markup('<b><span foreground="red">NO GO</span></b>') 1043 else: 1044 label.set_text("%.1f %%" % (rating,)) 1045 1046 labelAlignment = gtk.Alignment(xalign = 0.0, yalign = 0.5, 1047 xscale = 0.0, yscale = 0.0) 1048 labelAlignment.add(label) 1049 table.attach(labelAlignment, 1, 2, 4, 5) 1050 1051 dialog.add_button(xstr("button_cancel"), RESPONSETYPE_REJECT) 1052 dialog.add_button(xstr("sendPIREP"), RESPONSETYPE_OK) 1053 1054 return dialog 1055 1056 def sendPIREP(self, pirep, callback = None): 1057 """Send the given PIREP.""" 1058 self.beginBusy(xstr("sendPIREP_busy")) 1059 self._sendPIREPCallback = callback 1060 self.webHandler.sendPIREP(self._pirepSentCallback, pirep) 1061 1062 def _pirepSentCallback(self, returned, result): 1063 """Callback for the PIREP sending result.""" 1064 gobject.idle_add(self._handlePIREPSent, returned, result) 1065 1066 def _handlePIREPSent(self, returned, result): 1067 """Callback for the PIREP sending result.""" 1068 self.endBusy() 1069 secondaryMarkup = None 1070 type = MESSAGETYPE_ERROR 1071 if returned: 1072 if result.success: 1073 type = MESSAGETYPE_INFO 1074 messageFormat = xstr("sendPIREP_success") 1075 secondaryMarkup = xstr("sendPIREP_success_sec") 1076 elif result.alreadyFlown: 1077 messageFormat = xstr("sendPIREP_already") 1078 secondaryMarkup = xstr("sendPIREP_already_sec") 1079 elif result.notAvailable: 1080 messageFormat = xstr("sendPIREP_notavail") 1081 else: 1082 messageFormat = xstr("sendPIREP_unknown") 1083 secondaryMarkup = xstr("sendPIREP_unknown_sec") 1084 else: 1085 print "PIREP sending failed", result 1086 messageFormat = xstr("sendPIREP_failed") 1087 secondaryMarkup = xstr("sendPIREP_failed_sec") 1088 1089 dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow, 1090 type = type, message_format = messageFormat) 1091 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 1092 dialog.set_title(WINDOW_TITLE_BASE) 1093 if secondaryMarkup is not None: 1094 dialog.format_secondary_markup(secondaryMarkup) 1095 1096 dialog.run() 1097 dialog.hide() 1098 1099 callback = self._sendPIREPCallback 1100 self._sendPIREPCallback = None 1101 if callback is not None: 1102 callback(returned, result) -
src/mlx/gui/prefs.py
r149 r151 238 238 action = FILE_CHOOSER_ACTION_SELECT_FOLDER, 239 239 buttons = (gtk.STOCK_CANCEL, RESPONSETYPE_CANCEL, 240 gtk.STOCK_OK, RESPONSETYPE_OK)) 240 gtk.STOCK_OK, RESPONSETYPE_OK), 241 parent = self) 242 dialog.set_modal(True) 243 dialog.set_transient_for(self) 241 244 242 245 directory = self._pirepDirectory.get_text()
Note:
See TracChangeset
for help on using the changeset viewer.