View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0006877 | Scribus | Scripter | public | 2008-03-22 01:42 | 2009-03-29 21:01 |
Reporter | gpittman | Assigned To | cbradney | ||
Priority | normal | Severity | minor | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.3.3.12svn | ||||
Target Version | 1.3.3.13 | Fixed in Version | 1.3.3.13svn | ||
Summary | 0006877: trying to clean up and standardize the DocInfo in scripts | ||||
Description | have developed a pattern to use for scripts for author(s), licensing, synopsis, requirements, usage. | ||||
Additional Information | Will gradually try to get all scripts that need this uploaded as they are completed. No changes in script behavior are being made here. | ||||
Tags | No tags attached. | ||||
Patch | |||||
2008-03-22 01:42
|
ExtractText.py (2,449 bytes)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ (C)2006.03.04 Gregory Pittman (C)2008.02.28 Petr Vanek - fileDialog replaces valueDialog this version 2008.02.28 This program is free software; you can redistribute it and/or modify it under the terms of the GPL, v2 (GNU General Public License as published by the Free Software Foundation, version 2 of the License), or any later version. See the Scribus Copyright page in the Help Browser for further informaton about GPL, v2. SYNOPSIS This script takes the current document and extracts all the text from text frames, and also gets the pathnames to all images. This is then saved to a file named by the user. REQUIREMENTS You must run from Scribus and must have a file open. USAGE Start the script. A file dialog appears for the name of the file to save to. The above information is saved to the file. """ # Craig Bradney, Scribus Team # 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826, script is GPLd import scribus def exportText(textfile): page = 1 pagenum = scribus.pageCount() T = [] content = [] while (page <= pagenum): scribus.gotoPage(page) d = scribus.getPageItems() strpage = str(page) T.append('Page '+ strpage + '\n\n') for item in d: if (item[1] == 4): contents = scribus.getAllText(item[0]) if (contents in content): contents = 'Duplication, perhaps linked-to frame' T.append(item[0]+': '+ contents + '\n\n') content.append(contents) elif (item[1] == 2): imgname = scribus.getImageFile(item[0]) T.append(item[0]+': ' + imgname + '\n') page += 1 T.append('\n') output_file = open(textfile,'w') output_file.writelines(T) output_file.close() endmessage = textfile + ' was created' scribus.messageBox("Finished", endmessage,icon=0,button1=1) if scribus.haveDoc(): textfile = scribus.fileDialog('Enter name of file to save to', \ filter='Text Files (*.txt);;All Files (*)') try: if textfile == '': raise Exception exportText(textfile) except Exception, e: print e else: scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \ icon=0, button1=1) |
2008-03-22 01:43
|
UnflipContent.py (1,714 bytes)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ (C) 2007 Jeremy Brown Craig Bradney, Scribus Team 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826. This program is free software; you can redistribute it and/or modify it under the terms of the GPL, v2 (GNU General Public License as published by the Free Software Foundation, version 2 of the License), or any later version. See the Scribus Copyright page in the Help Browser for further informaton about GPL, v2. REQUIREMENTS Must be run from Scribus. You should have a document open with items selected. Script fails with no output if these are not met. SYNOPSIS This script unflips all the items by switching their horizontal and vertical flip flags to False. One might typically use this after you have grouped a number of items on the page, then flipped the group so the positions are a mirror image of the original. Unfortunately this flips the content as well, so this script flips the content back. USAGE Select the items you wish to have their content flipped to their original state. If you also Group them, the script will run more reliably. Run the script. """ from scribus import * if haveDoc(): nbrSelected = selectionCount() objList = [] for i in range(nbrSelected): objList.append(getSelectedObject(i)) for i in range(nbrSelected): try: obj = objList[i] setProperty(obj, "m_ImageIsFlippedH", False) setProperty(obj, "m_ImageIsFlippedV", False) moveObject(1, 0, obj) moveObject(-1, 0, obj) docChanged(1) setRedraw(True) except: nothing = "nothing" |
2008-03-22 02:33
|
DrawGrid.py (5,542 bytes)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ AUTHOR (C) 2006 Rüdiger Härtel <r_haertel [at] gmx [dot] de> Craig Bradney, Scribus Team 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826, script is GPLd This program is free software; you can redistribute it and/or modify it under the terms of the GPL, v2 (GNU General Public License as published by the Free Software Foundation, version 2 of the License), or any later version. See the Scribus Copyright page in the Help Browser for further informaton about GPL, v2. SYNOPSIS This script draws a grid-like structure, specifically in this case a grid formed from individual horizontal and vertical lines. REQUIREMENTS You must run this from Scribus, and have a document open. You must also have tkinter installed on your system. USAGE You are presented with a Tk dialog in which there are default values for X-Pos, Y-Pos of the left upper corner, the overall width and height of the grid, and the x and y spacing (X-step and Y-step). LIMITATIONS Since the same defaults are used regardless of page units, for some units these may be unrealistic. The numbers are defined as integers, so decimals cannot be entered - the script stalls in this case. The grid is made up of individual lines, so be sure to group them to move the grid en bloc. """ import sys try: import scribus except ImportError,err: print 'This Python script is written for the Scribus scripting interface.' print 'It can only be run from within Scribus.' sys.exit(1) try: # I wish PyQt installed everywhere :-/ from Tkinter import * from tkFont import Font except ImportError: print "This script requires Python's Tkinter properly installed." messageBox('Script failed', 'This script requires Python\'s Tkinter properly installed.', ICON_CRITICAL) sys.exit(1) def grid(x,y,width,height,xstep,ystep,color): """ """ xend = x + width yend = y + height for _x in range(x,xend+1,xstep): line = scribus.createLine(_x,y,_x,yend) scribus.setLineColor(color, line) for _y in range(y,yend+1,ystep): line = scribus.createLine(x,_y,xend,_y) scribus.setLineColor(color, line) class TkGrid(Frame): """ GUI interface for Scribus calendar wizard. It's ugly and very simple. I can say I hate Tkinter :-/""" def __init__(self, master=None): """ Setup the dialog """ # reference to the localization dictionary self.key = 'default' Frame.__init__(self, master) self.grid() self.master.title('Scribus Grid Wizard') #define variables self.x = IntVar() self.y = IntVar() self.w = IntVar() self.h = IntVar() self.xs = IntVar() self.ys = IntVar() # default values self.x.set(15) self.y.set(15) self.w.set(100) self.h.set(100) self.xs.set(5) self.ys.set(5) #define widgets self.xLabel = Label(self, text='x-Pos') self.yLabel = Label(self, text='y-Pos') self.wLabel = Label(self, text='Width') self.hLabel = Label(self, text='Height') self.xsLabel = Label(self, text='x-Step') self.ysLabel = Label(self, text='y-Step') self.xEntry = Entry(self, textvariable=self.x, width=4) self.yEntry = Entry(self, textvariable=self.y, width=4) self.wEntry = Entry(self, textvariable=self.w, width=4) self.hEntry = Entry(self, textvariable=self.h, width=4) self.xsEntry = Entry(self, textvariable=self.xs, width=4) self.ysEntry = Entry(self, textvariable=self.ys, width=4) self.okButton = Button(self, text=" OK ", width=6, command=self.okButon_pressed) self.cancelButton = Button(self, text="Cancel", command=self.quit) self.xLabel.grid(column=0,row=0,padx=5,pady=5) self.xEntry.grid(column=1,row=0) self.yLabel.grid(column=0,row=1,padx=5,pady=5) self.yEntry.grid(column=1,row=1) self.wLabel.grid(column=2,row=0,padx=5,pady=5) self.wEntry.grid(column=3,row=0) self.hLabel.grid(column=2,row=1,padx=5,pady=5) self.hEntry.grid(column=3,row=1) self.xsLabel.grid(column=0,row=2,padx=5,pady=5) self.xsEntry.grid(column=1,row=2) self.ysLabel.grid(column=0,row=3,padx=5,pady=5) self.ysEntry.grid(column=1,row=3,padx=5) self.okButton.grid(column=0,columnspan=2,row=4) self.cancelButton.grid(column=2,columnspan=2,row=4,padx=5,pady=5) def okButon_pressed(self): grid(self.x.get(),self.y.get(),self.w.get(),self.h.get(),self.xs.get(),self.ys.get(),"Black") self.quit() def quit(self): self.master.destroy() def main(): """ Application/Dialog loop with Scribus sauce around """ if scribus.haveDoc() == 0: scribus.messageBox("Error", "Please create a Document", ICON_WARNING, BUTTON_OK) return try: scribus.statusMessage('Running script...') scribus.progressReset() root = Tk() app = TkGrid(root) root.mainloop() finally: if scribus.haveDoc(): scribus.redrawAll() scribus.statusMessage('Done.') scribus.progressReset() if __name__ == '__main__': main() |
|
for DrawGrid.py added a new category: LIMITATIONS |
|
Will add DirectImageImport.py This one also needed some fixes for 1.3.3.x -- file dialog did not appear. Also changed "from scribus import *" to "import scribus" |
2008-03-22 14:28
|
DirectImageImport.py (3,028 bytes)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ (C)2006 Konrad Stania (C)2008 Gregory Pittman - fixes for version 1.3.3.x This program is free software; you can redistribute it and/or modify it under the terms of the GPL, v2 (GNU General Public License as published by the Free Software Foundation, version 2 of the License), or any later version. See the Scribus Copyright page in the Help Browser for further informaton about GPL, v2. REQUIREMENTS You must run from Scribus, and have a document open. SYNOPSIS This script will do an automatic import of an image to a frame, with standard settings. Original German: Diese Skript importiert ein Bild und setzt es auf die akutelle Seite. Der Bildrahmen wird dem Bild angepasst und in den nicht-proportionalen Modus gesetzt, das heisst, beliebige Verzerrungen sind moeglich. Um das Bild proportional zu vergroessern, die STRG-Taste beim Bearbeiten druecken. USAGE Start script. A file dialog appears for selecting your image. Save to select -- if no file is selected or you click Cancel, a frame is created with no image. LIMITATIONS Some adjustments may be made in the height of your frame in order to make X- and Y-scaling the same - width will remain 80% of page size. This is because Scripter does not have a command for Adjust Frame to Image. Note that Scale Image to Frame is set, but Proportional is not, in case you decide to resize the frame. """ # Craig Bradney, Scribus Team # 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826, script is GPLd import sys try: import scribus except ImportError: print "This script only runs from within Scribus." sys.exit(1) def main(): #setRedraw(False) pageX,pageY = scribus.getPageSize() ImageFileName = scribus.fileDialog("Image Import", 'Images(*.jpg *.png *.tif *.pdf *.JPG *.PNG *.TIF *.PDF *.jpeg *.JPEG)',"" ,haspreview=1, issave = 0) Breite = pageX*0.8 Hoehe = Breite if pageX >= pageY: Breite = pageY*0.8 Hoehe = Breite ImageFrame = scribus.createImage(pageX/2 - Breite/2, pageY/2 - Hoehe/2, Breite, Hoehe) scribus.loadImage(ImageFileName, ImageFrame) scribus.setScaleImageToFrame(True, False,ImageFrame) scribus.setFillColor("None", ImageFrame) scribus.setLineColor("None", ImageFrame) scaleX,scaleY = scribus.getImageScale(ImageFrame) if scaleX > scaleY: Breite = Breite * scaleY / scaleX scribus.sizeObject(Breite, Hoehe, ImageFrame) scribus.setScaleImageToFrame(True, False,ImageFrame) if scaleX < scaleY: Hoehe = Hoehe * scaleX / scaleY scribus.setScaleImageToFrame(True, False,ImageFrame) scribus.sizeObject(Breite, Hoehe, ImageFrame) #setRedraw(True) if __name__ == '__main__': if scribus.haveDoc(): main() else: scribus.messageBox("Image Import", "You need to have a document open <i>before</i> you can run this script succesfully.", scribus.ICON_INFORMATION) |
|
Someone please delete InfoBox.py so I can change to the file dialog to select more image types. Also, would it be useful to adopt Konrad Stania's work around for Adjust Frame to Image using image scaling? I think that's pretty clever. |
|
Ok, I've modified the script to automatically adjust infobox height for images. Waiting for InfoBox.py to be deleted so I can upload the new version. |
2008-03-22 23:08
|
InfoBox.py (8,499 bytes)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ (C) 2005 by Thomas R. Koll, <tomk32@gmx.de>, http://verlag.tomk32.de Craig Bradney, Scribus Team 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826 (c) 2008 modifications, additional features by Gregory Pittman Craig Bradney, Scribus Team 20/3/08: Replaced previous version in Scribus 1.3.3.12svn distribution from Scribus wiki for bug #6869 This program is free software; you can redistribute it and/or modify it under the terms of the GPL, v2 (GNU General Public License as published by the Free Software Foundation, version 2 of the License), or any later version. See the Scribus Copyright page in the Help Browser for further informaton about GPL, v2. SYNOPSIS A simple script for exact placement and sizing of a frame (infobox) over the current textbox, asking the user for the width of the infobox (number of columns) and in which column to place it. Some enhancements (2008): * You can now create a text frame or an image frame, and also load an image. * More than one infobox can be added to a text frame (related to change in the naming scheme). * Height and Y-Pos of top of infobox can be specified. * Works with any page unit - pts, mm, in, picas, cm, or ciceros. * Infobox has Text Flows Around Frame activated, also Scale Image to Frame for images. * In addition, the script also has a workaround for Adjust Frame to Image, so that a loaded image will adjust frame height automatically. REQUIREMENTS Must be used in Scribus and must have document open with text frame selected. Frame can have one or more columns, and is not required to have content. USAGE Select a textframe, start the script. Default name for the infobox is "'infobox' + index + name_of_selected_frame", but this can be changed. Select height (defaults to height of selected frame), then Y-Pos distance from top of page (defaults to top of selected frame). In the dialog titled "Frame Type" * Enter 'text' (no quotes) for a text infobox - this is the default. * Enter 'imageL' for an image infobox AND to bring up a file dialog to load an image. * Enter anything else, even blank, for empty image infobox. Since a unique name is generated for each infobox, you can run this again for the same selected frame. """ try: 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." sys.exit(1) def main(argv): unit = scribus.getUnit() units = [' pts','mm',' inches',' picas','cm',' ciceros'] unitlabel = units[unit] 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) sys.exit(2) 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) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() boxcount = 1 for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # While we're finding out what kind of frame is selected, we'll also make sure we # will come up with a unique name for our infobox frame - it's possible we may want # more than one for a multicolumn frame. if (item[0] == ("infobox" + str(boxcount) + textbox)): boxcount += 1 left, top = scribus.getPosition(textbox) o_width, o_height = scribus.getSize(textbox) o_cols = int(scribus.getColumns(textbox)) o_gap = scribus.getColumnGap(textbox) 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 = scribus.valueDialog('Width', 'How many columns width shall the '+ 'box be (max ' + str(o_cols) + ')?','1') columns_width = int(columns_width) if (columns_width < o_cols): max = o_cols - columns_width while (column_pos > max or column_pos < 0): column_pos = scribus.valueDialog('Placement', 'In which column do you want ' 'to place the box (1 to ' + str(o_cols) + ')?','1') column_pos = int(column_pos) - 1 if (o_cols == 1): columns_width = 1 column_pos = 0 new_height = 0 while (new_height == 0): new_height = scribus.valueDialog('Height','Your frame height is '+ str(o_height) + unitlabel +'. How tall\n do you want your ' + 'infobox to be in '+ unitlabel + '?\nIf you are going to load an image,\nno need to change this setting', str(o_height)) new_height_float = float(new_height) new_top = -1 while (new_top < 0): new_top = scribus.valueDialog('Y-Pos','The top of your infobox is currently\n'+ str(top) + unitlabel +'. Where do you want \n' + 'the top to be in '+ unitlabel +'?', str(top)) framename = scribus.valueDialog('Name of Frame','Name your frame or use this default name',"infobox" + str(boxcount) + textbox) frametype = 'text' frametype = scribus.valueDialog('Frame Type', 'Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image', frametype) new_width = columns_width * o_colwidth + (columns_width-1) * o_gap new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap) if (frametype == 'text'): new_textbox = scribus.createText(new_left, float(new_top), new_width, new_height_float, framename) scribus.setColumnGap(0, new_textbox) scribus.setColumns(1, new_textbox) scribus.textFlowsAroundFrame(new_textbox, 1) else: new_image = scribus.createImage(new_left, float(new_top), new_width, new_height_float, framename) if (frametype == 'imageL'): imageload = scribus.fileDialog('Load image','Images(*.jpg *.png *.tif *.pdf *.JPG *.PNG *.TIF *.PDF *.jpeg *.JPEG)',haspreview=1) scribus.loadImage(imageload, new_image) scribus.textFlowsAroundFrame(new_image, 1) scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=new_image) scaleX,scaleY = scribus.getImageScale(new_image) # this was borrowed from DirectImageImport.py as a workaround for Adjust Frame to Image, # modified to maintain the width as determined by column specs if (scaleX > scaleY): new_height_float = new_height_float * scaleX / scaleY scribus.sizeObject(new_width, new_height_float, new_image) scribus.setScaleImageToFrame(True, False, new_image) if (scaleX < scaleY): new_height_float = new_height_float * scaleX / scaleY scribus.setScaleImageToFrame(True, False, new_image) scribus.sizeObject(new_width, new_height_float, new_image) if __name__ == '__main__': # This script makes no sense without a document open if not scribus.haveDoc(): scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(1) # Disable redraws scribus.setRedraw(False) # Run the main script, ensuring redraws are re-enabled even if the # script aborts with an exception, and don't fail with an exception # even if the document is closed while the script runs. try: main(sys.argv) finally: try: scribus.setRedraw(True) except: pass |
|
New InfoBox.py uploaded |
|
[00:07] <MrB> FeistyDragoon, can u please check 0006877 and the included scripts in 1.3.3.x svn? the bug has been resolved however I dont believe the files were ever updated from the bug into svn [00:07] <FeistyDragoon> k [00:07] <MrB> FeistyDragoon, and if u have 1.3.5svn compatible versions, add those too? |
|
Yes, you are right, MrB. Either these weren't updated or were reverted. The exception is InfoBox.py, which is the correct one in both 1.3.3.xsvn and 1.3.5svn. I think we may have decided to delete DrawGrid.py, since it was not felt to be such an especially useful script. I will have to check to see if the others work in 1.3.5svn. |
|
ExtractText.py seems to work Ok in 1.3.5svn. UnFlipContent.py does not work in 1.3.5svn -- will see if I can figure out why. |
|
DirectImageImport.py does indeed work in 1.3.5.py, and curiously when the image is imported, Proportional is set, while it isn't in 1.3.3.xsvn (maybe different default behavior). This having been said, the script is a bit clumsy in the way it adjusts the size of the frame to the image. It would be better, I think, to use the PIL method I used in InfoBox.py. This way, you can center every picture. Right now, they don't get centered when the picture is taller than it is wide. Will work on this. |
|
I have reworked DirectImageImport.py (DirectImageImport_mod.py). 1. Use PIL to get image size 2. Fix a problem with frames when image taller than wide 3. Got rid of readjustment of frame size - no longer needed 4. Made Doc Info more informative This also works in 1.3.5svn |
2009-03-28 14:29
|
|
|
I cannot seem to get UnFlipContent.py to work in 1.3.5svn. I think the problem is with setProperty, which seems to be nonfunctional in 1.3.5svn. |
|
Summary: 1. Except for InfoBox.py, the above scripts have not been added to current svn of 1.3.3.x and 1.3.5 2. DrawGrid.py is not felt to be needed in either version 3. ExtractText.py needs to be replaced by above version in both versions 3. DirectImageImport.py should be replaced by DirectImageImport_mod.py in both versions 4. UnFlipContent.py does not work in 1.3.5svn, so should not be included in that version at this time, but can replace it in 1.3.3.x |
Date Modified | Username | Field | Change |
---|---|---|---|
2008-03-22 01:42 | gpittman | New Issue | |
2008-03-22 01:42 | gpittman | File Added: ExtractText.py | |
2008-03-22 01:43 | gpittman | File Added: InfoBox.py | |
2008-03-22 01:43 | gpittman | File Added: UnflipContent.py | |
2008-03-22 01:45 | christoph_s | Status | new => assigned |
2008-03-22 01:45 | christoph_s | Assigned To | => plinnell |
2008-03-22 02:33 | gpittman | File Added: DrawGrid.py | |
2008-03-22 02:34 | gpittman | Note Added: 0019258 | |
2008-03-22 14:27 | gpittman | Note Added: 0019260 | |
2008-03-22 14:28 | gpittman | File Added: DirectImageImport.py | |
2008-03-22 14:38 | gpittman | Note Added: 0019261 | |
2008-03-22 19:10 | gpittman | Note Added: 0019265 | |
2008-03-22 20:23 |
|
File Deleted: InfoBox.py | |
2008-03-22 23:08 | gpittman | File Added: InfoBox.py | |
2008-03-22 23:09 | gpittman | Note Added: 0019269 | |
2009-01-01 21:58 |
|
Status | assigned => resolved |
2009-01-01 21:58 |
|
Fixed in Version | => 1.3.3.13svn |
2009-01-01 21:58 |
|
Resolution | open => fixed |
2009-02-22 23:08 | cbradney | Assigned To | plinnell => |
2009-02-22 23:08 | cbradney | Note Added: 0021197 | |
2009-02-22 23:08 | cbradney | Status | resolved => feedback |
2009-02-22 23:08 | cbradney | Resolution | fixed => reopened |
2009-02-23 00:08 | gpittman | Note Added: 0021199 | |
2009-02-23 00:26 | gpittman | Note Added: 0021201 | |
2009-02-23 00:50 | gpittman | Note Added: 0021202 | |
2009-03-15 01:36 | christoph_s | Target Version | => 1.3.3.13 |
2009-03-28 14:29 | gpittman | Note Added: 0021432 | |
2009-03-28 14:29 | gpittman | File Added: DirectImageImport_mod.py | |
2009-03-28 15:45 | gpittman | Note Added: 0021433 | |
2009-03-28 15:55 | gpittman | Note Added: 0021434 | |
2009-03-29 20:22 | cbradney | Status | feedback => assigned |
2009-03-29 20:22 | cbradney | Assigned To | => cbradney |
2009-03-29 20:59 | cbradney | Status | assigned => resolved |
2009-03-29 20:59 | cbradney | Resolution | reopened => fixed |
2009-03-29 21:01 | cbradney | Status | resolved => closed |