gtkpygtkgtk3geditgedit-plugin

How to get name of current gedit document with python?


I'm writing a gedit plugin for gtk3. Is there an easy way to get the name of the current document using python ?


Solution

  • Here is a very good tutorial on writing gedit 3 plugins. The example #3 does what you want: connect to a "open new tab" signal and write the document name.

    And here you have the complete Gedit API reference.

    handler_id = self.window.connect("tab-added", self.on_tab_added)
    
    (...)
    
    def on_tab_added(self, window, tab, data=None):
        document = tab.get_document()
        print "'%s' has been added." % document.get_short_name_for_display()
        print "New file's path: %s" % document.get_uri_for_display()