Pygobject style question

Chris Green cl at isbd.net
Sat Aug 1 08:32:54 EDT 2020


Having (after lots of help from here, thank you) finally converted my
Python 2, gtk 2 program to Python 3 and pygobject gtk 3 I'm left with
a couple of what might be called style questions.

I guess it's mostly down to what feels right to me but there may be
good reasons for choosing one way over another and, if so, I'd like to
know what they are.

So, my original code had:-

    ...
    ...
    self.buffer = gtk.TextBuffer()
    self.view = gtk.TextView(self.buffer)
    ...
    ...


This doesn't work in gtk+ 3 (or at least I don't think it does, the
converter script changed it) and there seem to be several ways of
doing it now:-

    ...
    ...
    self.buffer = Gtk.TextBuffer()
    self.view = Gtk.TextView(buffer = self.buffer)
    ...
    ...


    ...
    ...
    self.buffer = Gtk.TextBuffer()
    self.view = Gtk.TextView.new_with_buffer(self.buffer)
    ...
    ...


    ...
    ...
    self.view = Gtk.TextView()
    self.buffer = self.view.get_buffer()
    ...
    ...


    ...
    ...
    self.view = Gtk.TextView()
    self.buffer = Gtk.TextBuffer()
    self.view.set_buffer(self.buffer)
    ...
    ...

Is there any reason to prefer any one of the above over the others?

Obviously the last one is a line more but lends itself to using
several Gtk.TextBuffer objects in on Gtk.TextView.

-- 
Chris Green
·


More information about the Python-list mailing list