eric7/Debugger/StartHistoryEditDialog.py

Sun, 16 May 2021 20:07:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 16 May 2021 20:07:24 +0200
branch
eric7
changeset 8318
962bce857696
parent 8312
800c432b34c8
child 8356
68ec9c3d4de5
permissions
-rw-r--r--

Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.

# -*- coding: utf-8 -*-

# Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to edit a list of history entries.
"""

from PyQt6.QtCore import pyqtSlot, Qt
from PyQt6.QtWidgets import QDialog, QInputDialog, QLineEdit

from E5Gui import E5MessageBox

from .Ui_StartHistoryEditDialog import Ui_StartHistoryEditDialog


class StartHistoryEditDialog(QDialog, Ui_StartHistoryEditDialog):
    """
    Class implementing a dialog to edit a list of history entries.
    """
    def __init__(self, history, parent=None):
        """
        Constructor
        
        @param history list of history entries to be edited
        @type list of str
        @param parent reference to the parent widget
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.historyList.addItems(history)
        for row in range(self.historyList.count()):
            itm = self.historyList.item(row)
            flags = itm.flags() | Qt.ItemFlag.ItemIsEditable
            itm.setFlags(flags)
        
        self.__updateEditButtons()
    
    def __updateEditButtons(self):
        """
        Private method to set the state of the edit buttons.
        """
        selectedCount = len(self.historyList.selectedItems())
        self.editButton.setEnabled(selectedCount == 1)
        self.deleteButton.setEnabled(selectedCount > 0)
        self.deleteAllButton.setEnabled(self.historyList.count() > 0)
    
    @pyqtSlot()
    def on_historyList_itemSelectionChanged(self):
        """
        Private slot to handle the selection of entries.
        """
        self.__updateEditButtons()
    
    @pyqtSlot()
    def on_editButton_clicked(self):
        """
        Private slot to edit the selected entry.
        """
        itm = self.historyList.selectedItems()[0]
        historyText, ok = QInputDialog.getText(
            self,
            self.tr("Edit History Entry"),
            self.tr("Enter the new text:"),
            QLineEdit.EchoMode.Normal,
            itm.text())
        if ok:
            itm.setText(historyText)
    
    @pyqtSlot()
    def on_deleteButton_clicked(self):
        """
        Private slot to delete the selected entries.
        """
        yes = E5MessageBox.yesNo(
            self,
            self.tr("Delete Selected Entries"),
            self.tr("""Do you really want to delete the selected"""
                    """ history entries?"""))
        if yes:
            for itm in self.historyList.selectedItems():
                row = self.historyList.row(itm)
                self.historyList.takeItem(row)
                del itm
    
    @pyqtSlot()
    def on_deleteAllButton_clicked(self):
        """
        Private slot to delete all entries.
        """
        yes = E5MessageBox.yesNo(
            self,
            self.tr("Delete All Entries"),
            self.tr("""Do you really want to delete the shown history?"""))
        if yes:
            self.historyList.clear()
    
    def getHistory(self):
        """
        Public method to get the new list of history entries.
        
        @return list of history entries
        @rtype list of str
        """
        history = []
        for row in range(self.historyList.count()):
            entry = self.historyList.item(row).text()
            history.append(entry)
        
        return history

eric ide

mercurial