def goto_result(self):
self.overlay.hide()
self.finder.setText("")
filename, part_title = self.overlay.get_selected_indices()
i_filename = -1
for i_filename in range(self.list1.count()):
item_fn = self.list1.itemWidget(self.list1.item(i_filename)).get_filename()
if item_fn == filename:
break
self.list1.setCurrentRow(i_filename)
items = self.list_parts.findItems(part_title, Qt.MatchExactly)
self.list_parts.setCurrentItem(items[0])
self.view1.setFocus()
python类MatchExactly()的实例源码
def expand_to_node(self, node):
"""
Expand tree until given node and select it
"""
if isinstance(node, str):
idxlist = self.model.match(self.model.index(0, 0), Qt.DisplayRole, node, 1, Qt.MatchExactly|Qt.MatchRecursive)
node = self.model.data(idxlist[0], Qt.UserRole)
path = node.get_path()
for node in path:
# FIXME: this would be the correct way if it would work
#idxlist = self.model.match(self.model.index(0, 0), Qt.UserRole, QVariantnode, 2, Qt.MatchExactly|Qt.MatchRecursive)
try:
text = node.get_display_name().Text
except UaError as ex:
return
idxlist = self.model.match(self.model.index(0, 0), Qt.DisplayRole, text, 1, Qt.MatchExactly|Qt.MatchRecursive)
if idxlist:
idx = idxlist[0]
self.view.setExpanded(idx, True)
self.view.setCurrentIndex(idx)
self.view.activated.emit(idx)
def setEditorData(self, editor, index):
comboBox = editor
if not comboBox:
return
pos = comboBox.findText(index.model().data(index), Qt.MatchExactly)
comboBox.setCurrentIndex(pos)
def setEditorData(self, editor, index):
comboBox = editor
if not comboBox:
return
pos = comboBox.findText(index.model().data(index), Qt.MatchExactly)
comboBox.setCurrentIndex(pos)
def remove_from_file_list(self, filename):
found_items = self.list1.findItems(filename, Qt.MatchExactly)
if len(found_items) != 1:
raise RuntimeError("remove_from_file_list(fn={}}): {} found items".format(filename, len(found_items)))
self.list1.takeItem(self.list1.row(found_items[0]))
def find_item(self, text):
idxlist = self.widget.model.match(self.widget.model.index(0, 0), Qt.DisplayRole, text, 1, Qt.MatchExactly | Qt.MatchRecursive)
idx = idxlist[0]
return idx
def modify_item(self, text, val, match_to_use=0):
"""
modify the current item and set its displayed value to 'val'
"""
idxlist = self.widget.model.match(self.widget.model.index(0, 0), Qt.DisplayRole, text, match_to_use + 1, Qt.MatchExactly | Qt.MatchRecursive)
if not idxlist:
raise RuntimeError("Item with text '{}' not found".format(text))
idx = idxlist[match_to_use]
self.widget.view.setCurrentIndex(idx)
idx = idx.sibling(idx.row(), 1)
self.widget.view.edit(idx)
editor = self.widget.view.focusWidget()
if not editor:
print(app.focusWidget())
print("NO EDITOR WIDGET")
#QTest.keyClick(self.widget.view, Qt.Key_Return)
from IPython import embed
embed()
raise RuntimeError("Could not get editor widget!, it does not have the focus")
if hasattr(editor, "_current_node"):
editor._current_node = val
elif hasattr(editor, "setCurrentText"):
editor.setCurrentText(val)
else:
editor.setText(val)
self.widget.view.commitData(editor)
self.widget.view.closeEditor(editor, QAbstractItemDelegate.NoHint)
self.widget.view.reset()
def setEditorData(self, editor, index):
comboBox = editor
if not comboBox:
return
pos = comboBox.findText(index.model().data(index), Qt.MatchExactly)
comboBox.setCurrentIndex(pos)
def file_modified(self, filename):
# modified event is sometimes fired twice. prevent trouble
if filename not in self.data:
self.file_added(filename)
title_old = self.data[filename]["title"]
try:
self.data[filename] = self.load_file(filename)
except BadFormatError as e:
print(e)
self.file_deleted(filename)
return
title_new = self.data[filename]["title"]
# change title in file list if changed
if title_old and title_new != title_old:
found_items = self.list1.findItems(filename, Qt.MatchExactly)
if len(found_items) != 1:
raise RuntimeError("file_modified(fn={}}): {} found items".format(filename, len(found_items)))
self.list1.itemWidget(found_items[0]).label_title.setText(title_new)
# update part list if active file was changed
if self.list1.currentItem().text() == filename:
old_index = self.list_parts.currentRow()
self.update_part_list(filename)
self.list_parts.setCurrentRow(old_index)
# update index
writer = self.ix.writer()
deleted_count = writer.delete_by_term("path", filename)
topic = self.data[filename]
for part in topic["content"]:
writer.add_document(
title="",
_stored_title=part["title"],
content=part["content"],
time=topic["time"],
path=filename
)
writer.add_document(
title=part["title"],
time=topic["time"],
path=filename
)
writer.commit()
self.searcher = self.ix.searcher()