我正在努力将一些Gedit 2插件移植到Gedit 3并且我遇到了错误'Document' object has no attribute 'get_uri'
并且我很难过。对于它的价值,该插件的Gedit 2版本可以工作。
def view_result(self, widget):
# Get the selection object
tree_selection = self.results_list.get_selection()
# Get the model and iterator for the row selected
(model, iterator) = tree_selection.get_selected()
if (iterator):
# Get the absolute path of the file
absolute_path = model.get_value(iterator, 3)
# Get the line number
line_number = int(model.get_value(iterator, 2)) - 1
# Get all open tabs
documents = self.window.get_documents()
# Loop through the tabs until we find which one matches the file
# If we don't find it, we'll create it in a new tab afterwards.
for each in documents:
# This is the line throwing the error:
if (each.get_uri().replace("file://", "") == absolute_path):
# This sets the active tab to "each"
(self.window.set_active_tab
(Gedit.tab_get_from_document(each)))
each.goto_line(line_number)
# Get the bounds of the document
(start, end) = each.get_bounds()
self.window.get_active_view().scroll_to_iter(end, 0.0)
x = each.get_iter_at_line_offset(line_number, 0)
self.window.get_active_view().scroll_to_iter(x, 0.0)
return
# If we got this far, then we didn't find the file open in a tab.
# Thus, we'll want to go ahead and open it...
self.window.create_tab_from_uri("file://" + absolute_path,
self.encoding, int(model.get_value(iterator, 2)), False, True)
另外,我的文件中有以下导入行:
from gi.repository import Gtk, Gio, GObject, Gedit
import os
我已经尝试查看我已经拥有的Gedit 3插件用于类似的行以查看是否有更改,但是它们具有相同类型的代码,并且搜索Google和StackOverflow都没有给我任何可以使用的内容。我是Python新手并且这样做是为了学习它,所以我可能会遗漏一些完全明显的东西,但是它是什么?
修改 print each, type(each), dir(each)
会产生以下结果:
<Document object at 0x20ea3c0 (GeditDocument at 0x21d2030)>
<class 'gi.repository.Gedit.Document'>
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__gdoc__', '__ge__', '__getattribute__', '__grefcount__', '__gt__', '__gtype__', '__hash__', '__info__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_get_or_create_tag_table', 'add_mark', 'add_selection_clipboard', 'apply_tag', 'apply_tag_by_name', 'backspace', 'backward_iter_to_source_mark', 'begin_not_undoable_action', 'begin_user_action', 'buffer', 'can_redo', 'can_undo', 'chain', 'connect', 'connect_after', 'connect_object', 'connect_object_after', 'copy_clipboard', 'create_child_anchor', 'create_mark', 'create_source_mark', 'create_tag', 'cut_clipboard', 'delete', 'delete_interactive', 'delete_mark', 'delete_mark_by_name', 'delete_selection', 'deserialize', 'deserialize_get_can_create_tags', 'deserialize_set_can_create_tags', 'disconnect', 'disconnect_by_func', 'do_apply_tag', 'do_begin_user_action', 'do_bracket_matched', 'do_changed', 'do_cursor_moved', 'do_delete_range', 'do_end_user_action', 'do_insert_child_anchor', 'do_insert_pixbuf', 'do_insert_text', 'do_load', 'do_loaded', 'do_loading', 'do_mark_deleted', 'do_mark_set', 'do_modified_changed', 'do_paste_done', 'do_redo', 'do_remove_tag', 'do_save', 'do_saved', 'do_saving', 'do_search_highlight_updated', 'do_undo', 'emit', 'emit_stop_by_name', 'end_not_undoable_action', 'end_user_action', 'ensure_highlight', 'error_quark', 'forward_iter_to_source_mark', 'freeze_notify', 'get_bounds', 'get_can_search_again', 'get_char_count', 'get_compression_type', 'get_content_type', 'get_context_classes_at_iter', 'get_copy_target_list', 'get_data', 'get_deleted', 'get_deserialize_formats', 'get_enable_search_highlighting', 'get_encoding', 'get_end_iter', 'get_has_selection', 'get_highlight_matching_brackets', 'get_highlight_syntax', 'get_insert', 'get_iter_at_child_anchor', 'get_iter_at_line', 'get_iter_at_line_index', 'get_iter_at_line_offset', 'get_iter_at_mark', 'get_iter_at_offset', 'get_language', 'get_line_count', 'get_location', 'get_mark', 'get_max_undo_levels', 'get_metadata', 'get_mime_type', 'get_modified', 'get_newline_type', 'get_paste_target_list', 'get_properties', 'get_property', 'get_readonly', 'get_search_text', 'get_selection_bound', 'get_selection_bounds', 'get_serialize_formats', 'get_short_name_for_display', 'get_slice', 'get_source_marks_at_iter', 'get_source_marks_at_line', 'get_start_iter', 'get_style_scheme', 'get_tag_table', 'get_text', 'get_undo_manager', 'get_uri_for_display', 'goto_line', 'goto_line_offset', 'handler_block', 'handler_block_by_func', 'handler_disconnect', 'handler_is_connected', 'handler_unblock', 'handler_unblock_by_func', 'insert', 'insert_at_cursor', 'insert_child_anchor', 'insert_interactive', 'insert_interactive_at_cursor', 'insert_pixbuf', 'insert_range', 'insert_range_interactive', 'insert_with_tags', 'insert_with_tags_by_name', 'is_local', 'is_untitled', 'is_untouched', 'iter_backward_to_context_class_toggle', 'iter_forward_to_context_class_toggle', 'iter_has_context_class', 'load', 'load_cancel', 'load_stream', 'move_mark', 'move_mark_by_name', 'new', 'new_with_language', 'notify', 'parent_instance', 'paste_clipboard', 'place_cursor', 'priv', 'props', 'redo', 'register_deserialize_format', 'register_deserialize_tagset', 'register_serialize_format', 'register_serialize_tagset', 'remove_all_tags', 'remove_selection_clipboard', 'remove_source_marks', 'remove_tag', 'remove_tag_by_name', 'replace_all', 'save', 'save_as', 'search_backward', 'search_forward', 'select_range', 'serialize', 'set_content_type', 'set_data', 'set_enable_search_highlighting', 'set_highlight_matching_brackets', 'set_highlight_syntax', 'set_language', 'set_location', 'set_max_undo_levels', 'set_modified', 'set_properties', 'set_property', 'set_search_text', 'set_short_name_for_display', 'set_style_scheme', 'set_text', 'set_undo_manager', 'stop_emission', 'thaw_notify', 'undo', 'unregister_deserialize_format', 'unregister_serialize_format', 'weak_ref']
答案 0 :(得分:1)
我怀疑,这很简单。他们将Gedit.Document.get_uri()
更改为Gedit.Document.get_location()
或Gedit.Document.get_uri_for_display()
(取决于您的目的)。
对于可能在查找Gedit文档时遇到问题的其他人,他们是 - http://developer.gnome.org/gedit/