[PyKDE] strange seg fault with SIGNAL('PyObject *')
Patrick Stinson
patrickkidd at gmail.com
Thu Mar 23 03:47:30 GMT 2006
I don't have debuggin symbols installed, but I am consistently getting a seg
fault after calling the python slot connected to SIGNAL('PyObject *') from a
QWidget subclass. I am usually passing a python string with the signal, but
if I pass None instead, it doesn't crash. I have a button group emitting
clicked(QAbstractButton *), which emits this signal.
the connecting code is as follows (sorry for the length), good luck:
import os
from PyQt4.QtCore import QObject, SIGNAL
from PyQt4.QtGui import QPushButton, QApplication, QWidget, QHBoxLayout
from PyQt4.QtGui import QButtonGroup, QPalette, QColor
# ~/.pksampler
PATCH_DIR = os.path.join(os.environ['HOME'], '.pksampler')
LAYERS = ['bass', 'drums', 'lead', 'misc', 'pads']
def find_patches():
patches = [i for i in os.listdir(PATCH_DIR)
if os.path.isdir(os.path.join(PATCH_DIR, i))]
return patches
def extension(fpath):
""" return the extension of fpath, not including the . """
return fpath[fpath.rfind('.')+1:]
def can_open(fpath):
exists = os.access(fpath, os.R_OK)
supported = extension(fpath) in ('wav', 'aiff')
return exists and supported
class PatchSelector(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
Layout = QHBoxLayout(self)
self.group = QButtonGroup(self)
self.buttons = []
for index, name in enumerate(find_patches()):
button = QPushButton(name)
palette = QPalette(button.palette())
palette.setColor(QPalette.Button,
QColor('grey').dark(150))
button.setPalette(palette)
self.group.addButton(button)
self.group.setId(button, index)
self.buttons.append(button)
Layout.addWidget(button)
QObject.connect(self.group,
SIGNAL('buttonClicked(QAbstractButton *)'),
self.clicked)
def clicked(self, button):
name = str(button.text())
self.selected = name
self.emit(SIGNAL('selected(PyObject *)'), name)
#self.emit(SIGNAL('selected()'))
class Patch:
name = None
layers = None
def __init__(self, name):
self.name = name
self.homedir = os.path.join(PATCH_DIR, name)
self.layers = {}
for layer in LAYERS:
self.layers[layer] = []
lpath = os.path.join(self.homedir, layer)
if os.path.isdir(lpath):
self.layers[layer] = []
for fname in os.listdir(lpath):
print 'LPATH',lpath
# THIS CRASHES IF I ENABLE THESE **************************8
# fpath = os.path.join(lpath, fname)
# print 'FPATH',fpath
# #if can_open(fpath):
# # self.layers[layer].append(fpath)
if __name__ == '__main__':
import sys
def selected(name):
print 'Selected:',name, Patch(name)
a = QApplication(sys.argv)
w = PatchSelector()
QObject.connect(w, SIGNAL('selected(PyObject *)'), selected)
#QObject.connect(w, SIGNAL('selected()'), selected)
w.show()
a.exec_()
--
Patrick Kidd Stinson
http://www.patrickkidd.com/
http://pkaudio.sourceforge.net/
http://pksampler.sourceforge.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060323/0efafdde/attachment.html
More information about the PyQt
mailing list