View Single Post
Old 11-06-2010, 04:36 PM   #3
oecherprinte
Zealot
oecherprinte began at the beginning.
 
Posts: 115
Karma: 20
Join Date: Jul 2010
Device: Kindle3 3G, Kindle Paperwhite 2
I have come up with a solution that I find quite elegant:

I just open up dialog popups to poll the parameter from the recipe itself. This is how I did it:

1. Add the following lines to the top of the recipe to load pyqt4 (the qt implementation for python)

Code:
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
2. Open a dialog window in the recipe wherever you need to poll a parameter. I placed it in the "parse_index" function to poll the number of feeds that should be processed. Just place the following code wherever you need it. I am polling an integer value, but getting a text is equally easy (I commented out the corresponding line).

Code:
    
            #####################
	    # dialog to get parameters
	    #####################
    
    
            #create gui application for dialog (I think you do not need it it's a leftover)	    
	    app = QtGui.QApplication(sys.argv)

	    #get widget
	    widget = QtGui.QWidget()
	    
	    
	    #open dialog to input integer variables
	    tmp_no_feeds, ok=QtGui.QInputDialog.getInteger(widget, 'Input Dialog - Number of Feeds', 'Number of feeds:',8)
	    
	    #this would be the text input dialog
	    #no_feeds, ok=QtGui.QInputDialog.getText(widget, 'Input Dialog - Text example', 'Enter text:',QtGui.QLineEdit.Normal,'default text')

	    
	    #take value if ok was pressed otherwise use default value
	    if ok:
	     no_feeds=tmp_no_feeds
	    else:
	    #default
	     no_feeds=8
	    
	    #you may now use the variable no_feeds
	    self.log('\t\tno_feeds=',no_feeds) 
	     
	    ###########################
	    # end dialog
	    ###########################
An in depth description of the pyqt4 library can be found here:

http://zetcode.com/tutorials/pyqt4/

I used a procedural style to open the dialogs since I find it simpler to integrate into a recipe.

Hope this helps some people having the same problems.

Cheers,

Jens

P.S.: This approach is of course problematic if you would like to automatically schedule your recipes in the middle of the night since it will not run if you do not respond to the dialog boxes ...

Last edited by oecherprinte; 11-06-2010 at 05:00 PM.
oecherprinte is offline   Reply With Quote