Active Topics

 


Reply
Thread Tools
Posts: 291 | Thanked: 398 times | Joined on Jan 2011 @ USA
#1
As most of you already know most PyQt4 apps are taking quite sometimes at start up and most of the time users are getting initial black screen while it's loading, this is just not only the case with Python apps but all the apps on n900. Nokia has used a trick to snapshot of apps start up screen and load image instantly when the app icon is pressed, which give users an impression that apps was started up instantly but in reality they were not. (modest, note, sketch, control panel, application manager, pdfviewer, worldclock, xterm, and calculator are using this trick). Some debates whether this is a good idea or not, but I for one rather see a false image than a black screen. . Thanks to MOhammadAG and caco3 in this post http://talk.maemo.org/showthread.php...99#post1001799 for getting my attention on this trick otherwise, I don't even know it exists.

So here I like to share how to make your Python Qt app fly at start up... only..... since i haven't seen any tutorial on how to get this work with pyqt on the web.

There are three basic things to make it works:
1. A dbus service file( name whatever e.g. yourapp.service) in /usr/share/dbus-1/services/ folder even though yourapp is not using dbus related service at all and it should like this format in yourapp.service.

Code:
[D-BUS Service]
Name=what.ever.yourapp
Exec=/opt/yourapp/main.py
2. Adding "X-Osso-Service=what.ever.yourapp" in your yourapp.desktop file in /usr/share/applications/hildon/ folder, something like this.

Code:
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Name=YourApp
Icon=YourApp
Exec=/opt/yourapp/main.py
X-Osso-Service=what.ever.yourapp
3. Lastly, A function code in your app to take a snapshot of your app startup screen when it starts up the first time or when it exits whichever your prefer. Below is an basic example of PyQt4 app code which take a snapshot of the screen at start up if it's not already exist and save it into /home/user/.cache/launch/what.ever.yourapp.pvr (ps. the file name has to match with your X-Osso-Service, and D-BUS Service Name plus .pvr extension)



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

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

import osso # only needed for osso_initialize

class MainWindow(QMainWindow):
    def __init__(self, parent = None):        
        self.dbus_service_name = "what.ever.yourapp"  #must be the same as your X-osso-service in yourapp.desktop file
        """
        self.osso_c = osso.Context(self.dbus_service_name, "0.0.1", False)
        is only needed if your app is not launched from run-standalone.sh,
        Otherwise, your app will be terminated after ~ 2mins running
        don't ask me why :)
        """
        self.osso_c = osso.Context(self.dbus_service_name, "0.0.1", False)
        
        QMainWindow.__init__(self, parent)

        self.centralwidget = QWidget(self)
        self.setCentralWidget(self.centralwidget)

        """
        the rest of your code here....
        """

    def takeScreenShot(self):
        pvr = "/home/user/.cache/launch/%s.pvr" % self.dbus_service_name
        if not QFile.exists(pvr): # skipped if it's already there
            QPixmap.grabWidget(self.centralwidget).save(pvr, 'png') # tell it to grab only your self.centralwidget screen, which is just window screen without the menu status bar on top. 

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    app.setApplicationName("YourAppName")
    YourApp = MainWindow()
    YourApp.show()
    YourApp.takeScreenShot() # run this after the YourApp.show()
    sys.exit(app.exec_())

Last edited by khuong; 2011-05-09 at 19:49.
 

The Following 5 Users Say Thank You to khuong For This Useful Post:
Saturn's Avatar
Posts: 1,648 | Thanked: 2,122 times | Joined on Mar 2007 @ UNKLE's Never Never Land
#2
Thanks for taking the time to write it so cleanly an understandable.

Care to put it in the wiki too?
 
Posts: 137 | Thanked: 81 times | Joined on May 2010
#3
I don't know sometimes it's kind of annoying. If you don't keep it in mind you sit there trying to click on things and you can't.

Wouldn't it be better to put up a welcome image or something?
 

The Following User Says Thank You to tushyd For This Useful Post:
Posts: 291 | Thanked: 398 times | Joined on Jan 2011 @ USA
#4
Originally Posted by Saturn View Post
Thanks for taking the time to write it so cleanly an understandable.

Care to put it in the wiki too?
It's in the wiki now



Originally Posted by tushyd View Post
I don't know sometimes it's kind of annoying. If you don't keep it in mind you sit there trying to click on things and you can't.

Wouldn't it be better to put up a welcome image or something?
If the app is well coded and small, it shouldn't take more ~1 sec to load, so users don't even know it's just an image.
For big app which take a while at startup, yes a welcome or a loading screen is more appropriate. This same trick works for welcome or loading screen as well, since it load the image before it started executing the code in the app, in fact it's much better and faster than loading a splashscreen or a welcome screen in from the app itself.
 

The Following 3 Users Say Thank You to khuong For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 15:56.