def show_context_menu(self, pos): """ desc: Pops up the item context menu. arguments: pos: desc: The cursor position. type: QPoint """ from libqtopensesame.widgets.item_context_menu import item_context_menu menu = item_context_menu(self.main_window, self) menu.popup(pos)
def mousePressEvent(self, e): """ Open the tab on a left click and show the context menu on a right click Arguments: e -- a QMouseEvent """ if e.button() == QtCore.Qt.LeftButton: QtGui.QPushButton.mousePressEvent(self, e) elif e.button() == QtCore.Qt.RightButton: item = self.container._list.sequence.experiment.items[self.item[0]] m = item_context_menu.item_context_menu("Item", self, item, self.container._list.sequence.name, self.container.index) m.popup(e.globalPos())
def context_menu(self, item, pos=None): """ Present a context menu for an item. Arguments: item -- a QTreeWidgetItem Keyword arguments: A position for the top-left of the menu (default=None) """ target_item = item item_name = unicode(target_item.text(0)) parent_item = target_item.parent() if parent_item != None: parent_name = unicode(parent_item.text(0)) else: parent_name = None index = None if parent_name in self.main_window.experiment.items: parent_type = \ self.main_window.experiment.items[parent_name].item_type # If the parent is a sequence, get the position of the item in the # sequence, because the name by itself is ambiguous since the name # may occur multiple times in one sequence if parent_type == "sequence": index = 0 for index in range(parent_item.childCount()): child = parent_item.child(index) if child == target_item: break index += 1 if item_name not in self.main_window.experiment.items: return item = self.main_window.experiment.items[item_name] m = item_context_menu.item_context_menu("Item", self, item, \ parent_name, index) if pos == None: m.popup(self.mapToGlobal(self.pos())) else: m.popup(pos)