发出Pyqt检查信号

时间:2019-02-26 17:01:44

标签: python pyqt signals receiver emit

在我的pyqt应用程序中,一旦按下特定键,我将发出不同的信号,例如:

def keyPressEvent(self, event):
    """
    keyboard events that enable actions

    . starts single correction mode
    m stats multiple correction mode
    \ starts zeroing
    ESC stops any action
    s starts suggestion mode
    n starts neutralisation mode
    :param event: keyboard event
    :return:
    """

    if event.key() == Qt.Key_Period:
        logger.log(5, "{} has been pressed".format(event.text()))
        self.single_correction.emit() # single correction mode
    if event.key() == Qt.Key_M:
        logger.log(5, "{} has been pressed".format(event.text()))
        self.multiple_correction.emit()  # multiple correction mode
    if event.key() == Qt.Key_S: # m key
        logger.log(5, " {} has been pressed".format(event.text()))
        self.suggested_correction.emit() # suggestion mode
    if event.key() == Qt.Key_N:
        logger.log(5, " {} has been pressed".format(event.text()))
        self.neutralisation_mode.emit() # neutralisation mode
    if event.key() == Qt.Key_Backslash:
        logger.log(5, " {} has been pressed".format(event.text()))
        self.zeroing.emit() # zeroing
    if event.key() == Qt.Key_Return:
        logger.log(5, " {} has been pressed".format(event.text()))
        self.unzeroing.emit() # unzeroring
    if event.key() == Qt.Key_Escape: # esc key
        logger.log(5, " {} has been pressed".format(event.text()))
        self.stop.emit() #stop

然后我还有另一个功能,可以将每个信号连接到一个动作

def create_connections(self):
    """
    function that handles connections
    when a signal is emitted it connects to the appropriate action
    :return:
    """
    self.lineEdit_mancorr.signal_evoke_kb.connect(self.show_kb)
    self.single_correction.connect(self.singlecorrection)
    self.multiple_correction.connect(self.multiplecorrection)
    self.zeroing.connect(self.zeroingcorrection)
    self.unzeroing.connect(self.unzeroingcorrection)
    self.stop.connect(self.stopcorrection)
    self.neutralisation_mode.connect(self.neutralisatecorrections)
    self.suggested_correction.connect(self.suggestcorrection)

我想了解是否可以通过if语句检查是否已发出信号。

0 个答案:

没有答案