Last active
July 26, 2022 20:26
-
-
Save me-suzy/4b480ef9aee45635d79587892f9f7cdd to your computer and use it in GitHub Desktop.
How to make a Pop-Up/Prompt message on notepad++ (Plugins -> Python Script)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I've been wondering how to make a pop-up/prompt window in notepad ++, on the Python Script Plugin. I figured it out, so I'm writing here maybe someone needs it. | |
Basicaly, this is the prompt line: | |
`result = notepad.prompt('Number of modified files: ', '', number_files)` | |
The code below will make multiple search and replace on notepad++. | |
Two Pop-Up/Prompt windows will apear: first, when put the file path for replacing the files from a particular folder. And second pop-up/prompt window will be displayed after the replacement was made, with a message: "Number of modified files" | |
This code works with Python Script Plugon on notepad++. Save this code as .py, and copy it in c:\Program Files\Notepad++\plugins\PythonScript\scripts\ | |
Use Menu -> Plugins -> Python Script -> Scripts -> THIS-SCRIPT.py | |
Remember to change the path on the script, the location of folder where you want to change all files: Path="C:\\python-test" | |
------------------------------------------------------------------------------------------------------------------------------------- | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
from Npp import * | |
import os | |
import sys | |
#------------------------------------------------------------------------------- | |
class T22601(object): | |
def __init__(self): | |
top_level_dir = notepad.prompt('Paste path to top-level folder to process:', '', '') | |
number_files = 0 | |
for root, dirs, files in os.walk(top_level_dir): | |
nested_levels = root.split('/') | |
if len(nested_levels) > 0: | |
del dirs[:] | |
for filename in files: | |
if filename[-5:] == '.html': | |
notepad.open(root + "\\" + filename) | |
console.write(root + "\\" + filename + "\r\n") | |
notepad.runMenuCommand("Encodage", "Convertir en UTF-8") | |
regex_find_repl_dict_list = [ | |
{ 'find' : '<title>(.*?)</title>', 'replace' : r'\3\2\1' }, | |
{ 'find' : '<head>\s+', 'replace' : r'\n baba ' }, | |
] | |
editor.beginUndoAction() | |
for d in regex_find_repl_dict_list: editor.rereplace(d['find'], d['replace']) | |
editor.endUndoAction() | |
notepad.save() | |
notepad.close() | |
number_files += 1 | |
result = notepad.prompt('Number of modified files: ', '', number_files) | |
print("Number of modified files: ", number_files) | |
#------------------------------------------------------------------------------- | |
if __name__ == '__main__': T22601() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment