Changeset 811:e84ebe7c6497 for src/mlx
- Timestamp:
- 09/08/16 12:10:44 (8 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx/gui
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r810 r811 2 2 from mlx.gui.common import * 3 3 import mlx.gui.cef as cef 4 from mlx.gui.flightlist import ColumnDescriptor, FlightList 4 5 5 6 import mlx.const as const … … 436 437 class FlightSelectionPage(Page): 437 438 """The page to select the flight.""" 439 columnDescriptors = [ 440 ColumnDescriptor("callsign", xstr("flightsel_no")), 441 ColumnDescriptor("departureTime", xstr("flightsel_deptime")), 442 ColumnDescriptor("departureICAO", xstr("flightsel_from")), 443 ColumnDescriptor("arrivalICAO", xstr("flightsel_to")) 444 ] 445 438 446 def __init__(self, wizard): 439 447 """Construct the flight selection page.""" … … 444 452 help, completedHelp = completedHelp) 445 453 446 447 self._listStore = gtk.ListStore(str, str, str, str) 448 self._flightList = gtk.TreeView(self._listStore) 449 column = gtk.TreeViewColumn(xstr("flightsel_no"), gtk.CellRendererText(), 450 text = 1) 451 column.set_expand(True) 452 self._flightList.append_column(column) 453 column = gtk.TreeViewColumn(xstr("flightsel_deptime"), gtk.CellRendererText(), 454 text = 0) 455 column.set_expand(True) 456 self._flightList.append_column(column) 457 column = gtk.TreeViewColumn(xstr("flightsel_from"), gtk.CellRendererText(), 458 text = 2) 459 column.set_expand(True) 460 self._flightList.append_column(column) 461 column = gtk.TreeViewColumn(xstr("flightsel_to"), gtk.CellRendererText(), 462 text = 3) 463 column.set_expand(True) 464 self._flightList.append_column(column) 454 self._flightList = FlightList(FlightSelectionPage.columnDescriptors, 455 popupMenuProducer = 456 self._createListPopupMenu, 457 widthRequest = 400) 465 458 self._flightList.connect("row-activated", self._rowActivated) 466 self._flightList.connect("button-press-event", self._listButtonPressed) 467 468 self._flightListPopupMenu = None 469 470 flightSelection = self._flightList.get_selection() 471 flightSelection.connect("changed", self._selectionChanged) 472 473 scrolledWindow = gtk.ScrolledWindow() 474 scrolledWindow.add(self._flightList) 475 scrolledWindow.set_size_request(400, -1) 476 # FIXME: these should be constants in common.py 477 scrolledWindow.set_policy(gtk.PolicyType.AUTOMATIC if pygobject 478 else gtk.POLICY_AUTOMATIC, 479 gtk.PolicyType.AUTOMATIC if pygobject 480 else gtk.POLICY_AUTOMATIC) 481 scrolledWindow.set_shadow_type(gtk.ShadowType.IN if pygobject 482 else gtk.SHADOW_IN) 483 484 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 0.0, yscale = 1.0) 485 alignment.add(scrolledWindow) 486 487 self.setMainWidget(alignment) 459 self._flightList.connect("selection-changed", self._selectionChanged) 460 461 self.setMainWidget(self._flightList) 488 462 489 463 self._saveButton = self.addButton(xstr("flightsel_save"), … … 547 521 """Rebuild the flights from the login result.""" 548 522 self._flights = [] 549 self._ listStore.clear()523 self._flightList.clear() 550 524 if self._wizard.loggedIn: 551 525 for flight in self._wizard.loginResult.flights: … … 555 529 """Add the given file to the list of flights.""" 556 530 self._flights.append(flight) 557 self._listStore.append([str(flight.departureTime), 558 flight.callsign, 559 flight.departureICAO, 560 flight.arrivalICAO]) 531 self._flightList.addFlight(flight) 561 532 562 533 def _saveClicked(self, button): … … 608 579 self._buildFlights() 609 580 610 def _selectionChanged(self, selection):581 def _selectionChanged(self, flightList, index): 611 582 """Called when the selection is changed.""" 612 selected = selection.count_selected_rows()==1583 selected = index is not None 613 584 self._saveButton.set_sensitive(selected) 614 585 self._button.set_sensitive(selected) … … 649 620 self._flightSelected() 650 621 651 def _rowActivated(self, flightList, path, column):622 def _rowActivated(self, flightList, index): 652 623 """Called when a row is activated.""" 653 624 if not self._completed: … … 664 635 def _getSelectedFlight(self): 665 636 """Get the currently selected flight.""" 666 selection = self._flightList.get_selection() 667 (listStore, iter) = selection.get_selected() 668 path = listStore.get_path(iter) 669 [index] = path.get_indices() if pygobject else path 670 637 index = self._flightList.selectedIndex 671 638 return self._flights[index] 672 673 def _listButtonPressed(self, widget, event):674 """Called when a mouse button is pressed on the flight list."""675 if event.type!=EVENT_BUTTON_PRESS or event.button!=3:676 return677 678 (path, _, _, _) = self._flightList.get_path_at_pos(int(event.x),679 int(event.y))680 selection = self._flightList.get_selection()681 selection.unselect_all()682 selection.select_path(path)683 684 menu = self._getListPopupMenu()685 if pygobject:686 menu.popup(None, None, None, None, event.button, event.time)687 else:688 menu.popup(None, None, None, event.button, event.time)689 639 690 640 def _updateDepartureGate(self): … … 786 736 return dialog 787 737 788 def _ getListPopupMenu(self):738 def _createListPopupMenu(self): 789 739 """Get the flight list popup menu.""" 790 if self._flightListPopupMenu is None: 791 menu = gtk.Menu() 792 793 menuItem = gtk.MenuItem() 794 menuItem.set_label(xstr("flightsel_popup_select")) 795 menuItem.set_use_underline(True) 796 menuItem.connect("activate", self._popupSelect) 797 menuItem.show() 798 799 menu.append(menuItem) 800 801 menuItem = gtk.MenuItem() 802 menuItem.set_label(xstr("flightsel_popup_save")) 803 menuItem.set_use_underline(True) 804 menuItem.connect("activate", self._popupSave) 805 menuItem.show() 806 807 menu.append(menuItem) 808 809 self._flightListPopupMenu = menu 810 811 return self._flightListPopupMenu 740 menu = gtk.Menu() 741 742 menuItem = gtk.MenuItem() 743 menuItem.set_label(xstr("flightsel_popup_select")) 744 menuItem.set_use_underline(True) 745 menuItem.connect("activate", self._popupSelect) 746 menuItem.show() 747 748 menu.append(menuItem) 749 750 menuItem = gtk.MenuItem() 751 menuItem.set_label(xstr("flightsel_popup_save")) 752 menuItem.set_use_underline(True) 753 menuItem.connect("activate", self._popupSave) 754 menuItem.show() 755 756 menu.append(menuItem) 757 758 return menu 812 759 813 760 def _popupSelect(self, menuItem):
Note:
See TracChangeset
for help on using the changeset viewer.