How do I create a new signal in pygtk

I've created a python object, but I want to send signals on it. I made it inherit from gobject.GObject, but there doesn't seem to be any way to create a new signal on my object.


Asked by: Aida741 | Posted: 28-01-2022






Answer 1

You can also define signals inside the class definition:

class MyGObjectClass(gobject.GObject):
    __gsignals__ = {
      "some-signal": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (object, )),
    }

The contents of the tuple are the the same as the three last arguments to gobject.signal_new.

Answered by: Joyce454 | Posted: 01-03-2022



Answer 2

Here is how:

import gobject

class MyGObjectClass(gobject.GObject):
    ...

gobject.signal_new("signal-name", MyGObjectClass, gobject.SIGNAL_RUN_FIRST,
    None, (str, int))

Where the second to last argument is the return type and the last argument is a tuple of argument types.

Answered by: Joyce313 | Posted: 01-03-2022



Answer 3

If you use kiwi available here you can just do:

from kiwi.utils import gsignal

class MyObject(gobject.GObject):
    gsignal('signal-name')

Answered by: Kellan407 | Posted: 01-03-2022



Similar questions

python - Create a List that contain each Line of a File

This question already has answers here:


python - Any way to create a NumPy matrix with C API?

I read the documentation on NumPy C API I could find, but still wasn't able to find out whether there is a possibility to construct a matrix object with C API — not a two-dimensional array. The function is intended for work with math matrices, and I don't want strange results if the user calls matrix multiplication forgetting to convert this value from an array to a matrix (multiplication and exponentiation being the only ...


python - How can i create a lookup in Django?

I have a Question model & Form, one of the fields in this model is userid=ForeignKey(User), this Works perfectly well on the Question Model, am able to pick the user from a drop down. But kind a tricky when i want to list the question from the model, which is the best way to lookup the user name from the Users table? becouse at this point i cant have the dropdown! I wa...


python - create an array from a txt file

I'm new in python and I have a problem. I have some measured data saved in a txt file. the data is separated with tabs, it has this structure: 0 0 -11.007001 -14.222319 2.336769 i have always 32 datapoints per simulation (0,1,2,...,31) and i have 300 simulations (0,1,2...,299), so the data is sorted at first with the number of simulation and then the number of the data point.


python - Create numpy matrix filled with NaNs

I have the following code: r = numpy.zeros(shape = (width, height, 9)) It creates a width x height x 9 matrix filled with zeros. Instead, I'd like to know if there's a function or way to initialize them instead to NaNs in an easy way.


python - How can I create 1000 files that I can use to test a script?

I would like to create 1000+ text files with some text to test a script, how to create this much if text files at a go using shell script or Perl. Please could anyone help me?


python - How to create a custom django filter tag

I am having trouble in getting my site to recognise custom template tags. I have the following dir structure: project_name project_name templatetags _ __init __ _.py getattribute.py views _ __init __ _.py index.html views settings.py main.py manage.py urls.py


python - how does create a new app in pinax?

thanks only need 'python manage.py startapp xx' ???


python - Should I create each class in its own .py file?

I'm quite new to Python in general. I'm aware that I can create multiple classes in the same .py file, but I'm wondering if I should create each class in its own .py file. In C# for instance, I would have a class that handles all Database interactions. Then another class that had the business rules. Is this the case in Python?


python - how to create a theme with QT

im looking for a way to make my pyqt interface look nicer by adding a theme to it. im new to Qt and i still have no idea how to add a custom theme for widgets.. so how is that possible ? and is it possible through qt designer ? sorry for my bad english , its my third language. i hope the idea is clear enough . please let me know if something was unclear .. thanks in advace


python - What's the best Django search app?


How can I use a DLL file from Python?

What is the easiest way to use a DLL file from within Python? Specifically, how can this be done without writing any additional wrapper C++ code to expose the functionality to Python? Native Python functionality is strongly preferred over using a third-party library.


python - PubSub lib for c#

Is there a c# library which provides similar functionality to the Python PubSub library? I think it's kind of an Observer Pattern which allows me to subscribe for messages of a given topic instead of using events.


python - What is the best way to copy a list?

This question already has answers here:


python - Possible Google Riddle?

My friend was given this free google website optimizer tshirt and came to me to try and figure out what the front logo meant. t-shirt So, I have a couple of guesses as to what it means, but I was just wondering if there is something more. My first guess is that eac...


How do you check whether a python method is bound or not?

Given a reference to a method, is there a way to check whether the method is bound to an object or not? Can you also access the instance that it's bound to?


ssh - How to scp in Python?

What's the most pythonic way to scp a file in Python? The only route I'm aware of is os.system('scp "%s" "%s:%s"' % (localfile, remotehost, remotefile) ) which is a hack, and which doesn't work outside Linux-like systems, and which needs help from the Pexpect module to avoid password prompts unless you already have passwordless SSH set up to the remote host. I'm aware of Twisted'...


python - What do I need to import to gain access to my models?

I'd like to run a script to populate my database. I'd like to access it through the Django database API. The only problem is that I don't know what I would need to import to gain access to this. How can this be achieved?


python - How do I edit and delete data in Django?

I am using django 1.0 and I have created my models using the example in the Django book. I am able to perform the basic function of adding data; now I need a way of retrieving that data, loading it into a form (change_form?! or something), EDIT it and save it back to the DB. Secondly how do I DELETE the data that's in the DB? i.e. search, select and then delete! Please show me an example of the code ...


python - How do I turn an RSS feed back into RSS?

According to the feedparser documentation, I can turn an RSS feed into a parsed object like this: import feedparser d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml') but I can't find anything showing how to go the other way; I'd like to be able do manipulate 'd' and then output the result as XM...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top