本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.setCursorPosition方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.setCursorPosition方法的具體用法?Python QLineEdit.setCursorPosition怎麽用?Python QLineEdit.setCursorPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.setCursorPosition方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Window
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setCursorPosition [as 別名]
#.........這裏部分代碼省略.........
accessGroup = QGroupBox("Access")
accessLabel = QLabel("Read-only:")
accessComboBox = QComboBox()
accessComboBox.addItem("False")
accessComboBox.addItem("True")
self.accessLineEdit = QLineEdit()
echoComboBox.activated.connect(self.echoChanged)
validatorComboBox.activated.connect(self.validatorChanged)
alignmentComboBox.activated.connect(self.alignmentChanged)
inputMaskComboBox.activated.connect(self.inputMaskChanged)
accessComboBox.activated.connect(self.accessChanged)
echoLayout = QGridLayout()
echoLayout.addWidget(echoLabel, 0, 0)
echoLayout.addWidget(echoComboBox, 0, 1)
echoLayout.addWidget(self.echoLineEdit, 1, 0, 1, 2)
echoGroup.setLayout(echoLayout)
validatorLayout = QGridLayout()
validatorLayout.addWidget(validatorLabel, 0, 0)
validatorLayout.addWidget(validatorComboBox, 0, 1)
validatorLayout.addWidget(self.validatorLineEdit, 1, 0, 1, 2)
validatorGroup.setLayout(validatorLayout)
alignmentLayout = QGridLayout()
alignmentLayout.addWidget(alignmentLabel, 0, 0)
alignmentLayout.addWidget(alignmentComboBox, 0, 1)
alignmentLayout.addWidget(self.alignmentLineEdit, 1, 0, 1, 2)
alignmentGroup. setLayout(alignmentLayout)
inputMaskLayout = QGridLayout()
inputMaskLayout.addWidget(inputMaskLabel, 0, 0)
inputMaskLayout.addWidget(inputMaskComboBox, 0, 1)
inputMaskLayout.addWidget(self.inputMaskLineEdit, 1, 0, 1, 2)
inputMaskGroup.setLayout(inputMaskLayout)
accessLayout = QGridLayout()
accessLayout.addWidget(accessLabel, 0, 0)
accessLayout.addWidget(accessComboBox, 0, 1)
accessLayout.addWidget(self.accessLineEdit, 1, 0, 1, 2)
accessGroup.setLayout(accessLayout)
layout = QGridLayout()
layout.addWidget(echoGroup, 0, 0)
layout.addWidget(validatorGroup, 1, 0)
layout.addWidget(alignmentGroup, 2, 0)
layout.addWidget(inputMaskGroup, 0, 1)
layout.addWidget(accessGroup, 1, 1)
self.setLayout(layout)
self.setWindowTitle("Line Edits")
def echoChanged(self, index):
if index == 0:
self.echoLineEdit.setEchoMode(QLineEdit.Normal)
elif index == 1:
self.echoLineEdit.setEchoMode(QLineEdit.Password)
elif index == 2:
self.echoLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)
elif index == 3:
self.echoLineEdit.setEchoMode(QLineEdit.NoEcho)
def validatorChanged(self, index):
if index == 0:
self.validatorLineEdit.setValidator(0)
elif index == 1:
self.validatorLineEdit.setValidator(QIntValidator(self.validatorLineEdit))
elif index == 2:
self.validatorLineEdit.setValidator(QDoubleValidator(-999.0, 999.0, 2, self.validatorLineEdit))
self.validatorLineEdit.clear()
def alignmentChanged(self, index):
if index == 0:
self.alignmentLineEdit.setAlignment(Qt.AlignLeft)
elif index == 1:
self.alignmentLineEdit.setAlignment(Qt.AlignCenter)
elif index == 2:
self.alignmentLineEdit.setAlignment(Qt.AlignRight)
def inputMaskChanged(self, index):
if index == 0:
self.inputMaskLineEdit.setInputMask('')
elif index == 1:
self.inputMaskLineEdit.setInputMask('+99 99 99 99 99;_')
elif index == 2:
self.inputMaskLineEdit.setInputMask('0000-00-00')
self.inputMaskLineEdit.setText('00000000')
self.inputMaskLineEdit.setCursorPosition(0)
elif index == 3:
self.inputMaskLineEdit.setInputMask('>AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#')
def accessChanged(self, index):
if index == 0:
self.accessLineEdit.setReadOnly(False)
elif index == 1:
self.accessLineEdit.setReadOnly(True)
示例2: CloudRootPage
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setCursorPosition [as 別名]
class CloudRootPage(QWizardPage):
complete_trigger = pyqtSignal(name='complete')
selection_trigger = pyqtSignal(name='selection')
def __init__(self, folder_wizard, cloud_root_override=None):
super().__init__()
self.prior_time = 0
self.prior_is_complete = None
self.cloud_folder_list = WizardFolderListWidget(self.isComplete)
self.cloud_folder_list.SelectionMode(QAbstractItemView.SingleSelection)
self.folder_wizard = folder_wizard
self.cloud_root_override = cloud_root_override
self.progress_line = QLineEdit()
self.progress_line.setReadOnly(True)
self.progress_line.setText('...')
self.folder_wizard.set_found_alert(self.wizard_alert)
self.folder_wizard.set_progress(self.progress_method)
self.folder_wizard.start()
self.setTitle("Cloud storage folder")
self.setSubTitle("Please specify the folder you use for Dropbox, Microsoft's OneDrive, Google Drive, "
"etc.\n\n"
"Your computer is automatically being scanned for this folder. Once your cloud storage folder"
" is shown, please select it and hit 'Next'. Alternatively, you can click the button below"
" to manually provide the cloud storage path.")
self.manual_button = QPushButton()
self.manual_button.setText('Click here to manually provide the cloud storage path')
self.manual_button.pressed.connect(self.manual_cloud_folder_entry)
layout = QGridLayout()
layout.addWidget(self.cloud_folder_list, 0, 0)
layout.addWidget(self.progress_line, 1, 0)
layout.addWidget(self.manual_button, 2, 0)
self.setLayout(layout)
# use this for the value that's been selected
self.cloud_folder_line = QLineEdit()
self.registerField(CLOUD_FOLDER_FIELD_STRING, self.cloud_folder_line)
self.cloud_folder_list.show()
def isComplete(self):
if self.cloud_folder_list.currentItem():
is_complete = True
else:
is_complete = False
if is_complete != self.prior_is_complete:
self.prior_is_complete = is_complete
self.complete_trigger.connect(self.completeChanged)
self.complete_trigger.emit() # inform the window to update the 'next' button state (call this method)
return is_complete
def progress_method(self, folder):
t = time.time()
if folder:
rate = 1.0
if t - self.prior_time > rate:
self.progress_line.setText('Searching: ' + folder)
self.progress_line.setCursorPosition(0) # left justify
self.prior_time = t
else:
self.progress_line.setText('Search complete.')
def wizard_alert(self, folders):
item_count = 0
for folder in folders:
item_string = self.cloud_folder_list.item(item_count)
if not item_string:
self.cloud_folder_list.insertItem(item_count, folder)
item_count += 1
def validatePage(self):
if self.cloud_folder_list.currentItem():
self.cloud_folder_line.setText(self.cloud_folder_list.currentItem().text())
if self.cloud_root_override:
self.cloud_folder_line.setText(self.cloud_root_override)
return super().validatePage()
def manual_cloud_folder_entry(self):
cloud_folder = QFileDialog.getExistingDirectory(None, 'Select a folder:', None, QFileDialog.ShowDirsOnly)
self.cloud_folder_line.setText(cloud_folder)
self.cloud_folder_list.insertItem(0, cloud_folder)
self.cloud_folder_list.setCurrentItem(self.cloud_folder_list.item(0))
示例3: EditView
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setCursorPosition [as 別名]
#.........這裏部分代碼省略.........
self.Folio.setContextMenuPolicy(Qt.NoContextMenu)
self.Folio.setFrameShape(QFrame.StyledPanel)
self.Folio.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.Folio.setObjectName("Folio display")
self.Folio.setToolTip(_TR("EditViewWidget", "Folio value for current page", "tooltip"))
self.Folio.setStatusTip(_TR("EditViewWidget", "Folio value for the page under the edit cursor", "statustip"))
self.Folio.setWhatsThis(_TR("EditViewWidget", "The Folio (page number) value for the page under the edit cursor. Use the Pages panel to adjust folios to agree with the printed book.","whats this"))
HBL.addWidget(self.Folio)
spacerItem = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
HBL.addItem(spacerItem)
FolioLabel.setBuddy(self.Folio)
# Set up the image filename lineedit and its buddy label.
ImageFilenameLabel = QLabel(bot_frame)
ImageFilenameLabel.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
ImageFilenameLabel.setText(_TR("EditViewWidget", "Image", "Image field label"))
HBL.addWidget(ImageFilenameLabel)
self.ImageFilename = QLineEdit(bot_frame)
sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Fixed )
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
self.ImageFilename.setSizePolicy(sizePolicy)
self.ImageFilename.setMinimumSize(QSize(30, 12))
self.ImageFilename.setMouseTracking(False)
self.ImageFilename.setFocusPolicy(Qt.ClickFocus)
self.ImageFilename.setContextMenuPolicy(Qt.NoContextMenu)
self.ImageFilename.setAcceptDrops(True)
self.ImageFilename.setInputMask("")
self.ImageFilename.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.ImageFilename.setObjectName("ImageFilename")
self.ImageFilename.setToolTip(_TR("EditViewWidget", "Scan image filename", "Image tooltip"))
self.ImageFilename.setStatusTip(_TR("EditViewWidget", "Filename of the scan image under the edit cursor", "Image status tip"))
self.ImageFilename.setWhatsThis(_TR("EditViewWidget", "This is the name of the scanned image that produced the text under the edit cursor. This image file is displayed in the Image panel.","Image whats this"))
HBL.addWidget(self.ImageFilename)
spacerItem = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
HBL.addItem(spacerItem)
ImageFilenameLabel.setBuddy(self.ImageFilename)
# Set up the line number lineedit and its buddy label.
LineNumberLabel = QLabel(bot_frame)
LineNumberLabel.setText(_TR("EditViewWidget", "Line#", "Line number label"))
LineNumberLabel.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
HBL.addWidget(LineNumberLabel)
self.LineNumber = QLineEdit(bot_frame)
sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
self.LineNumber.setSizePolicy(sizePolicy)
self.LineNumber.setMinimumSize(QSize(0, 12))
self.LineNumber.setMouseTracking(False)
self.LineNumber.setFocusPolicy(Qt.ClickFocus)
self.LineNumber.setContextMenuPolicy(Qt.NoContextMenu)
self.LineNumber.setAcceptDrops(True)
self.LineNumber.setLayoutDirection(Qt.LeftToRight)
self.LineNumber.setCursorPosition(0)
self.LineNumber.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.LineNumber.setPlaceholderText("")
self.LineNumber.setCursorMoveStyle(Qt.LogicalMoveStyle)
self.LineNumber.setObjectName("LineNumber")
self.LineNumber.setToolTip(_TR("EditViewWidget", "Line number at cursor", "Line number tooltip"))
self.LineNumber.setStatusTip(_TR("EditViewWidget", "Line number under cursor or top of current selection","Line number statustip"))
self.LineNumber.setWhatsThis(_TR("EditViewWidget", "The line number in the document where the edit cursor is, or the top line of the selection. Enter a new number to jump to that line.","Line number whatsthis"))
ImageFilenameLabel.setBuddy(self.ImageFilename)
HBL.addWidget(self.LineNumber)
spacerItem = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
HBL.addItem(spacerItem)
# Set up the column number field and its buddy label.
ColNumberLabel = QLabel(bot_frame)
ColNumberLabel.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
ColNumberLabel.setText(_TR("EditViewWidget", "Col#", "Col number label"))
HBL.addWidget(ColNumberLabel)
self.ColNumber = QLabel(bot_frame)
sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred )
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
self.ColNumber.setSizePolicy(sizePolicy)
self.ColNumber.setMinimumSize(QSize(30, 12))
self.ColNumber.setContextMenuPolicy(Qt.NoContextMenu)
self.ColNumber.setFrameShape(QFrame.StyledPanel)
self.ColNumber.setFrameShadow(QFrame.Plain)
self.ColNumber.setLineWidth(1)
self.ColNumber.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.ColNumber.setObjectName("ColNumber")
self.ColNumber.setToolTip(_TR("EditViewWidget", "Cursor column number", "tool tip"))
self.ColNumber.setStatusTip(_TR("EditViewWidget", "Cursor column number", "status tip"))
self.ColNumber.setWhatsThis(_TR("EditViewWidget", "The column number position of the cursor in the current line.","whatsthis"))
HBL.addWidget(self.ColNumber)
# Set up a vertical layout and put two items in it, the editor and HBL
VBL = QVBoxLayout()
VBL.setContentsMargins(8, 8, 8, 8)
VBL.addWidget(self.Editor)
VBL.addWidget(bot_frame)
self.setLayout(VBL)
# end of _uic
示例4: EditView
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setCursorPosition [as 別名]
#.........這裏部分代碼省略.........
self.Folio.setContextMenuPolicy(Qt.NoContextMenu)
self.Folio.setFrameShape(QFrame.StyledPanel)
self.Folio.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.Folio.setObjectName("Folio display")
self.Folio.setToolTip(_TR("EditViewWidget", "Folio value for current page", "tooltip"))
self.Folio.setStatusTip(_TR("EditViewWidget", "Folio value for the page under the edit cursor", "statustip"))
self.Folio.setWhatsThis(_TR("EditViewWidget", "The Folio (page number) value for the page under the edit cursor. Use the Pages panel to adjust folios to agree with the printed book.","whats this"))
HBL.addWidget(self.Folio)
spacerItem = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
HBL.addItem(spacerItem)
FolioLabel.setBuddy(self.Folio)
# Set up the image filename lineedit and its buddy label.
ImageFilenameLabel = QLabel(bot_frame)
ImageFilenameLabel.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
ImageFilenameLabel.setText(_TR("EditViewWidget", "Image", "Image field label"))
HBL.addWidget(ImageFilenameLabel)
self.ImageFilename = QLineEdit(bot_frame)
sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Fixed )
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
self.ImageFilename.setSizePolicy(sizePolicy)
self.ImageFilename.setMinimumSize(QSize(30, 12))
self.ImageFilename.setMouseTracking(False)
self.ImageFilename.setFocusPolicy(Qt.ClickFocus)
self.ImageFilename.setContextMenuPolicy(Qt.NoContextMenu)
self.ImageFilename.setAcceptDrops(True)
self.ImageFilename.setInputMask("")
self.ImageFilename.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.ImageFilename.setObjectName("ImageFilename")
self.ImageFilename.setToolTip(_TR("EditViewWidget", "Scan image filename", "Image tooltip"))
self.ImageFilename.setStatusTip(_TR("EditViewWidget", "Filename of the scan image under the edit cursor", "Image status tip"))
self.ImageFilename.setWhatsThis(_TR("EditViewWidget", "This is the name of the scanned image that produced the text under the edit cursor. This image file is displayed in the Image panel.","Image whats this"))
HBL.addWidget(self.ImageFilename)
spacerItem = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
HBL.addItem(spacerItem)
ImageFilenameLabel.setBuddy(self.ImageFilename)
# Set up the line number lineedit and its buddy label.
LineNumberLabel = QLabel(bot_frame)
LineNumberLabel.setText(_TR("EditViewWidget", "Line#", "Line number label"))
LineNumberLabel.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
HBL.addWidget(LineNumberLabel)
self.LineNumber = QLineEdit(bot_frame)
sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
self.LineNumber.setSizePolicy(sizePolicy)
self.LineNumber.setMinimumSize(QSize(0, 12))
self.LineNumber.setMouseTracking(False)
self.LineNumber.setFocusPolicy(Qt.ClickFocus)
self.LineNumber.setContextMenuPolicy(Qt.NoContextMenu)
self.LineNumber.setAcceptDrops(True)
self.LineNumber.setLayoutDirection(Qt.LeftToRight)
self.LineNumber.setCursorPosition(0)
self.LineNumber.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.LineNumber.setPlaceholderText("")
self.LineNumber.setCursorMoveStyle(Qt.LogicalMoveStyle)
self.LineNumber.setObjectName("LineNumber")
self.LineNumber.setToolTip(_TR("EditViewWidget", "Line number at cursor", "Line number tooltip"))
self.LineNumber.setStatusTip(_TR("EditViewWidget", "Line number under cursor or top of current selection","Line number statustip"))
self.LineNumber.setWhatsThis(_TR("EditViewWidget", "The line number in the document where the edit cursor is, or the top line of the selection. Enter a new number to jump to that line.","Line number whatsthis"))
ImageFilenameLabel.setBuddy(self.ImageFilename)
HBL.addWidget(self.LineNumber)
spacerItem = QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum)
HBL.addItem(spacerItem)
# Set up the column number field and its buddy label.
ColNumberLabel = QLabel(bot_frame)
ColNumberLabel.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
ColNumberLabel.setText(_TR("EditViewWidget", "Col#", "Col number label"))
HBL.addWidget(ColNumberLabel)
self.ColNumber = QLabel(bot_frame)
sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred )
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
self.ColNumber.setSizePolicy(sizePolicy)
self.ColNumber.setMinimumSize(QSize(30, 12))
self.ColNumber.setContextMenuPolicy(Qt.NoContextMenu)
self.ColNumber.setFrameShape(QFrame.StyledPanel)
self.ColNumber.setFrameShadow(QFrame.Plain)
self.ColNumber.setLineWidth(1)
self.ColNumber.setAlignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter )
self.ColNumber.setObjectName("ColNumber")
self.ColNumber.setToolTip(_TR("EditViewWidget", "Cursor column number", "tool tip"))
self.ColNumber.setStatusTip(_TR("EditViewWidget", "Cursor column number", "status tip"))
self.ColNumber.setWhatsThis(_TR("EditViewWidget", "The column number position of the cursor in the current line.","whatsthis"))
HBL.addWidget(self.ColNumber)
# Set up a vertical layout and put two items in it, the editor and HBL
VBL = QVBoxLayout()
VBL.setContentsMargins(8, 8, 8, 8)
VBL.addWidget(self.Editor)
VBL.addWidget(bot_frame)
self.setLayout(VBL)
# end of _uic
示例5: LigneCommande
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setCursorPosition [as 別名]
class LigneCommande(QWidget):
"""Un TextCtrl muni d'un historique et associé à un bouton pour valider.
On peut personnaliser le texte du bouton (via `texte="Mon texte"`),
ou même directement le bouton, en utilisant `bouton=...`.
"""
def __init__(self, parent, longueur = 500, texte = None, bouton = None,
action = (lambda *args, **kw: True), afficher_bouton = True,
legende = None):
self.parent = parent
self.action = action
QWidget.__init__(self, parent)
sizer = QHBoxLayout()
self.texte = QLineEdit()
self.texte.setMinimumWidth(longueur)
if bouton is None:
self.bouton = QPushButton('OK' if texte is None else texte)
else:
self.bouton = bouton
self.bouton.setVisible(afficher_bouton)
self.bouton.clicked.connect(self.valider)
if legende is not None:
sizer.addWidget(QLabel(legende, self))
sizer.addWidget(self.texte)
sizer.addWidget(self.bouton)
self.setLayout(sizer)
self.initialiser()
def initialiser(self):
self.historique = []
self.position = None
self.setFocus()
self.clear()
def text(self):
return self.texte.text()
def setText(self, value):
self.texte.setText(value)
def setFocus(self):
self.texte.setFocus()
def clear(self):
self.texte.clear()
def getSelection(self):
if self.texte.hasSelectedText():
start = self.texte.selectionStart()
length = len(self.texte.selectedText())
end = start + length
else:
start = end = self.texte.cursorPosition()
return start, end
def cursorPosition(self):
return self.texte.cursorPosition()
def setCursorPosition(self, num):
return self.texte.setCursorPosition(num)
def insert(self, texte):
self.texte.insert(texte)
def setSelection(self, deb, fin):
self.texte.setSelection(deb, fin)
def setToolTip(self, tip):
self.texte.setToolTip(tip)
def valider(self, **kw):
# kw: shift|alt|meta|control=True|False'
commande = str(self.text())
self.position = None
if commande:
self.historique.append(commande)
elif self.historique:
# Appuyer une deuxième fois sur [Entrée] permet de répéter l'action précédente.
commande = self.historique[-1]
self.action(commande, **kw)
def keyPressEvent(self, event):
key = event.key()
commande = self.text()
if key == Qt.Key_Up and self.historique:
# On remonte dans l'historique (-> entrées plus anciennes)
if self.position is None:
# cas d'une commande en cours d'édition :
if commande:
if commande != self.historique[-1]:
# on enregistre la commande en cours
self.historique.append(commande)
self.position = len(self.historique) - 1
else:
self.position = len(self.historique)
#.........這裏部分代碼省略.........