Date Setting by Script

From Scribus Wiki
Revision as of 02:07, 21 September 2012 by Gpittman (talk | contribs)
Jump to navigation Jump to search

A small chore I have been having is to daily create a page which has a header including the date. This kind of thing might come up with someone making a newsletter or other periodical.

Here is something like I wanted my header to look:


To the left is a static title, then the date is displayed with a particular format, and there is a right tab to place the date properly in the frame. Top and Left distances bring the line of text in the middle of the frame. I thought it would be nice to just run a short script to update the date each time I made another, and such commands are avaiable in a standard Python distribution.

The script

#!/usr/bin/env python
# -*- coding: utf-8  -*-

     import scribus
except ImportError:
     print "Unable to import the 'scribus' module. This script will only run within"
     print "the Python interpreter embedded in Scribus. Try Script->Execute Script."

from datetime import date

if not scribus.haveDoc():
     scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)

if scribus.selectionCount() == 0:
     scribus.messageBox('Scribus - Script Error',
             "There is no object selected.\nPlease select a text frame and try again.",
             scribus.ICON_WARNING, scribus.BUTTON_OK)
if scribus.selectionCount() > 1:
     scribus.messageBox('Scribus - Script Error',
             "You have more than one object selected.\nPlease select one text frame and try again.",
             scribus.ICON_WARNING, scribus.BUTTON_OK)
textbox = scribus.getSelectedObject()
ftype = scribus.getObjectType(textbox)

if (ftype != "TextFrame"):
     scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)


today =
d = today.strftime("%A, %B %d, %Y")
headerstr = "Scribus Times & Gazette\t" + d
scribus.setText(headerstr, textbox)
scribus.setStyle("header", textbox)