Active Topics

 


Reply
Thread Tools
Posts: 99 | Thanked: 75 times | Joined on Nov 2009
#1
I've started writing an app to let you see live departures and arrivals of trains in the UK.

I decided to use Python and QT for this. However I've come across a problem I've not been able to solve.

Because there are a number of stations in the UK I wanted to have a the QT equivalent of the hildon PickerButton that give you a button which, when pressed, presents a list of options. You also have the ability to type into a text box to take you to the option you want.

I started searching for the QT version and came across this post:
http://qt.nokia.com/doc/qt-maemo-4.6...kselector.html

So I tried to implement this in python. The first problem I came across was that PyQT didn't seem to support the QtMaemo5 module so I switched to pyside.

This ran fine up until I clicked the button and then the app seg faults.

The code I'm using to try and create this is:

Code:
        model = QtGui.QStandardItemModel(0,1);

        for i in range(1, 5):
            item = QtGui.QStandardItem(QtCore.QString("Station "+str(i)))
            item.setTextAlignment(QtCore.Qt.AlignCenter)
            item.setEditable(0)
            model.appendRow(item)

        stationsFrom = QtMaemo5.QMaemo5ValueButton("Departing From:")
        stationsFrom.setValueLayout(QtMaemo5.QMaemo5ValueButton.ValueBesideText)

        selectorFrom = QtMaemo5.QMaemo5ListPickSelector()
        selectorFrom.setModel(model)
        stationsFrom.setPickSelector(selectorFrom)
If I comment out the "setPickSelector" call the button doesn't do anything when clicked but at least it doesn't crash. This makes me think it has to be something to do with QMaemo5ListPickSelector.

A google for QMaemo5ListPickSelector and pyside brings up only a git commit log.

Is there a chance this just doesn't work yet or am I doing something stupid? This is my first python project in about 4 years and my first time using QT so perhaps it's pebkac.

Any help would be greatly appreciated.
 
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#2
Originally Posted by SirMuttley View Post
If I comment out the "setPickSelector" call the button doesn't do anything when clicked but at least it doesn't crash. This makes me think it has to be something to do with QMaemo5ListPickSelector.

A google for QMaemo5ListPickSelector and pyside brings up only a git commit log.

Is there a chance this just doesn't work yet or am I doing something stupid? This is my first python project in about 4 years and my first time using QT so perhaps it's pebkac.

Any help would be greatly appreciated.
the code seems alright to me, this is exactly how Ive used it in C++ as well for an app
doing exactly the same for the london underground.
Code:
	QStandardItemModel *stationListModel = new QStandardItemModel(0, 1);

	foreach(QString station, stationList)

	{
		QStandardItem *item = new QStandardItem(station);
                // the Maemo 5 design spec recommends this.
		item->setTextAlignment(Qt::AlignCenter); 
		item->setEditable(false); // prevent editing of the item
		stationListModel->appendRow(item);
	}
        QMaemo5ListPickSelector *fromSelector = new QMaemo5ListPickSelector;
	QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector;
	QMaemo5ListPickSelector *viaSelector = new QMaemo5ListPickSelector;
	fromSelector->setModel(stationListModel);
	toSelector->setModel(stationListModel);
	viaSelector->setModel(stationListModel);
	// not setting the current index means that the value is empty.
	fromButton->setPickSelector(fromSelector);
	toButton->setPickSelector(toSelector);
	viaButton->setPickSelector(viaSelector);
If I find something about this Ill post today, dont know much about python but this will be a start for me as well
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”

Last edited by krk969; 2010-03-01 at 12:02.
 
Posts: 99 | Thanked: 75 times | Joined on Nov 2009
#3
So far not had any luck.

I asked a few times on the pyside irc channel but didn't get any response.

Will try on their mailing lists next to see if that helps.

Quite a pain, will have to try and use something else in the short term so I can at least continue coding the project.
 
krk969's Avatar
Posts: 754 | Thanked: 630 times | Joined on Sep 2009 @ London
#4
Originally Posted by SirMuttley View Post
So far not had any luck.

I asked a few times on the pyside irc channel but didn't get any response.

Will try on their mailing lists next to see if that helps.

Quite a pain, will have to try and use something else in the short term so I can at least continue coding the project.
I couldnt find much issue with the above code too as it seems to be exactly what Ive done in C++.

as Ive already said I dont know much about python, but most cases the crash happens when you are trying to access a QT object that doesnt exist.
Is there any scope for the QT objects you are defining ? , any chance that where you access the button the selectorFrom is out of scope ?
__________________
Developer of :
Buddy - budget/expense manager ( website )
Showtime - a telly channel listing viewer/reminder ( website )
Travelapp - london underground status/planner ( website )
Batlevel - desktop widget for battery level ( website )

“I hear and I forget. I see and I remember. I do and I understand.”
 
Posts: 53 | Thanked: 90 times | Joined on Nov 2009 @ Manaus, Brazil
#5
As discussed on IRC (#pyside @ freenode):

Replacing all "model" occurrences with "self.model" and all "pickselector" references with "self.pickselector" should avoid the segfault.

It happens because these two objects are being destroyed by the Python's GC once they leave the constructor scope. It still needs to be checked whether this needs fixing on PySide or not, but the changes above should work just fine.
__________________
Anderson Lizardo
 
Posts: 99 | Thanked: 75 times | Joined on Nov 2009
#6
Many thanks.

That now works great.

However it wasn't entirely the functionality I was looking for. It seems the QT version of the PickerButton was only half of what I was looking for, what I'd like it to then pop up is a version of Hildon's TouchSelectorEntry (http://maemomm.garage.maemo.org/docs...ctorentry.html).

It seems this doesn't exist in QT which is a bit of a shame as the list of stations (http://www.nationalrail.co.uk/stations/codes/) is quite long and it would probably be nice for a user to be able to start typing in a box the name of their town. I know you can still type in the list anyway to move down to a particular item, but I was quite fond of the TouchSelectorEntry style.

Oh well.

Many thanks again for the help Lizardo and krk969
 
Reply


 
Forum Jump


All times are GMT. The time now is 02:53.