def __init__(self, parent = None): super().__init__(parent) # Drag/drop self.setSelectionMode(self.ExtendedSelection) self.setDragEnabled(True) # Double click self.doubleClicked.connect(self._onDoubleClicked) # Context menu self._menu = Menu(self, translate("menu", "History")) self._menu.addItem(translate("menu", "Copy ::: Copy selected lines"), iep.icons.page_white_copy, self.copy, "copy") self._menu.addItem(translate("menu", "Run ::: Run selected lines in current shell"), iep.icons.run_lines, self.runSelection, "run") self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self._onCustomContextMenuRequested)
def __init__(self, path, parent): Menu.__init__(self, parent, " ") self._path = path
class HistoryViewer(QtGui.QListView): """ The history viewer has several ways of using the data stored in the history: - double click a single item to execute in the current shell - drag and drop one or multiple selected lines into the editor or any other widget or application accepting plain text - copy selected items using the copy item in the IEP edit menu - copy selected items using the context menu - execute selected items in the current shell using the context menu """ def __init__(self, parent = None): super().__init__(parent) # Drag/drop self.setSelectionMode(self.ExtendedSelection) self.setDragEnabled(True) # Double click self.doubleClicked.connect(self._onDoubleClicked) # Context menu self._menu = Menu(self, translate("menu", "History")) self._menu.addItem(translate("menu", "Copy ::: Copy selected lines"), iep.icons.page_white_copy, self.copy, "copy") self._menu.addItem(translate("menu", "Run ::: Run selected lines in current shell"), iep.icons.run_lines, self.runSelection, "run") self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self._onCustomContextMenuRequested) def runSelection(self, event = None): text = self.model().plainText(self.selectedIndexes()) shell = iep.shells.getCurrentShell() if shell is not None: shell.executeCommand(text) def copy(self, event = None): text = self.model().plainText(self.selectedIndexes()) QtGui.qApp.clipboard().setText(text) def _onCustomContextMenuRequested(self, pos): self._menu.popup(self.viewport().mapToGlobal(pos)) def _onDoubleClicked(self, index): text = self.model().data(index, QtCore.Qt.DisplayRole) shell = iep.shells.getCurrentShell() if shell is not None: shell.executeCommand(text + '\n') def setModel(self, model): """ As QtGui.QListView.setModel, but connects appropriate signals """ if self.model() is not None: self.model().rowsInserted.disconnect(self.scrollToBottom) super().setModel(model) self.model().rowsInserted.connect(self.scrollToBottom) self.scrollToBottom()