Infobox in column: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 22: Line 22:


"""
"""
(C) 2005 by Thomas R. Koll, <tomk32@tomk32.de>, http://verlag.tomk32.de
(C) 2005 by Thomas R. Koll, <tomk32@gmx.de>, http://verlag.tomk32.de


A simple script for exact placment of a textbox (infobox)
A simple script for exact placment of a textbox (infobox)
over the current textbox, asking the user for the width
over the current textbox, asking the user for the width
of the infobox and in which column to place it.
of the infobox and in which column to place it.
I normally use it for a table-like box above the regular text.


USAGE
USAGE
Line 52: Line 53:
         o_width, o_height = getSize(textbox)
         o_width, o_height = getSize(textbox)
         o_cols = int(getColumns(textbox))
         o_cols = int(getColumns(textbox))
        o_gap = getColumnGap(textbox)
     except:
     except:
MessageBox(TITLE, "Can't get size of object, maybe not a textframe", ICON_WARNING, BUTTON_OK)
        messageBox('Error', "Can't get size of object, maybe not a textframe", ICON_WARNING, BUTTON_OK)
return
 
     columns_width = 0
     columns_width = 0
     column_pos = 1
     column_pos = 1
     o_colwidth = (o_width - ((o_cols - 1) * getColumnGap(textbox))) / o_cols
     o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
     if (o_cols > 1):
     if (o_cols > 1):
         while (columns_width > o_cols or columns_width < 1):
         while (columns_width > o_cols or columns_width < 1):
Line 73: Line 73:
                                         str(o_cols) + ')?')
                                         str(o_cols) + ')?')
             column_pos = int(column_pos) - 1  
             column_pos = int(column_pos) - 1  
     new_width = columns_width * o_colwidth + (columns_width-1) * getColumnGap(textbox)
     new_width = columns_width * o_colwidth + (columns_width-1) * o_gap
     new_left = left + column_pos * (columns_width * o_colwidth
     new_left = left + column_pos * (columns_width * o_colwidth
                                     + ((column_pos - 1) * getColumnGap(textbox)))
                                     + ((column_pos - 1) * o_gap))
     new_textbox = createText(new_left, top, new_width, o_height,
     new_textbox = createText(new_left, top, new_width, o_height,
                             "infobox " + textbox)
                             "infobox " + textbox)
Line 84: Line 84:


else:
else:
MessageBox(TITLE, "No document open", ICON_WARNING, BUTTON_OK)
messageBox('Error', "No document open", ICON_WARNING, BUTTON_OK)
</nowiki></pre>
</nowiki></pre>

Revision as of 08:09, 31 March 2005

This article is part of the Scripts series.
# -*- coding: utf-8  -*-

# ****************************************************************************
#  This program is free software; you can redistribute it and/or modify 
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 
# ****************************************************************************


"""
(C) 2005 by Thomas R. Koll, <tomk32@gmx.de>, http://verlag.tomk32.de

A simple script for exact placment of a textbox (infobox)
over the current textbox, asking the user for the width
of the infobox and in which column to place it.
I normally use it for a table-like box above the regular text.

USAGE
Select a textframe, start the script and have phun
Default name for the infobox is 'infobox' + name_of_selected_frame

TODO
* ask for height
* ask for name
* ask for content?

"""

from scribus import *
import re, string

if haveDoc():    
    
    unit = getUnit()
    setUnit(UNIT_MILLIMETERS)
    
    try:
        textbox = getSelectedObject()
        left, top = getPosition(textbox)
        o_width, o_height = getSize(textbox)
        o_cols = int(getColumns(textbox))
        o_gap = getColumnGap(textbox)
    except:
        messageBox('Error', "Can't get size of object, maybe not a textframe", ICON_WARNING, BUTTON_OK)
    columns_width = 0
    column_pos = 1
    o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
    if (o_cols > 1):
        while (columns_width > o_cols or columns_width < 1):
            columns_width = valueDialog('Width',
                                            'How many columns width shall the '+
                                            'box be (max ' + str(o_cols) + ')?')
            columns_width = int(columns_width)
        if (columns_width < o_cols):
            max = o_cols - columns_width
            while (column_pos <= max and column_pos <= 1):
                column_pos = valueDialog('Placement',
                                         'In which column do you want '
                                         'to place the box (1 to ' +
                                         str(o_cols) + ')?')
            column_pos = int(column_pos) - 1 
    new_width = columns_width * o_colwidth + (columns_width-1) * o_gap
    new_left = left + column_pos * (columns_width * o_colwidth
                                    + ((column_pos - 1) * o_gap))
    new_textbox = createText(new_left, top, new_width, o_height,
                             "infobox " + textbox)
        
    setColumnGap(5, new_textbox)
    setColumns(1, new_textbox)
    setUnit(unit)

else:
	messageBox('Error', "No document open", ICON_WARNING, BUTTON_OK)