Menu

replacing text with regular expressions by invoking a python function.

2017-04-24
2020-01-16
  • Maurizio D.

    Maurizio D. - 2017-04-24

    Hi all,

    Firstly, I would like to thanks Dave on his wonderful work. I made several scripts with your plugin and I use it for different tasks.

    I want to share with you a script that I made recently for text replacement with regular expressions: sometimes I have to modify data streams and using regular expression replace command is limiting; but at the same time I don't wont to create a new python script for "one time" task. so I created a GUI script (my first GUI with python!) in order to replace text calling a python function (it's basically a wrapper for research and rereplace functions).

    Comments in code and text strings were in my native language (italian), so I've decided to translate it in english. For this duty I created a small translator so I can continue to use it in my language! For this tiny translator I got the idea from python module gettext and this translate the text at runtime.

    screenshot

    Since is 3 modules script (for fun I've also created some examples) I cannot attach code on this post, but you can download it here:
    https://drive.google.com/open?id=0BxGBbauIeyxiMTdMN3RMWUx0X0U

    To start the script extract and copy the folder "regexReplace" into your script folder (tipically %appdata%\Notepad++\plugins\config\PythonScript\scripts) and run the module "regexReplaceApp.py" from notepad ++ "plugin >> Python script >> scripts >> regReplace >> regexReplaceApp".

    You need PythonScript 1.0.8.0 Full (PythonScript_Full_1.0.8.0.zip) because I used the tkinter libraries. Tested with notepad++ 6.5.3, 6.9.1 and 7.3.3.

    thank you all

    regards
    Maurizio

     

    Last edit: Maurizio D. 2017-08-11
  • CFrank

    CFrank - 2017-04-24

    Nice job and thank you for sharing it.
    Cheers
    Claudia

     
  • Sasumner

    Sasumner - 2017-04-24

    Nice work. There are some interesting ideas here. One "problem" I noticed, that makes complete sense in the framework of how Pythonscript works: If you leave the Tk window open and switch back to Notepad++ to continue editing, then you do something which invokes another Pythonscript, this action is disallowed because another Pythonscript (yours) is already running. Not sure how/if this can be worked around, but it is completely natural to want to leave a Tk window open (like a modeless dialog) while one continues to work.

     
    • Maurizio D.

      Maurizio D. - 2017-05-02

      Hi Sasumner,
      thanks for your reply.

      Unfortunately I cannot do anything, this is the behavior of the "pythonscript" plugin. If you need to use other scripts you can save your function by using the button "save script ..." and terminate my script. Then you can reload it after with the load button.

      regards
      Maurizio

       

      Last edit: Maurizio D. 2017-05-02
  • Benyamin Limanto

    When will x64 in development phase?

     
  • Maurizio D.

    Maurizio D. - 2017-05-02

    Hi Benyamin,
    I dont understand the question.

    My script should work regardless on 32 or 64 bit OS... Anyway I have developed it on Intel i3 64 bit processor, Windows 10 OS.

    regards
    Maurizio

     
    • Mirimmar

      Mirimmar - 2017-05-03

      I think he ment, when will it work with notepad++ x64 bit version. As far as I know, it is compiled on 32 bit. I do not see any download of x64 bit version.

       
      • Maurizio D.

        Maurizio D. - 2017-05-04

        Ok, thanks for the explanation. I dont know if an x64 version of the "pythonscript" plugin is expected. My script is just python code that runs on it.

        bye
        Maurizio

         

        Last edit: Maurizio D. 2017-05-04
  • Dan Padric

    Dan Padric - 2017-06-03

    Hello Maurizio.

    From the screen capture it seems as though your script is impressive. I have been struggling hard to get it running though. Each time it was crashing. I am starting at ground-zero with Notepad++ and Python - so I though I missed something.

    You need PythonScript 1.0.8.0 Full (PythonScriptFull1.0.8.0.zip) because I used the tkinter libraries. Tested with notepad++ 6.5.3, 6.9.1 and 7.3.3.

    My first mistake was loading PythonScript from the "Plugin Manager" of Notepad++. But even when loading the prescribed ZIP as prescribed in help documents did not help. The call to the "tkinter" library remained an issue (shown in Console). Only the MSI offering of the PythonScript (with all selected) ensured that all was in place for your script to work.

    Very probably I did something else wrong down the road - but just maybe this note is helpful to you, Dave and whomever else.

    Regards.
    - Dan

     

    Last edit: Dan Padric 2017-06-03
  • Maurizio D.

    Maurizio D. - 2017-08-11

    Thanks Dan.
    You're right, the correct package is the MSI! I updated my previous post to fix the mistake you reported. I hope you've solved and ran the script.

    bye
    Maurizio

     
  • Dan Padric

    Dan Padric - 2017-08-14

    Maurizio - Yes thank you, I did get your script to run.
    I even designed some custom script based on things I learnt from you..
    nothing worthy to show in public though.

    I have since moved over to Atom as text editor for Python V3 coding.
    :-) Your script would have gone well as part of Atom.

    My complements to what you produced and shared with us.
    Regards.
    - Dan

     
  • notepad++ windows 7

    Very nice blog, its informative and helped allot . thanks for sharing this information with us
    notepad++ windows 7

     

Log in to post a comment.