I would like to open a new file and then replace this empty file with the strings from my list. Each list item on a separate line. I am using Sublime 3. Currently my plugin opens the new file, but does not change the view to the new file to edit (add the strings from my list).
I have the following code:
size = len(TheList)
count = 0
view = self.view.window().new_file()
allcontent = sublime.Region(0, self.view.size())
while size!=count:
self.view.replace(edit, allcontent, TheList)
count+=1
I need to use:
self.view = self.view.window().new_file()
Related
I will like to do a follow up question to this question here : How to search and bookmark multiple strings at once in emeditor?
However, #Yutaka gave this response: https://i.stack.imgur.com/HLYoo.png and that is my follow up question.
How can each bookmarked strings saved differently or opened differently in emeditor when use the "extract bookmark lines to new file".
I will appreciate your response.
I am expecting the result of each bookmark strings to open in different files in em editor.
Batch Extract
The Batch Extract button in the Batch Find dialog will output all matched lines to a file, with labels indicating the entry that the lines matched with.
Example output:
===== a =====
a
apple
===== b =====
b
Macro
This macro finds the given array of strings with the extract option, and it saves each result to separate files. Make sure to change the marked lines.
var filePath = document.FullName;
var strings = ["a", "b", "e"]; // Change these
for (var i = 0; i < strings.length; i++) {
editor.OpenFile(filePath);
document.selection.Find(strings[i], eeFindSelectAll | eeFindExtract, 0);
document.Save("%HOMEPATH%\\Downloads\\" + strings[i] + ".txt"); // Change path
}
I tested it on this file. Make sure to save it before running the macro.
a
b
c
d
apple
How rename multiple files adding one symbol at the end of files
From this:
New Text Document.txt
New Text Document (2).txt
New Text Document (3).txt
New Text Document (4).txt
To this:
New Text Document1.txt
New Text Document2.txt
New Text Document3.txt
New Text Document4.txt
Thanks!
With an input of
from os.path import splitext
file_list = ["New Text Document.txt", "New Text Document (2).txt",
"New Text Document (3).txt", "New Text Document (4).txt"]
You get the desired output with
def parse(file, no):
body, ext = splitext(file)
new_body_str = ' '.join(body.split()[:3])
return f"{new_body_str}{no}{ext}"
output_list = [parse(filename, no+1) for no, filename in enumerate(file_list)]
If you need this to work for other files than New Text Document use a regular expression instead of body.split()[:3]
I have the following problem: I want to low-pass filter 240 WAV files. The script is running only till the low-pass filtered sounds are created and shown in the object list ("..._band"). However, Praat does not export them as WAV files. After choosing the output folder, I get the warning message "Command 'Get number of strings' not available for current selection".
In short, my question is how can I save the WAV sounds in the object list individually with their new file names? See also Screenshot.
Script see below.
Thank you very much for your help!
Greetings,
#determine praat version
ver1$ = left$(praatVersion$, (rindex(praatVersion$, ".")-1));
ver1 = 'ver1$'
if ver1 < 5.2
exit Please download a more recent version of Praat
endif
if ver1 == 5.2
ver2$ = right$(praatVersion$, length(praatVersion$) - (rindex(praatVersion$, ".")));
ver2 = 'ver2$'
if ver2 < 4
exit Please download a more recent version of Praat (minor)
endif
endif
beginPause ("Low-Pass Filter Instructions")
comment ("1. Select a folder containing the wave files to be low-pass filtered")
comment ("2. Wave files will be low-pass filtered (0 - 400 Hz)")
comment ("3. Select an output folder for the low-pass filtered wave files to be saved to")
comment ("Click 'Next' to begin")
clicked = endPause("Next", 1);
#wavefile folder path
sourceDir$ = chooseDirectory$ ("Select folder containing wave files")
if sourceDir$ == ""
exit Script exited. You did not select a folder.
else
sourceDir$ = sourceDir$ + "/";
endif
Create Strings as file list... list 'sourceDir$'/*.wav
numberOfFiles = Get number of strings
levels$ = ""
for ifile to numberOfFiles
select Strings list
currentList = selected ("Strings")
filename$ = Get string... ifile
Read from file... 'sourceDir$'/'filename$'
currentSound = selected ("Sound")
filterFreqRange = Filter (pass Hann band)... 0 400 20
select currentSound
Remove
endfor
select currentList
Remove
#output folder path - where the wave files get saved
outputDir$ = chooseDirectory$ ("Select folder to save wave files")
if outputDir$ == ""
exit Script exited. You did not select a folder.
else
outputDir$ = outputDir$ + "/";
endif
numberOfFiles = Get number of strings
for ifile to numberOfFiles
select Strings list
currentList = selected ("Strings")
filename$ = Get string... ifile
currentSound = selected ("Sound")
endif
Save as WAV file... 'outputDir$'/'filename$'
select currentSound
Remove
endfor
#clean up
select currentList
Remove
#clear the info window
clearinfo
#print success message
printline Successfully low-pass filtered 'numberOfFiles' wave files.
At a glance, the command is not available because when you get to that point in the script the selection is empty. It is empty because at the end of the first loop, you select your Strings object and then Remove it.
More generally, your script is not handling the object selection properly, which is a big problem in Praat because available commands change depending on the active selection.
So even if you remove the line where you Remove the list, you will bump into a problem the second time you run Get number of strings because by then you have changed the selection. And even if you remove that line (which you don't really need), you'll still bump into a problem when you run selected("Sound") after selecting the Strings object, because by then you won't have any selected Sound objects (you didn't have them before anyway).
A more idiomatic version of your script, which also runs on a single loop where sounds are read, filtered, and removed one by one (which is also more memory efficient) would look like this:
form Low-Pass Filter...
real From_frequency_(Hz) 0
real To_frequency_(Hz) 400
real Smoothing_(Hz) 20
comment Leave paths empty for GUI selectors
sentence Source_dir
sentence Output_dir
endform
if praatVersion < 5204
exitScript: "Please download a more recent version of Praat"
endif
if source_dir$ == ""
source_dir$ = chooseDirectory$("Select folder containing wave files")
if source_dir$ == ""
exit
endif
endif
if output_dir$ == ""
output_dir$ = chooseDirectory$("Select folder to save filtered files")
if output_dir$ == ""
exit
endif
endif
list = Create Strings as file list: "list", source_dir$ + "/*.wav"
numberOfFiles = Get number of strings
levels$ = ""
for i to numberOfFiles
selectObject: list
filename$ = Get string: i
sound = Read from file: source_dir$ + "/" + filename$
filtered = Filter (pass Hann band): from_frequency, to_frequency, smoothing
Save as WAV file: output_dir$ + "/" + selected$("Sound")
removeObject: sound, filtered
endfor
Although you might be interested to know that, if you do not need the automatic file reading and saving (ie, if you are OK with having your script work on objects from the list) your script could be reduced to
Filter (pass Hann band): 0, 400, 20
which works on multiple selected Sound objects.
If you absolutely need the looping (ie, if you'll be working on really large sets of files) you might also be interested in using the vieweach plugin, with was written to try and minimise this sort of boilerplate (full disclaimer: I wrote the plugin). I wrote a longer blog post about it as well.
I am trying to get files from filedialog and display the name of the file names inside the listview. And also checkboxes should also be created before the filenames inside the listview based on the number of files added. Below is my code that returns only one file with the check box, irrespective of any number of files selected. Help would be appreciated.
def OpenTheFile(self):
file = QtGui.QFileDialog.getOpenFileNames(self.dlg, "Select one or more files to open", os.getenv("HOME"),'.sql (*.sql)')
str_file = ','.join(file)
fileinfo = QFileInfo(str_file)
filename = QFileInfo.fileName(fileinfo)
if fileName:
for files in str_file:
model = QStandardItemModel()
item = QStandardItem('%s' % fileName)
item.setCheckable(True)
model.appendRow(item)
self.dlg.DatacheckerlistView2.setModel(model)
self.dlg.DatacheckerlistView2.show()
It is really unclear what you are doing (there is very little context to your question), but the following code should work. There were several issues with the code in your original question, namely:
You were joining all of the files into a single string and iterating over the string, rather than iterating over the list of filenames.
You were recreating the model each iteration of your loop, effectively deleting any previously added rows.
The code:
files = QtGui.QFileDialog.getOpenFileNames(self.dlg, "Select one or more files to open", os.getenv("HOME"),'.sql (*.sql)')
if files:
model = QStandardItemModel()
for file in files:
item = QStandardItem('%s' % file)
item.setCheckable(True)
model.appendRow(item)
self.dlg.DatacheckerlistView2.setModel(model)
self.dlg.DatacheckerlistView2.show()
I created a list in a button ADD:
{
List <string> Names = new List<string>();
Names.Add(textBox1.Text);
textBox1.Text = " ";
}
I created another button SHOW NAMES and i want these names I entered in the list, to be listed in the listbox? How can this be done?
First, you need to move that first line outside of the button click method, because if you declare the list inside the method, it will be gone once that method returns.
For your SHOW NAMES method, if all you want to do is display the list, you could use a TextBlock instead of a listbox, and it will be a little easier:
TextBlock tb = new TextBlock();
tb.text = string.Concat(Names);