Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we use self.set_title(title="...") instead #200

Open
osamuaoki opened this issue Jul 6, 2021 · 3 comments
Open

Should we use self.set_title(title="...") instead #200

osamuaoki opened this issue Jul 6, 2021 · 3 comments

Comments

@osamuaoki
Copy link
Contributor

Hi,

I just send the PR #199. I was conservative.

It may be even nicer to change all instances from:

super().__init__(title="...")

to even cleaner style:

super().__init__()
self.set_title(title="...")

This example is more expandable for user in future. Just a thought ...

@sebp
Copy link
Owner

sebp commented Jul 6, 2021

It's not a big difference, IMHO. I think it's clear what the code's intent is. I would leave it as it is.

@osamuaoki
Copy link
Contributor Author

For me, if subclassed, code it as really subclassed .. that was the thought.. (So I am not so keen on all the super() things, after all. Please read on.)

Let me re-remind you that one code was in python2 style. layout_listbox_example.py at:

        super(Gtk.ListBoxRow, self).__init__()

Considering the reason behind adopting the syntax change on super() with PEP-3135, at least, we need to get rid of this old python2 syntax code in tutorial document. https://www.python.org/dev/peps/pep-3135/#rationale

Maybe I am wrong. But this and the following are what I saw today by poking upstream documents which seems to demand more style changes.

As I learn more on coding in Python, subclassing seems to be a bad idea these days for overhead etc.

The example code by the upstream pyobject developer doesn't use subclass with __init__ like this tutorial.

Gtk.Template codes, of course, need class but no __init__ used like ones in other parts of this tutorial..

As a tutorial, complicating code by subclass may not be desirable thing if it has clear merits. For example, Section 6.1.1 Examples can be as simple as the following without class:

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

def on_button1_clicked(widget):
    print("Hello")

def on_button2_clicked(widget):
    print("Goodbye")

win = Gtk.Window()
win.set_title("Hello World")

win.box = Gtk.Box(spacing=6)
win.box.set_homogeneous(True)
win.add(win.box)

win.button1 = Gtk.Button(label="Hello")
win.button1.connect("clicked", on_button1_clicked)
win.box.add(win.button1)

win.button2 = Gtk.Button(label="Goodbye")
win.button2.connect("clicked", on_button2_clicked)
win.box.add(win.button2)

win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

Although, we are more likely to use Gtk.Template, it is very educational how each Gtk components are used.

I thank your effort which gave me good heads up. Thank you.

@sebp
Copy link
Owner

sebp commented Jul 8, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants