Fit to frame with vertical justification options - scripting

Working with InDesign script I am using
TF.fit(FitOptions.frameToContent). //TF as a textFrame
to fit the content into the textframe and remove the extra space
But when I have a condition for vertical justification options set to Align: Bottom i am not able to fit the content.
Assuming this to be my TextFrame (Image 1)
Here are the properties of the text frame (Image 2)
When I do FitOptions.frameToContent i get this (Image 3)
But when the text frame has the align property set to the bottom I want this to fit it like this(this was achieved by double-clicking on the top center alignment as shown in the red indicator below. (Image 4) (Image 5)
I tried all the available options at http://jongware.mit.edu/idcs4js/pe_FitOptions.html but I had no luck making it work. Please help me to achieve the same using scripting.
Cross-reference: https://community.adobe.com/t5/indesign/fit-to-frame-with-vertical-justification-options/td-p/11120458?page=1
================== First try ==================
var tf = app.selection[0];
var tfp = tf.textFramePreferences;
tfp.autoSizingReferencePoint = AutoSizingReferenceEnum.BOTTOM_CENTER_POINT;
tfp.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
tf.fit(FitOptions.frameToContent)
This still gives me the same result(image 3) but expected result is image 4.
================== Second try ==================
This is the auto-sizing property.

This command indeed seems to work only with the top edge as a reference point, just as it does in the UI (if you actually use the menu command, not clicking any borders).
What you could do to work around this, is to temporarily enable auto-sizing (height only) and setting the reference point for auto-sizing to the bottom:
var tf = app.selection[0];
var tfp = tf.textFramePreferences;
tfp.autoSizingReferencePoint = AutoSizingReferenceEnum.BOTTOM_CENTER_POINT;
tfp.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
tfp.autoSizingType = AutoSizingTypeEnum.OFF;
Note, the last line turns off the auto sizing again and is optional; if you don't mind that the frame keeps auto sizing you don't need to turn it off.

Related

How do I resize an array of squished PyQt5 widgets? [duplicate]

I have a QScrollArea Widget, which starts empty;
It has a vertical layout, with a QGridLayout, and a vertical spacer to keep it at the top, and prevent it from stretching over the whole scroll area;
Elsewhere in the program, there is a QTextEdit, which when changed, has its contents scanned for "species" elements, and then they are added to the QGridLayout. Any species elements which have been removed are removed too. This bit works;
I have turned the vertical scrollbar on all the time, so that when it appears it does not sit on top of the other stuff in there. Note that the scroll bar is larger than the scroll box already though, despite not needing to be.
This is the problem. The scroll area seems to be preset, and i cannot change it. If i add more rows to the QGridLayout, the scroll area doesn't increase in size.
Instead, it stays the same size, and squeezes the QGridLayout, making it look ugly (at first);
And then after adding even more it becomes unusable;
Note that again, the scroll bar is still the same size as in previous images. The first two images are from Qt Designer, the subsequent 3 are from the program running.
If I resize the window so that the QScrollArea grows, then I see this:
Indicating that there's some layout inside the scroll area that is not resizing properly.
My question is; what do I need to do to make the scrollable area of the widget resize dynamically as I add and remove from the QGridLayout?
If you're coming here from Google and not having luck with the accepted answer, that's because you're missing the other secret invocation: QScrollArea::setWidget. You must create and explicitly identify a single widget which is to be scrolled. It's not enough to just add the item as a child! Adding multiple items directly to the ScrollArea will also not work.
This script demonstrates a simple working example of QScrollArea:
from PySide.QtGui import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
inner.layout().addWidget(b)
scroll.show()
app.exec_()
The documentation provide an answer :
widgetResizable : bool
This property holds whether the scroll area should resize the view widget.
If this property is set to false (the default), the scroll area honors the size of its widget.
Set it to true.
Why don't you use a QListView for your rows, it will manage all the issues for you? Just make sure that after you add it you click on the Class (top right window of designer) and assign a layout or it wont expand properly.
I use a QLIstWidget inside a QScrollArea to make a scrollable image list
Try this for adding other objects to the list, this is how I add an image to the list.
QImage& qim = myclass.getQTImage();
QImage iconImage = copyImageToSquareRegion(qim, ui->display_image->palette().color(QWidget::backgroundRole()));
QListWidgetItem* pItem = new QListWidgetItem(QIcon(QPixmap::fromImage(iconImage)), NULL);
pItem->setData(Qt::UserRole, "thumb" + QString::number(ui->ImageThumbList->count())); // probably not necessary for you
QString strTooltip = "a tooltip"
pItem->setToolTip(strTooltip);
ui->ImageThumbList->addItem(pItem);
Update on Artfunkel's answer:
Here's a PySide6 demo that uses a "Populate" button to run the for loop adding items to the scroll area. Each button will also delete itself when clicked.
from PySide6.QtWidgets import *
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True) # CRITICAL
inner = QFrame(scroll)
inner.setLayout(QVBoxLayout())
scroll.setWidget(inner) # CRITICAL
def on_remove_widget(button):
button.deleteLater()
def populate():
for i in range(40):
b = QPushButton(inner)
b.setText(str(i))
b.clicked.connect(b.deleteLater)
inner.layout().addWidget(b)
b = QPushButton(inner)
b.setText("Populate")
b.clicked.connect(populate)
inner.layout().addWidget(b)
scroll.show()
app.exec()

Remove black values in a modis merge image

the following image shows my actuall result of a merged modis image.
I used pyhdf.SD to open and manipulate and plot the data in a loop. It started on the right upper corner.
The plot is ok... put on some areas overlaped. The easiest way is to remove the black borders.
I wanted to use this:
np.ma.masked_where(rgb_projected==0.,rgb_projected)
rgb_projected is the original rgb matix.
rgb_projected = np.zeros((1000, 1000,3))
rgb_projected[:,:,0] = z_01[:,:]
rgb_projected[:,:,1] = z_02[:,:]
rgb_projected[:,:,2] = z_03[:,:]
rgb_projected.shape
whereAreNaNs = np.isnan(rgb_projected);
rgb_projected[whereAreNaNs] = 0.;
rgb_plot=np.ma.masked_where(rgb_projected==0.,rgb_projected)
The interesting thing is, that everything is True although the first valueas are 0.
Any ideas?

How to display more than one image dynamically with python (pyqt5)?

I'm using python to build an application by PyQt5, the main idea is to display images from a directory and for each image some masks show up next to it to select one of them (i.e. for each image there are different number of masks). So, I want to display these masks in a "container" that can handle this dynamically.
I tried QlistWidget in a scroll area and the masks are displayed as icons in it, but I want to use something else to handle them easier and retrieve any mask as Qpixmap or QImage to use it in another operations without convert it multiple times (which slows down the program)
this is the part that displays the masks (this is the only way that worked with me)
for ann in annotations:
mask = self.coco.annToMask(ann)
mask_img = Image.fromarray((mask*255).astype(np.uint8))
qt_img = ImageQt.ImageQt(mask_img) # convert Image to ImageQt
icon = QtGui.QIcon(QtGui.QPixmap.fromImage(qt_img))
item = QtWidgets.QListWidgetItem(icon, f"{annIndex}")
self.listWidget.addItem(item)
annIndex += 1

GIMP Script-fu changing default scripts

I am having issues re-writing one of the default logo scripts in GIMP(using Script-fu based on scheme). For one thing the alpha layer is not shown in the layer browser after the image is shown. I am re-writing the Create Neon Logo script(neon-logo.scm) and I want it to do the following before it displays the new image:
add an alpha channel
change black(background color) to transparent via colortoalpha
return the generated image as an object to be used in another python script(using for loops to generate 49 images)
I have tried modifying the following code to the default script:
(gimp-image-undo-disable img)
(apply-neon-logo-effect img tube-layer size bg-color glow-color shadow) *Generates neon logo
(set! end-layer (car (gimp-image-flatten img))) *Flattens image
(gimp-layer-add-alpha end-layer) *Adds alpha layer as last layer in img(img=the image)
(plug-in-colortoalpha img 0 (255 255 255)) *Uses color to alpha-NOT WORKING
(gimp-image-undo-enable img) *Enables undo
(gimp-display-new img) *Displays new image
For number 3 my python code is this:
for str1 in list1:
for color1 in list3:
img = pdb.script_fu_neon_logo(str1,50,"Swis721 BdOul BT",(0,0,0),color1,0)
But img is a "Nonetype" object. I would like to make it so that instead of displaying the generated image in a new window, it just returns the generated image for use with my python script.
Can anyone help?
Maybe to keep everything more managaeable and readable, you should translate theoriginal script into Python - that way you willhaveno surprises on otherwiser trivial things as variable assignment, picking elements from sequences and so on.
1 and 2) your calls are apparantly correct to flaten an "add an alpha channel " (not "alpha layer",a s you write, please) to the image - but you are calling color-to-alpha to make White (255 255 255) transparemt not black. Trey changing that to (0 0 0) - if it does not work, make]
each of the calls individually, either on script-fu console or on python console, and check what is wrong.
3) Script-fu can't return values to the caller (as can be seen by not having a "return value type" parameter to the register call. That means that scripts in scheme in GIMP can only render thigns on themselves and not be used to compose more complex chains.
That leaves you with 2 options: port the original script to Python-fu (and them just register it to return a PF-IMAGE) - or hack around the call like this, in Python:
create a set with all images opened, call your script-fu, check which of your images currently open is not on the set of images previously opened - that will be your new image:
The tricky part with this is that: there is no unique identifier to an image when you see it from Python-fu - so you 'dhave to compose a value like (name, number_of_layers, size) to go on those comparison sets and even that might not suffice - or youg could juggle with "parasites" (arbitrary data that can be attached to an image). As you can see, having the original script-fu rewriten in Python, since all the work is done by PDB calls, and these translate 1:1, is preferable.

GTKmm - unable to set fixed size to Gtk::Scale widget

I am writing a simple photo viewer in C++ using gtkmm and I can not sort out how to set widget size. In the bottom of main window I have Gtk::Box with 3 buttons, a label and a Gtk::Scale widget. I would like to set fixed size to Gtk::Scale widget and buttons, and give rest of the space to label. I have only managed to set fixed size to buttons, and divide extra space evenly between label and scale widgets, by adding widgets like this:
bottom_box->pack_start(*left_button, false, false);
bottom_box->pack_start(*right_button, false, false);
bottom_box->pack_start(*filename_label, true, true);
bottom_box->pack_start(*image_zoom, true, true);
bottom_box->pack_start(*fit_button, false, false);
When I try to set both expand and fill to false while adding image_zoom to bottom_box, the widget is way to small, and set_size_request() makes no change. Is there another way to do it?
Code responsible for creating the window is here (the rest is in the repository): https://github.com/jjkrol/ZPR/blob/master/src/gui.cpp
Thank you very much in advance.
I've sorted this out, I think the problem was associated with fact that I've called set_size_request() before adding Gtk::Scale to Gtk::Box.