[scribus] Python selector dialog in Scribus

Gregory Pittman gpittman at iglou.com
Tue Dec 30 03:19:16 CET 2008


Roger wrote:
> I have need to use a dialog/spin box  which provides a range of 5 
> selections for inserting certain text into a text box on a Scribus 
> page based on choice made from the dialog.
> I have been through all the python scripts but haven't found an example.
> Can someone help please
There are various ways of doing this.
Example: This is a complete 7-line program you can run in Scribus.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import scribus
colortext = ['The flower is red','The table is blue','The auto is 
yellow','The tree is green', 'The shirt is magenta']
choice = scribus.valueDialog('Enter your choice by number','0 = The 
flower is red\n1 = The table is blue\n2 = The auto is yellow\n3 = The 
tree is green\n4 = The shirt is magenta','0')
selectedtext = colortext[int(choice)] # Note the need to convert to an 
integer since even a number in a valueDialog is returned as a string
result = scribus.messageBox('Here it is!',selectedtext)

Obviously, you could have done something more important with 
selectedtext than just display it. Also, in your own usage, you may not 
need to show the entire string in the dialog, perhaps just showing the 
colors would have been enough. You also might want to add some assurance 
that the entered value is an appropriate one.

>
>
> Also        
> valueDialog('Select', 'message is', 'optional')
> doesn't work, is there something more that I'm missing
 From the Scripter API:

valueDialog(caption, message [,defaultvalue]) -> string


so what you want is something like

selectedvalue = scribus.valueDialog('Title in Frame', 'Message', 
'Default value if you wish')


so then the variable selectedvalue contains the string entered in the 
dialog.


Note in the above 7-line program how you can use a small python script 
like this to test dialogs when they don't seem to be working.

Greg





More information about the scribus mailing list