Changeset 279:192aeea89424


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

Added a popup menu to the checklist editor's file list

File:
1 edited

Legend:

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

    r268 r279  
    141141        self._fileListModel = gtk.ListStore(str, str)
    142142        self._fileList = gtk.TreeView(model = self._fileListModel)
     143        self._fileList.connect("button-press-event",
     144                               self._fileListButtonPressed)
    143145        column = gtk.TreeViewColumn(xstr("chklst_header"),
    144146                                    gtk.CellRendererText(), text = 0)
     
    149151        self._fileList.set_tooltip_column(1)
    150152        self._fileList.set_reorderable(True)
     153        self._fileListPopupMenu = None
    151154        selection = self._fileList.get_selection()
    152155        selection.set_mode(SELECTION_MULTIPLE)
    153156        selection.connect("changed", self._fileListSelectionChanged)
     157
     158        self._buildFileListPopupMenu()
    154159
    155160        scrolledWindow = gtk.ScrolledWindow()
     
    206211    def _removeButtonClicked(self, button):
    207212        """Called when the Remove button is clicked."""
     213        self._removeSelected()
     214
     215    def _removeSelected(self):
     216        """Remove the currently selected files."""
    208217        selection = self._fileList.get_selection()
    209218        (model, paths) = selection.get_selected_rows()
     
    250259        anySelected = selection.count_selected_rows()>0
    251260        self._removeButton.set_sensitive(anySelected)
     261        self._popupRemoveItem.set_sensitive(anySelected)
    252262
    253263        if anySelected:
     
    261271                       
    262272            self._moveUpButton.set_sensitive(minIndex>0)
     273            self._popupMoveUpItem.set_sensitive(minIndex>0)
    263274
    264275            numRows = model.iter_n_children(None)
    265276            self._moveDownButton.set_sensitive(maxIndex<(numRows-1))
     277            self._popupMoveDownItem.set_sensitive(maxIndex<(numRows-1))
    266278        else:
    267279            self._moveUpButton.set_sensitive(False)
     280            self._popupMoveUpItem.set_sensitive(False)
    268281            self._moveDownButton.set_sensitive(False)
     282            self._popupMoveDownItem.set_sensitive(False)
    269283
    270284    def _getAircraftType(self):
     
    299313            self._fileListModel.append([os.path.basename(path), path])
    300314       
     315    def _fileListButtonPressed(self, widget, event):
     316        """Called when a mouse button is pressed on the file list."""
     317        if event.type!=EVENT_BUTTON_PRESS or event.button!=3:
     318            return
     319
     320        # (path, _, _, _) = self._flightList.get_path_at_pos(int(event.x),
     321        #                                                    int(event.y))
     322        # selection = self._flightList.get_selection()
     323        # selection.unselect_all()
     324        # selection.select_path(path)
     325
     326        menu = self._fileListPopupMenu
     327        if pygobject:
     328            menu.popup(None, None, None, None, event.button, event.time)
     329        else:
     330            menu.popup(None, None, None, event.button, event.time)
     331
     332    def _buildFileListPopupMenu(self):
     333        """Get the file list popup menu."""
     334        menu = gtk.Menu()
     335
     336        menuItem = gtk.MenuItem()
     337        menuItem.set_label(xstr("chklst_remove"))
     338        menuItem.set_use_underline(True)
     339        menuItem.connect("activate", self._popupRemove)
     340        menuItem.show()
     341        self._popupRemoveItem = menuItem
     342
     343        menu.append(menuItem)
     344
     345        menuItem = gtk.MenuItem()
     346        menuItem.set_label(xstr("chklst_moveUp"))
     347        menuItem.set_use_underline(True)
     348        menuItem.connect("activate", self._popupMoveUp)
     349        menuItem.show()
     350        self._popupMoveUpItem = menuItem
     351
     352        menu.append(menuItem)
     353
     354        menuItem = gtk.MenuItem()
     355        menuItem.set_label(xstr("chklst_moveDown"))
     356        menuItem.set_use_underline(True)
     357        menuItem.connect("activate", self._popupMoveDown)
     358        menuItem.show()
     359        self._popupMoveDownItem = menuItem
     360
     361        menu.append(menuItem)
     362
     363        self._fileListPopupMenu = menu
     364
     365    def _popupRemove(self, menuItem):
     366        """Remove the currently selected menu items."""
     367        self._removeSelected()
     368
     369    def _popupMoveUp(self, menuItem):
     370        """Move up the currently selected menu items."""
     371        self._moveSelected(True)
     372
     373    def _popupMoveDown(self, menuItem):
     374        """Move down the currently selected menu items."""
     375        self._moveSelected(False)
    301376       
    302377#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.