Ignore:
Timestamp:
07/07/12 09:23:28 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added popup menu to the list of flights

Location:
src/mlx/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/common.py

    r276 r277  
    6565    SORT_ASCENDING = gtk.SORT_ASCENDING
    6666    SORT_DESCENDING = gtk.SORT_DESCENDING
     67
     68    EVENT_BUTTON_PRESS = gdk.BUTTON_PRESS
    6769
    6870    pixbuf_new_from_file = gdk.pixbuf_new_from_file
     
    128130    SORT_DESCENDING = gtk.SortType.DESCENDING
    129131
     132    EVENT_BUTTON_PRESS = gdk.EventType.BUTTON_PRESS
     133
    130134    pixbuf_new_from_file = gdkPixbuf.Pixbuf.new_from_file
    131135
  • src/mlx/gui/flight.py

    r275 r277  
    381381        column.set_expand(True)
    382382        self._flightList.append_column(column)
     383        self._flightList.connect("row-activated", self._rowActivated)
     384        self._flightList.connect("button-press-event", self._listButtonPressed)
     385
     386        self._flightListPopupMenu = None
    383387
    384388        flightSelection = self._flightList.get_selection()
    385         flightSelection.connect("changed", self._selectionChanged)
     389        flightSelection.connect("changed", self._selectionChanged)       
    386390
    387391        scrolledWindow = gtk.ScrolledWindow()
     
    454458    def _saveClicked(self, button):
    455459        """Called when the Save flight button is clicked."""
     460        self._saveSelected()
     461
     462    def _saveSelected(self):
     463        """Save the selected flight."""
    456464        flight = self._getSelectedFlight()
    457465        date = flight.departureTime.date()
     
    533541            self._wizard.jumpPage(self._nextDistance, finalize = False)
    534542        else:
    535             flight = self._getSelectedFlight()
    536             self._wizard._bookedFlight = flight
    537             self._wizard.gui.enableFlightInfo()
    538 
    539             self._updateDepartureGate()
     543            self._flightSelected()
     544
     545    def _rowActivated(self, flightList, path, column):
     546        """Called when a row is activated."""
     547        if not self._completed:
     548            self._flightSelected()
     549
     550    def _flightSelected(self):
     551        """Called when a flight has been selected."""
     552        flight = self._getSelectedFlight()
     553        self._wizard._bookedFlight = flight
     554        self._wizard.gui.enableFlightInfo()
     555       
     556        self._updateDepartureGate()
    540557
    541558    def _getSelectedFlight(self):
     
    547564       
    548565        return self._flights[index]
     566
     567    def _listButtonPressed(self, widget, event):
     568        """Called when a mouse button is pressed on the flight list."""
     569        if event.type!=EVENT_BUTTON_PRESS or event.button!=3:
     570            return
     571
     572        (path, _, _, _) = self._flightList.get_path_at_pos(int(event.x),
     573                                                           int(event.y))
     574        selection = self._flightList.get_selection()
     575        selection.unselect_all()
     576        selection.select_path(path)
     577
     578        menu = self._getListPopupMenu()
     579        if pygobject:
     580            menu.popup(None, None, None, None, event.button, event.time)
     581        else:
     582            menu.popup(None, None, None, event.button, event.time)
    549583       
    550584    def _updateDepartureGate(self):
     
    645679       
    646680        return dialog       
     681
     682    def _getListPopupMenu(self):
     683        """Get the flight list popup menu."""
     684        if self._flightListPopupMenu is None:
     685            menu = gtk.Menu()
     686
     687            menuItem = gtk.MenuItem()
     688            menuItem.set_label(xstr("flightsel_popup_select"))
     689            menuItem.set_use_underline(True)
     690            menuItem.connect("activate", self._popupSelect)
     691            menuItem.show()
     692
     693            menu.append(menuItem)
     694       
     695            menuItem = gtk.MenuItem()
     696            menuItem.set_label(xstr("flightsel_popup_save"))
     697            menuItem.set_use_underline(True)
     698            menuItem.connect("activate", self._popupSave)
     699            menuItem.show()
     700
     701            menu.append(menuItem)
     702
     703            self._flightListPopupMenu = menu
     704
     705        return self._flightListPopupMenu
     706
     707    def _popupSelect(self, menuItem):
     708        """Called when the Select menu item is activated in the popup menu."""
     709        if not self._completed:
     710            self._flightSelected()
     711   
     712    def _popupSave(self, menuItem):
     713        """Called when the Save menu item is activated in the popup menu."""
     714        if not self._completed:
     715            self._saveSelected()
    647716   
    648717#-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.