Importação automática de imagens através de script: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 12: | Line 12: | ||
As implementações Python tem a vantagem de usar o próprio Scribus para criar um documento, sendo assim, enquanto o script funcionar o arquivo resultante estará atualizado. Outro benefício é a facilidade de modificação do script para ser ajustado a outras necessidades. | As implementações Python tem a vantagem de usar o próprio Scribus para criar um documento, sendo assim, enquanto o script funcionar o arquivo resultante estará atualizado. Outro benefício é a facilidade de modificação do script para ser ajustado a outras necessidades. | ||
= Descrição = | |||
= scribalbum.pl = | == scribalbum.pl == | ||
Eu não irei dizer nada sobre este programa. Se você conhece alguma coisa de Perl, verá que isto não é "elegante", mas faz o trabalho. Sua operação é através da linha de comando. | Eu não irei dizer nada sobre este programa. Se você conhece alguma coisa de Perl, verá que isto não é "elegante", mas faz o trabalho. Sua operação é através da linha de comando. | ||
= scribalbum.py e scribalbuma4.py = | == scribalbum.py e scribalbuma4.py == | ||
Estes scripts são similares, ambos criam um novo documento e quantas páginas forem necessárias. O '''scribalbum.py''' coloca quatro imagens desalinhadas uma das outras em uma página de tamanho carta (americana), permitindo anotações nos espaços remanescentes. Já o '''scribalbum4.py''' coloca 8 imagens por página A4, deixando pouco espaço livre restante. Ambas as versões farão um quadro de texto no canto superior esquerdo de cada página, indicando qual o diretório que a imagem está. | Estes scripts são similares, ambos criam um novo documento e quantas páginas forem necessárias. O '''scribalbum.py''' coloca quatro imagens desalinhadas uma das outras em uma página de tamanho carta (americana), permitindo anotações nos espaços remanescentes. Já o '''scribalbum4.py''' coloca 8 imagens por página A4, deixando pouco espaço livre restante. Ambas as versões farão um quadro de texto no canto superior esquerdo de cada página, indicando qual o diretório que a imagem está. | ||
Line 42: | Line 42: | ||
* Se nesse ponto o Scribus quebrar/travar, provavelmente toda a memória RAM e swap foi usada no seu sistema. Ainda não há uma proteção incluida neste script contra essa possibilidade. Se você tiver sorte, o Scribus terá salvo um arquivo de emergência começando com '''DocumentN...''', mas, se o arquivo for grande demais, o Scribus não conseguirá o carregar, já que a memória continuará criando essa restição (o arquivo por sí só não é grande, o requerimento de memória para todas as imagens que é a fonte do problema). | * Se nesse ponto o Scribus quebrar/travar, provavelmente toda a memória RAM e swap foi usada no seu sistema. Ainda não há uma proteção incluida neste script contra essa possibilidade. Se você tiver sorte, o Scribus terá salvo um arquivo de emergência começando com '''DocumentN...''', mas, se o arquivo for grande demais, o Scribus não conseguirá o carregar, já que a memória continuará criando essa restição (o arquivo por sí só não é grande, o requerimento de memória para todas as imagens que é a fonte do problema). | ||
= Arquivos = | |||
== scribalbum.pl == | |||
<pre><nowiki> | |||
#!/usr/bin/perl -w | |||
###################################### | |||
# # | |||
# Program scribalbum.pl # | |||
# Created 2004.09.12 # | |||
# Last modified 2004.09.14 # | |||
# Gregory Pittman # | |||
# # | |||
###################################### | |||
print "This program will create a picture album as a Scribus .sla file from all the pictures in a directory.\n"; | |||
print "Enter the name of the directory:\t"; | |||
chomp ($folder =<STDIN>); | |||
opendir (DIR, $folder) || die "Do you have the drive mounted?"; | |||
# First we'll eliminate anything starting with a period | |||
@files = grep { !/^\./} readdir(DIR); | |||
# Then sift out the image files; Scribus can show at least some PDFs | |||
# Not having so much luck with SVGs, but at least you'll know they are there | |||
@files = grep { ( /\Z jpeg|jpg|tif|pdf|png|gif|svg/i ) } @files ; | |||
closedir (DIR); | |||
$numfiles = scalar(@files); | |||
$anzpages = int $numfiles/4; | |||
if ($numfiles/4 gt ($anzpages)){ | |||
++$anzpages; | |||
} | |||
print "There are $numfiles pictures in this directory.\nThis will make $anzpages pages.\n"; | |||
print "What do you want to name this album? (\".sla\" will be appended)\t"; | |||
chomp ($album =<STDIN>); | |||
$album = "$album.sla"; | |||
$utf = "<SCRIBUSUTF8 Version=\"1.2cvs\" >"; | |||
# The only variable in $document is $anzpages | |||
$document = " <DOCUMENT MAJGRID=\"100\" ABSTSPALTEN=\"11\" PAGEWITH=\"612\" AUTOCHECK=\"0\" LANGUAGE=\"English\" DPIn2=\"\" DPgam=\"0\" HCMS=\"1\" DGAP=\"0\" ORIENTATION=\"0\" MINWORDLEN=\"3\" VTIEFSC=\"100\" DOCLANGINFO=\"\" COMMENTS=\"\" TITLE=\"\" KEYWORDS=\"\" DSIZE=\"12\" AUTOSPALTEN=\"1\" GROUPC=\"7\" DOCFORMAT=\"\" DOCDATE=\"\" BORDERTOP=\"9\" GUIDELOCK=\"0\" DIMo=\"1\" DIPr=\"0\" DPuse=\"0\" DPSo=\"0\" DOCSOURCE=\"\" FIRSTNUM=\"1\" DPbla=\"1\" VHOCHSC=\"100\" DOCTYPE=\"\" BORDERBOTTOM=\"40\" BASEGRID=\"12\" VTIEF=\"33\" DOCCONTRIB=\"\" DOCRELATION=\"\" BASEO=\"0\" DOCIDENT=\"\" PUBLISHER=\"\" ANZPAGES=\"$anzpages\" HYCOUNT=\"2\" DIMo2=\"1\" AUTHOR=\"\" UNITS=\"0\" BORDERRIGHT=\"9\" DPPr=\"\" DPMo=\"\" PAGEHEIGHT=\"792\" MINGRID=\"20\" VHOCH=\"33\" DOCCOVER=\"\" DCOL=\"1\" AUTOMATIC=\"1\" ALAYER=\"0\" DOCRIGHTS=\"\" DPIn=\"\" VKAPIT=\"75\" DFONT=\"Bitstream Vera Sans Mono Roman\" BORDERLEFT=\"9\" >"; | |||
$colorlayer = " <COLOR RGB=\"\#000000\" CMYK=\"\#000000ff\" NAME=\"Black\" />\n <COLOR RGB=\"\#ffffff\" CMYK=\"\#00000000\" NAME=\"White\" />\n <LAYERS DRUCKEN=\"1\" NUMMER=\"0\" NAME=\"Background\" SICHTBAR=\"1\" LEVEL=\"0\" />"; | |||
$pdf = " <PDF ImagePr=\"0\" BTop=\"9\" UseProfiles=\"0\" BLeft=\"9\" PrintP=\"\" RecalcPic=\"0\" ImageP=\"\" SolidP=\"\" PicRes=\"300\" Thumbnails=\"0\" CMethod=\"0\" Encrypt=\"0\" BRight=\"9\" Binding=\"0\" Articles=\"0\" InfoString=\"\" RGBMode=\"1\" PresentMode=\"0\" Permissions=\"-4\" Intent=\"1\" Compress=\"1\" Version=\"14\" Resolution=\"300\" Bookmarks=\"0\" UseProfiles2=\"0\" Quality=\"0\" UseLpi=\"0\" PassUser=\"\" BBottom=\"40\" Intent2=\"1\" PassOwner=\"\" >\n <LPI Angle=\"45\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Black\" />\n <LPI Angle=\"105\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Cyan\" />\n <LPI Angle=\"75\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Magenta\" />\n <LPI Angle=\"90\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Yellow\" />\n </PDF>"; | |||
# This goes at the end when we're done | |||
$docend = " <PAGE NUM=\"0\" NAM=\"Normal\" LEFT=\"0\" NumVGuides=\"0\" HorizontalGuides=\"\" MNAM=\"\" NumHGuides=\"0\" VerticalGuides=\"\" />\n </DOCUMENT>\n</SCRIBUSUTF8>\n"; | |||
open (FILE, ">$album"); | |||
print FILE "$utf\n$document\n$colorlayer\n$pdf\n"; | |||
# Now let's build some pages | |||
$pagecount = 0; | |||
$image = 0; | |||
$piccount = 0; # will use this to place each picture on the page | |||
@xpos = qw( 16 310 16 310 ); # $xpos[$piccount] will give this value | |||
@ypos = qw( 14 187 360 533 );# ditto for $ypos | |||
@xpostxt = qw( 16 450 16 450 ); # $xpostxt[$piccount] label for image | |||
@ypostxt = qw( 232 165 578 510 );# ditto for $ypostxt | |||
@cab = qw( 0 2 0 2 );# alternates left and right justification for image labels | |||
foreach $file (@files) { | |||
if ($piccount gt 3) { | |||
$piccount = 0; | |||
print FILE "</PAGE>\n"; | |||
++$pagecount; | |||
} | |||
if ($piccount == 0) { | |||
print FILE " <PAGE NUM=\"$pagecount\" NAM=\"\" LEFT=\"0\" NumVGuides=\"0\" HorizontalGuides=\"\" MNAM=\"Normal\" NumHGuides=\"0\" VerticalGuides=\"\" >\n"; | |||
# This will print the directory name in the upper right hand corner of the page | |||
print FILE " <PAGEOBJECT BottomLine=\"0\" REXTRA=\"1\" ALIGN=\"2\" LANGUAGE=\"English\" NUMPO=\"16\" PLINEART=\"1\" TXTSCALE=\"100\" RightLine=\"0\" LOCALSCX=\"1\" LINESP=\"12\" ROT=\"0\" TXTSTROKE=\"Black\" WIDTH=\"195\" BACKPAGE=\"-1\" GROUPS=\"\" LOCKR=\"0\" IFONT=\"Luxi Sans Regular\" LOCALSCY=\"1\" NAMEDLST=\"\" AUTOTEXT=\"0\" FLIPPEDV=\"0\" EXTRAV=\"0\" PCOLOR=\"None\" RADRECT=\"0\" REVERS=\"0\" PRINTABLE=\"1\" RATIO=\"1\" FLIPPEDH=\"0\" COLGAP=\"0\" PCOLOR2=\"None\" NEXTITEM=\"-1\" NUMGROUP=\"0\" TransValue=\"0\" INVERS=\"0\" PLINEEND=\"0\" FRTYPE=\"0\" PTYPE=\"4\" isTableItem=\"0\" TEXTFLOW2=\"0\" SHADE2=\"100\" PWIDTH=\"1\" HEIGHT=\"25\" DASHOFF=\"0\" PFILE2=\"\" PFILE=\"\" TEXTFLOW3=\"0\" ISIZE=\"10\" PLTSHOW=\"0\" TXTSTYLE=\"0\" CLIPEDIT=\"0\" BACKITEM=\"-1\" BookNr=\"0\" TransValueS=\"0\" EMBEDDED=\"1\" PFILE3=\"\" ANNAME=\"\" SHADE=\"100\" COCOOR=\"0 0 0 0 195 0 195 0 195 0 195 0 195 25 195 25 195 25 195 25 0 25 0 25 0 25 0 25 0 0 0 0 \" BASEOF=\"0\" PICART=\"1\" COLUMNS=\"1\" LAYER=\"0\" BOOKMARK=\"0\" TopLine=\"0\" LOCK=\"0\" EPROF=\"\" BBOXX=\"0\" DASHS=\"\" IRENDER=\"0\" TEXTFLOW=\"0\" BBOXH=\"0\" TXTFILLSH=\"100\" YPOS=\"11\" ANNOTATION=\"0\" LOCALX=\"0\" GRTYP=\"0\" XPOS=\"400\" NUMCO=\"16\" POCOOR=\"0 0 0 0 195 0 195 0 195 0 195 0 195 25 195 25 195 25 195 25 0 25 0 25 0 25 0 25 0 0 0 0 \" EXTRA=\"1\" LOCALY=\"0\" NEXTPAGE=\"-1\" TABS=\"\" NUMTAB=\"0\" NUMDASH=\"0\" LeftLine=\"0\" PRFILE=\"\" TEXTRA=\"1\" SCALETYPE=\"1\" TXTFILL=\"Black\" BEXTRA=\"1\" PLINEJOIN=\"0\" TXTSTRSH=\"100\" >\n <ITEXT CAB=\"2\" CCOLOR=\"Black\" CSIZE=\"10\" CH=\"$folder/\" CSHADE2=\"100\" CSCALE=\"100\" CSHADE=\"100\" CSTYLE=\"0\" CFONT=\"Luxi Sans Regular\" CEXTRA=\"0\" CSTROKE=\"Black\" />\n </PAGEOBJECT>"; | |||
} | |||
# The individual image files | |||
print FILE " <PAGEOBJECT BottomLine=\"0\" REXTRA=\"1\" ALIGN=\"0\" LANGUAGE=\"English\" NUMPO=\"16\" PLINEART=\"1\" TXTSCALE=\"100\" RightLine=\"0\" LOCALSCX=\"0.18\" LINESP=\"14.4\" ROT=\"0\" TXTSTROKE=\"Black\" WIDTH=\"288\" BACKPAGE=\"-1\" GROUPS=\"\" LOCKR=\"0\" IFONT=\"Bitstream Vera Sans Mono Roman\" LOCALSCY=\"0.18\" NAMEDLST=\"\" AUTOTEXT=\"0\" FLIPPEDV=\"0\" EXTRAV=\"0\" PCOLOR=\"White\" RADRECT=\"0\" REVERS=\"0\" PRINTABLE=\"1\" RATIO=\"1\" FLIPPEDH=\"0\" COLGAP=\"0\" PCOLOR2=\"None\" NEXTITEM=\"-1\" NUMGROUP=\"0\" TransValue=\"0\" INVERS=\"0\" PLINEEND=\"0\" FRTYPE=\"0\" PTYPE=\"2\" isTableItem=\"0\" TEXTFLOW2=\"0\" SHADE2=\"100\" PWIDTH=\"1\" HEIGHT=\"217\" DASHOFF=\"0\" PFILE2=\"\" PFILE=\"$folder/$file\" TEXTFLOW3=\"0\" ISIZE=\"12\" PLTSHOW=\"0\" TXTSTYLE=\"0\" CLIPEDIT=\"0\" BACKITEM=\"-1\" BookNr=\"0\" TransValueS=\"0\" EMBEDDED=\"1\" PFILE3=\"\" ANNAME=\"Image$image\" SHADE=\"100\" COCOOR=\"0 0 0 0 288 0 288 0 288 0 288 0 288 217 288 217 288 217 288 217 0 217 0 217 0 217 0 217 0 0 0 0 \" BASEOF=\"0\" PICART=\"1\" COLUMNS=\"1\" LAYER=\"0\" BOOKMARK=\"0\" TopLine=\"0\" LOCK=\"0\" EPROF=\"\" BBOXX=\"0\" DASHS=\"\" IRENDER=\"1\" TEXTFLOW=\"0\" BBOXH=\"1200\" TXTFILLSH=\"100\" YPOS=\"$ypos[$piccount]\" ANNOTATION=\"0\" LOCALX=\"0\" GRTYP=\"0\" XPOS=\"$xpos[$piccount]\" NUMCO=\"16\" POCOOR=\"0 0 0 0 288 0 288 0 288 0 288 0 288 217 288 217 288 217 288 217 0 217 0 217 0 217 0 217 0 0 0 0 \" EXTRA=\"1\" LOCALY=\"0\" NEXTPAGE=\"-1\" TABS=\"\" NUMTAB=\"0\" NUMDASH=\"0\" LeftLine=\"0\" PRFILE=\"\" TEXTRA=\"1\" SCALETYPE=\"0\" TXTFILL=\"Black\" BEXTRA=\"1\" PLINEJOIN=\"0\" TXTSTRSH=\"100\" />\n"; | |||
# The image file name in a text frame | |||
print FILE " <PAGEOBJECT BottomLine=\"0\" REXTRA=\"1\" ALIGN=\"0\" LANGUAGE=\"English\" NUMPO=\"16\" PLINEART=\"1\" TXTSCALE=\"100\" RightLine=\"0\" LOCALSCX=\"1\" LINESP=\"12\" ROT=\"0\" TXTSTROKE=\"Black\" WIDTH=\"148\" BACKPAGE=\"-1\" GROUPS=\"\" LOCKR=\"0\" IFONT=\"Luxi Sans Regular\" LOCALSCY=\"1\" NAMEDLST=\"\" AUTOTEXT=\"0\" FLIPPEDV=\"0\" EXTRAV=\"0\" PCOLOR=\"None\" RADRECT=\"0\" REVERS=\"0\" PRINTABLE=\"1\" RATIO=\"1\" FLIPPEDH=\"0\" COLGAP=\"0\" PCOLOR2=\"None\" NEXTITEM=\"-1\" NUMGROUP=\"0\" TransValue=\"0\" INVERS=\"0\" PLINEEND=\"0\" FRTYPE=\"0\" PTYPE=\"4\" isTableItem=\"0\" TEXTFLOW2=\"0\" SHADE2=\"100\" PWIDTH=\"1\" HEIGHT=\"22\" DASHOFF=\"0\" PFILE2=\"\" PFILE=\"\" TEXTFLOW3=\"0\" ISIZE=\"10\" PLTSHOW=\"0\" TXTSTYLE=\"0\" CLIPEDIT=\"0\" BACKITEM=\"-1\" BookNr=\"0\" TransValueS=\"0\" EMBEDDED=\"1\" PFILE3=\"\" ANNAME=\"\" SHADE=\"100\" COCOOR=\"0 0 0 0 148 0 148 0 148 0 148 0 148 22 148 22 148 22 148 22 0 22 0 22 0 22 0 22 0 0 0 0 \" BASEOF=\"0\" PICART=\"1\" COLUMNS=\"1\" LAYER=\"0\" BOOKMARK=\"0\" TopLine=\"0\" LOCK=\"0\" EPROF=\"\" BBOXX=\"0\" DASHS=\"\" IRENDER=\"-279058628\" TEXTFLOW=\"0\" BBOXH=\"0\" TXTFILLSH=\"100\" YPOS=\"$ypostxt[$piccount]\" ANNOTATION=\"0\" LOCALX=\"0\" GRTYP=\"0\" XPOS=\"$xpostxt[$piccount]\" NUMCO=\"16\" POCOOR=\"0 0 0 0 148 0 148 0 148 0 148 0 148 22 148 22 148 22 148 22 0 22 0 22 0 22 0 22 0 0 0 0 \" EXTRA=\"1\" LOCALY=\"0\" NEXTPAGE=\"-1\" TABS=\"\" NUMTAB=\"0\" NUMDASH=\"0\" LeftLine=\"0\" PRFILE=\"\" TEXTRA=\"1\" SCALETYPE=\"1\" TXTFILL=\"Black\" BEXTRA=\"1\" PLINEJOIN=\"0\" TXTSTRSH=\"100\" >\n <ITEXT CAB=\"$cab[$piccount]\" CCOLOR=\"Black\" CSIZE=\"10\" CH=\"$file\" CSHADE2=\"100\" CSCALE=\"100\" CSHADE=\"100\" CSTYLE=\"0\" CFONT=\"Luxi Sans Regular\" CEXTRA=\"0\" CSTROKE=\"Black\" />\n </PAGEOBJECT>\n "; | |||
++$piccount; | |||
++$image; | |||
} | |||
# All the pics should be in now...finish up | |||
print FILE "</PAGE>\n"; | |||
print FILE "$docend\n"; | |||
close (FILE); | |||
print "All finished printing to $album\n"; | |||
</nowiki></pre> | |||
== scribalbum.py == | |||
<pre><nowiki> | |||
#!/usr/bin/env python | |||
# File: scribalbum.py | |||
# originally 2005.02.13 Gregory Pittman | |||
# modified 2005.02.27 - from scribalbuma4.py | |||
# This version for US Letter paper | |||
# Also, puts only 4 pictures per page, to allow for text frame notes in between | |||
# | |||
# Uses Tkinter to give you an Entry box for the name of a directory | |||
# then filters out files ending with .jpg, .png, and so on (user selectable) | |||
# Note: at this time will not pick up uppercase extension equivalents | |||
# Makes a new document | |||
# | |||
# Some things to be fixed: needs a more elegant closure; right now you click | |||
# on the X in the upper right corner of the root frame, but at least it tells | |||
# you when. | |||
# Eventually want to be able to browse for a directory, perhaps show a | |||
# Listbox for selecting a choice. | |||
from scribus import * | |||
import Tkinter | |||
import os | |||
class ImageDialog(Tkinter.Toplevel): | |||
def __init__(self, parent): | |||
global jpg, tif, png, pdf, svg, gif | |||
Tkinter.Toplevel.__init__(self, parent, bg="#bbbbff") | |||
Tkinter.Label(self, text='Enter the Image Directory, Click OK',bg="#bbbbff").grid(row=0,columnspan=6) | |||
self.e = Tkinter.Entry(self) | |||
self.e.grid(row=1,columnspan=6) | |||
self.jpg = Tkinter.StringVar() | |||
self.tif = Tkinter.StringVar() | |||
self.png = Tkinter.StringVar() | |||
self.pdf = Tkinter.StringVar() | |||
self.svg = Tkinter.StringVar() | |||
self.gif = Tkinter.StringVar() | |||
b = Tkinter.Button(self, text='OK', bg="#55ff88", command=self.ok) | |||
b.grid(row=2,columnspan=6) | |||
self.protocol("WM_DELETE_WINDOW", self.quit) | |||
Tkinter.Label(self, text='Filters',bg="#bbbbff").grid(row=3) | |||
j = Tkinter.Checkbutton(self, text = '.jpg', variable = self.jpg,onvalue='.jpg') | |||
j.grid(row=4,column=0) | |||
t = Tkinter.Checkbutton(self, text = '.tif', variable = self.tif,onvalue='.tif') | |||
t.grid(row=4,column=2) | |||
p = Tkinter.Checkbutton(self, text = '.png', variable = self.png,onvalue='.png') | |||
p.grid(row=4, column=4) | |||
P = Tkinter.Checkbutton(self, text = '.pdf', variable = self.pdf,onvalue='.pdf') | |||
P.grid(row=5, column=0) | |||
s = Tkinter.Checkbutton(self, text = '.svg', variable = self.svg,onvalue='.svg') | |||
s.grid(row=5, column=2) | |||
g = Tkinter.Checkbutton(self, text = '.gif', variable = self.gif,onvalue='.gif') | |||
g.grid(row=5, column=4) | |||
j.select() # uncomment these to have default on settings in Checkbuttons | |||
# t.select() # j = .jpg, t = .tif, etc. | |||
# s.select() | |||
# p.select() | |||
# P.select() | |||
# g.select() | |||
def ok(self): | |||
m = Tkinter.Message(root, text="Now click the X in the upper right corner of this window") | |||
m.grid(row=0, columnspan=4) | |||
try: | |||
D=[] | |||
imagecount = 0 | |||
framecount = 0 | |||
filetype = [] | |||
if len(self.jpg.get()) == 4: filetype.append(self.jpg.get()) | |||
if len(self.tif.get()) == 4: filetype.append(self.tif.get()) | |||
if len(self.png.get()) == 4: filetype.append(self.png.get()) | |||
if len(self.pdf.get()) == 4: filetype.append(self.pdf.get()) | |||
if len(self.svg.get()) == 4: filetype.append(self.svg.get()) | |||
if len(self.gif.get()) == 4: filetype.append(self.gif.get()) | |||
d = os.listdir(self.e.get()) | |||
for file in d: | |||
for format in filetype: | |||
if file.endswith(format): | |||
D.append(file) | |||
D.sort() | |||
# There are 4 pictures per page; xpos and ypos are the x,y coord of the upper left corners | |||
# Coords are: (15, 42),(15, 388), (310, 187), (310, 533) | |||
xpos = (15, 310) | |||
ypos = (42, 388, 187, 533) | |||
# This proportion is right for photographs (at least for my digital Olympus) | |||
pwidth = 288 | |||
pheight = 217 | |||
if newDoc(PAPER_LETTER, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT): | |||
while D[imagecount]: | |||
if imagecount > 0: | |||
newPage(-1) | |||
framecount = 0 | |||
# L is the frame at the top of each page showing the directory name | |||
L = createText(15, 20, 200, 20) | |||
setText("Dir: " + self.e.get(), L) | |||
setTextAlignment(ALIGN_LEFT, L) | |||
setFont("Luxi Sans Regular", L) | |||
setFontSize(10, L) | |||
# Here is where we're loading images into the page, four at a time, then go back up for a newPage | |||
for xframe in xpos: | |||
if D[imagecount]: | |||
f = createImage(xframe, ypos[framecount], pwidth, pheight) | |||
loadImage(self.e.get() + '/' + D[imagecount], f) | |||
setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) | |||
lenfilename = len(D[imagecount]) | |||
Lpiclen = int(5.3 * lenfilename) | |||
# Lpic is the label for each picture, with position and length adjusted | |||
# according to the text length. | |||
# So if you change the font or its size, you may need to adjust | |||
# this only approximate calculation. | |||
Lpic = createText(xframe, ypos[framecount] + 217, Lpiclen, 15) | |||
setText(D[imagecount], Lpic) | |||
setTextAlignment(ALIGN_RIGHT, Lpic) | |||
setFont("Luxi Mono Regular", Lpic) | |||
setFontSize(8, Lpic) | |||
setFillColor("White", Lpic) | |||
imagecount = imagecount + 1 | |||
framecount = framecount + 1 | |||
if D[imagecount]: | |||
f = createImage(xframe, ypos[framecount], pwidth, pheight) | |||
loadImage(self.e.get() + '/' + D[imagecount], f) | |||
setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) | |||
lenfilename = len(D[imagecount]) | |||
Lpiclen = int(5.3 * lenfilename) | |||
Lpic = createText(xframe, ypos[framecount] + 217, Lpiclen, 15) | |||
setText(D[imagecount], Lpic) | |||
setTextAlignment(ALIGN_RIGHT, Lpic) | |||
setFont("Luxi Mono Regular", Lpic) | |||
setFontSize(8, Lpic) | |||
setFillColor("White", Lpic) | |||
imagecount = imagecount + 1 | |||
framecount = framecount + 1 | |||
setRedraw(1) | |||
redrawAll() | |||
self.Tkinter.Toplevel.destroy() | |||
except os.error, value: | |||
Tkinter.Button(root, text=value[1], bg="#ffff55").grid(row=3, columnspan = 4) | |||
root = Tkinter.Tk() | |||
root.update() | |||
d = ImageDialog(root) | |||
root.wait_window(d) | |||
</nowiki> | |||
</pre> | |||
== scribalbum.py == | |||
<pre><nowiki> | |||
#!/usr/bin/env python | |||
# File: scribalbuma4.py | |||
# 2005.02.13 Gregory Pittman | |||
# Uses Tkinter to give you an Entry box for the name of a directory | |||
# then filters out files ending with .jpg, .png, and so on (user selectable) | |||
# Note: at this time will not pick up uppercase extension equivalents | |||
# Makes a new document | |||
# | |||
# Some things to be fixed: needs a more elegant closure; right now you click | |||
# on the X in the upper right corner of the root frame, but at least it tells | |||
# you when. | |||
# Eventually want to be able to browse for a directory, perhaps show a | |||
# Listbox for selecting a choice. | |||
from scribus import * | |||
import Tkinter | |||
import os | |||
class ImageDialog(Tkinter.Toplevel): | |||
def __init__(self, parent): | |||
global jpg, tif, png, pdf, svg, gif | |||
Tkinter.Toplevel.__init__(self, parent, bg="#bbbbff") | |||
Tkinter.Label(self, text='Enter the Image Directory, Click OK',bg="#bbbbff").grid(row=0,columnspan=6) | |||
self.e = Tkinter.Entry(self) | |||
self.e.grid(row=1,columnspan=6) | |||
self.jpg = Tkinter.StringVar() | |||
self.tif = Tkinter.StringVar() | |||
self.png = Tkinter.StringVar() | |||
self.pdf = Tkinter.StringVar() | |||
self.svg = Tkinter.StringVar() | |||
self.gif = Tkinter.StringVar() | |||
b = Tkinter.Button(self, text='OK', bg="#55ff88", command=self.ok) | |||
b.grid(row=2,columnspan=6) | |||
self.protocol("WM_DELETE_WINDOW", self.quit) | |||
Tkinter.Label(self, text='Filters',bg="#bbbbff").grid(row=3) | |||
j = Tkinter.Checkbutton(self, text = '.jpg', variable = self.jpg,onvalue='.jpg') | |||
j.grid(row=4,column=0) | |||
t = Tkinter.Checkbutton(self, text = '.tif', variable = self.tif,onvalue='.tif') | |||
t.grid(row=4,column=2) | |||
p = Tkinter.Checkbutton(self, text = '.png', variable = self.png,onvalue='.png') | |||
p.grid(row=4, column=4) | |||
P = Tkinter.Checkbutton(self, text = '.pdf', variable = self.pdf,onvalue='.pdf') | |||
P.grid(row=5, column=0) | |||
s = Tkinter.Checkbutton(self, text = '.svg', variable = self.svg,onvalue='.svg') | |||
s.grid(row=5, column=2) | |||
g = Tkinter.Checkbutton(self, text = '.gif', variable = self.gif,onvalue='.gif') | |||
g.grid(row=5, column=4) | |||
j.select() # uncomment these to have default on settings in Checkbuttons | |||
# t.select() # j = .jpg, t = .tif, etc. | |||
# s.select() | |||
# p.select() | |||
# P.select() | |||
# g.select() | |||
def ok(self): | |||
m = Tkinter.Message(root, text="Now click the X in the upper right corner of this window") | |||
m.grid(row=0, columnspan=4) | |||
try: | |||
D=[] | |||
imagecount = 0 | |||
filetype = [] | |||
if len(self.jpg.get()) == 4: filetype.append(self.jpg.get()) | |||
if len(self.tif.get()) == 4: filetype.append(self.tif.get()) | |||
if len(self.png.get()) == 4: filetype.append(self.png.get()) | |||
if len(self.pdf.get()) == 4: filetype.append(self.pdf.get()) | |||
if len(self.svg.get()) == 4: filetype.append(self.svg.get()) | |||
if len(self.gif.get()) == 4: filetype.append(self.gif.get()) | |||
d = os.listdir(self.e.get()) | |||
for file in d: | |||
for format in filetype: | |||
if file.endswith(format): | |||
D.append(file) | |||
D.sort() | |||
# There are 8 pictures per page; xpos and ypos are the x,y coord of the upper left corners | |||
xpos = (25, 321) | |||
ypos = (42, 236, 430, 624) | |||
# This proportion is right for photographs (at least for my digital Olympus) | |||
pwidth = 250 | |||
pheight = 187 | |||
if newDoc(PAPER_A4, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT): | |||
while D[imagecount]: | |||
if imagecount > 0: | |||
newPage(-1) | |||
# L is the frame at the top of each page showing the directory name | |||
L = createText(15, 20, 200, 20) | |||
setText("Dir: " + self.e.get(), L) | |||
setTextAlignment(ALIGN_LEFT, L) | |||
setFont("Luxi Sans Regular", L) | |||
setFontSize(10, L) | |||
# Here is where we're loading images into the page, eight at a time, then go back up for a newPage | |||
for yframe in ypos: | |||
for xframe in xpos: | |||
if D[imagecount]: | |||
f = createImage(xframe, yframe, pwidth, pheight) | |||
loadImage(self.e.get() + '/' + D[imagecount], f) | |||
setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) | |||
lenfilename = len(D[imagecount]) | |||
Lpiclen = int(5.3 * lenfilename) | |||
# Lpic is the label for each picture, with position and length adjusted according to the text length | |||
# so if you change in font or its size, you may need to adjust this only approximate calculation | |||
Lpic = createText(xframe + (250 - Lpiclen), yframe + 172, Lpiclen, 15) | |||
setText(D[imagecount], Lpic) | |||
setTextAlignment(ALIGN_RIGHT, Lpic) | |||
setFont("Luxi Mono Regular", Lpic) | |||
setFontSize(8, Lpic) | |||
setFillColor("White", Lpic) | |||
imagecount = imagecount + 1 | |||
setRedraw(1) | |||
redrawAll() | |||
self.Tkinter.Toplevel.destroy() | |||
except os.error, value: | |||
Tkinter.Button(root, text=value[1], bg="#ffff55").grid(row=3, columnspan = 4) | |||
root = Tkinter.Tk() | |||
root.update() | |||
d = ImageDialog(root) | |||
root.wait_window(d) | |||
</nowiki></pre> |
Revision as of 19:54, 28 January 2006
Scripts para iniciantes • Scripts de extensão/PyQt • Questões sobre Py • Plugins • Outros |
Versão em inglês.
Básico
Primeiramente, a razão de eu ter criado esse scripts foi para aprender alguma coisa sobre Python e para poder criar um arquivador de imagens ou album no Scribus. Geralmente eu uso o script para organizar as imagens digitais que eu tiro nas minhas viagens. Uma das vantagens do Scribus é que o seu formato de arquivo .sla não inclui nenhum dado de imagem, mas apenas suas referências, então, este arquivo de catálogo é relativamente pequeno. Eu irei adicionar anotações, fazer um PDF e imprimir um album com algumas coleções.
Inicialmente eu criei um programa em Perl a parte (scribalbum.pl) para fazer a criação fora do Scribus. O script ainda funciona, mesmo tendo sido projetado para os formatos de arquivo da versão 1.2.x. Uma de suas vantagens é a velocidade com que ele gera diversas páginas com informações. Sua desvantagem é que ele foi criado para o formato 1.2.x, ou seja, potêncialmente incompatível com as novas versões (e até um tanto quanto perigoso). Ajusta-lo para gerar os documentos na nova versão é mais trabalho do que eu gostaria. Melhor carrega-lo no Scribus 1.3.x e então salvar de lá mesmo.
As implementações Python tem a vantagem de usar o próprio Scribus para criar um documento, sendo assim, enquanto o script funcionar o arquivo resultante estará atualizado. Outro benefício é a facilidade de modificação do script para ser ajustado a outras necessidades.
Descrição
scribalbum.pl
Eu não irei dizer nada sobre este programa. Se você conhece alguma coisa de Perl, verá que isto não é "elegante", mas faz o trabalho. Sua operação é através da linha de comando.
scribalbum.py e scribalbuma4.py
Estes scripts são similares, ambos criam um novo documento e quantas páginas forem necessárias. O scribalbum.py coloca quatro imagens desalinhadas uma das outras em uma página de tamanho carta (americana), permitindo anotações nos espaços remanescentes. Já o scribalbum4.py coloca 8 imagens por página A4, deixando pouco espaço livre restante. Ambas as versões farão um quadro de texto no canto superior esquerdo de cada página, indicando qual o diretório que a imagem está. Cada imagem possui um título indicando o nome de arquivo da imagem.
Aqui estão alguns dos recursos que ambos os scripts compartilham:
- Quando você executar o script no Scribus, duas janelas Tk aparecerão, uma branca e outra que pergunta o nome do diretório e possui caixas de marcação. Você pode usar um caminho relativo. O absoluto será mais preciso.
- Você pode marcar um ou mais formatos de imagens que você quer. TODAS as imagens daquele tipo serão incluidas - você não pode selecionar e/ou escolher imagens individualmente.
Elas aparecerão na ordem alfa-numérica no seu documento, sendo a coluna da esquerda a primeira.
- PDFs serão importados mas somente a sua primeira página.
- Por enquanto este script não importa SVGs. O que você tem é um quadro branco. Essa é uma das coisas na lista do meu "a fazer" (TODO).
- Todas as imagens são ajustadas para coresponder ao tamanho do quadro, sendo o mesmo tamanho de quadro em cada script.. Ajustar um quadro para uma imagem individual é uma tarefa melhor feita no Scribus após você ter feito o arquivo. Estes scripts foram desenvolvidos para fazer o trabalho "grosso". Vamos deixar que o Scribus faça o trabalho de refino.
- Uma vez que você tenha fornecido o diretório e selecionado os formatos das imagens, basta clicar em OK. Aguarde um tempo (durante este processo os quadros e os ícones do Scribus podem piscar).
- Quando o script terminar, a janela TK que estava branca agora dirá: "Now click the X in the upper right corner of this window" (Agora clique no X no canto superior direito desta janela), significando que o X no canto da janela Tk irá a apagar. Com esta ação o script termina e o Scribus assume.
- Neste ponto o Scribus está - em teoria - carregando o arquivo para exibição. Esse processo pode demorar até minutos dependendo do número e do tamanho das imagens, além das configurações de sua máquina (memória, processador etc).
- Se nesse ponto o Scribus quebrar/travar, provavelmente toda a memória RAM e swap foi usada no seu sistema. Ainda não há uma proteção incluida neste script contra essa possibilidade. Se você tiver sorte, o Scribus terá salvo um arquivo de emergência começando com DocumentN..., mas, se o arquivo for grande demais, o Scribus não conseguirá o carregar, já que a memória continuará criando essa restição (o arquivo por sí só não é grande, o requerimento de memória para todas as imagens que é a fonte do problema).
Arquivos
scribalbum.pl
#!/usr/bin/perl -w ###################################### # # # Program scribalbum.pl # # Created 2004.09.12 # # Last modified 2004.09.14 # # Gregory Pittman # # # ###################################### print "This program will create a picture album as a Scribus .sla file from all the pictures in a directory.\n"; print "Enter the name of the directory:\t"; chomp ($folder =<STDIN>); opendir (DIR, $folder) || die "Do you have the drive mounted?"; # First we'll eliminate anything starting with a period @files = grep { !/^\./} readdir(DIR); # Then sift out the image files; Scribus can show at least some PDFs # Not having so much luck with SVGs, but at least you'll know they are there @files = grep { ( /\Z jpeg|jpg|tif|pdf|png|gif|svg/i ) } @files ; closedir (DIR); $numfiles = scalar(@files); $anzpages = int $numfiles/4; if ($numfiles/4 gt ($anzpages)){ ++$anzpages; } print "There are $numfiles pictures in this directory.\nThis will make $anzpages pages.\n"; print "What do you want to name this album? (\".sla\" will be appended)\t"; chomp ($album =<STDIN>); $album = "$album.sla"; $utf = "<SCRIBUSUTF8 Version=\"1.2cvs\" >"; # The only variable in $document is $anzpages $document = " <DOCUMENT MAJGRID=\"100\" ABSTSPALTEN=\"11\" PAGEWITH=\"612\" AUTOCHECK=\"0\" LANGUAGE=\"English\" DPIn2=\"\" DPgam=\"0\" HCMS=\"1\" DGAP=\"0\" ORIENTATION=\"0\" MINWORDLEN=\"3\" VTIEFSC=\"100\" DOCLANGINFO=\"\" COMMENTS=\"\" TITLE=\"\" KEYWORDS=\"\" DSIZE=\"12\" AUTOSPALTEN=\"1\" GROUPC=\"7\" DOCFORMAT=\"\" DOCDATE=\"\" BORDERTOP=\"9\" GUIDELOCK=\"0\" DIMo=\"1\" DIPr=\"0\" DPuse=\"0\" DPSo=\"0\" DOCSOURCE=\"\" FIRSTNUM=\"1\" DPbla=\"1\" VHOCHSC=\"100\" DOCTYPE=\"\" BORDERBOTTOM=\"40\" BASEGRID=\"12\" VTIEF=\"33\" DOCCONTRIB=\"\" DOCRELATION=\"\" BASEO=\"0\" DOCIDENT=\"\" PUBLISHER=\"\" ANZPAGES=\"$anzpages\" HYCOUNT=\"2\" DIMo2=\"1\" AUTHOR=\"\" UNITS=\"0\" BORDERRIGHT=\"9\" DPPr=\"\" DPMo=\"\" PAGEHEIGHT=\"792\" MINGRID=\"20\" VHOCH=\"33\" DOCCOVER=\"\" DCOL=\"1\" AUTOMATIC=\"1\" ALAYER=\"0\" DOCRIGHTS=\"\" DPIn=\"\" VKAPIT=\"75\" DFONT=\"Bitstream Vera Sans Mono Roman\" BORDERLEFT=\"9\" >"; $colorlayer = " <COLOR RGB=\"\#000000\" CMYK=\"\#000000ff\" NAME=\"Black\" />\n <COLOR RGB=\"\#ffffff\" CMYK=\"\#00000000\" NAME=\"White\" />\n <LAYERS DRUCKEN=\"1\" NUMMER=\"0\" NAME=\"Background\" SICHTBAR=\"1\" LEVEL=\"0\" />"; $pdf = " <PDF ImagePr=\"0\" BTop=\"9\" UseProfiles=\"0\" BLeft=\"9\" PrintP=\"\" RecalcPic=\"0\" ImageP=\"\" SolidP=\"\" PicRes=\"300\" Thumbnails=\"0\" CMethod=\"0\" Encrypt=\"0\" BRight=\"9\" Binding=\"0\" Articles=\"0\" InfoString=\"\" RGBMode=\"1\" PresentMode=\"0\" Permissions=\"-4\" Intent=\"1\" Compress=\"1\" Version=\"14\" Resolution=\"300\" Bookmarks=\"0\" UseProfiles2=\"0\" Quality=\"0\" UseLpi=\"0\" PassUser=\"\" BBottom=\"40\" Intent2=\"1\" PassOwner=\"\" >\n <LPI Angle=\"45\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Black\" />\n <LPI Angle=\"105\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Cyan\" />\n <LPI Angle=\"75\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Magenta\" />\n <LPI Angle=\"90\" Frequency=\"75\" SpotFunction=\"2\" Color=\"Yellow\" />\n </PDF>"; # This goes at the end when we're done $docend = " <PAGE NUM=\"0\" NAM=\"Normal\" LEFT=\"0\" NumVGuides=\"0\" HorizontalGuides=\"\" MNAM=\"\" NumHGuides=\"0\" VerticalGuides=\"\" />\n </DOCUMENT>\n</SCRIBUSUTF8>\n"; open (FILE, ">$album"); print FILE "$utf\n$document\n$colorlayer\n$pdf\n"; # Now let's build some pages $pagecount = 0; $image = 0; $piccount = 0; # will use this to place each picture on the page @xpos = qw( 16 310 16 310 ); # $xpos[$piccount] will give this value @ypos = qw( 14 187 360 533 );# ditto for $ypos @xpostxt = qw( 16 450 16 450 ); # $xpostxt[$piccount] label for image @ypostxt = qw( 232 165 578 510 );# ditto for $ypostxt @cab = qw( 0 2 0 2 );# alternates left and right justification for image labels foreach $file (@files) { if ($piccount gt 3) { $piccount = 0; print FILE "</PAGE>\n"; ++$pagecount; } if ($piccount == 0) { print FILE " <PAGE NUM=\"$pagecount\" NAM=\"\" LEFT=\"0\" NumVGuides=\"0\" HorizontalGuides=\"\" MNAM=\"Normal\" NumHGuides=\"0\" VerticalGuides=\"\" >\n"; # This will print the directory name in the upper right hand corner of the page print FILE " <PAGEOBJECT BottomLine=\"0\" REXTRA=\"1\" ALIGN=\"2\" LANGUAGE=\"English\" NUMPO=\"16\" PLINEART=\"1\" TXTSCALE=\"100\" RightLine=\"0\" LOCALSCX=\"1\" LINESP=\"12\" ROT=\"0\" TXTSTROKE=\"Black\" WIDTH=\"195\" BACKPAGE=\"-1\" GROUPS=\"\" LOCKR=\"0\" IFONT=\"Luxi Sans Regular\" LOCALSCY=\"1\" NAMEDLST=\"\" AUTOTEXT=\"0\" FLIPPEDV=\"0\" EXTRAV=\"0\" PCOLOR=\"None\" RADRECT=\"0\" REVERS=\"0\" PRINTABLE=\"1\" RATIO=\"1\" FLIPPEDH=\"0\" COLGAP=\"0\" PCOLOR2=\"None\" NEXTITEM=\"-1\" NUMGROUP=\"0\" TransValue=\"0\" INVERS=\"0\" PLINEEND=\"0\" FRTYPE=\"0\" PTYPE=\"4\" isTableItem=\"0\" TEXTFLOW2=\"0\" SHADE2=\"100\" PWIDTH=\"1\" HEIGHT=\"25\" DASHOFF=\"0\" PFILE2=\"\" PFILE=\"\" TEXTFLOW3=\"0\" ISIZE=\"10\" PLTSHOW=\"0\" TXTSTYLE=\"0\" CLIPEDIT=\"0\" BACKITEM=\"-1\" BookNr=\"0\" TransValueS=\"0\" EMBEDDED=\"1\" PFILE3=\"\" ANNAME=\"\" SHADE=\"100\" COCOOR=\"0 0 0 0 195 0 195 0 195 0 195 0 195 25 195 25 195 25 195 25 0 25 0 25 0 25 0 25 0 0 0 0 \" BASEOF=\"0\" PICART=\"1\" COLUMNS=\"1\" LAYER=\"0\" BOOKMARK=\"0\" TopLine=\"0\" LOCK=\"0\" EPROF=\"\" BBOXX=\"0\" DASHS=\"\" IRENDER=\"0\" TEXTFLOW=\"0\" BBOXH=\"0\" TXTFILLSH=\"100\" YPOS=\"11\" ANNOTATION=\"0\" LOCALX=\"0\" GRTYP=\"0\" XPOS=\"400\" NUMCO=\"16\" POCOOR=\"0 0 0 0 195 0 195 0 195 0 195 0 195 25 195 25 195 25 195 25 0 25 0 25 0 25 0 25 0 0 0 0 \" EXTRA=\"1\" LOCALY=\"0\" NEXTPAGE=\"-1\" TABS=\"\" NUMTAB=\"0\" NUMDASH=\"0\" LeftLine=\"0\" PRFILE=\"\" TEXTRA=\"1\" SCALETYPE=\"1\" TXTFILL=\"Black\" BEXTRA=\"1\" PLINEJOIN=\"0\" TXTSTRSH=\"100\" >\n <ITEXT CAB=\"2\" CCOLOR=\"Black\" CSIZE=\"10\" CH=\"$folder/\" CSHADE2=\"100\" CSCALE=\"100\" CSHADE=\"100\" CSTYLE=\"0\" CFONT=\"Luxi Sans Regular\" CEXTRA=\"0\" CSTROKE=\"Black\" />\n </PAGEOBJECT>"; } # The individual image files print FILE " <PAGEOBJECT BottomLine=\"0\" REXTRA=\"1\" ALIGN=\"0\" LANGUAGE=\"English\" NUMPO=\"16\" PLINEART=\"1\" TXTSCALE=\"100\" RightLine=\"0\" LOCALSCX=\"0.18\" LINESP=\"14.4\" ROT=\"0\" TXTSTROKE=\"Black\" WIDTH=\"288\" BACKPAGE=\"-1\" GROUPS=\"\" LOCKR=\"0\" IFONT=\"Bitstream Vera Sans Mono Roman\" LOCALSCY=\"0.18\" NAMEDLST=\"\" AUTOTEXT=\"0\" FLIPPEDV=\"0\" EXTRAV=\"0\" PCOLOR=\"White\" RADRECT=\"0\" REVERS=\"0\" PRINTABLE=\"1\" RATIO=\"1\" FLIPPEDH=\"0\" COLGAP=\"0\" PCOLOR2=\"None\" NEXTITEM=\"-1\" NUMGROUP=\"0\" TransValue=\"0\" INVERS=\"0\" PLINEEND=\"0\" FRTYPE=\"0\" PTYPE=\"2\" isTableItem=\"0\" TEXTFLOW2=\"0\" SHADE2=\"100\" PWIDTH=\"1\" HEIGHT=\"217\" DASHOFF=\"0\" PFILE2=\"\" PFILE=\"$folder/$file\" TEXTFLOW3=\"0\" ISIZE=\"12\" PLTSHOW=\"0\" TXTSTYLE=\"0\" CLIPEDIT=\"0\" BACKITEM=\"-1\" BookNr=\"0\" TransValueS=\"0\" EMBEDDED=\"1\" PFILE3=\"\" ANNAME=\"Image$image\" SHADE=\"100\" COCOOR=\"0 0 0 0 288 0 288 0 288 0 288 0 288 217 288 217 288 217 288 217 0 217 0 217 0 217 0 217 0 0 0 0 \" BASEOF=\"0\" PICART=\"1\" COLUMNS=\"1\" LAYER=\"0\" BOOKMARK=\"0\" TopLine=\"0\" LOCK=\"0\" EPROF=\"\" BBOXX=\"0\" DASHS=\"\" IRENDER=\"1\" TEXTFLOW=\"0\" BBOXH=\"1200\" TXTFILLSH=\"100\" YPOS=\"$ypos[$piccount]\" ANNOTATION=\"0\" LOCALX=\"0\" GRTYP=\"0\" XPOS=\"$xpos[$piccount]\" NUMCO=\"16\" POCOOR=\"0 0 0 0 288 0 288 0 288 0 288 0 288 217 288 217 288 217 288 217 0 217 0 217 0 217 0 217 0 0 0 0 \" EXTRA=\"1\" LOCALY=\"0\" NEXTPAGE=\"-1\" TABS=\"\" NUMTAB=\"0\" NUMDASH=\"0\" LeftLine=\"0\" PRFILE=\"\" TEXTRA=\"1\" SCALETYPE=\"0\" TXTFILL=\"Black\" BEXTRA=\"1\" PLINEJOIN=\"0\" TXTSTRSH=\"100\" />\n"; # The image file name in a text frame print FILE " <PAGEOBJECT BottomLine=\"0\" REXTRA=\"1\" ALIGN=\"0\" LANGUAGE=\"English\" NUMPO=\"16\" PLINEART=\"1\" TXTSCALE=\"100\" RightLine=\"0\" LOCALSCX=\"1\" LINESP=\"12\" ROT=\"0\" TXTSTROKE=\"Black\" WIDTH=\"148\" BACKPAGE=\"-1\" GROUPS=\"\" LOCKR=\"0\" IFONT=\"Luxi Sans Regular\" LOCALSCY=\"1\" NAMEDLST=\"\" AUTOTEXT=\"0\" FLIPPEDV=\"0\" EXTRAV=\"0\" PCOLOR=\"None\" RADRECT=\"0\" REVERS=\"0\" PRINTABLE=\"1\" RATIO=\"1\" FLIPPEDH=\"0\" COLGAP=\"0\" PCOLOR2=\"None\" NEXTITEM=\"-1\" NUMGROUP=\"0\" TransValue=\"0\" INVERS=\"0\" PLINEEND=\"0\" FRTYPE=\"0\" PTYPE=\"4\" isTableItem=\"0\" TEXTFLOW2=\"0\" SHADE2=\"100\" PWIDTH=\"1\" HEIGHT=\"22\" DASHOFF=\"0\" PFILE2=\"\" PFILE=\"\" TEXTFLOW3=\"0\" ISIZE=\"10\" PLTSHOW=\"0\" TXTSTYLE=\"0\" CLIPEDIT=\"0\" BACKITEM=\"-1\" BookNr=\"0\" TransValueS=\"0\" EMBEDDED=\"1\" PFILE3=\"\" ANNAME=\"\" SHADE=\"100\" COCOOR=\"0 0 0 0 148 0 148 0 148 0 148 0 148 22 148 22 148 22 148 22 0 22 0 22 0 22 0 22 0 0 0 0 \" BASEOF=\"0\" PICART=\"1\" COLUMNS=\"1\" LAYER=\"0\" BOOKMARK=\"0\" TopLine=\"0\" LOCK=\"0\" EPROF=\"\" BBOXX=\"0\" DASHS=\"\" IRENDER=\"-279058628\" TEXTFLOW=\"0\" BBOXH=\"0\" TXTFILLSH=\"100\" YPOS=\"$ypostxt[$piccount]\" ANNOTATION=\"0\" LOCALX=\"0\" GRTYP=\"0\" XPOS=\"$xpostxt[$piccount]\" NUMCO=\"16\" POCOOR=\"0 0 0 0 148 0 148 0 148 0 148 0 148 22 148 22 148 22 148 22 0 22 0 22 0 22 0 22 0 0 0 0 \" EXTRA=\"1\" LOCALY=\"0\" NEXTPAGE=\"-1\" TABS=\"\" NUMTAB=\"0\" NUMDASH=\"0\" LeftLine=\"0\" PRFILE=\"\" TEXTRA=\"1\" SCALETYPE=\"1\" TXTFILL=\"Black\" BEXTRA=\"1\" PLINEJOIN=\"0\" TXTSTRSH=\"100\" >\n <ITEXT CAB=\"$cab[$piccount]\" CCOLOR=\"Black\" CSIZE=\"10\" CH=\"$file\" CSHADE2=\"100\" CSCALE=\"100\" CSHADE=\"100\" CSTYLE=\"0\" CFONT=\"Luxi Sans Regular\" CEXTRA=\"0\" CSTROKE=\"Black\" />\n </PAGEOBJECT>\n "; ++$piccount; ++$image; } # All the pics should be in now...finish up print FILE "</PAGE>\n"; print FILE "$docend\n"; close (FILE); print "All finished printing to $album\n";
scribalbum.py
#!/usr/bin/env python # File: scribalbum.py # originally 2005.02.13 Gregory Pittman # modified 2005.02.27 - from scribalbuma4.py # This version for US Letter paper # Also, puts only 4 pictures per page, to allow for text frame notes in between # # Uses Tkinter to give you an Entry box for the name of a directory # then filters out files ending with .jpg, .png, and so on (user selectable) # Note: at this time will not pick up uppercase extension equivalents # Makes a new document # # Some things to be fixed: needs a more elegant closure; right now you click # on the X in the upper right corner of the root frame, but at least it tells # you when. # Eventually want to be able to browse for a directory, perhaps show a # Listbox for selecting a choice. from scribus import * import Tkinter import os class ImageDialog(Tkinter.Toplevel): def __init__(self, parent): global jpg, tif, png, pdf, svg, gif Tkinter.Toplevel.__init__(self, parent, bg="#bbbbff") Tkinter.Label(self, text='Enter the Image Directory, Click OK',bg="#bbbbff").grid(row=0,columnspan=6) self.e = Tkinter.Entry(self) self.e.grid(row=1,columnspan=6) self.jpg = Tkinter.StringVar() self.tif = Tkinter.StringVar() self.png = Tkinter.StringVar() self.pdf = Tkinter.StringVar() self.svg = Tkinter.StringVar() self.gif = Tkinter.StringVar() b = Tkinter.Button(self, text='OK', bg="#55ff88", command=self.ok) b.grid(row=2,columnspan=6) self.protocol("WM_DELETE_WINDOW", self.quit) Tkinter.Label(self, text='Filters',bg="#bbbbff").grid(row=3) j = Tkinter.Checkbutton(self, text = '.jpg', variable = self.jpg,onvalue='.jpg') j.grid(row=4,column=0) t = Tkinter.Checkbutton(self, text = '.tif', variable = self.tif,onvalue='.tif') t.grid(row=4,column=2) p = Tkinter.Checkbutton(self, text = '.png', variable = self.png,onvalue='.png') p.grid(row=4, column=4) P = Tkinter.Checkbutton(self, text = '.pdf', variable = self.pdf,onvalue='.pdf') P.grid(row=5, column=0) s = Tkinter.Checkbutton(self, text = '.svg', variable = self.svg,onvalue='.svg') s.grid(row=5, column=2) g = Tkinter.Checkbutton(self, text = '.gif', variable = self.gif,onvalue='.gif') g.grid(row=5, column=4) j.select() # uncomment these to have default on settings in Checkbuttons # t.select() # j = .jpg, t = .tif, etc. # s.select() # p.select() # P.select() # g.select() def ok(self): m = Tkinter.Message(root, text="Now click the X in the upper right corner of this window") m.grid(row=0, columnspan=4) try: D=[] imagecount = 0 framecount = 0 filetype = [] if len(self.jpg.get()) == 4: filetype.append(self.jpg.get()) if len(self.tif.get()) == 4: filetype.append(self.tif.get()) if len(self.png.get()) == 4: filetype.append(self.png.get()) if len(self.pdf.get()) == 4: filetype.append(self.pdf.get()) if len(self.svg.get()) == 4: filetype.append(self.svg.get()) if len(self.gif.get()) == 4: filetype.append(self.gif.get()) d = os.listdir(self.e.get()) for file in d: for format in filetype: if file.endswith(format): D.append(file) D.sort() # There are 4 pictures per page; xpos and ypos are the x,y coord of the upper left corners # Coords are: (15, 42),(15, 388), (310, 187), (310, 533) xpos = (15, 310) ypos = (42, 388, 187, 533) # This proportion is right for photographs (at least for my digital Olympus) pwidth = 288 pheight = 217 if newDoc(PAPER_LETTER, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT): while D[imagecount]: if imagecount > 0: newPage(-1) framecount = 0 # L is the frame at the top of each page showing the directory name L = createText(15, 20, 200, 20) setText("Dir: " + self.e.get(), L) setTextAlignment(ALIGN_LEFT, L) setFont("Luxi Sans Regular", L) setFontSize(10, L) # Here is where we're loading images into the page, four at a time, then go back up for a newPage for xframe in xpos: if D[imagecount]: f = createImage(xframe, ypos[framecount], pwidth, pheight) loadImage(self.e.get() + '/' + D[imagecount], f) setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) # Lpic is the label for each picture, with position and length adjusted # according to the text length. # So if you change the font or its size, you may need to adjust # this only approximate calculation. Lpic = createText(xframe, ypos[framecount] + 217, Lpiclen, 15) setText(D[imagecount], Lpic) setTextAlignment(ALIGN_RIGHT, Lpic) setFont("Luxi Mono Regular", Lpic) setFontSize(8, Lpic) setFillColor("White", Lpic) imagecount = imagecount + 1 framecount = framecount + 1 if D[imagecount]: f = createImage(xframe, ypos[framecount], pwidth, pheight) loadImage(self.e.get() + '/' + D[imagecount], f) setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) Lpic = createText(xframe, ypos[framecount] + 217, Lpiclen, 15) setText(D[imagecount], Lpic) setTextAlignment(ALIGN_RIGHT, Lpic) setFont("Luxi Mono Regular", Lpic) setFontSize(8, Lpic) setFillColor("White", Lpic) imagecount = imagecount + 1 framecount = framecount + 1 setRedraw(1) redrawAll() self.Tkinter.Toplevel.destroy() except os.error, value: Tkinter.Button(root, text=value[1], bg="#ffff55").grid(row=3, columnspan = 4) root = Tkinter.Tk() root.update() d = ImageDialog(root) root.wait_window(d)
scribalbum.py
#!/usr/bin/env python # File: scribalbuma4.py # 2005.02.13 Gregory Pittman # Uses Tkinter to give you an Entry box for the name of a directory # then filters out files ending with .jpg, .png, and so on (user selectable) # Note: at this time will not pick up uppercase extension equivalents # Makes a new document # # Some things to be fixed: needs a more elegant closure; right now you click # on the X in the upper right corner of the root frame, but at least it tells # you when. # Eventually want to be able to browse for a directory, perhaps show a # Listbox for selecting a choice. from scribus import * import Tkinter import os class ImageDialog(Tkinter.Toplevel): def __init__(self, parent): global jpg, tif, png, pdf, svg, gif Tkinter.Toplevel.__init__(self, parent, bg="#bbbbff") Tkinter.Label(self, text='Enter the Image Directory, Click OK',bg="#bbbbff").grid(row=0,columnspan=6) self.e = Tkinter.Entry(self) self.e.grid(row=1,columnspan=6) self.jpg = Tkinter.StringVar() self.tif = Tkinter.StringVar() self.png = Tkinter.StringVar() self.pdf = Tkinter.StringVar() self.svg = Tkinter.StringVar() self.gif = Tkinter.StringVar() b = Tkinter.Button(self, text='OK', bg="#55ff88", command=self.ok) b.grid(row=2,columnspan=6) self.protocol("WM_DELETE_WINDOW", self.quit) Tkinter.Label(self, text='Filters',bg="#bbbbff").grid(row=3) j = Tkinter.Checkbutton(self, text = '.jpg', variable = self.jpg,onvalue='.jpg') j.grid(row=4,column=0) t = Tkinter.Checkbutton(self, text = '.tif', variable = self.tif,onvalue='.tif') t.grid(row=4,column=2) p = Tkinter.Checkbutton(self, text = '.png', variable = self.png,onvalue='.png') p.grid(row=4, column=4) P = Tkinter.Checkbutton(self, text = '.pdf', variable = self.pdf,onvalue='.pdf') P.grid(row=5, column=0) s = Tkinter.Checkbutton(self, text = '.svg', variable = self.svg,onvalue='.svg') s.grid(row=5, column=2) g = Tkinter.Checkbutton(self, text = '.gif', variable = self.gif,onvalue='.gif') g.grid(row=5, column=4) j.select() # uncomment these to have default on settings in Checkbuttons # t.select() # j = .jpg, t = .tif, etc. # s.select() # p.select() # P.select() # g.select() def ok(self): m = Tkinter.Message(root, text="Now click the X in the upper right corner of this window") m.grid(row=0, columnspan=4) try: D=[] imagecount = 0 filetype = [] if len(self.jpg.get()) == 4: filetype.append(self.jpg.get()) if len(self.tif.get()) == 4: filetype.append(self.tif.get()) if len(self.png.get()) == 4: filetype.append(self.png.get()) if len(self.pdf.get()) == 4: filetype.append(self.pdf.get()) if len(self.svg.get()) == 4: filetype.append(self.svg.get()) if len(self.gif.get()) == 4: filetype.append(self.gif.get()) d = os.listdir(self.e.get()) for file in d: for format in filetype: if file.endswith(format): D.append(file) D.sort() # There are 8 pictures per page; xpos and ypos are the x,y coord of the upper left corners xpos = (25, 321) ypos = (42, 236, 430, 624) # This proportion is right for photographs (at least for my digital Olympus) pwidth = 250 pheight = 187 if newDoc(PAPER_A4, (10,10,20,20),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT): while D[imagecount]: if imagecount > 0: newPage(-1) # L is the frame at the top of each page showing the directory name L = createText(15, 20, 200, 20) setText("Dir: " + self.e.get(), L) setTextAlignment(ALIGN_LEFT, L) setFont("Luxi Sans Regular", L) setFontSize(10, L) # Here is where we're loading images into the page, eight at a time, then go back up for a newPage for yframe in ypos: for xframe in xpos: if D[imagecount]: f = createImage(xframe, yframe, pwidth, pheight) loadImage(self.e.get() + '/' + D[imagecount], f) setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) # Lpic is the label for each picture, with position and length adjusted according to the text length # so if you change in font or its size, you may need to adjust this only approximate calculation Lpic = createText(xframe + (250 - Lpiclen), yframe + 172, Lpiclen, 15) setText(D[imagecount], Lpic) setTextAlignment(ALIGN_RIGHT, Lpic) setFont("Luxi Mono Regular", Lpic) setFontSize(8, Lpic) setFillColor("White", Lpic) imagecount = imagecount + 1 setRedraw(1) redrawAll() self.Tkinter.Toplevel.destroy() except os.error, value: Tkinter.Button(root, text=value[1], bg="#ffff55").grid(row=3, columnspan = 4) root = Tkinter.Tk() root.update() d = ImageDialog(root) root.wait_window(d)