#!/usr/bin/python # Align_image_in_frame2.py # This version 2016.04.30 """ This script will align an image inside a frame to one of 9 possible positions: Upper left, upper center, upper right; middle left, middle center, middle right; or lower left, lower center, lower right. USAGE Select one or more image frames. Run the script, which asks for your alignment choice (all selected frames will need to have the same alignment). This modification does away with tkinter and uses a valueDialog instead. Note There is minimal error checking, in particular no checking for frame type. See the wiki page for further info: wiki.scribus.net/canvas/Align_an_Image_in_its_Frame """ import scribus if scribus.haveDoc(): restore_units = scribus.getUnit() # since there is an issue with units other than points, scribus.setUnit(0) # we switch to points then restore later. nbrSelected = scribus.selectionCount() objList = [] for i in range(nbrSelected): objList.append(scribus.getSelectedObject(i)) scribus.deselectAll() alignment = scribus.valueDialog("Align where?", "UL\tUC\tUR\nML\tMC\tMR\nLL\tLC\tLR\n Enter one 2-letter choice\nUL = Upper Left LR = Lower Right", "UL") alignment = alignment.upper() for i in range(nbrSelected): try: obj = objList[i] scribus.selectObject(obj) frameW, frameH = scribus.getSize(obj) saveScaleX, saveScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(1, 0, obj) fullScaleX, fullScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(0, 0, obj) scribus.setImageScale(saveScaleX, saveScaleY, obj) imageW = frameW * (saveScaleX / fullScaleX) imageH = frameH * (saveScaleY / fullScaleY) imageX = 0.0 imageY = 0.0 if alignment[0] == "U": imageY = 0.0 elif alignment[0] == "M": imageY = (frameH - imageH) / 2.0 elif alignment[0] == "L": imageY = (frameH - imageH) if alignment[1] == "L": imageX = 0.0 elif alignment[1] == "C": imageX = (frameW - imageW) / 2.0 elif alignment[1] == "R": imageX = (frameW - imageW) scribus.setImageOffset(imageX, imageY, obj) scribus.docChanged(1) scribus.setRedraw(True) scribus.deselectAll() except: nothing = "nothing" scribus.setUnit(restore_units) if scribus.haveDoc(): scribus.redrawAll()