Sets the context menu of the tree view.

        :param context_menu: QMenu
772023
def set_context_menu(self, context_menu):
        
        self.context_menu = context_menu
        self.context_menu.tree_view = self
        self.context_menu.init_actions()
        for action in self.context_menu.actions():
            self.addAction(action)
689626
def setupHeaderMenu(self, menu, index):
        
        if not self.userGroupingEnabled():
            return False
        
        first_action = menu.actions()[1]
        column = self.columnOf(index)
        
        enable_action = QAction(menu)
        enable_action.setText('Enable Grouping')
        
        disable_action = QAction(menu)
        disable_action.setText('Disable Grouping')
        
        quick_action = QAction(menu)
        quick_action.setText('Group by "%s"' % column)
        
#        adv_action = QAction(menu)
#        adv_action.setText('More Grouping Options...')
        
        menu.insertSeparator(first_action)
        menu.insertAction(first_action, enable_action)
        menu.insertAction(first_action, disable_action)
        menu.insertSeparator(first_action)
        menu.insertAction(first_action, quick_action)
#        menu.insertAction(first_action, adv_action)
        
        quick_action.triggered.connect(self.groupByHeaderIndex)
#        adv_action.triggered.connect(self.showAdvancedGroupingOptions)
        enable_action.triggered.connect(self.activateGrouping)
        disable_action.triggered.connect(self.deactivateGrouping)
        return True
951955
def init_with_context(self, context):
        
        from admin_tools.menu.models import Bookmark

        for b in Bookmark.objects.filter(user=context['request'].user):
            self.children.append(MenuItem(mark_safe(b.title), b.url))

        if not len(self.children):
            self.enabled = False
1215583
public void addContextMenuTreeListener(
        CmsContextMenu.ContextMenuOpenedListener.TreeListener contextMenuTreeListener) {

        addListener(
            ContextMenuOpenedOnTreeItemEvent.class,
            contextMenuTreeListener,
            ContextMenuOpenedListener.TreeListener.MENU_OPENED_FROM_TREE_ITEM_METHOD);
    }
1129830
def setup_context_menu(self):
        """"""
        PythonShellWidget.setup_context_menu(self)
        self.help_action = create_action(self, _("Help..."),
                           icon=ima.icon('DialogHelpButton'),
                           triggered=self.help)
        self.menu.addAction(self.help_action)
206933
def _popup_menu(self, icon, button, time, extended=True):
        """"""
        m = self.create_context_menu(extended)
        m.show_all()
        m.popup(parent_menu_shell=None,
                parent_menu_item=None,
                func=icon.position_menu,
                data=icon,
                button=button,
                activate_time=time)
        # need to store reference or menu will be destroyed before showing:
        self._m = m
1165960
def contextMenuEvent(self, event):
        
        if self.contextMenuPolicy() == Qt.DefaultContextMenu:
            self.showMenu(event.pos())
        else:
            super(XOrbTreeWidget, self).contextMenuEvent(event)
75748
def mk_notebook_context_menu(callback_object):
    
    callback_object.context_menu = Gtk.Menu()
    menu = callback_object.context_menu
    mi = Gtk.MenuItem(_("New Tab"))
    mi.connect("activate", callback_object.on_new_tab)
    menu.add(mi)
    menu.add(Gtk.SeparatorMenuItem())
    mi = Gtk.MenuItem(_("Save Tabs"))
    mi.connect("activate", callback_object.on_save_tabs)
    menu.add(mi)
    mi = Gtk.MenuItem(_("Restore Tabs"))
    mi.connect("activate", callback_object.on_restore_tabs_with_dialog)
    menu.add(mi)
    menu.add(Gtk.SeparatorMenuItem())
    mi = Gtk.ImageMenuItem("gtk-preferences")
    mi.set_use_stock(True)
    mi.connect("activate", callback_object.on_show_preferences)
    menu.add(mi)
    mi = Gtk.ImageMenuItem("gtk-about")
    mi.set_use_stock(True)
    mi.connect("activate", callback_object.on_show_about)
    menu.add(mi)
    menu.add(Gtk.SeparatorMenuItem())
    mi = Gtk.MenuItem(_("Quit"))
    mi.connect("activate", callback_object.on_quit)
    menu.add(mi)
    menu.show_all()
    return menu
827650
def inject_context(self, __context_dict__=None, **context):
        
        context = context or __context_dict__
        self.context_keys |= set(context.keys())
        for key, value in context.items():
            setattr(self, key, value)
        for command in self.subcommands.values():
            command.inject_context(context)
712474
def _show_context_menu(self, point):
        
        tc = self.textCursor()
        nc = self.cursorForPosition(point)
        if not nc.position() in range(tc.selectionStart(), tc.selectionEnd()):
            self.setTextCursor(nc)
        self._mnu = self.get_context_menu()
        if len(self._mnu.actions()) > 1 and self.show_context_menu:
            self._mnu.popup(self.mapToGlobal(point))
1298121
public void setMenu(Menu menu) {
        this.menu = menu;

        RadialMenuItem.setupMenuButton(this, radialMenuParams, (menu != null) ? menu.getGraphic() : null, (menu != null) ? menu.getText() : null, true);
    }
1357937
def contextMenuEvent(self, event):
        
        menu = QtWidgets.QTextEdit.createStandardContextMenu(self)

        # create max.lines spin box:
        w = QtWidgets.QWidget()
        l = QtWidgets.QHBoxLayout()
        w.setLayout(l)
        e = QtWidgets.QSpinBox()
        e.setRange(1, 1e6)
        e.setValue(self.MAXLINES)
        e.valueChanged.connect(self.document().setMaximumBlockCount)
        l.addWidget(QtWidgets.QLabel('Max. lines'))
        l.addWidget(e)

        # add spinbox to menu:
        a = QtWidgets.QWidgetAction(self)
        a.setDefaultWidget(w)
        menu.addAction(a)

        menu.exec_(event.globalPos())
183060
def get_context_menu(self, qpoint):
        
        menu = QMenu(self)
        index = self.view.indexAt(qpoint)

        def add_action(menu, text, handler, icon=None):
            a = None
            if icon is None:
                a = QAction(text, self)
            else:
                a = QAction(icon, text, self)
            a.triggered.connect(handler)
            menu.addAction(a)

        add_action(menu, "Color selection", self._handle_color_selection)

        # duplication here with vstructui
        color_menu = menu.addMenu("Color selection...")

        # need to escape the closure capture on the color loop variable below
        # hint from: http://stackoverflow.com/a/6035865/87207
        def make_color_selection_handler(color):
            return lambda: self._handle_color_selection(color=color)

        for color in QT_COLORS:
            add_action(color_menu, "{:s}".format(color.name),
                       make_color_selection_handler(color.qcolor), make_color_icon(color.qcolor))

        start = self._hsm.start
        end = self._hsm.end
        cm = self.getColorModel()
        if (start == end and cm.is_index_colored(start)) or cm.is_region_colored(start, end):
            def make_remove_color_handler(r):
                return lambda: self._handle_remove_color_range(r)

            remove_color_menu = menu.addMenu("Remove color...")
            for cr in cm.get_region_colors(start, end):
                pixmap = QPixmap(10, 10)
                pixmap.fill(cr.color)
                icon = QIcon(pixmap)
                add_action(remove_color_menu,
                       "Remove color [{:s}, {:s}], len: {:s}".format(h(cr.begin), h(cr.end), h(cr.end - cr.begin)),
                       make_remove_color_handler(cr), make_color_icon(cr.color))

        menu.addSeparator()  # -----------------------------------------------------------------

        add_action(menu, "Copy selection (binary)", self._handle_copy_binary)
        copy_menu = menu.addMenu("Copy...")
        add_action(copy_menu, "Copy selection (binary)", self._handle_copy_binary)
        add_action(copy_menu, "Copy selection (text)", self._handle_copy_text)
        add_action(copy_menu, "Copy selection (hex)", self._handle_copy_hex)
        add_action(copy_menu, "Copy selection (hexdump)", self._handle_copy_hexdump)
        add_action(copy_menu, "Copy selection (base64)", self._handle_copy_base64)

        menu.addSeparator()  # -----------------------------------------------------------------

        add_action(menu, "Add origin", lambda: self._handle_add_origin(index))
        return menu
387483
private void initContextMenauAndToolBar() {
        toolbar = new JToolBar();
        toolbar.add(new Button(saveAction));
        toolbar.add(new Button(printAction));
        toolbar.addSeparator();
        toolbar.add(new Button(zoomInAction));
        toolbar.add(new Button(zoomOutAction));
        toolbar.add(new Button(resetAction));
        toolbar.addSeparator();
        toolbar.add(new Button(enlargePlotAreaAction));
        toolbar.add(new Button(shrinkPlotAreaAction));
        toolbar.add(new Button(increaseHeightAction));
        toolbar.add(new Button(decreaseHeightAction));
        toolbar.add(new Button(increaseWidthAction));
        toolbar.add(new Button(decreaseWidthAction));
        toolbar.addSeparator();
        toolbar.add(new Button(propertyAction));
    
        decreaseHeightAction.setEnabled(false);
        decreaseWidthAction.setEnabled(false);
        
        //Initialize popup menu.
        popup = new JPopupMenu();        
        popup.add(new JMenuItem(saveAction));
        popup.add(new JMenuItem(printAction));
        popup.addSeparator();
        popup.add(new JMenuItem(zoomInAction));
        popup.add(new JMenuItem(zoomOutAction));
        popup.add(new JMenuItem(resetAction));
        popup.addSeparator();
        popup.add(new JMenuItem(enlargePlotAreaAction));
        popup.add(new JMenuItem(shrinkPlotAreaAction));
        popup.add(new JMenuItem(increaseHeightAction));
        popup.add(new JMenuItem(decreaseHeightAction));
        popup.add(new JMenuItem(increaseWidthAction));
        popup.add(new JMenuItem(decreaseWidthAction));
        popup.addSeparator();
        popup.add(new JMenuItem(propertyAction));
        
        AncestorListener ancestorListener = new AncestorListener() {

            @Override
            public void ancestorAdded(AncestorEvent ae) {
                boolean inScrollPane = false;
                Container parent = getParent();
                while (parent != null) {
                    if (parent instanceof JScrollPane) {
                        inScrollPane = true;
                        scrollPane = (JScrollPane) parent;
                        break;
                    }
                    
                    parent = parent.getParent();
                }
                
                increaseHeightAction.setEnabled(inScrollPane);
                increaseWidthAction.setEnabled(inScrollPane);
            }

            @Override
            public void ancestorRemoved(AncestorEvent ae) {
            }

            @Override
            public void ancestorMoved(AncestorEvent ae) {
            }
        };
        
        addAncestorListener(ancestorListener);
    }
1133527
def init_with_context(self, context):
        
        items = self._visible_models(context['request'])
        apps = {}
        for model, perms in items:
            if not (perms['change'] or perms.get('view', False)):
                continue
            app_label = model._meta.app_label
            if app_label not in apps:
                apps[app_label] = {
                    'title':
                        django_apps.get_app_config(app_label).verbose_name,
                    'url': self._get_admin_app_list_url(model, context),
                    'models': []
                }
            apps[app_label]['models'].append({
                'title': model._meta.verbose_name_plural,
                'url': self._get_admin_change_url(model, context)
            })

        for app in sorted(apps.keys()):
            app_dict = apps[app]
            item = MenuItem(title=app_dict['title'], url=app_dict['url'])
            # sort model list alphabetically
            apps[app]['models'].sort(key=lambda x: x['title'])
            for model_dict in apps[app]['models']:
                item.children.append(MenuItem(**model_dict))
            self.children.append(item)
1098550
private void mapTreeHierarchy(final WComponent currentComponent,
			final StringTreeNode currentNode, final WText selectedMenuText) {
		if (currentNode.isLeaf()) {
			WMenuItem menuItem = new WMenuItem(currentNode.getData(), new ExampleMenuAction(
					selectedMenuText));
			menuItem.setActionObject(currentNode.getData());
			if (currentComponent instanceof WMenu) {
				((WMenu) currentComponent).add(menuItem);
			} else {
				((WSubMenu) currentComponent).add(menuItem);
			}
		} else {
			WSubMenu subMenu = new WSubMenu(currentNode.getData());
			subMenu.setSelectMode(SelectMode.SINGLE);

			if (currentComponent instanceof WMenu) {
				((WMenu) currentComponent).add(subMenu);
			} else {
				((WSubMenu) currentComponent).add(subMenu);
			}

			// Expand the first couple of levels in the tree by default.
			if (currentNode.getLevel() < 2) {
				subMenu.setOpen(true);
			}

			for (Iterator<TreeNode> i = currentNode.children(); i.hasNext();) {
				mapTreeHierarchy(subMenu, (StringTreeNode) i.next(), selectedMenuText);
			}
		}
	}
110601
def add_menu(self, menu):
        
        self._menus.append(menu)
        self._menus = sorted(list(set(self._menus)), key=lambda x: x.title())
        for action in menu.actions():
            action.setShortcutContext(QtCore.Qt.WidgetShortcut)
        self.addActions(menu.actions())