def __popupAt(self, pos): index = self.tableWidget.indexAt(pos) if not index.isValid(): return menu = QMenu() styler = style.Styler() styler.initStyle(menu) acts = [] menu_options = ["Delete", "Change type", "Show in Explorer"] for opt in menu_options: if opt is None: menu.addSeparator() else: action = menu.addAction(opt) acts.append(action) try: ind = acts.index( menu.exec_(self.tableWidget.viewport().mapToGlobal(pos))) item = self.tableWidget.item(index.row(), 1).text() if ind == 0: self.attachments.pop(item) self.update_files() elif ind == 1: self.attachments[item] = not self.attachments[item] self.update_files() elif ind == 2: utils.show_dir(item) except ValueError: pass
def menu(task, pos_global, option_list, menu_name, extra_args={}): from tentaculo.core import fmanager ret = None fman = fmanager.FManager() styler = style.Styler() menu = QMenu() styler.initStyle(menu) extra_args["option_list"] = [{ "text": val, "index": i } for i, val in enumerate(option_list)] extra_options = fman.gui_processor(task, menu_name, extra_args) if extra_options[1] and len(extra_options[0]) > 0: for opt in extra_options[0]: extra_args["option_list"].insert(int(opt.get("index", 0)), opt) for i in range(len(extra_args["option_list"])): extra_args["option_list"][i]["index"] = i action_list = [] for opt in extra_args["option_list"]: if opt["text"] is None: menu.addSeparator() action_list.append(None) else: action = menu.addAction(opt["text"]) action_list.append(action) action_selected = menu.exec_(pos_global) if action_selected is not None and action_selected in action_list: ret = action_selected.text() if ret not in option_list: extra_args["option"] = ret fman.gui_processor( task, "{}_execute".format(menu_name), extra_args, extra_args["option_list"][action_list.index(action_selected)]) return ret
def initStyle(self): styler = style.Styler() styler.initStyle(self)