[PATCH] Don't use positional arguments to initialize Gtk objects
Vratislav Podzimek
vpodzime at redhat.com
Tue Feb 18 10:05:07 UTC 2014
On Mon, 2014-02-17 at 18:02 -0500, David Shea wrote:
> "PyGTKDeprecationWarning: Using positional arguments with the GObject
> constructor has been deprecated."
>
> Ok. Use keyword arguments everywhere we were using positional arguments
> (mostly labels), except for a couple of instances of GtkTreeViewColumn
> in network.py because they kinda half-assed the interface for that one
> and pygobject doesn't complain about those anyway. Also rolled up some
> lists of .set_<property> calls into constructor arguments.
> ---
> pyanaconda/ui/gui/hubs/__init__.py | 14 +++------
> pyanaconda/ui/gui/spokes/lib/accordion.py | 47 +++++++++++--------------------
> pyanaconda/ui/gui/spokes/network.py | 7 ++---
> pyanaconda/ui/gui/spokes/software.py | 12 +++-----
> 4 files changed, 26 insertions(+), 54 deletions(-)
>
> diff --git a/pyanaconda/ui/gui/hubs/__init__.py b/pyanaconda/ui/gui/hubs/__init__.py
> index e0f4d13..9afbd14 100644
> --- a/pyanaconda/ui/gui/hubs/__init__.py
> +++ b/pyanaconda/ui/gui/hubs/__init__.py
> @@ -155,11 +155,8 @@ class Hub(GUIObject, common.Hub):
> cats_and_spokes = self._collectCategoriesAndSpokes()
> categories = cats_and_spokes.keys()
>
> - grid = Gtk.Grid()
> - grid.set_row_spacing(6)
> - grid.set_column_spacing(6)
> - grid.set_column_homogeneous(True)
> - grid.set_margin_bottom(12)
> + grid = Gtk.Grid(row_spacing=6, column_spacing=6, column_homogeneous=True,
> + margin_bottom=12)
>
> row = 0
>
> @@ -229,11 +226,8 @@ class Hub(GUIObject, common.Hub):
> if not selectors:
> continue
>
> - label = Gtk.Label("<span font-desc=\"Sans 14\">%s</span>" % escape_markup(_(obj.title)))
> - label.set_use_markup(True)
> - label.set_halign(Gtk.Align.START)
> - label.set_margin_top(12)
> - label.set_margin_bottom(12)
> + label = Gtk.Label(label="<span font-desc=\"Sans 14\">%s</span>" % escape_markup(_(obj.title)),
> + use_markup=True, halign=Gtk.Align.START, margin_top=12, margin_bottom=12)
> grid.attach(label, 0, row, 2, 1)
> row += 1
>
> diff --git a/pyanaconda/ui/gui/spokes/lib/accordion.py b/pyanaconda/ui/gui/spokes/lib/accordion.py
> index f62f2fe..6528477 100644
> --- a/pyanaconda/ui/gui/spokes/lib/accordion.py
> +++ b/pyanaconda/ui/gui/spokes/lib/accordion.py
> @@ -79,11 +79,9 @@ class Accordion(Gtk.Box):
> self._expanders = []
>
> def addPage(self, contents, cb=None):
> - label = Gtk.Label()
> - label.set_markup("""<span size='large' weight='bold' fgcolor='black'>%s</span>""" %
> - escape_markup(contents.pageTitle))
> - label.set_alignment(0, 0.5)
> - label.set_line_wrap(True)
> + label = Gtk.Label(label="""<span size='large' weight='bold' fgcolor='black'>%s</span>""" %
> + escape_markup(contents.pageTitle), use_markup=True,
> + xalign=0, yalign=0.5, wrap=True)
>
> expander = Gtk.Expander()
> expander.set_label_widget(label)
> @@ -273,19 +271,16 @@ class CreateNewPage(Page):
> self._createBox.set_column_spacing(6)
> self._createBox.set_margin_left(16)
>
> - label = Gtk.Label(_("You haven't created any mount points for your "
> + label = Gtk.Label(label=_("You haven't created any mount points for your "
> "%(product)s %(version)s installation yet. "
> - "You can:") % {"product" : productName, "version" : productVersion})
> - label.set_line_wrap(True)
> - label.set_alignment(0, 0.5)
> + "You can:") % {"product" : productName, "version" : productVersion},
> + wrap=True, xalign=0, yalign=0.5)
> self._createBox.attach(label, 0, 0, 2, 1)
>
> - dot = Gtk.Label("•")
> - dot.set_alignment(0.5, 0.4)
> - dot.set_hexpand(False)
> + dot = Gtk.Label(label="•", xalign=0.5, yalign=0.4, hexpand=False)
> self._createBox.attach(dot, 0, 1, 1, 1)
>
> - self._createNewButton = Gtk.LinkButton("", label=_("_Click here to create them automatically."))
> + self._createNewButton = Gtk.LinkButton(uri="", label=_("_Click here to create them automatically."))
> label = self._createNewButton.get_children()[0]
> label.set_alignment(0, 0.5)
> label.set_hexpand(True)
> @@ -303,33 +298,23 @@ class CreateNewPage(Page):
> self._createNewButton.connect("activate-link", lambda *args: Gtk.true())
> self._createBox.attach(self._createNewButton, 1, 1, 1, 1)
>
> - dot = Gtk.Label("•")
> - dot.set_alignment(0.5, 0)
> - dot.set_hexpand(False)
> + dot = Gtk.Label(label="•", xalign=0.5, yalign=0, hexpand=False)
> self._createBox.attach(dot, 0, 2, 1, 1)
>
> - label = Gtk.Label(_("Create new mount points by clicking the '+' button."))
> - label.set_alignment(0, 0.5)
> - label.set_hexpand(True)
> - label.set_line_wrap(True)
> + label = Gtk.Label(label=_("Create new mount points by clicking the '+' button."),
> + xalign=0, yalign=0.5, hexpand=True, wrap=True)
> self._createBox.attach(label, 1, 2, 1, 1)
>
> if partitionsToReuse:
> - dot = Gtk.Label("•")
> - dot.set_alignment(0.5, 0)
> - dot.set_hexpand(False)
> + dot = Gtk.Label(label="•", xalign=0.5, yalign=0, hexpand=False)
> self._createBox.attach(dot, 0, 3, 1, 1)
>
> - label = Gtk.Label(_("Or, assign new mount points to existing partitions after selecting them below."))
> - label.set_alignment(0, 0.5)
> - label.set_hexpand(True)
> - label.set_line_wrap(True)
> + label = Gtk.Label(label=_("Or, assign new mount points to existing partitions after selecting them below."),
> + xalign=0, yalign=0.5, hexpand=True, wrap=True)
> self._createBox.attach(label, 1, 3, 1, 1)
>
> - label = Gtk.Label(_("_New mount points will use the following partitioning scheme:"))
> - label.set_alignment(0, 0.5)
> - label.set_line_wrap(True)
> - label.set_use_underline(True)
> + label = Gtk.Label(label=_("_New mount points will use the following partitioning scheme:"),
> + xalign=0, yalign=0.5, wrap=True, use_underline=True)
> self._createBox.attach(label, 0, 4, 2, 1)
>
> label.set_mnemonic_widget(combo)
> diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
> index 609c498..7fec296 100644
> --- a/pyanaconda/ui/gui/spokes/network.py
> +++ b/pyanaconda/ui/gui/spokes/network.py
> @@ -1135,11 +1135,8 @@ class SecretAgentDialog(GUIObject):
> grid.set_column_spacing(6)
>
> for row, secret in enumerate(self._content['secrets']):
> - label = Gtk.Label(secret['label'])
> - label.set_halign(Gtk.Align.START)
> - entry = Gtk.Entry()
> - entry.set_visibility(False)
> - entry.set_hexpand(True)
> + label = Gtk.Label(label=secret['label'], halign=Gtk.Align.START)
> + entry = Gtk.Entry(visibility=False, hexpand=True)
> self._validate(entry, secret)
> entry.connect("changed", self._validate, secret)
> entry.connect("activate", self._password_entered_cb)
> diff --git a/pyanaconda/ui/gui/spokes/software.py b/pyanaconda/ui/gui/spokes/software.py
> index 424a98a..bc4694b 100644
> --- a/pyanaconda/ui/gui/spokes/software.py
> +++ b/pyanaconda/ui/gui/spokes/software.py
> @@ -278,19 +278,15 @@ class SoftwareSelectionSpoke(NormalSpoke):
>
> def _add_row(self, listbox, name, desc, button):
> row = Gtk.ListBoxRow()
> - box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
> - box.set_spacing(6)
> + box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
>
> button.set_valign(Gtk.Align.START)
> button.connect("clicked", self.on_button_toggled, row)
> box.add(button)
>
> - label = Gtk.Label()
> - label.set_line_wrap(True)
> - label.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
> - label.set_markup("<b>%s</b>\n%s" % (escape_markup(name), escape_markup(desc)))
> - label.set_hexpand(True)
> - label.set_alignment(0, 0.5)
> + label = Gtk.Label(label="<b>%s</b>\n%s" % (escape_markup(name), escape_markup(desc)),
> + use_markup=True, wrap=True, wrap_mode=Pango.WrapMode.WORD_CHAR,
> + hexpand=True, xalign=0, yalign=0.5)
> box.add(label)
>
> row.add(box)
I think that instead of doing this "fix", we should file a bug on
pygobject-introspection because we really do nothing wrong or
non-standard. What exactly causes the error? The empty constructor or
calling those set_* methods? I believe the latter is okay and the
constructor is the same as it is called in the C except we don't pass
the object as the first instance. This really looks to me like a bug in
some other place not in our code.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list