Reply
Thread Tools
Posts: 1,746 | Thanked: 2,100 times | Joined on Sep 2009
#1
Not terribly familiar with Python, so I'm working with a bit of N900 development while learning the ropes. Unfortunately, I've run into a bit of a problem.

I'm playing around with fatalsaint's example, and extended it to act on one of the buttons in the pop up dialog. The goal was to make a notification pop up on the screen when tapped.

Unfortunately, after paring the code down to this:

Code:
#I don't use PySide
import sys
import pynotify
from PyQt4 import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *

if __name__ == '__main__':
        app = QApplication(sys.argv)
I get a segfault on my device. Anyone else running into this, or is there a better way to go about it?
 
Posts: 13 | Thanked: 20 times | Joined on Jun 2010
#2
I just spent some time looking at this (Not that my python skills are that great), but, I can replicate this exact problem. I did find a work-around, though. I created a simple notifyMe class and in it's constructor (The __init__ bit, this is what gets called when the object gets created), I added the import there. This allows for the PyQt4 stuff to be imported, then pynotify.

Code:
#!/usr/bin/env python2.5
# -*- coding: utf-8 -*-
import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import * 
from PyQt4 import QtGui, QtCore

class notifyMe(object):
        def __init__(self, parent=None):
                # this is the constructor
                import pynotify
                pynotify.init('something')
                n = pynotify.Notification("my message", "message")
                n.show()

if __name__ == '__main__':
	app = QtGui.QApplication(sys.argv)
	print "hello, world"
	x = notifyMe()
I extensively tested this script on my n900 at least 2 or 3 times. I'm not sure how useful this would be with any sizable PyQt code, but this is at least a workaround.
 

The Following User Says Thank You to timconradinc For This Useful Post:
Posts: 1,746 | Thanked: 2,100 times | Joined on Sep 2009
#3
Originally Posted by timconradinc View Post
I just spent some time looking at this (Not that my python skills are that great), but, I can replicate this exact problem. I did find a work-around, though. I created a simple notifyMe class and in it's constructor (The __init__ bit, this is what gets called when the object gets created), I added the import there. This allows for the PyQt4 stuff to be imported, then pynotify.

Code:
#!/usr/bin/env python2.5
# -*- coding: utf-8 -*-
import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import * 
from PyQt4 import QtGui, QtCore

class notifyMe(object):
        def __init__(self, parent=None):
                # this is the constructor
                import pynotify
                pynotify.init('something')
                n = pynotify.Notification("my message", "message")
                n.show()

if __name__ == '__main__':
	app = QtGui.QApplication(sys.argv)
	print "hello, world"
	x = notifyMe()
I extensively tested this script on my n900 at least 2 or 3 times. I'm not sure how useful this would be with any sizable PyQt code, but this is at least a workaround.
Good to see it's not just me that hits it. Only question now is if including it in the __init__ constrains the scope to the class in question. My initial suspicion is that it does, but I can test that out on my own.

Thanks for the input!

EDIT:

Yup, scope limited like I expected. But it does work around the crash.

Last edited by wmarone; 2010-06-14 at 04:34.
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#4
This is a bit of a hack, but it does work (Im only showing relative parts, you'll have to figure where they go):

Code:
class notifyMe(object):
        def __init__(self, title=None, message=None):
                # this is the constructor
                import pynotify
                pynotify.init('something')
                n = pynotify.Notification(message, title)
                n.show()

def MyMainWindow(QWidget):
                #skip to buttons...
                f = QPushButton("With Chickes!")
                x = lambda: notifyMe("with", "chickens")
                #...
                self.connect(b, SIGNAL("clicked()"), d.close)
                self.connect(f, SIGNAL("clicked()"), x)
                #... rest of app
Then when you click the chickens button in my example it sends the notification. You just use lambda to execute, and create the class with the title/message you want.

Not super clean.. but functional.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!

Last edited by fatalsaint; 2010-06-14 at 05:30.
 

The Following User Says Thank You to fatalsaint For This Useful Post:
Posts: 13 | Thanked: 20 times | Joined on Jun 2010
#5
Going OT, but using lambda functions with buttons like that is a handy technique. There's a lot of times that you just want to use a signal/slot with a clicked() and identify the caller, this is a simple way to work around this.
 

The Following User Says Thank You to timconradinc For This Useful Post:
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#6
Originally Posted by timconradinc View Post
Going OT, but using lambda functions with buttons like that is a handy technique. There's a lot of times that you just want to use a signal/slot with a clicked() and identify the caller, this is a simple way to work around this.
This is actually originally how I found it . I had multiple buttons I wanted to send unique signals without making separate methods for each. Lambda worked out great for that.

I have read somewhere that using lambda isn't the most efficient though so I usually do point out that it may not be the cleanest method.. but so far it's worked great for me.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#7
Yeah, lambdas are cool, you can put them even within the connect statement, e.g. self.connect(f, SIGNAL("clicked()"), lambda: notifyMe("with", "chickens")). As for speed, as long it’s not something that is called several times per second (like events or quick change signals), you won’t see the difference.
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following 2 Users Say Thank You to attila77 For This Useful Post:
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#8
As far as I know, lambda functions are treated as first order objects in Python so there shouldn't be any special cost in using them.

When it comes to clean coding, they actually help in some way by locating call back code in one place close to where the callback link is created. The other side of that coin is that it might be hard to find the place where they are defined since they are lack identifying names.
 
Posts: 13 | Thanked: 20 times | Joined on Jun 2010
#9
epage provided this link on my pyqt tips thread for the 'proper' way of doing this.
 

The Following User Says Thank You to timconradinc For This Useful Post:
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#10
Originally Posted by timconradinc View Post
epage provided this link on my pyqt tips thread for the 'proper' way of doing this.
Wow... so much work.. such little gain.

I lied.. now that I'm reading through it, it actually looks pretty clean. I'll play with it a bit.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!

Last edited by fatalsaint; 2010-06-14 at 19:23.
 
Reply


 
Forum Jump


All times are GMT. The time now is 11:29.