How can i pick a folder that have another file not only .jpg - jython

I have to pick a folder that has another file that is not only .jpg.
How can I change it?
import os
def titleDirectory(dir):
for file in os.listdir(dir):
print "Processing:",dir+"//"+file
picture = makePicture(dir+"//"+file)
addText(picture,10,10,"This is from My CS Class")
writePictureTo(picture,dir+"//"+"titled-"+file)
Image of code

Related

How to set background image to shell or composite in SWT

public class createShell{
System.out.println("Inside shell create");
display = new Display();
shell = new Shell(display);
shell.setSize(990, 590);
shell.setLayout(new GridLayout());
Composite comp = new Composite(shell, SWT.NO_FOCUS);
comp.setBounds(10, 10, 720, 400);
}
I have existing code like this. Need to set a background image to shell. How to give relative path of image.
The folder structure of plug-in(com.vcc.rac.ks5lmpp) is as per image.path The code file is in package inside src folder(plugins\com.rac.ks5lmpp\src\com\kjj\rac\ks5lmpp\stylesheets\dialogs\createShell.java)
There exists a image folder(plugins\com.rac.ks5lmpp\src\com\kjj\rac\ks5lmpp\stylesheets\dialogs\images) in which the image is there which I want to pass as background.
Image size is of 676X324 of PNG type.
Thanks in advance.
You use FileLocator in an Eclipse plug-in to find resources in the plug-in.
Bundle bundle = FrameworkUtil.getBundle(getClass()); // Or some other way to find the current bundle
URL url = FileLocator.find(bundle, new Path("path within the plugin"));
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
shell.setBackgroundImage(image);
Note: You should arrange to dispose of the image when the shell closes.
Be sure that the build.properties for the plug-in includes the images.
FileLocator is org.eclipse.core.runtime.FileLocator.
Path is org.eclipse.core.runtime.Path (not the java.nio.file Path)
ImageDescriptor is org.eclipse.jface.resource.ImageDescriptor

I have to set a image on wizard dialogue,classpath load this image, but image not displayed properly

I have to set a image on wizard dialogue in swt,classpath load this image but image not displayed properly. In my design create a composit in this composit create a lebel.there after in this lebel I want add an image.After that i will create a runnable jar.This jar will be executed with proper image. In my implementation part i have create a resources (src folder) within src folder and in this resources folder kept image which i need.Please find the below code,
File file = new File("resources/Automatics_Logo.png");
Image image = new Image(Display.getDefault(), file.getPath());
Label lblNewLabel_4 = new Label(composite, SWT.NONE);
lblNewLabel_4.setImage(SWTResourceManager.getImage(CheckSystemConfigurationAndInstallation.class,image.toString()));
Image imgSWT=null; // Image class is the SWT Image class
ImageDescriptor imgDesc=null;
java.net.URL imgURL = IntroductionPage.class.getResource("/Automatics_Logo.png");
if (imgURL != null) {
imgDesc = ImageDescriptor.createFromURL(imgURL);
imgSWT = imgDesc.createImage();

Dialog to pick a file name like in the "Save As" dialog in Photoshop script

Is there an API to show a dialog that allows the user to browse/create folders and either pick an already existing file or enter the name for a new one in order to save some metadata.
Something like the "Save As" dialog in Photoshop but without actually saving anything, but just retrieve the path and filename entered by the user.
Not sure about a specific API, but is this the sort of thing you're looking for?
var inFolder = Folder.selectDialog("Please select folder to process");
if (inFolder != null)
{
var fileList = inFolder.getFiles(/\.(png)$/i);
}
or
var filterFiles = 'CSV:*.csv'; // I am windows
theFile = File.openDialog ("Choose the CSV file to load from" , filterFiles);
Whereas you can reference theFile or fileList to get the file or path you're after.

Flask - send_from_directory returns old file

When I fill and submit pdf form, send_from_directory returns the old file. I use pdftk to push fdf to pdf and flatten, but if I give the same filename as output with the old one, Flask shows the old file. Why isn't it overwritten by the new one? Thanks.
#app.route('/uploads/<filename>')
def show_pdf_form(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
#app.route('/get_data_as_fdf', methods = ['GET', 'POST'])
def get_pdf_data_as_fdf():
# create fdf file
fdf_string = request.data
fdf_file = open(os.path.join(app.config['UPLOAD_FOLDER'], "data.fdf"), "w")
fdf_file.write(fdf_string)
fdf_file.close()
# merge fdf to pdf and flatten pdf
call(["pdftk", "./uploads/send_data_as_fdf.pdf", "fill_form",
"./uploads/data.fdf", "output", "output.pdf", "flatten"])
return redirect(url_for('show_pdf_form', filename = filename))
These are related code snippets. Thank you.
Flask send_from_directory uses send_file internally. send_file has cache timeout which you can set to 0.
Try clearing the cache and hitting the URL in incognito mode. if it works, you can do:
send_from_directory(app.config['UPLOAD_FOLDER'], filename, cache_timeout=0)
Or you can try any of the options mentioned in:
Disabling caching in Flask

Load local HTML into WebView

Can I load a local HTML file (with images and ...) into a WebView?
Just setting the Source parameter does not do the trick.
You can load it from a file as long as the file is part of the app package, e.g.:
WebView2.Source = new Uri("ms-appx-web:///assets/text.html");
From WebView.Navigate
WebView can load content from the application’s package using
ms-appx-web://, from the network using http/https, or from a string
using NavigateToString. It cannot load content from the application’s
data storage. To access the intranet, the corresponding capability
must be turned on in the application manifest.
For a 'random' file, I suppose you could prompt user via file picker to select the file then read it into a string and use NavigateToString, but the user experience there may be a bit odd depending on what you're trying to accomplish.
I was working at this problem for a long time and I found a way to do that:
At first you should save it in InstalledLocation folder. If you haven't option to create a new .html file you can just use file.CopyAsync(htmlFolder, fname + ".html");
Look into my example:
StorageFolder htmlFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFolderAsync(#"HtmlFiles", CreationCollisionOption.GenerateUniqueName);
IStorageFile file = await htmlFolder .CreateFileAsync(fname + ".html", CreationCollisionOption.GenerateUniqueName);
and than you can easily open your .html file:
var fop = new FileOpenPicker();
fop.FileTypeFilter.Add(".html");
var file = await fop.PickSingleFileAsync();
if (file != null)
{
string myPath = file.Path.Substring(file.Path.IndexOf("HtmlFiles"));
myWebview.Navigate(new Uri("ms-appx-web:///" + myPath));
}
Remember just only from InstalledLocation you can open it with ms-appx-web:///