• Login
Community
  • Login

Little Dialog-wrapper for PythonScript

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
74 Posts 8 Posters 13.3k 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.
  • A
    Alan Kilborn
    last edited by Apr 24, 2023, 11:27 AM

    I wanted to use this in place of the “cheesy UI” in the script I linked earlier. When running that script, the first thing it prompts for is the regex and for that it needs an edit box so the user can supply it.

    I hit a stopper right away as I don’t see an edit box type control in the “Little Dialog-wrapper”. @Ekopalypse, is this correct, there isn’t support for such a control?

    Maybe the idea is to use notepad.prompt() for that, as it provides only an edit box, and then use your wrapper to gather other input? This is doable, but it breaks up the gathering of input into 2 stages when ideally it would all be on one input form. Granted, it IS done in 2 stages with the “cheesy UI” approach, but that whole thing is rather a hack.

    E 1 Reply Last reply Apr 24, 2023, 12:41 PM Reply Quote 2
    • E
      Ekopalypse @Alan Kilborn
      last edited by Apr 24, 2023, 12:41 PM

      @Alan-Kilborn said in Little Dialog-wrapper for PythonScript:

      is this correct, there isn’t support for such a control?

      That’s right, the idea was that you can use this “framework” to extend it to your needs.
      For example, to create an edit control, you need to do the following steps.

      1. create a file called e.g. NPPDIR\plugins\Config\PythonScript\lib\WinDialog\editbox.py
      2. import the things this class needs from dialog_template.py, win_helper.py etc… (you may need to define, create some more functions here too)
      3. create a class that inherits from Control, e.g. TextBox(Control)
      4. create the class methods needed to interact with the control
      5. make this available to the WinDialog object by adding it to the __all__ attribute of the __init__.py file
        and import it from .editbox import TextBox.

      That’s it, now you should be able to use it in a script.

      1 Reply Last reply Reply Quote 1
      • E
        Ekopalypse
        last edited by Apr 25, 2023, 2:10 PM

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • E
          Ekopalypse
          last edited by Apr 26, 2023, 8:46 PM

          And then I thought, what if … trailer … :-D

          M 2 Replies Last reply Apr 26, 2023, 10:38 PM Reply Quote 4
          • M
            Michael Vincent @Ekopalypse
            last edited by Apr 26, 2023, 10:38 PM

            @Ekopalypse said in Little Dialog-wrapper for PythonScript:

            And then I thought, what if … trailer … :-D

            Oh no you didn’t …

            … you did.

            That’s AWESOME!

            Cheers.

            E 1 Reply Last reply Apr 27, 2023, 8:41 AM Reply Quote 2
            • E
              Ekopalypse @Michael Vincent
              last edited by Apr 27, 2023, 8:41 AM

              @Michael-Vincent

              Thx, the only “issue” I see at the moment is how to name the instances of the automatically created controls.
              In the example below you see names like button3 and syslistview322, which are basically the second and third parameters of the rc definitions combined.

              rc = '''
              1 DIALOGEX 10, 100, 250, 100
              STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
              CAPTION "Git Status"
              LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
              FONT 19, "Ink Free"
              {
                 CONTROL "&OK", 3, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 130, 78, 50, 11
                 CONTROL "&Cancel", 4, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 187, 78, 50, 11
                 CONTROL "", 1, EDIT, ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 3, 4, 242, 14
                 CONTROL "", 2, "SysListView32", LVS_REPORT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 5, 20, 240, 48
              }
              '''
              
              def on_cancel(wparam, lparam): ...
              
              def on_commit(wparam, lparam): ...
              
              
              dlg = create_dialog_from_rc(rc_code=rc)
              # dlg.center = True
              dlg.button3.callback = on_commit
              dlg.button4.callback = on_cancel
              dlg.syslistview322.intialize_needed = True
              dlg.syslistview322.columns = ['Changed Files', 'Status']
              dlg.syslistview322.rows = get_status()
              dlg.show()
              

              I don’t like this. I’m currently thinking about changing the CONTROL statement to something like this

                 ...
                 CONTROL_my_listview "", 2, "SysListView32", LVS_REPORT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 5, 20, 240, 48
                 ...
              dlg.my_listview.intialize_needed = True
              dlg.my_listview.columns = ['Changed files', 'Status']
              dlg.my_listview.rows = get_status()
              

              which would not break the structure of the control statement, and looks nicer to me if referenced in the code.
              A bit more effort to type, but I think it’s defensible.
              If anyone has another idea, let me know.

              P 1 Reply Last reply Apr 27, 2023, 1:34 PM Reply Quote 1
              • P
                PeterJones @Ekopalypse
                last edited by PeterJones Apr 27, 2023, 1:52 PM Apr 27, 2023, 1:34 PM

                @Ekopalypse said in Little Dialog-wrapper for PythonScript:

                If anyone has another idea, let me know.

                it sticks in my craw to have to manually edit the RC text. At some point, users may want to just read an external .rc file without having to edit it.

                Since RC Files accept c-style comments, I might suggest a two-pronged approach

                1. If a CONTROL line ends in a // ps.XXXX or /* ps.XXXX */ , then use the XXXX as the name
                2. If not, then use the SysListView32_2 or similar (I would suggest an underscore separator between the two)

                But that’s just my preference. Really, however you define it, I will end up accepting it as better than what we have now (especially if the EDIT control is implemented, as your trailer&example implies).

                Actually, once you get it working sufficiently, I might recommend you submit a PR to see if PS3 will accept it as an additional top-level class (Notepad, Editor, Console, Dialog)

                -----
                edit: I have been informed I was confusing by saying it bothered me to have to edit the RC, and then suggested editing the RC. My implication, though it obviously wasn’t communicated properly, is that with a two-step process, you can edit the RC file to add a comment, to then be able to influence the naming convention for controls in Python Script. But if you don’t want to edit the RC file, you don’t have to, because if there aren’t comments matching the pattern, then it will fall back / default to using the control type and control number, which are always found in the RC file whether edited or not.

                M 1 Reply Last reply Apr 27, 2023, 2:26 PM Reply Quote 4
                • M
                  Michael Vincent @PeterJones
                  last edited by Apr 27, 2023, 2:26 PM

                  @PeterJones said in Little Dialog-wrapper for PythonScript:

                  it sticks in my craw to have to manually edit the RC text. At some point, users may want to just read an external .rc file without having to edit it.
                  Since RC Files accept c-style comments, I might suggest a two-pronged approach

                  If a CONTROL line ends in a // ps.XXXX or /* ps.XXXX */ , then use the XXXX as the name
                  If not, then use the SysListView32_2 or similar (I would suggest an underscore separator between the two)

                  Very much like that idea - using an .rc file as-is would be awesome! Adding a comment for better PythonScript naming is easy and won’t interfere with RC file format.

                  Cheers.

                  1 Reply Last reply Reply Quote 3
                  • E
                    Ekopalypse
                    last edited by Ekopalypse Apr 28, 2023, 8:07 AM Apr 28, 2023, 8:06 AM

                    Using comments seems like a reasonable approach,
                    and I’ll use the one-line comment that needs to be
                    at the end so the location is known in advance.
                    The use of the underscore is also reasonable.
                    Reading rc files, especially those created by Visual Studio (VS), sounds good,
                    but you need to know that I don’t plan to write an rc compiler myself.
                    The word “simple” in the first post is not by chance, unfortunately ;-(.
                    The generated rc files support macros and preprocessor directives … which I’m not trying to implement,
                    as that might require loading additional header files to determine which value is actually set.
                    That is, if the rc file does not match the implemented parser logic, I leave it to the inclined user to implement it :-)
                    And right now my parser logic is REALLY simple :-D
                    As for a PS-PR, let’s see. I have something else in mind, namely that PS offers additional docked dialogs that can be created by a PS script.
                    That would then mean that you can really create plugin-like functionality with PS.

                    A 2 Replies Last reply Apr 28, 2023, 12:22 PM Reply Quote 4
                    • A
                      Alan Kilborn @Ekopalypse
                      last edited by Apr 28, 2023, 12:22 PM

                      @Ekopalypse said in Little Dialog-wrapper for PythonScript:

                      I have something else in mind, namely that PS offers additional docked dialogs that can be created by a PS script.
                      That would then mean that you can really create plugin-like functionality with PS.

                      This is intriguing but I’m curious how one aspect would work.

                      Currently it is “discouraged” (by PS itself) to attempt to run multiple scripts at the same time. If you had such a “docked dialog” open (I presume its controlling script would be “running”); would it still be possible to run other scripts, e.g. from the PS menu?

                      If the “docked dialog” were modal, then this isn’t a concern (because it wouldn’t be possible to get to the PS menu). But the current plugin approach to a panel in a docked dialog is that it is modeless…

                      1 Reply Last reply Reply Quote 2
                      • A
                        Alan Kilborn @Ekopalypse
                        last edited by Apr 28, 2023, 12:52 PM

                        @Ekopalypse said in Little Dialog-wrapper for PythonScript:

                        Using comments seems like a reasonable approach,
                        and I’ll use the one-line comment that needs to be
                        at the end so the location is known in advance.

                        If one designs a dialog, then puts such comments in, THEN decides the UI needs more work…

                        Can the resource editing tool handle this, and KEEP the custom comments? Or would the comments be lost by such editing and need to be recreated when the revised dialog UI is ready for use again?

                        E 1 Reply Last reply Apr 28, 2023, 5:49 PM Reply Quote 0
                        • E
                          Ekopalypse @Alan Kilborn
                          last edited by Apr 28, 2023, 5:49 PM

                          @Alan-Kilborn

                          Can the resource editing tool handle this

                          This depends on the tool you use, ResourceHacker doesn’t seem to be able to do this. But the idea is rather that you use the design tool until you are satisfied with the result and then copy the generated code into the Python script to reuse it.
                          If you need to add an additional control at a later time, then all you have to do is copy the newly generated line.

                          This is intriguing but …

                          Of course, these dialogs would not be modal and you have to be careful about the objects you create, i.e. don’t use these objects for something else or delete them, but that is already the case today as well.

                          A 1 Reply Last reply Apr 28, 2023, 6:00 PM Reply Quote 0
                          • A
                            Alan Kilborn @Ekopalypse
                            last edited by Apr 28, 2023, 6:00 PM

                            @Ekopalypse said in Little Dialog-wrapper for PythonScript:

                            If you need to add an additional control at a later time, then all you have to do is copy the newly generated line.

                            Sure, easy enough for one control, one line.
                            I was more thinking about how I tend to do things… on a greater than 1 line basis. :-)

                            but that is already the case today as well.

                            Today we don’t have to think about script concurrency, because PS mostly prevents it. Anyway, just thought I’d raise the question.

                            E 1 Reply Last reply Apr 28, 2023, 6:03 PM Reply Quote 0
                            • E
                              Ekopalypse @Alan Kilborn
                              last edited by Apr 28, 2023, 6:03 PM

                              @Alan-Kilborn

                              oh no, it’s not a concurrency issue, it’s more like the callbacks we use today - event driven.
                              The script starts the dialog and ends. But the class that manages the dialog stays active until the dialog is closed.

                              1 Reply Last reply Reply Quote 3
                              • M
                                Michael Vincent @Ekopalypse
                                last edited by May 18, 2023, 11:46 PM

                                @Ekopalypse said in Little Dialog-wrapper for PythonScript:

                                And then I thought, what if … trailer … :-D

                                Any alpha / beta version ready to test yet? I keep checking your repo but don’t see any new commits. I have a pretty easy use case in mind - an edit box with checkboxes for regex and case insensitive - all for a filter search lifted from @Alan-Kilborn 's work!

                                Integrating my supreme Notepad++ experience by standing on the shoulders of giants!

                                Cheers.

                                E 2 Replies Last reply May 19, 2023, 6:32 AM Reply Quote 2
                                • E
                                  Ekopalypse @Michael Vincent
                                  last edited by May 19, 2023, 6:32 AM

                                  @Michael-Vincent

                                  Hi, I have quite a lot on my plate privately at the moment, but I promise to upload a new version this weekend.
                                  It’s actually going quite well and if you stick to what’s currently implemented, there shouldn’t be any difficulties. Sorry for the delays.

                                  1 Reply Last reply Reply Quote 2
                                  • E
                                    Ekopalypse @Michael Vincent
                                    last edited by May 20, 2023, 9:09 PM

                                    @Michael-Vincent

                                    Repo has been updated, but be warned that I’m not completely satisfied yet, which means it’s not API stable. Further updates could break things that currently work.

                                    E 1 Reply Last reply May 21, 2023, 6:56 AM Reply Quote 1
                                    • E
                                      Ekopalypse @Ekopalypse
                                      last edited by Ekopalypse May 21, 2023, 6:57 AM May 21, 2023, 6:56 AM

                                      @Michael-Vincent

                                      There was a typo that prevented the dialog from being created.
                                      I should have tested it before, sorry. Is fixed now.

                                      M 1 Reply Last reply May 24, 2023, 10:17 PM Reply Quote 1
                                      • M
                                        Michael Vincent @Ekopalypse
                                        last edited by May 24, 2023, 10:17 PM

                                        @Ekopalypse

                                        Great! I have my small example:

                                        from WinDialog import Button, Dialog, CheckBoxButton, Label, TextBox
                                        from WinDialog.controls.button import BM, BST
                                        from WinDialog.win_helper import SendMessage
                                        
                                        user_input = ''
                                        REGEX      = True
                                        IGNORECASE = True
                                        
                                        class FilerLinesEditDlg(Dialog):
                                            def __init__(self):
                                                super().__init__(            title='Filter Lines Editing', size=(250, 75), center = True)
                                                self.label  = Label(         title='Filter for:'         , position=(10, 12),  size=(30, 11) )
                                                self.edit   = TextBox(                                     position=(45, 10),  size=(195, 14) )
                                                self.case   = CheckBoxButton(title='Case Sensitive'      , position=(45, 30),  size=(80, 14)  )
                                                self.regex  = CheckBoxButton(title='Regular Expression'  , position=(145, 30), size=(80, 14)  )
                                                self.ok     = Button(        title='OK'                  , position=(130, 55), size=(50, 11)  )
                                                self.cancel = Button(        title='Cancel'              , position=(187, 55), size=(50, 11)  )
                                        
                                                self.ok.on_click     = self.on_ok
                                                self.cancel.on_click = self.on_cancel
                                                self.case.on_click   = self.on_case
                                                self.regex.on_click  = self.on_regex
                                                self.show()
                                        
                                            def initialize(self):
                                                global IGNORECASE
                                                global REGEX
                                                SendMessage(self.case.hwnd, BM.SETCHECK, IGNORECASE, 0)
                                                SendMessage(self.regex.hwnd, BM.SETCHECK, REGEX, 0)
                                        
                                            def on_ok(self):
                                                global user_input
                                                user_input = self.edit.get_text()
                                                self.terminate()
                                        
                                            def on_cancel(self):
                                                global user_input
                                                user_input = None
                                                self.terminate()
                                        
                                            def on_case(self):
                                                global IGNORECASE
                                                check = SendMessage(self.case.hwnd, BM.GETCHECK, 0, 0)
                                                if check & BST.CHECKED:
                                                    IGNORECASE = True
                                                else:
                                                    IGNORECASE = False
                                        
                                            def on_regex(self):
                                                global REGEX
                                                check = SendMessage(self.regex.hwnd, BM.GETCHECK, 0, 0)
                                                if check & BST.CHECKED:
                                                    REGEX = True
                                                else:
                                                    REGEX = False
                                        
                                        
                                        FilerLinesEditDlg()
                                        
                                        print(f"User:  {user_input}")
                                        print(f"Case:  {IGNORECASE}")
                                        print(f"Regex: {REGEX}")
                                        

                                        It seems to run correctly and prints status to the PythonScript console. I plan to integrate this into a larger script.

                                        I’m not sure I did the checkbox stuff correctly. It works, but I had to import some extra classes and the SendMessage function from your helper library. Did I do this right?

                                        Cheers.

                                        E 1 Reply Last reply May 25, 2023, 5:42 AM Reply Quote 2
                                        • E
                                          Ekopalypse @Michael Vincent
                                          last edited by May 25, 2023, 5:42 AM

                                          @Michael-Vincent

                                          You can do it this way, but I personally would put the globals as attributes in the class to avoid globals in the first place.
                                          For the GETCHECK, because the checkbox is a “boolean” value, I would do something like: …

                                          ...
                                              def on_case(self):
                                                  self.IGNORECASE = not self.IGNORECASE
                                          ...
                                          dlg = FilerLinesEditDlg()
                                          
                                          print(f"User:  {dlg.user_input}")
                                          print(f"Case:  {dlg.IGNORECASE}")
                                          print(f"Regex: {dlg.REGEX}")
                                          

                                          As for the SETCHECK, the SendMessage function is currently required.
                                          The next version, uploaded this weekend, will have a checkbox button method setCheckState (that’s the same kind of naming PS does … so it seems to make the most sense, right?). And now that I think about it, getCheckState makes sense too because of the 3-state checkboxes. Also, the next version will be able to handle IDOK and IDCANCEL, which means you can close a dialog with ESC and trigger the execution of the edit with ENTER.

                                          M 1 Reply Last reply May 25, 2023, 1:05 PM Reply Quote 3
                                          • First post
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors