def select_maps_context_menu(self, position):
global_position = self.general_map_selection.mapToGlobal(position)
def get_header_action(parent, map_name):
label = QLabel(map_name)
font = label.font()
font.setBold(True)
label.setFont(font)
label.setStyleSheet('color: black; margin:5px; margin-left: 15px;')
action = QWidgetAction(parent)
action.setDisabled(True)
action.setDefaultWidget(label)
return action
if self.general_map_selection.count():
row = self.general_map_selection.indexAt(position)
if row:
element = self.general_map_selection.item(row.row())
if element:
map_name = element.data(Qt.UserRole)
file_path = self._controller.get_model().get_data().get_file_path(map_name)
menu = QMenu()
menu.addAction(get_header_action(menu, map_name))
menu.addSeparator()
show_in_folder = menu.addAction('&Show in folder', lambda:
QDesktopServices.openUrl(QUrl.fromLocalFile(os.path.dirname(file_path))))
if file_path is None:
show_in_folder.setEnabled(False)
menu.addAction('Use as &mask', lambda: self._controller.apply_action(SetGeneralMask(map_name)))
menu.addAction('R&emove', lambda: self._controller.apply_action(
NewDataAction(self._controller.get_model().get_data().get_updated(removals=[map_name]))))
menu.exec(global_position)
评论列表
文章目录