From 39d98386f72c65826e162e3e8fd36752ec469252 Mon Sep 17 00:00:00 2001 From: tpearson Date: Tue, 16 Aug 2011 09:06:37 +0000 Subject: Move python-kde3 to the more correct python-trinity git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/python-trinity@1247483 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- doc/signal.html | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 doc/signal.html (limited to 'doc/signal.html') diff --git a/doc/signal.html b/doc/signal.html new file mode 100644 index 0000000..ab5b3f9 --- /dev/null +++ b/doc/signal.html @@ -0,0 +1,290 @@ +Signal and Slot Support
Python Bindings for KDE (PyKDE-3.16.0)
PrevNext

Signal and Slot Support

General Signals and Slots

A signal may be either a Qt signal (specified using +SIGNAL()) or a Python signal (specified using +PYSIGNAL()).

A slot can be either a Python callable object, a Qt signal (specified using +SIGNAL()), a Python signal (specified using +PYSIGNAL()), or a Qt slot (specified using +SLOT()).

You connect signals to slots (and other signals) as you would from C++. For +example:

QObject.connect(a,SIGNAL("QtSig()"),pyFunction)
+QObject.connect(a,SIGNAL("QtSig()"),pyClass.pyMethod)
+QObject.connect(a,SIGNAL("QtSig()"),PYSIGNAL("PySig"))
+QObject.connect(a,SIGNAL("QtSig()"),SLOT("QtSlot()"))
+QObject.connect(a,PYSIGNAL("PySig"),pyFunction)
+QObject.connect(a,PYSIGNAL("PySig"),pyClass.pyMethod)
+QObject.connect(a,PYSIGNAL("PySig"),SIGNAL("QtSig()"))
+QObject.connect(a,PYSIGNAL("PySig"),SLOT("QtSlot()"))

When a slot is a Python method that corresponds to a Qt slot then a signal can +be connected to either the Python method or the Qt slot. The following +connections achieve the same effect.

sbar = QScrollBar()
+lcd = QLCDNumber()
+
+QObject.connect(sbar,SIGNAL("valueChanged(int)"),lcd.display)
+QObject.connect(sbar,SIGNAL("valueChanged(int)"),lcd,SLOT("display(int)"))

The difference is that the second connection is made at the C++ level and is +more efficient.

Disconnecting signals works in exactly the same way.

Any instance of a class that is derived from the QObject +class can emit a signal using the emit method. This takes +two arguments. The first is the Python or Qt signal, the second is a Python +tuple which are the arguments to the signal. For example:

a.emit(SIGNAL("clicked()"),())
+a.emit(PYSIGNAL("pySig"),("Hello","World"))

Qt allows a signal to be connected to a slot that requires fewer arguments than +the signal passes. The extra arguments are quietly discarded. Python slots +can be used in the same way.

Slots in Menus, Toolbars and Actions

The C++ declarations for menu items or KActions are similar to these examples:

int QMenuData::insertItem (const QString & text,
+     const QObject * receiver, const char * member,
+     int accel = 0, int id = -1, int index = -1 )
+
+KAction ( const QString& text, int accel,
+     const QObject* receiver, const char* slot,
+     QObject* parent, const char* name = 0 )

Notice the "const QObject* receiver, const char* slot" parameters for each declaration.

In PyKDE, these two parameters are replaced with a SINGLE parameter that specifies the +slot to be connected to the menu item, toolbar button or KAction:

p = insertItem ("Open", self.slotOpen, 0, -1, -1)
+
+action = KAction ("Open", 0, self.slotOpen, None, 0)

This substitution applies to appropriate methods in KStdAction, KAction and related +subclasses, KAccelMenu and KToolBar


PrevHomeNext
General Limitations Static Member Functions
\ No newline at end of file -- cgit v1.2.1