| 1 |
======================================== |
| 2 |
Analysis of Classes without Constructors |
| 3 |
======================================== |
| 4 |
|
| 5 |
There are a number of classes in the GNOME APIs that are not intended for direct creation. The |
| 6 |
issue is there is not an accurate way to generically determine this. GI bindings are general and |
| 7 |
expose everything they can, this makes a number of classes available which crash when an attempt |
| 8 |
is made to instantiate them. However, we can look at classes which do not explicitly implement |
| 9 |
constructors as a hint. The following script and table attempts some analysis as to what classes |
| 10 |
do not have constructors and why. |
| 11 |
|
| 12 |
Script Used to Generate Initial Table |
| 13 |
====================================== |
| 14 |
|
| 15 |
This script iterates a number of Python GI imported namespaces and looks for GObject.Object |
| 16 |
based classes which do not provide a public constructor. |
| 17 |
|
| 18 |
.. code-block:: python |
| 19 |
|
| 20 |
import inspect |
| 21 |
import gi |
| 22 |
from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Gio |
| 23 |
|
| 24 |
repo = gi.gi.Repository.get_default() |
| 25 |
modules = dict(GObject=GObject, |
| 26 |
Gtk=Gtk, Gdk=Gdk, |
| 27 |
GdkPixbuf=GdkPixbuf, |
| 28 |
Gio=Gio) |
| 29 |
|
| 30 |
print("||'''Name'''||'''Bug'''||'''Alternative'''||'''Reason'''||") |
| 31 |
for modname, mod in sorted(modules.items()): |
| 32 |
for name in dir(mod): |
| 33 |
obj = getattr(mod, name) |
| 34 |
if not inspect.isclass(obj) or not issubclass(obj, GObject.Object): |
| 35 |
continue |
| 36 |
info = repo.find_by_name(modname, name) |
| 37 |
if isinstance(info, (gi.types.ObjectInfo, )) and not info.get_abstract(): |
| 38 |
if not any(meth.is_constructor() for meth in info.get_methods()): |
| 39 |
print('||`%s.%s` || || || ||' % (modname, name)) |
| 40 |
|
| 41 |
Classes without Constructors |
| 42 |
============================= |
| 43 |
|
| 44 |
==================================== ================================ =============================================== ============================================================================================================ |
| 45 |
**Name** **Bug** **Alternative** **Reason** |
| 46 |
==================================== ================================ =============================================== ============================================================================================================ |
| 47 |
``GObject.Binding`` `675581`_ GObject.Object.bind_property(...) Non-generic semantics, requires construct only arguments. |
| 48 |
``GObject.InitiallyUnowned`` [1] |
| 49 |
``Gdk.Display`` Gdk.Display.get_default() Singleton |
| 50 |
``Gdk.DisplayManager`` Gdk.Display.get_default() or Gdk.Display.get() Singleton |
| 51 |
``Gdk.DragContext`` Gdk.drag_begin() [1] |
| 52 |
``Gdk.Keymap`` Gdk.Keymap.get_default() Singleton |
| 53 |
``Gdk.Screen`` `687792`_ Screen.get_default() Singleton |
| 54 |
``Gdk.Visual`` [1] |
| 55 |
``GdkPixbuf.PixbufAnimationIter`` [1] |
| 56 |
``GdkPixbuf.PixbufSimpleAnimIter`` [1] |
| 57 |
``Gio.ApplicationCommandLine`` [1] (Usually created by GApplication) |
| 58 |
``Gio.DBusActionGroup`` Gio.DBusActionGroup.get() [1] |
| 59 |
``Gio.DBusMenuModel`` Gio.DBusMenuModel.get() [1] |
| 60 |
``Gio.DBusMethodInvocation`` [1] Received as argument to the handle_method_call() function |
| 61 |
``Gio.FileEnumerator`` Gio.File.enumerate_children() [1] |
| 62 |
``Gio.FileIOStream`` unknown |
| 63 |
``Gio.FileInputStream`` unknown |
| 64 |
``Gio.FileOutputStream`` unknown |
| 65 |
``Gio.MemoryOutputStream`` unknown |
| 66 |
``Gio.ProxyAddressEnumerator`` Gio.SocketConnectable.enumerate() [1] |
| 67 |
``Gio.Resolver`` Gio.Resolver [1] |
| 68 |
``Gio.SocketConnection`` unknown |
| 69 |
``Gio.TcpConnection`` unknown |
| 70 |
``Gio.TlsInteraction`` unknown |
| 71 |
``Gio.UnixConnection`` unknown |
| 72 |
``Gio.Vfs`` Gio.Vfs.get_default() or Gio.Vfs.get_local() Singleton |
| 73 |
``Gio.VolumeMonitor`` `647731`_ Gio.VolumeMonitor.get() Singleton |
| 74 |
``Gtk.AccelMap`` Gtk.AccelMap.get() [1] |
| 75 |
``Gtk.Accessible`` unknown |
| 76 |
``Gtk.CellAreaContext`` Gtk.CellAreaClass.create_context() [1] |
| 77 |
``Gtk.Clipboard`` Gtk.Clipboard.get() [1] |
| 78 |
``Gtk.FileChooserDialog`` Generic creation works and is necessary. Constructor skipped do to variadic arguments. |
| 79 |
``Gtk.MessageDialog`` Generic creation works and is necessary. Constructor skipped do to variadic arguments. |
| 80 |
``Gtk.NumerableIcon`` Works. gtk_numerable_icon_new marked as function not constructor do to annotation problem? |
| 81 |
``Gtk.PrintContext`` [1] Gtk.PrintContext objects gets passed to the ::begin-print, ::end-print, ::request-page-setup and ::draw-page signals on the Gtk.PrintOperation. |
| 82 |
``Gtk.RecentChooserDialog`` Generic creation works and is necessary. Constructor skipped do to variadic arguments. |
| 83 |
``Gtk.Settings`` Gtk.Settings.get_default() [1] |
| 84 |
``Gtk.ThemingEngine`` [1] |
| 85 |
``Gtk.Tooltip`` [1] Instance passed to "query-tooltip" signal handler |
| 86 |
``Gtk.TreeModelFilter`` Gtk.TreeModel.filter_new() [1] |
| 87 |
``Xkl.Engine`` `680202`_ Xkl.Engine.get_instance(display) |
| 88 |
==================================== ================================ =============================================== ============================================================================================================ |
| 89 |
|
| 90 |
.. _675581: http://bugzilla.gnome.org/show_bug.cgi?id=675581 |
| 91 |
.. _687792: http://bugzilla.gnome.org/show_bug.cgi?id=687792 |
| 92 |
.. _647731: http://bugzilla.gnome.org/show_bug.cgi?id=647731 |
| 93 |
.. _680202: http://bugzilla.gnome.org/show_bug.cgi?id=680202 |
| 94 |
|
| 95 |
[1] - Generic creation works but the class might not be necessary in Python. |