After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 530417 - Add a nicer constructor for GstElements
Add a nicer constructor for GstElements
Status: RESOLVED NOTABUG
Product: GStreamer
Classification: Platform
Component: gst-python
git master
Other Linux
: Normal normal
: 0.10.19
Assigned To: Johan (not receiving bugmail) Dahlin
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-04-28 18:31 UTC by Johan (not receiving bugmail) Dahlin
Modified: 2010-07-14 10:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gst-element-factory-fancy-constructor.diff (2.54 KB, patch)
2008-04-28 18:32 UTC, Johan (not receiving bugmail) Dahlin
rejected Details | Review

Description Johan (not receiving bugmail) Dahlin 2008-04-28 18:31:44 UTC
It's kind of strange to be forced to use a factory function to create an element.
It would be nicer if it would be similar to a normal constructor, eg:

 element = gst.Element('oggmux')
Comment 1 Johan (not receiving bugmail) Dahlin 2008-04-28 18:32:30 UTC
Created attachment 110057 [details] [review]
gst-element-factory-fancy-constructor.diff
Comment 2 Edward Hervey 2008-05-08 14:06:50 UTC
2008-05-08  Edward Hervey  <edward.hervey@collabora.co.uk>

	Patch by: Johan Dahlin  <johan at gnome dot org>
	* gst/__init__.py:
	* gst/gstelement.override:
	* testsuite/test_element.py:
	New 'fancy' constructor for gst.Element, allows creating elements in a
	more pythonic way (i.e. myelement = gst.Element("oggmux")).
	Fixes #530417

Comment 3 Alessandro Decina 2008-06-10 11:30:47 UTC
This breaks existing elements inheriting from gst.Element.

class RawVideoVarianceFilter(gst.Element):
   ...
    def __init__(self):
        gst.Element.__init__(self)

        self.sinkpad = gst.Pad(self.sink_template)
        self.sinkpad.set_chain_function(self.do_chain)
        self.sinkpad.set_event_function(self.do_sink_event)
        self.add_pad(self.sinkpad)
        ...

  • File "/home/alessandro/src/elisa/bzr/upicek_thumbnails/elisa-plugins/elisa/plugins/gstreamer/gst_metadata.py", line 260 in do_create_filter
    filter = RawVideoVarianceFilter()
TypeError: element_factory_make() takes at least 1 argument (0 given)

Comment 4 Jan Schmidt 2008-06-11 09:17:48 UTC
We should revert the change for this release, from the looks of it.
Comment 5 René Stadler 2008-06-11 14:28:38 UTC
I propose to revert this and close as NOTABUG.  Johan, you say it's strange to be forced to use factory functions, but I disagree.  Alessandro pointed out the obvious case where you are _not_ forced to use a factory to create an element.  It's clear how it suddenly becomes strange to have the factory name passed to the constructor here.

I also don't understand how the patch gets rid of the strangeness of the factory concept anyways.  Instead of gst.element_factory_make you just propose to call gst.Element instead, but it doesn't become any more pythonic that way.  It's quite the contrary because gst.Element is a class, and calling a class in python should return an instance of that class -- not some random subclass implicitely depending on a constructor argument.
Comment 6 Edward Hervey 2008-06-11 14:50:18 UTC
will revert it on Friday if johan hasn't answered and proposed a fix for this.
Comment 7 Edward Hervey 2008-06-13 11:11:56 UTC
2008-06-13  Edward Hervey  <edward.hervey@collabora.co.uk>

	* gst/__init__.py:
	* gst/gstelement.override:
	* testsuite/test_element.py:
	Revert 2008-05-08  Edward Hervey  <edward.hervey@collabora.co.uk>
	Re-opens #530417

Comment 8 Johan (not receiving bugmail) Dahlin 2008-06-17 20:15:18 UTC
Sorry, I was on vacation.

I was pretty sure that the gst.Element subclass code path was tested through a unittest. That needs to be added, to avoid breaking this again.

Now, one way of solving it is to do something like:

  def __call__(cls, *args, **kwargs):
      if cls == gst.Element:
         # new fancy constructor path
         return

      # just instantiate the object, so g_object_new() works

Fun fun fun!
Comment 9 Alessandro Decina 2010-07-14 10:44:29 UTC
I'm closing this. Maybe we can do something fancier when we move to pygi.