Пример #1
0
    def keyPressEvent(self, event):
        key = event.key()
        modifier = event.modifiers()
        is_goto_prev_tab = (modifier == QtCore.Qt.ControlModifier) and (key == QtCore.Qt.Key_BracketLeft)
        is_goto_next_tab = (modifier == QtCore.Qt.ControlModifier) and (key == QtCore.Qt.Key_BracketRight)
        is_send_msg = key == QtCore.Qt.Key_Return
        is_close_tab = key == QtCore.Qt.Key_Escape
        is_switch_tab = (modifier == QtCore.Qt.ControlModifier) and (key >= QtCore.Qt.Key_1 and key <= QtCore.Qt.Key_9)
        CHAR_START_AT = 48

        if is_close_tab:
            if not self.convTab.count():
                self.hide()
                return

            no_input = self.convTab.currentWidget().toPlainText()
            if not no_input:
                self._close_current_tab()
            else:
                msg = "Pressing the ESC key will close this conversation. <br />" \
                        "Are you sure you want to continue ?"
                if popup_confirm(self, msg):
                    self._close_current_tab()

        elif is_send_msg:
            widget = self.convTab.currentWidget()
            msg = widget.toPlainText()
            if not msg:
                return
            widget.clear()
            self.send_msg(qstr_to_unicode_obj(msg))

        elif is_switch_tab:
            count = self.convTab.count()
            k = key.real - CHAR_START_AT
            if 1 > k and k > 9:
                return
            if k < count + 1:
                self.convTab.setCurrentIndex(k - 1)
        elif is_goto_prev_tab:
            count = self.convTab.count()
            cur_idx = self.convTab.currentIndex()

            if count == 1:
                return
            elif cur_idx == 0:
                self.convTab.setCurrentIndex(count - 1)
            else:
                self.convTab.setCurrentIndex(cur_idx - 1)
        elif is_goto_next_tab:
            count = self.convTab.count()
            cur_idx = self.convTab.currentIndex()

            if count == 1:
                return
            elif (count - 1) == cur_idx:
                self.convTab.setCurrentIndex(0)
            else:
                self.convTab.setCurrentIndex(cur_idx + 1)
Пример #2
0
    def tab_close_requested(self, idx):
        no_input = self.convTab.widget(idx).toPlainText()
        if not no_input:
            self.convTab.removeTab(idx)
        else:
            msg = "Pressing the ESC key will close this conversation. <br />" \
                    "Are you sure you want to continue ?"
            if popup_confirm(self, msg):
                self.convTab.removeTab(idx)

        if not self.convTab.count():
            self.hide()