Python-fu/gimpfu parameters - What does "image" mean? - gimp

I've been trying to switch from script-fu to python-fu, and I can't figure out what I'm supposed to pass for the "image" parameter. In script-fu it was just an integer, but when I put the same integer into python-fu, it just says it's the wrong type. Same with strings and floats... what am I supposed to put in here? The documentation just says the parameter it takes is "IMAGE" but what does that mean? Where do I find it? How do I get it?
pdb.gimp_image_get_layers(image)
Here's a picture of the interpreter.

You pass an Image object -
Most of the parameters that are only integers in script-fu are not to be used - in their place, you have to pass an actual object reference. ANd how do you get those?
Simply all PDB functions and methods return these objects already - not their numeric IDs, like it happens in script-fu.
So, for Image, you either get the Image as parameter for your python-fu function, or on a call to pdb.gimp_image_new.
If, as it is often the case, you are making tests on the interactive console, you have to get references to the active images. In that case, call
gimp.image_list() to get a Python list with the currently open images - the image at index 0 on this list is the rightmost (newest) open image on the screen -so just do image = gimp.image_list()[0] to get a reference to it.
While you are at it, explore the image object with dir(image) you willfind it is populated with attributes and methods that are handy shortcuts to otherwise hard-to-type pdb calls. For example, image.layers gives you a Python list with reference to all layers on the image (as actual Layer objects, not their IDs), image.width gives you the width, and calling img.new_layer() creates a new layer and adds it to the image - this call has optional parameters to specify its name, width, height and so on.
As a last resort, there are reserved methods on the gimp module that can convert a numeric ID to the actual objects: '_id2display', '_id2drawable', '_id2image', '_id2vectors' - you should not need to use those. If you ever find your self needing to use those in the body of a script, due to some pdb function returning IDs instead of objects, please fill a bug report on GIMP's bugzilla.

Related

How to get the last element inside array using VTL?

I am writing AWS AppSync resolver. Where I do need to get the last element in my array. AWS AppSync supports VTL language.
Example:
#set($items=["color", "taste", "shape"])
#set($result="shape")
I am using $array.size() but didn't work. I don't see any option in Utility Helpers.
.
#set($result=$item[$item.size()-1])
Thanks,
The solution is to make sure you are making the arithmetic operation inside -> set($result=$item[$item.size()-1]);
Set the array size into a separate variable and use another variable to get the last index.
#set($length=$facts.size())
#set($lastIndex = $length - 1)
#set($fact=$facts.get($lastIndex))

AirPrint - Make number of copies default to 2 and not just 1 copy

When I open the print options using AirPrint, I want to make it default to 2 copies and not just 1 copy.
Couldn't find any methods that could change the number of copies. Wondering if anyone has any ideas if this is possible since it seems that this printing option is pretty limited.
So I found my own solution. Basically under the UIPrintInteraction Controller there is a method called printItems. What I did is make an NSArray and put two copies of the object I wanted to print and used that method instead of printItem.
However, since my application used the printFormatter I was unable to use this method since in the IOS developer documentation it says
"If you set this property (printFormatter), UIPrintInteractionController sets the printingItems, printingItem, and printPageRenderer properties to nil. (Only one of these properties can be set for a print job.)"
So what I did was just doubled the html page I was formatting and I trusted that the formatting was correct for it to print two pages.
Another way would be to add the same printFormatter to page 1 and page 2 in a printPageRenderer.

In transaction NACE, is it possible to find out the print program and form routine, if i know the name of the Smartform?

I want to find out the name of the Print Program, and the name of the subroutine (form) that prints my SmartForm.
Now luckily in NACE (Conditions for Output Control), one can "kinna" figure out the application and the output type by oneself, and then the print program is obviously written there.
So what about if one wouldn't know what application and Output Type, and would have to check all applicatios and output types manually? isn't there an easier way to do this?
The table TNAPR contains some print program -> script links, search for your smartform name in field SFORM. This is by no means an exhaustive list, however.
OR
Do a "where used" search for "SSF_FUNCTION_MODULE_NAME", which will give you a list of all smartform calling programs. You'd still need to go through it manually, but you might find a suitably matching program description or similar.
If you need to find out the actual printing program for a certain form and it is possible to get a print preview, you can always enter the debugger using /h and examine the call stack.

How can I most efficiently iterate over a hash of hashes in order based on key value in inner hash?

I've got a JSON hash of hashes returned by a website API that I want to parse and display based on a specific key's value within the internal hashes.
I can think of solutions that would achieve this, but they would take a number of lines of code and don't seem efficient. Surely there must be a way to natively in Rails, given the focus on convention over configuration. I've googled around a bit, but found nothing that covers this issue.
Sample Response from API:
[{"banner":"01197271","birthday":"1991-01-11","committee_id":1,"created_at":"2012-08-08T01:56:02-05:00","email":"me#example.com","first_name":"Dan","graduation_date":"May 2013","hometown":"San Antonio","hours_enrolled":15,"id":2,"image":{"url":null,"thumb":{"url":null},"large":{"url":null}},"invitation_accepted_at":null,"invitation_limit":null,"invitation_sent_at":null,"invitation_token":null,"invited_by_id":null,"invited_by_type":null,"last_name":"Tester","local_apt":"","local_city":"San Antonio","local_state":"Texas","local_street":"One UTSA Circle","local_zip":"78249","major":"Computer Science","permanent_apt":"","permanent_city":"","permanent_state":"","permanent_street":"One UTSA Circle","permanent_zip":"","phone":"5558813284","same_address":true,"tour_trained":false,"updated_at":"2012-08-17T03:35:26-05:00","utsa_id":"uoi431"},
{"banner":"","birthday":"1990-10-25","committee_id":null,"created_at":"2012-08-03T16:19:23-05:00","email":"you#example.com","first_name":"Test","graduation_date":null,"hometown":null,"hours_enrolled":null,"id":1,"image":{"url":null,"thumb":{"url":null},"large":{"url":null}},"invitation_accepted_at":null,"invitation_limit":null,"invitation_sent_at":null,"invitation_token":null,"invited_by_id":null,"invited_by_type":null,"last_name":"User","local_apt":"","local_city":"","local_state":"","local_street":"","local_zip":"","major":null,"permanent_apt":"","permanent_city":"","permanent_state":"","permanent_street":"","permanent_zip":"","phone":"","same_address":false,"tour_trained":false,"updated_at":"2012-08-15T10:05:54-05:00","utsa_id":""}]
Potential solution would be to go through each internal hash, determining value of relevant key value, then store, based on where the key value places it compared to already tested hashes. When complete, return.
Ok so if you have objects that are set up to parse this information, those objects can build themselves based off the parameters of your hash. So you could do something like this
object = MyObject.create(your_hash_parameters)
Where your_hash_parameters are the parameters that you presented in your example.
I'm not sure what would happen if there were more paramaters than your object knew what to do with, if it would still build itself or not. If that is the case, you could use the delete_if method to exclude attributes that are unwanted.
One more note, if this isn't something that you want saved to your database, and its only to display temporary information. I would set up a model with attr_accessors that represent the attributes that you are displaying.
As told in comment, I'd create an ActiveResource object and add relevant methods to it.

cvRetrieveFrame intricacies - openCV

The Documentation of OpenCV mentions that "the returned image (by cvRetrieveFrame) should not be released or modified by the user" ...
Link: http://opencv.willowgarage.com/documentation/c/highgui_reading_and_writing_images_and_video.html#retrieveframe
I am trying to debug my code, which involves the following steps:
Retrieve frame from video using cvRetrieveFrame()
Do some processing on the frame
output results
My instinct says that something is wrong with cvRetrieveFrame() because if I manually input frames using cvLoadImage, the program works fine. But I am not getting same results while using cvRetrieveFrame().
Since the documentation mentions such a restriction, any reason for such a restriction ? And, any alternatives ?
Have a great day
Before you call this function, you should have used another function which is cvGrabFrame() in order to be able to use the mentioned function, which you can use it for doing any necessary processing on the frame (such as the decompression stage in
the codec) and then return an IplImage* pointer that points to another internal buff er
(so do not rely on this image, because it will be overwritten the next time you call
cvGrabFrame()).

Resources