Re: Pygobject style question
On 01Aug2020 13:32, Chris Green wrote: >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) I like this first one. It is least verbose, and it makes the buffer before it makes the view, which I prefer. If they are all legal and all correct and equivalent, go with the one which is easiest to read. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Pygobject style question
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 ยท -- https://mail.python.org/mailman/listinfo/python-list