Community
    • Login

    RFC / Beta Testers Wanted: pyscFilteredViewer

    Scheduled Pinned Locked Moved General Discussion
    53 Posts 7 Posters 12.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Eko palypseE
      Eko palypse
      last edited by

      Final conclusion - it is a python script plugin bug because calling
      via SendMessage does not crash (tried it 1000x)

      import ctypes
      from Npp import notepad, LANGTYPE
      
      LANGUAGES = LANGTYPE.values.values()
      SendMessage = ctypes.windll.user32.SendMessageW
      
      # #define NPPM_GETLANGUAGEDESC  (NPPMSG + 84)
      NPPM_GETLANGUAGEDESC = 2024+84
      # // INT NPPM_GETLANGUAGEDESC(int langType, TCHAR *langDesc)
      # // Get programming language short description from the given language type (LangType)
      # // Return value is the number of copied character / number of character to copy (\0 is not included)
      # // You should call this function 2 times - the first time you pass langDesc as NULL to get the number of characters to copy.
      # // You allocate a buffer of the length of (the number of characters + 1) then call NPPM_GETLANGUAGEDESC function the 2nd time
      # // by passing allocated buffer as argument langDesc
      npp_hwnd = ctypes.windll.user32.FindWindowW(u'Notepad++', None)
      for language in LANGUAGES:
          length = ctypes.windll.user32.SendMessageW(npp_hwnd, NPPM_GETLANGUAGEDESC, language, None)
          buffer = ctypes.create_unicode_buffer(length+1)
          return_value = ctypes.windll.user32.SendMessageW(npp_hwnd, NPPM_GETLANGUAGEDESC, language, ctypes.byref(buffer))
          print buffer.value
      
      # crash
      # for language in LANGUAGES:
          # print notepad.getLanguageDesc(language)
      
      1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones
        last edited by

        Strange. I could not get a crash, or even weird behavior, using your “simplified version” (2019-01-24T19:06:19.201Z). With the code before that (2019-01-24T18:33:47.183Z), I never got a crash, but I did get one or two times when NPP prompted me that it was about to exit, and did I want to cancel – whether I said YES or NO to canceling, it stayed in NPP and the script continued looping.

        Notepad++ v7.6.2   (64-bit)
        Build time : Jan  1 2019 - 00:02:38
        Path : C:\usr\local\apps\notepad++\notepad++.exe
        Admin mode : OFF
        Local Conf mode : ON
        OS : Windows 10 (64-bit)
        Plugins : ComparePlugin.dll DSpellCheck.dll MarkdownViewerPlusPlus.dll mimeTools.dll NppConverter.dll NppExec.dll NppFTP.dll PythonScript.dll 
        

        I guess I’ll keep an eye out for crashes while using pyscFilteredViewer, and I’ll investigate that call as the culprit.

        I’m reluctant to just switch to an alternate method, because the getLanguageDesc() method returns slightly different information than getLexerLanguage(), especially on UDL: “User Defined language file - CustomLanguageName”, vs “user”, and I filter at least one UDL regularly. The getLanguageDesc() appears to match what’s normally put in the STATUSBARSECTION.DOCTYPE location. (If there were just a getStatusBar(statusBarSection) to read back what was previously written with setStatusBar(statusBarSection,text), that would get rid of the need for getLanguageDesc() in my utility. Added #3 to explore this more in the future)

        Meta ChuhM Eko palypseE 2 Replies Last reply Reply Quote 2
        • Meta ChuhM
          Meta Chuh moderator @PeterJones
          last edited by Meta Chuh

          @PeterJones

          looks very promising
          side note: the first thing i read this morning was “psychicFilteredReader” … i guess my coffee hadn’t kicked in yet 😂

          i didn’t have much time to test it enough for much feedback yet (no crash so far), but i’ll probably compile a static, stand alone one file pyscfr command executable (let’s call it phprun.exe or phpysc.exe for now) to render php files to stdout to fiddle around a bit more.

          currently i only have suggestions for the guide:

          first feedback about the documentation:
          i’d simplify it a bit for newer users, it seems more info than necessary, and missing plug and play examples for the .ini at the “getting started” section.

          simplified Installation Procedure (on 7.6.2):

          • extract pyscFilteredViewer-0.01-beta.zip and copy the containing folder pyscFilteredViewer to %AppData%\Notepad++\plugins\config\PythonScript\scripts

          the current pyscfr manual explains a bit much about where to put the files (18 lines instead of 1-2), and it’s doubled as long as it would have been, by giving the user the choice on whether to install it to machine or user scripts, also leaving some users helpless, as they wouldn’t know which location is right for them.

          any further explanation, or guide to an alternative script location, can be done at the end, after a simple getting started guide.

          pyscFilteredViewer.ini template:
          as it is a completely new product, it’s imperative to ensure an immediate, easy start for any new user, eg. by delivering prebuilt, functioning configuration files (pyscFilteredViewer.ini) to attract people to a new application.

          a default ini should be fully working, without relying that a new user understands what to do, in order to ensure a high acceptance count.
          (unless it’s an already huge product, like apache, where the devs can say: everyone uses it, so learn it or leave it 😉)

          a distributed ini example would be:

          [PHPFile]									;   => this is the name of the section; it must be unique.  Typically, based on the language
          Extension=.php								;   => space-separated list of filename extensions, including the period.
          Language=PHP								;   => this is the name of the language (from Notepad++'s perspective): for a UDL, use your "UserName" from the UDL dialog
          Command=C:\usr\local\bin\phpysc.exe "%1"	;   => this is the filter command; %1 is the name of the active file/buffer; the command must result in the HTML being dumped to STDOUT
          

          or even better, an ini using a working preview-ini.bat or exe which is already deployed from the pyscFilteredViewer folder in the zip, as it would always be in %AppData%\Notepad++\plugins\config\PythonScript\scripts\ pyscFilteredViewer instead of a non predictable location on each user’s unique setup as example.

          btw: nice, i like the emoji based ⇉📺⇉ in the readme.md 😃

          1 Reply Last reply Reply Quote 2
          • Meta ChuhM
            Meta Chuh moderator @PeterJones
            last edited by Meta Chuh

            @PeterJones

            btw: wasn’t there someone who recently said:

            and I just don’t have the py-knowledge to keep up for long

            ? 😉👍

            1 Reply Last reply Reply Quote 1
            • Eko palypseE
              Eko palypse @PeterJones
              last edited by

              @PeterJones @Meta-Chuh

              huh - that is strange as this is 100% reproducible at my side.
              Later this day I will do further tests with clean npp and clean PS startup.py.

              1 Reply Last reply Reply Quote 1
              • Eko palypseE
                Eko palypse
                last edited by

                Very strange - I download both latest npp and full PythonScript plugin zips.
                Create a new minimal test script and boom - crash? 10 tries ten crashes.

                Notepad++ v7.6.2   (64-bit)
                Build time : Jan  1 2019 - 00:02:38
                Path : D:\temp\clean_762_x64\notepad++.exe
                Admin mode : OFF
                Local Conf mode : ON
                OS : Windows 7 (64-bit)
                Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll PythonScript.dll 
                
                1 Reply Last reply Reply Quote 1
                • PeterJonesP
                  PeterJones
                  last edited by

                  @Meta-Chuh ,

                  Thanks for the feedback. I do tend toward detailed wordiness. I’ll try to simplify, and maybe move the details to the end, or to supporting documentation.

                  1 Reply Last reply Reply Quote 1
                  • PeterJonesP
                    PeterJones
                    last edited by

                    oh, and

                    btw: wasn’t there someone who recently said:

                    and I just don’t have the py-knowledge to keep up for long

                    Yes, I said that. And I think I said elsewhere (I cannot find the exact quote: google-search no longer returns results inside the forum, and the forum search isn’t always as helpful as I’d like), I said something to the effect of “time to go practice my Python” – this is what I was working toward with that practice. :-)

                    Meta ChuhM 1 Reply Last reply Reply Quote 1
                    • PeterJonesP
                      PeterJones
                      last edited by

                      Ah, there we go: this post: “Now back to studying Python”. That’s what I was looking for.

                      In languages I’m fluent in, pyscFilteredViewer would have been much faster for me to write. For Python, I still have to look up some basic syntax or command at least once per day, that would be at a Python expert’s fingertip muscle memory.

                      1 Reply Last reply Reply Quote 1
                      • PeterJonesP
                        PeterJones
                        last edited by

                        side note: the first thing i read this morning was “psychicFilteredReader” … i guess my coffee hadn’t kicked in yet 😂

                        Yeah, “pysc” is my shorthand prefix for PythonScript. I wanted something to indicate the intended audience (Notepad++ PythonScript), without getting too huge or getting in the way of the main name. I don’t know if I was successful. :-)

                        btw: nice, i like the emoji based ⇉📺⇉ in the readme.md 😃

                        Thanks. There’s no place for a real “icon” in a PythonScript, and didn’t want to have to design one anyway. I tried looking for a unicode “filter” symbol, but the standard Y-shaped filter icon doesn’t have a unicode-equivalent. Arrows through a display unit (like a TV) seemed a reasonable compromise.

                        I’ve added your suggestions as issues, so I won’t forget about them.

                        1 Reply Last reply Reply Quote 1
                        • PeterJonesP
                          PeterJones
                          last edited by

                          @Eko-palypse said,

                          Very strange - I download both latest npp and full PythonScript plugin zips.
                          Create a new minimal test script and boom - crash? 10 tries ten crashes.

                          I have no idea why our systems are behaving differently. It seems odd that my couple of extra plugins would make my system more stable than yours.

                          Maybe Windows 7 is less stable than Win10? (Hard to believe, I know).

                          1 Reply Last reply Reply Quote 1
                          • Meta ChuhM
                            Meta Chuh moderator @PeterJones
                            last edited by Meta Chuh

                            @PeterJones

                            Thanks for the feedback. I do tend toward detailed wordiness. I’ll try to simplify, and maybe move the details to the end, or to supporting documentation.

                            wordiness comes only because it’s your own baby ;-)
                            if you answer any notepad++ question, you keep it as short and easy to read as possible, with a syntax always matched to the original poster’s capabilities.

                            btw: i hope you don’t mind my feedback, i just think psychicFilteredReader ;-) has potential and a simplified guide might attract more unexperienced users.

                            pyscFilteredReader or pyscfr is a fine name, it will be easy to find in google at it is unique.

                            Yes, I said that. And I think I said elsewhere (I cannot find the exact quote: google-search no longer returns results inside the forum, and the forum search isn’t always as helpful as I’d like), I said something to the effect of “time to go practice my Python” – this is what I was working toward with that practice. :-)

                            >>> this <<< was your post i was referring to … because it was the last chat we had with scott around here … sigh :-(

                            1 Reply Last reply Reply Quote 1
                            • PeterJonesP
                              PeterJones
                              last edited by

                              I asked for feedback, why would I mind?

                              The name might change eventually.

                              You seem to have latched on Reader rather than Viewer. Other than the psychic connection, is there a reason you prefer FilteredReader to FilteredViewer?

                              I thought of it as a “filtered viewer”, because it based on using the “filtered” feature of PreviewHTML. But really, my script is neither doing the filtering (it delegates that to an external process) nor a viewer (it delegates that to an external process) – so it might not be the best name. Maybe something like “ConvertAndLaunch”. I don’t know. I don’t want it to include “HTML” in the name, even though right now it does “ConvertToHTMLAndLaunch”, because I’m hoping to make it allow other filter-destinations. Maybe “ConvertThenPreview”?

                              Hmm, it just hit me: if I do get the alternate destination, other than HTML, it’s basically become a generic utility that could not only be used for convert-from-X-to-HTML-and-view, but also compile-then-run, by using the compiler command (or make or whatever) for the Command=, and telling it that the output is an executable rather than HTML. Interesting. More things to ponder.

                              1 Reply Last reply Reply Quote 1
                              • Alan KilbornA
                                Alan Kilborn
                                last edited by

                                I have done nothing except read the discussion here, and (again, with not further exploration) I keep thinking about how it might be similar to or different from Don’s porcine offering: https://github.com/npp-plugins/pork2sausage

                                1 Reply Last reply Reply Quote 2
                                • PeterJonesP
                                  PeterJones
                                  last edited by

                                  @Alan-Kilborn ,

                                  I keep thinking about how it might be similar to or different from Don’s porcine offering: https://github.com/npp-plugins/pork2sausage

                                  Thanks for that. Yeah, they are similar. The primary difference is that mine doesn’t replace the source file. For one of my primary use cases – rending the POD from inside my Perl code into an HTML document – it would be rather destructive to the Perl code to have it be replaced by HTML. :-)

                                  1 Reply Last reply Reply Quote 1
                                  • chcgC
                                    chcg
                                    last edited by

                                    @Peter-Jones I added it as addon example to https://github.com/bruderstein/PythonScript. Hope that is ok for your.

                                    1 Reply Last reply Reply Quote 1
                                    • PeterJonesP
                                      PeterJones
                                      last edited by PeterJones

                                      v0.02-beta has been released.

                                      • per #5, add an ExampleConverterCommand.bat, update the default pyscFilteredViewer.ini file to have valid filter defined using that batch file, so now there is a working filter out-of-the-box.
                                      • per #4, simplify the installation instructions, moving the alternate-situations to separate documentation

                                      Also, per @Alan-Kilborn , I made a brief mention of how it differs from pork2sausage

                                      @chcg: as I meant to imply by my upvote, I’m fine with you linking to it from PythonScript. I’m a little surprised there’s only two “interesting addon scripts” in the universe right now. :-) I guess you cannot just link to every wonderful script that @Claudia-Frank (or any other PythonScript contributor) posted to this Community… though probably some of her gists would be worth linking to.

                                      1 Reply Last reply Reply Quote 3
                                      • guy038G
                                        guy038
                                        last edited by guy038

                                        Hello, @peterjones and All,

                                        I’ve just tried your pyscFilteredViewer and everything went fine ! Well…, as long as if I’ve already started my browser !

                                        Indeed, if I use the One-time filtering mode, on my weak XP configuration, the temporary file <Hex number>.<filename>.FILTERED.html seems already deleted… by the time the browser gets opened, leading, for instance, to the browser message( in French, of course ) :

                                        " Firefox cannot find the file at the address /c:/docume~1/guy/locals~1/temp/37B82996.Test.txt.FILTERED.html "

                                        Luckily, subsequent tests seem OK. I’m saying “seem” and not “are”, as yesterday, Notepad++ crashed several times ! Unfortunately, I could not understand the sequence of actions which causes N++ to crash, when using your script !

                                        Today, once my browser opened ( while listening music on NET, too ! ) , I tried to run your script, successively, on the same file ( Your README.md file ) => Sometimes it’s opened, correctly, in the browser but in some other cases, it displays :

                                        " Firefox cannot find the file at the address /c:/docume~1/guy/locals~1/temp/2BF64FA9.README.md.FILTERED.html "

                                        Moreover, in a few cases, it, also, exits Notepad++, immediately !

                                        An another time, on the Python console, this error occurred :

                                        File “D:@@\763\plugins\Config\PythonScript\scripts\pyscFilteredViewer\pyscFilteredViewerLibrary.py”, line 312, in pyscfv_FilteredViewer
                                        os.unlink(tmpfile)

                                        WindowsError: [Error 32] The process cannot access the file as this file is used by an other process : ‘c:\docume~1\guy\locals~1\temp\2BF64FA9.README.md.FILTERED.html’

                                        I noticed that, if I’m not listening simultaneously music on WEB, it’s getting better : no more error occurs and the browser seems to display the HTML version of files, a bit quicker !

                                        So, Peter, don’t worry about it. Probably, some side-effects of my old XP machine :-))

                                        Best Regards,

                                        guy038

                                        For the record, in the pyscFilteredViewer.ini file, I only added the section, below :

                                        [Txtfile]
                                        Language=Normal text
                                        Extension=.txt .md .log
                                        Command="D:\@@\763\plugins\Config\PythonScript\scripts\pyscFilteredViewer\ExampleConverterCommand.bat" "%1"
                                        

                                        And here is my Debug info :

                                        Notepad++ v7.6.3   (32-bit)
                                        Build time : Jan 27 2019 - 17:20:30
                                        Path : D:\@@\763\notepad++.exe
                                        Admin mode : OFF
                                        Local Conf mode : ON
                                        OS : Windows XP (32-bit)
                                        Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll NppExport.dll PythonScript.dll 
                                        
                                        Meta ChuhM 1 Reply Last reply Reply Quote 2
                                        • PeterJonesP
                                          PeterJones
                                          last edited by

                                          @guy038,

                                          Thanks, that’s actually quite useful: I probably should just leave the temporary files there, rather than deleting every time. (The auto-delete was a holdover from when I used a random tmpfile name, before I had the FilterOnSave option.)

                                          As for the crash: it’s probably the same issue @Eko-palypse had with crashing. So far, 7.6.2 64-b on Win7 and 7.6.3 32-bit on XP see the crashes, whereas my 7.6.4 64-bit on Win10 does not. Maybe it is an older-windows thing. Since I don’t have access to Win7 or earlier machines, that will be hard for me to test. Maybe I’ll have to look into “if OS<Win10, don’t use the command eko noticed”… I’ll have to research how to look up Windows-rev in Python.

                                          Meta ChuhM 1 Reply Last reply Reply Quote 1
                                          • Eko palypseE
                                            Eko palypse
                                            last edited by

                                            @Peter-Jones
                                            Still strange this crashes - I will setup a Windows10 in VirtualBox and see if I can get the same
                                            result as you have. If so, I guess it’s time to upgrade - Win7 comes to end anyway.

                                            Meta ChuhM 1 Reply Last reply Reply Quote 2
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors