Stuart Axon
Stuart Axon

Reputation: 1874

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 ?

Upvotes: 2

Views: 950

Answers (2)

liberforce
liberforce

Reputation: 11454

I think you'd improve your chances of getting an answer by asking on the gedit mailing list.

There's also a GEdit python plugin howto on the GNOME wiki.

Upvotes: 1

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()

Upvotes: 3

Related Questions