示例#1
0
 def listKeyPressEvent(self, event):
     if event.matches(QKeySequence.Delete):
         self.__deleteList()
     elif event.key() == Qt.Key_Escape:
         self.playlistList.setCurrentRow(-1)
     else:
         QListWidget.keyPressEvent(self.playlistList, event)
 def keyPressEvent(self, event):
     if event.matches(QKeySequence.Delete):
         self.__removeSelected()
     elif event.key() == Qt.Key_Escape:
         self.currentList.currentList.setCurrentRow(-1)
     else:
         QListWidget.keyPressEvent(self.currentList, event)
 def keyPressEvent(self, event):
     if event.matches(QKeySequence.Delete):
         self.__removeSelected()
     elif event.key() == Qt.Key_Escape:
         self.currentList.currentList.setCurrentRow(-1)
     else:
         QListWidget.keyPressEvent(self.currentList, event)
示例#4
0
 def keyPressEvent(self, event):
     text, key = event.text(), event.key()
     if (key in (Qt.Key_Return, Qt.Key_Enter) and self.enter_select) \
        or key == Qt.Key_Tab:
         self.item_selected()
         event.accept()
     elif key in (Qt.Key_Return, Qt.Key_Enter,
                  Qt.Key_Period, Qt.Key_Left, Qt.Key_Right):
         self.hide()
         self.textedit.keyPressEvent(event)
     elif event.modifiers() & Qt.ShiftModifier:
         self.textedit.keyPressEvent(event)
         if len(text):
             self.update_current()
         event.accept()
     elif key in (Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown,
                  Qt.Key_Home, Qt.Key_End):
         QListWidget.keyPressEvent(self, event)
     elif len(text) or key == Qt.Key_Backspace:
         self.textedit.keyPressEvent(event)
         self.update_current()
         event.accept()
     else:
         self.hide()
         event.ignore()
示例#5
0
 def keyPressEvent(self, event):
     text, key = event.text(), event.key()
     if (key in (Qt.Key_Return, Qt.Key_Enter) and self.enter_select) \
        or key == Qt.Key_Tab:
         self.item_selected()
         event.accept()
     elif key in (Qt.Key_Return, Qt.Key_Enter,
                  Qt.Key_Period, Qt.Key_Left, Qt.Key_Right):
         self.hide()
         self.textedit.keyPressEvent(event)
     elif event.modifiers() & Qt.ShiftModifier:
         self.textedit.keyPressEvent(event)
         if len(text):
             self.update_current()
         event.accept()
     elif key in (Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown,
                  Qt.Key_Home, Qt.Key_End):
         QListWidget.keyPressEvent(self, event)
     elif len(text) or key == Qt.Key_Backspace:
         self.textedit.keyPressEvent(event)
         self.update_current()
         event.accept()
     else:
         self.hide()
         event.ignore()
示例#6
0
 def keyPressEvent(self, event):
     text, key = event.text(), event.key()
     alt = event.modifiers() & Qt.AltModifier
     shift = event.modifiers() & Qt.ShiftModifier
     ctrl = event.modifiers() & Qt.ControlModifier
     modifier = shift or ctrl or alt
     if (key in (Qt.Key_Return, Qt.Key_Enter) and self.enter_select) \
        or key == Qt.Key_Tab:
         self.item_selected()
     elif key in (Qt.Key_Return, Qt.Key_Enter, Qt.Key_Left,
                  Qt.Key_Right) or text in ('.', ':'):
         self.hide()
         self.textedit.keyPressEvent(event)
     elif key in (Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown,
                  Qt.Key_Home, Qt.Key_End,
                  Qt.Key_CapsLock) and not modifier:
         QListWidget.keyPressEvent(self, event)
     elif len(text) or key == Qt.Key_Backspace:
         self.textedit.keyPressEvent(event)
         self.update_current()
     elif modifier:
         self.textedit.keyPressEvent(event)
     else:
         self.hide()
         QListWidget.keyPressEvent(self, event)
示例#7
0
 def listKeyPressEvent(self, event):
     if event.matches(QKeySequence.Delete):
         self.__deleteList()
     elif event.key() == Qt.Key_Escape:
         self.playlistList.setCurrentRow(-1)
     else:
         QListWidget.keyPressEvent(self.playlistList, event)
示例#8
0
文件: base.py 项目: koll00/Gui_SM
 def keyPressEvent(self, event):
     text, key = event.text(), event.key()
     alt = event.modifiers() & Qt.AltModifier
     shift = event.modifiers() & Qt.ShiftModifier
     ctrl = event.modifiers() & Qt.ControlModifier
     modifier = shift or ctrl or alt
     if (key in (Qt.Key_Return, Qt.Key_Enter) and self.enter_select) \
        or key == Qt.Key_Tab:
         self.item_selected()
     elif key in (Qt.Key_Return, Qt.Key_Enter,
                  Qt.Key_Left, Qt.Key_Right) or text in ('.', ':'):
         self.hide()
         self.textedit.keyPressEvent(event)
     elif key in (Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown,
                  Qt.Key_Home, Qt.Key_End,
                  Qt.Key_CapsLock) and not modifier:
         QListWidget.keyPressEvent(self, event)
     elif len(text) or key == Qt.Key_Backspace:
         self.textedit.keyPressEvent(event)
         self.update_current()
     elif modifier:
         self.textedit.keyPressEvent(event)
     else:
         self.hide()
         QListWidget.keyPressEvent(self, event)
示例#9
0
    def keyPressEvent(self, e):
        """
		Handle key presses

		Arguments:
		e -- a QKeyEvent
		"""

        if e.key() == Qt.Key_Up and self.currentRow() == 0:
            self.qnotero.ui.lineEditQuery.selectAll()
            self.qnotero.ui.lineEditQuery.setFocus()
            return
        QListWidget.keyPressEvent(self, e)
示例#10
0
	def keyPressEvent(self, e):

		"""
		Handle key presses

		Arguments:
		e -- a QKeyEvent
		"""

		if e.key() == Qt.Key_Up and self.currentRow() == 0:
			self.qnotero.ui.lineEditQuery.selectAll()
			self.qnotero.ui.lineEditQuery.setFocus()
			return
		QListWidget.keyPressEvent(self, e)
示例#11
0
class CommandWindow(QFrame):
    """Miow main window
    """

    def __init__(self, parent=None):
        super(CommandWindow, self).__init__(parent)
        self.parent = parent
        self.setWindowFlags(QtCore.Qt.Popup)

        self.setFont(QFont("Monospace", 14))
        self.setMinimumWidth(400)
        self.setMinimumHeight(300)
        self.setGeometry(0, 0, 600, 300)


        # create widgets
        layout = QVBoxLayout(self)
        
        self.line_edit = QLineEdit(self)
        layout.addWidget(self.line_edit)

        self.list_widget = QListWidget(self)
        self.list_widget.currentItemChanged.connect(self.on_current_item_changed)
        layout.addWidget(self.list_widget)
        layout.setStretchFactor(self.list_widget, 15)

        layout.setMargin(0)
        layout.setSpacing(0)
        layout.setContentsMargins(0,0,0,0)
        self.setLayout(layout)
        self.line_edit.setFocus()

        self.full_command = QPlainTextEdit(self)
        self.full_command.setFont(QFont("Monospace", 8))
        size_policy = self.full_command.sizePolicy()
        size_policy.setVerticalPolicy(QSizePolicy.Ignored)
        self.full_command.setSizePolicy(size_policy)
        layout.addWidget(self.full_command)
        layout.setStretchFactor(self.full_command, 3)


        layout2 = QHBoxLayout(self)
        
        self.weight = QLabel(self)
        self.weight.setFont(QFont("Monospace", 8))
        size_policy = self.weight.sizePolicy()
        size_policy.setVerticalPolicy(QSizePolicy.Ignored)
        self.weight.setSizePolicy(size_policy)
        layout2.addWidget(self.weight)
        layout2.setStretchFactor(self.weight, 1)

        self.labels = QLabel(self)
        self.labels.setFont(QFont("Monospace", 8))
        size_policy = self.labels.sizePolicy()
        size_policy.setVerticalPolicy(QSizePolicy.Ignored)
        self.labels.setSizePolicy(size_policy)
        layout2.addWidget(self.labels)
        layout2.setStretchFactor(self.labels, 8)

        layout.addLayout(layout2)
        layout.setStretchFactor(layout2, 1)
        
        self.line_edit.textChanged.connect(self.on_text_changed)
        self.list_widget.itemDoubleClicked.connect(self.on_item_double_clicked)

        self.event_selected_command = Event()
        


    def show_hide(self, context):
        if self.isVisible() == False or context is not None:        
            self.command_list = self.parent.get_command_list(context)
            self.filter_commands("")
            self.show()
        else:
            self.hide()

    def showEvent(self, event):
        geom = self.frameGeometry()
        self.line_edit.setFocus()
        self.line_edit.clear()
        #parent_widget = self.parentWidget()
        if self.parent:
            geom.moveCenter(QtCore.QPoint(self.parent.pos().x()+self.parent.width()/2,
                                          self.parent.pos().y()+self.parent.height()/3))
            self.setGeometry(geom)
            super(QFrame, self).showEvent(event)

    def _get_command_from_text(self, text):
        for command_text, tags, weight, command in self.command_list:
            if command_text == text:
                return command
        return None

    def _get_full_command_from_text(self, text):
        for command_text, tags, weight, command in self.command_list:
            if command_text == text:
                return (command_text, tags, weight, command)
        return None
        
    def keyPressEvent(self, event):
        if event.type() == QEvent.KeyPress:
            key_event = QKeyEvent(event)
            if(key_event.key() == Qt.Key_Down
              or key_event.key() == Qt.Key_Up):
                return self.list_widget.keyPressEvent(event)
            elif((event.key() == Qt.Key_Enter  or  event.key() == Qt.Key_Return)
                    and self.list_widget.currentItem()>=0):
                self.hide()
                self.event_selected_command(str(self.full_command.toPlainText()))
        return super(CommandWindow, self).keyPressEvent(event)

    def on_item_double_clicked(self, item):
        self.hide()
        self.event_selected_command(str(self.full_command.toPlainText()))


    def on_current_item_changed(self, prev, current):
        if(self.list_widget.currentItem()):
            command_text, tags, weight, command = self._get_full_command_from_text(
                                        self.list_widget.currentItem().text())
            self.full_command.setPlainText(command)
            self.labels.setText(tags)
            self.weight.setText(str(weight))
        else:
            self.full_command.setPlainText("")
            self.labels.setText("")
            self.weight.setText("")


    def filter_commands(self, text):
        self.list_widget.clear()
        text = str(text).upper()

        def get_item_map_def0(_map, key):
            if(key in _map):
                return _map[key]
            else:
                return 0.

        def get_command_matches(command_list, words):
            result_map = {}
            for command, tags, _, _ in command_list:
                for word in words:
                    located_command_weight = 1
                    located_tag_weight = 0.3
                    if word == '':
                        located_command_weight = 0.
                        located_tag_weight = 0.
                    if command.upper().find(word) != -1:
                        result_map[command] = (get_item_map_def0(result_map,
                                                    command)
                                                    - located_command_weight)
                    for tag in tags.split(" "):
                        if tag.upper().find(word) != -1:
                            result_map[command] = (get_item_map_def0(result_map,
                                                    command)
                                                    - located_tag_weight)
            for command, _, current_weight, _ in command_list:
                if command in result_map:
                    result_map[command] -= current_weight
            return sorted(result_map, key=result_map.get)


        words = str(text).strip().split(" ")
        matches_map = get_command_matches(self.command_list, words)
        for command in matches_map:
            self.list_widget.addItem(command)
        self.list_widget.setCurrentRow(0)


    def on_text_changed(self, text):
        self.filter_commands(text)
示例#12
0
class AutoComplete(PopupWidget):
    def init_popup(self):
        self.list = QListWidget(self)
        self.connect(self.list, SIGNAL("itemClicked(QListWidgetItem*)"),
                     self.insertItem)
        self.layout().addWidget(self.list)
        self.items = []

    def insertItem(self, item):
        self.insert()

    def insert(self):
        completion = self.items[self.list.currentRow()].value
        cursor = self.textedit.textCursor()
        col = cursor.columnNumber()
        line = unicode(cursor.block().text())
        i = self.cursor_start_col
        while i > 0:
            #print `line[i:col]`
            if completion.startswith(line[i:col]):
                #print "break"
                break
            i -= 1
        #print col,i
        cursor.insertText(completion[col - i:])
        self.hide()

    def setItems(self, proposals):
        proposals = sorted(proposals, cmp=lambda p1, p2: cmp(p1.name, p2.name))
        del self.items[:]
        self.list.clear()
        for entry in proposals:
            i = AutoCompleteItem(entry)
            self.list.addItem(i)
            self.items.append(i)

    def keyPressEvent(self, event):
        self.list.keyPressEvent(event)
        key = event.key()
        text = event.text()
        if key in [Qt.Key_Right, Qt.Key_Enter, Qt.Key_Return]:
            text = ""
        cursor = self.textedit.textCursor()
        line = unicode(cursor.block().text())
        col = cursor.columnNumber()
        prefix = line[self.cursor_start_col:col] + unicode(text)

        found = False
        for row, item in enumerate(self.items):
            if item.value.startswith(prefix):
                current = self.items[self.list.currentRow()].value
                if not current.startswith(prefix):
                    self.list.setCurrentRow(row)
                found = True
                break
        if not found:
            self.hide()
            return

        if key in [Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown]:
            return True
        elif key in [Qt.Key_Tab, Qt.Key_Right, Qt.Key_Enter, Qt.Key_Return]:
            self.insert()
            return True
        elif not text:
            self.hide()
示例#13
0
 def keyHandler(self, event):
     if event.key() == Qt.Key_Delete:
         self.menu.delete_action.trigger()
         event.accept()
         return
     QListWidget.keyPressEvent(self.widget, event)
示例#14
0
 def keyPressEvent(self, event):
     if event.matches(QKeySequence.Delete):
         self.delete()
     else:
         QListWidget.keyPressEvent(self.view.bookmarkList, event)
示例#15
0
文件: assist.py 项目: gyuris/scribus
class AutoComplete(PopupWidget):
    def init_popup(self):
        self.list = QListWidget(self)
        self.connect(self.list, SIGNAL("itemClicked(QListWidgetItem*)"), self.insertItem)
        self.layout().addWidget(self.list)
        self.items = []

    def insertItem(self, item):
        self.insert()

    def insert(self):
        completition = self.items[self.list.currentRow()].value
        cursor = self.textedit.textCursor()
        col = cursor.columnNumber()
        line = unicode(cursor.block().text())
        i = self.cursor_start_col
        while i > 0:
            # print `line[i:col]`
            if completition.startswith(line[i:col]):
                # print "break"
                break
            i -= 1
        # print col,i
        cursor.insertText(completition[col - i :])
        self.hide()

    def setItems(self, proposals):
        proposals = sorted(proposals, cmp=lambda p1, p2: cmp(p1.name, p2.name))
        del self.items[:]
        self.list.clear()
        for entry in proposals:
            i = AutoCompleteItem(entry)
            self.list.addItem(i)
            self.items.append(i)

    def keyPressEvent(self, event):
        self.list.keyPressEvent(event)
        key = event.key()
        text = event.text()
        if key in [Qt.Key_Right, Qt.Key_Enter, Qt.Key_Return]:
            text = ""
        cursor = self.textedit.textCursor()
        line = unicode(cursor.block().text())
        col = cursor.columnNumber()
        prefix = line[self.cursor_start_col : col] + unicode(text)

        found = False
        for row, item in enumerate(self.items):
            if item.value.startswith(prefix):
                current = self.items[self.list.currentRow()].value
                if not current.startswith(prefix):
                    self.list.setCurrentRow(row)
                found = True
                break
        if not found:
            self.hide()
            return

        if key in [Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown]:
            return True
        elif key in [Qt.Key_Tab, Qt.Key_Right, Qt.Key_Enter, Qt.Key_Return]:
            self.insert()
            return True
        elif not text:
            self.hide()