Skip to content

Latest commit

 

History

History

readme.md

WinDialog Module

The WinDialog module is a simple wrapper around the DialogBoxIndirectParam function and the controls used in a dialog. It provides an easy way to create and interact with dialogs in Notepad++ using the PythonScript plugin.

Installation

Please note that PythonScript version 3.0.16 is required!

Copy the complete WinDialog directory into your user config lib directory. For example via the menu

  • Plugins->Open Plugins Folder...
  • Change to Config
  • Change to PythonScript.
  • Create a directory named lib
  • Change to lib and copy the WinDialog directory there.
  • Restart Npp

Usage and Examples

To use the WinDialog module, follow these steps:

  1. Create a dialog and its controls using a resource editor or by defining it programmatically.
  2. Define the properties and event handlers.
  3. Call the show() method of the WinDialog instance to display the dialog and start the message loop.

Here are two basic example of creating a dialog with two buttons. The first one creates the dialog based on resource code generated by ResourceHacker. The second example creates the same dialog using the respective classes directly.

from WinDialog import Dialog, Button, create_dialog_from_rc

rc = '''
1 DIALOGEX 0, 0, 250, 100
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Test Dialog"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
FONT 9, "Segoe UI"
{
   CONTROL "&Okay", 1, BUTTON, BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 130, 78, 50, 11 , 0x00000000
   CONTROL "&Close Dialog", 2, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 187, 78, 50, 11 , 0x00000000
}
'''
dlg = create_dialog_from_rc(rc_code=rc)
dlg.button_1.onClick = lambda: print('oookaayyy')
dlg.button_2.onClick = dlg.terminate
dlg.center = True
dlg.show()
from WinDialog import Dialog, Button

class MyDialog(Dialog):
    def __init__(self, title='Test Dialog'):
        super().__init__(title)
        self.size = (250, 100)
        self.btn1 = Button(title='&Okay', size=(50, 11), position=(130, 78))
        self.btn1.onClick = lambda: print('oookaayyy')
        self.btn2 = Button(title='&Close Dialog', size=(50, 11), position=(187, 78))
        self.btn2.onClick = self.on_close
        self.center = True
        self.show()

    def on_close(self):
        self.terminate()

MyDialog()

For more detailed usage instructions and additional examples, please refer to the __tests__ directory and help(WinDialog) documentation.

but if you still have questions, don't hesitate ... to read the code ;-)

License

This module is released under the MIT License.