Skip to content

Commit 09a1c0f

Browse files
committed
Option to allow appending N++ PythonLib paths, rather than inserting
This essentially allows using the old behaviour - it may be useful if someone has a local python installation, and wishes to use their own Lib paths.
1 parent 32fb919 commit 09a1c0f

4 files changed

Lines changed: 39 additions & 18 deletions

File tree

PythonScript/res/PythonScript.rc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ BEGIN
7373
LTEXT ">>>",IDC_PROMPT,7,161,17,8
7474
END
7575

76-
IDD_SCRIPTCONFIG DIALOGEX 0, 0, 376, 325
76+
IDD_SCRIPTCONFIG DIALOGEX 0, 0, 376, 363
7777
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
7878
CAPTION "Python Script Shortcut Configuration"
7979
FONT 8, "MS Shell Dlg", 400, 0, 0x1
8080
BEGIN
81-
DEFPUSHBUTTON "OK",IDOK,265,304,50,14
82-
PUSHBUTTON "Cancel",IDCANCEL,319,304,50,14
81+
DEFPUSHBUTTON "OK",IDOK,265,342,50,14
82+
PUSHBUTTON "Cancel",IDCANCEL,319,342,50,14
8383
CONTROL "",IDC_FILETREE,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,14,31,343,105
8484
GROUPBOX "Scripts",IDC_STATIC,7,7,362,136
8585
CONTROL "Machine Scripts",IDC_RADMACHINE,"Button",BS_AUTORADIOBUTTON,19,18,65,10
@@ -96,6 +96,9 @@ BEGIN
9696
COMBOBOX IDC_COMBOINITIALISATION,58,285,69,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
9797
LTEXT "Initialisation:",IDC_STATIC,9,287,44,12
9898
LTEXT "Lazy initialisation initialises Python when it is first used. Use ATSTARTUP if you want your startup.py scripts to run as soon as Notepad++ starts.",IDC_STATIC,131,282,232,21
99+
CONTROL "Prefer installed Python libraries - use only if you have Python 2.7 installed, and you have copied the python27.dll from your Windows directory to the Notepad++ directory. ",IDC_CHECKPREFERINSTALLEDPYTHON,
100+
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | WS_TABSTOP,11,303,352,19
101+
LTEXT "This has the effect that the directories under Notepad++ that contain Python libraries are searched AFTER the standard Python directories. If in doubt, leave unchecked.",IDC_STATIC,21,321,348,19
99102
END
100103

101104
IDD_PROMPTDIALOG DIALOGEX 0, 0, 313, 105
@@ -139,7 +142,7 @@ BEGIN
139142
LEFTMARGIN, 7
140143
RIGHTMARGIN, 369
141144
TOPMARGIN, 7
142-
BOTTOMMARGIN, 318
145+
BOTTOMMARGIN, 356
143146
END
144147

145148
IDD_PROMPTDIALOG, DIALOG

PythonScript/res/resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@
3737
#define IDC_USERTEXT 1017
3838
#define IDC_COPYRIGHT 1018
3939
#define IDC_VERSION 1019
40+
#define IDC_CHECKPREFERINSTALLEDPYTHON 1020
4041

4142
// Next default values for new objects
4243
//
4344
#ifdef APSTUDIO_INVOKED
4445
#ifndef APSTUDIO_READONLY_SYMBOLS
4546
#define _APS_NEXT_RESOURCE_VALUE 119
4647
#define _APS_NEXT_COMMAND_VALUE 40001
47-
#define _APS_NEXT_CONTROL_VALUE 1020
48+
#define _APS_NEXT_CONTROL_VALUE 1021
4849
#define _APS_NEXT_SYMED_VALUE 101
4950
#endif
5051
#endif

PythonScript/src/PythonHandler.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "MenuManager.h"
1111
#include "WcharMbcsConverter.h"
1212
#include "GILManager.h"
13+
#include "ConfigFile.h"
1314

1415
namespace NppPythonScript
1516
{
@@ -110,14 +111,26 @@ void PythonHandler::initPython()
110111

111112
// Init paths
112113
char initBuffer[1024];
114+
char pathCommands[500];
115+
116+
// If the user wants to use their installed python version, append the paths.
117+
// If not (and they want to use the bundled python install), the default, then prepend the paths
118+
if (ConfigFile::getInstance()->getSetting(_T("PREFERINSTALLEDPYTHON")) == _T("1")) {
119+
strcpy_s<500>(pathCommands, "import sys\n"
120+
"sys.path.append(r'%slib'%s)\n"
121+
"sys.path.append(r'%slib'%s)\n"
122+
"sys.path.append(r'%sscripts'%s)\n"
123+
"sys.path.append(r'%sscripts'%s)\n");
124+
} else {
125+
strcpy_s<500>(pathCommands, "import sys\n"
126+
"sys.path.insert(0,r'%slib'%s)\n"
127+
"sys.path.insert(1,r'%slib'%s)\n"
128+
"sys.path.insert(2,r'%sscripts'%s)\n"
129+
"sys.path.insert(3,r'%sscripts'%s)\n");
130+
}
113131

114132
_snprintf_s(initBuffer, 1024, 1024,
115-
"import sys\n"
116-
"sys.path.insert(0,r'%slib'%s)\n"
117-
"sys.path.insert(1,r'%slib'%s)\n"
118-
"sys.path.insert(2,r'%sscripts'%s)\n"
119-
"sys.path.insert(3,r'%sscripts'%s)\n",
120-
133+
pathCommands,
121134
smachineDir.c_str(),
122135
machineIsUnicode ? ".decode('utf8')" : "",
123136

@@ -135,12 +148,6 @@ void PythonHandler::initPython()
135148
// Init Notepad++/Scintilla modules
136149
initModules();
137150

138-
/* Old manual version of PyEval_SaveThread()
139-
mp_mainThreadState = PyThreadState_Get();
140-
PyThreadState_Swap(NULL);
141-
142-
PyEval_ReleaseLock();
143-
*/
144151
mp_mainThreadState = PyEval_SaveThread();
145152

146153
}

PythonScript/src/ShortcutDlg.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ void ShortcutDlg::populateCurrentItems()
500500
ComboBox_SetCurSel(m_hComboInitialisation, 0);
501501
}
502502

503+
if (configFile->getSetting(_T("PREFERINSTALLEDPYTHON")) == _T("1")) {
504+
CheckDlgButton(_hSelf, IDC_CHECKPREFERINSTALLEDPYTHON, BST_CHECKED);
505+
} else {
506+
CheckDlgButton(_hSelf, IDC_CHECKPREFERINSTALLEDPYTHON, BST_UNCHECKED);
507+
}
503508
}
504509

505510

@@ -524,9 +529,14 @@ void ShortcutDlg::saveConfig()
524529
TCHAR startupBuffer[50];
525530
ComboBox_GetText(m_hComboInitialisation, startupBuffer, 50);
526531
configFile->setSetting(_T("STARTUP"), startupBuffer);
532+
533+
if (BST_CHECKED == IsDlgButtonChecked(_hSelf, IDC_CHECKPREFERINSTALLEDPYTHON)) {
534+
configFile->setSetting(_T("PREFERINSTALLEDPYTHON"), _T("1"));
535+
} else {
536+
configFile->setSetting(_T("PREFERINSTALLEDPYTHON"), _T("0"));
537+
}
527538

528539
configFile->save();
529-
530540
}
531541

532542

0 commit comments

Comments
 (0)