def _copy_text_to_clipboard(self): # Get tab indented text for all selected items def get_distance(item, ancestor, distance=0): parent = item.parent() if parent == None: return distance else: return get_distance(parent, ancestor, distance + 1) text = '' for i in self.get_all_items(): if i in self.selectedItems(): text += ('\t' * (get_distance(i, None))) + i.text(0) + '\n' # Copy the text to the clipboard clipboard = QApplication.clipboard() clipboard.setText(text)
def _copy_text_to_clipboard(self): # Get tab indented text for all selected items def get_distance(item, ancestor, distance=0): parent = item.parent() if parent == None: return distance else: return get_distance(parent, ancestor, distance + 1) text = '' for i in self.get_all_items(): if i in self.selectedItems(): text += ('\t' * (get_distance(i, None))) + i.text(0) + '\n' # Copy the text to the clipboard clipboard = QApplication.clipboard() clipboard.setText(text)
def _rightclick_menu(self, event): """ Dynamically builds the rightclick menu based on the unique column data from the passed in datamodel and then launches it modally :param event: the mouse event object, ''QMouseEvent'' """ severities = {} for severity, label in Message.SEVERITY_LABELS.items(): if severity in self._model.get_unique_severities(): severities[severity] = label nodes = sorted(self._model.get_unique_nodes()) topics = sorted(self._model.get_unique_topics()) # menutext entries turned into menutext = [] menutext.append([ self.tr('Exclude'), [[self.tr('Severity'), severities], [self.tr('Node'), nodes], [self.tr('Topic'), topics], [self.tr('Selected Message(s)')]] ]) menutext.append([ self.tr('Highlight'), [[self.tr('Severity'), severities], [self.tr('Node'), nodes], [self.tr('Topic'), topics], [self.tr('Selected Message(s)')]] ]) menutext.append([self.tr('Copy Selected')]) menutext.append([self.tr('Browse Selected')]) menu = QMenu() submenus = [] subsubmenus = [] for item in menutext: if len(item) > 1: submenus.append(QMenu(item[0], menu)) for subitem in item[1]: if len(subitem) > 1: subsubmenus.append(QMenu(subitem[0], submenus[-1])) if isinstance(subitem[1], dict): for key in sorted(subitem[1].keys()): action = subsubmenus[-1].addAction( subitem[1][key]) action.setData(key) else: for subsubitem in subitem[1]: subsubmenus[-1].addAction(subsubitem) submenus[-1].addMenu(subsubmenus[-1]) else: submenus[-1].addAction(subitem[0]) menu.addMenu(submenus[-1]) else: menu.addAction(item[0]) action = menu.exec_(event.globalPos()) if action is None or action == 0: return elif action.text() == self.tr('Browse Selected'): self._show_browsers() elif action.text() == self.tr('Copy Selected'): rowlist = [] for current in self.table_view.selectionModel().selectedIndexes(): rowlist.append(self._proxy_model.mapToSource(current).row()) copytext = self._model.get_selected_text(rowlist) if copytext is not None: clipboard = QApplication.clipboard() clipboard.setText(copytext) elif action.text() == self.tr('Selected Message(s)'): if action.parentWidget().title() == self.tr('Highlight'): self._process_highlight_exclude_filter(action.text(), 'Message', False) elif action.parentWidget().title() == self.tr('Exclude'): self._process_highlight_exclude_filter(action.text(), 'Message', True) else: raise RuntimeError( "Menu format corruption in ConsoleWidget._rightclick_menu()" ) else: # This processes the dynamic list entries (severity, node and topic) try: roottitle = action.parentWidget().parentWidget().title() except: raise RuntimeError( "Menu format corruption in ConsoleWidget._rightclick_menu()" ) if roottitle == self.tr('Highlight'): self._process_highlight_exclude_filter( action.text(), action.parentWidget().title(), False) elif roottitle == self.tr('Exclude'): self._process_highlight_exclude_filter( action.text(), action.parentWidget().title(), True) else: raise RuntimeError( "Unknown Root Action %s selected in ConsoleWidget._rightclick_menu()" % roottitle)
def _rightclick_menu(self, event): """ Dynamically builds the rightclick menu based on the unique column data from the passed in datamodel and then launches it modally :param event: the mouse event object, ''QMouseEvent'' """ severities = {} for severity, label in Message.SEVERITY_LABELS.items(): if severity in self._model.get_unique_severities(): severities[severity] = label nodes = sorted(self._model.get_unique_nodes()) topics = sorted(self._model.get_unique_topics()) # menutext entries turned into menutext = [] menutext.append([self.tr('Exclude'), [[self.tr('Severity'), severities], [self.tr('Node'), nodes], [self.tr('Topic'), topics], [self.tr('Selected Message(s)')]]]) menutext.append([self.tr('Highlight'), [[self.tr('Severity'), severities], [self.tr('Node'), nodes], [self.tr('Topic'), topics], [self.tr('Selected Message(s)')]]]) menutext.append([self.tr('Copy Selected')]) menutext.append([self.tr('Browse Selected')]) menu = QMenu() submenus = [] subsubmenus = [] for item in menutext: if len(item) > 1: submenus.append(QMenu(item[0], menu)) for subitem in item[1]: if len(subitem) > 1: subsubmenus.append(QMenu(subitem[0], submenus[-1])) if isinstance(subitem[1], dict): for key in sorted(subitem[1].keys()): action = subsubmenus[-1].addAction(subitem[1][key]) action.setData(key) else: for subsubitem in subitem[1]: subsubmenus[-1].addAction(subsubitem) submenus[-1].addMenu(subsubmenus[-1]) else: submenus[-1].addAction(subitem[0]) menu.addMenu(submenus[-1]) else: menu.addAction(item[0]) action = menu.exec_(event.globalPos()) if action is None or action == 0: return elif action.text() == self.tr('Browse Selected'): self._show_browsers() elif action.text() == self.tr('Copy Selected'): rowlist = [] for current in self.table_view.selectionModel().selectedIndexes(): rowlist.append(self._proxy_model.mapToSource(current).row()) copytext = self._model.get_selected_text(rowlist) if copytext is not None: clipboard = QApplication.clipboard() clipboard.setText(copytext) elif action.text() == self.tr('Selected Message(s)'): if action.parentWidget().title() == self.tr('Highlight'): self._process_highlight_exclude_filter(action.text(), 'Message', False) elif action.parentWidget().title() == self.tr('Exclude'): self._process_highlight_exclude_filter(action.text(), 'Message', True) else: raise RuntimeError("Menu format corruption in ConsoleWidget._rightclick_menu()") else: # This processes the dynamic list entries (severity, node and topic) try: roottitle = action.parentWidget().parentWidget().title() except: raise RuntimeError("Menu format corruption in ConsoleWidget._rightclick_menu()") if roottitle == self.tr('Highlight'): self._process_highlight_exclude_filter(action.text(), action.parentWidget().title(), False) elif roottitle == self.tr('Exclude'): self._process_highlight_exclude_filter(action.text(), action.parentWidget().title(), True) else: raise RuntimeError("Unknown Root Action %s selected in ConsoleWidget._rightclick_menu()" % roottitle)