Repository navigation
Expand file tree
/
Copy pathPythonInterpreter.cpp
More file actions
257 lines (230 loc) · 8.24 KB
/
Copy pathPythonInterpreter.cpp
File metadata and controls
257 lines (230 loc) · 8.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "PythonInterpreter.h"
#include <configurationpanel.h>
#include <wx/regex.h>
//#include "ConfigDialog.h"
#ifdef TOOLSPLUSLINK
#include "ToolsPlus.h"
#endif
// Register the plugin with Code::Blocks.
// We are using an anonymous namespace so we don't litter the global one.
namespace
{
PluginRegistrant<PythonInterpreter> reg(_T("PythonInterpreter"));
}
bool WildCardListMatch(wxString list, wxString name)
{
if(list==_T("")) //any empty list matches everything by default
return true;
wxString wildlist=list;
wxString wild=list.BeforeFirst(';');
while(wildlist!=_T(""))
{
if(wild!=_T("") && ::wxMatchWild(wild,name))
return true;
wildlist=wildlist.AfterFirst(';');
wild=wildlist.BeforeFirst(';');
}
return false;
}
int ID_LangMenu_Settings=wxNewId();
int ID_LangMenu_Run=wxNewId();
int ID_LangMenu_DebugSendCommand=wxNewId();
int ID_LangMenu_ShowWatch=wxNewId();
int ID_LangMenu_UpdateWatch=wxNewId();
int ID_PipedProcess=wxNewId();
int ID_TimerPollDebugger=wxNewId();
//assign menu IDs to correspond with toolbar buttons
int ID_LangMenu_RunPiped = wxNewId();//XRCID("idPyDebuggerMenuDebug");
// events handling
BEGIN_EVENT_TABLE(PythonInterpreter, cbToolPlugin)
// add any events you want to handle here
// EVT_MENU(ID_LangMenu_Run,PythonInterpreter::OnRun)
// EVT_MENU(ID_LangMenu_RunPiped,PythonInterpreter::OnDebugTarget)
// EVT_MENU(XRCID("idPyDebuggerMenuDebug"),PythonInterpreter::OnContinue)
// EVT_MENU(XRCID("idPyDebuggerMenuNext"),PythonInterpreter::OnNext)
// EVT_MENU(XRCID("idPyDebuggerMenuStep"),PythonInterpreter::OnStep)
// EVT_MENU(XRCID("idPyDebuggerMenuStop"),PythonInterpreter::OnStop)
// EVT_MENU(ID_LangMenu_DebugSendCommand,PythonInterpreter::OnSendCommand)
// EVT_MENU(ID_LangMenu_ShowWatch,PythonInterpreter::OnViewWatch)
// EVT_MENU(ID_LangMenu_UpdateWatch,PythonInterpreter::OnUpdateWatch)
// EVT_END_PROCESS(ID_PipedProcess, PythonInterpreter::OnTerminatePipedProcess)
// EVT_TIMER(ID_TimerPollDebugger, PythonInterpreter::OnTimer)
END_EVENT_TABLE()
// constructor
PythonInterpreter::PythonInterpreter()
{
// Make sure our resources are available.
// In the generated boilerplate code we have no resources but when
// we add some, it will be nice that this code is in place already ;)
// if(!Manager::LoadResource(_T("PythonInterpreter.zip")))
// {
// NotifyMissingFile(_T("PythonInterpreter.zip"));
// }
}
cbConfigurationPanel* PythonInterpreter::GetConfigurationPanel(wxWindow* parent)
{
// MyDialog* dlg = new MyDialog(this, *m_pKeyProfArr, parent,
// wxT("Keybindings"), mode);
return 0;
// return new ConfigDialog(parent, this);
}
// destructor
PythonInterpreter::~PythonInterpreter()
{
}
void PythonInterpreter::OnAttach()
{
#ifndef TOOLSPLUSLINK
m_shellmgr = new ShellManager(Manager::Get()->GetAppWindow());
CodeBlocksDockEvent evt(cbEVT_ADD_DOCK_WINDOW);
evt.name = _T("PythonWindow");
evt.title = _("Python Interpreters");
evt.pWindow = m_shellmgr;
evt.dockSide = CodeBlocksDockEvent::dsFloating;
evt.desiredSize.Set(400, 300);
evt.floatingSize.Set(400, 300);
evt.minimumSize.Set(200, 150);
Manager::Get()->ProcessEvent(evt);
CodeBlocksDockEvent evt2(cbEVT_SHOW_DOCK_WINDOW);
evt2.pWindow = m_shellmgr;
Manager::Get()->ProcessEvent(evt2);
wxArrayString as;
m_shellmgr->LaunchProcess(_T(""),_T("Python"),_("Python Interpreter"),as);
m_shellmgr->Enable();
#endif
}
void PythonInterpreter::OnRelease(bool appShutDown)
{
#ifndef TOOLSPLUSLINK
if (m_shellmgr) //remove the Shell Terminals Notebook from its dockable window and delete it
{
CodeBlocksDockEvent evt(cbEVT_REMOVE_DOCK_WINDOW);
evt.pWindow = m_shellmgr;
Manager::Get()->ProcessEvent(evt);
m_shellmgr->Destroy();
}
m_shellmgr = 0;
#endif
}
int PythonInterpreter::Execute()
{
#ifdef TOOLSPLUSLINK
ToolsPlus *tp = dynamic_cast<ToolsPlus*>(Manager::Get()->GetPluginManager()->FindPluginByName(_T("ToolsPlus")));
wxArrayString as;
if (tp && tp->IsAttached())
return tp->LaunchProcess(_T(""),_T("Python"),_T("Python Interpreter"),as);
else
return -1;
#else
CodeBlocksDockEvent evt(cbEVT_SHOW_DOCK_WINDOW);
evt.pWindow = m_shellmgr;
Manager::Get()->ProcessEvent(evt);
wxArrayString as;
return m_shellmgr->LaunchProcess(_T(""),_T("Python"),_("Python Interpreter"),as);
#endif
}
int PythonInterpreter::Configure()
{
//create and display the configuration dialog for the plugin
cbConfigurationDialog dlg(Manager::Get()->GetAppWindow(), wxID_ANY, _("Python Language Properties"));
cbConfigurationPanel* panel = GetConfigurationPanel(&dlg);
if (panel)
{
dlg.AttachConfigurationPanel(panel);
PlaceWindow(&dlg);
return dlg.ShowModal() == wxID_OK ? 0 : -1;
}
return -1;
}
void PythonInterpreter::BuildMenu(wxMenuBar* menuBar)
{
//The application is offering its menubar for your plugin,
//to add any menu items you want...
//Append any items you need in the menu...
//NOTE: Be careful in here... The application's menubar is at your disposal.
// LangMenu=new wxMenu;
// CreateMenu();
// int pos = menuBar->FindMenu(_T("Plugins"));
// if(pos!=wxNOT_FOUND)
// menuBar->Insert(pos, LangMenu, _T("P&yDebug"));
// else
// {
// delete LangMenu;
// LangMenu=0;
// }
}
void PythonInterpreter::BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data)
{
//Some library module is ready to display a pop-up menu.
//Check the parameter \"type\" and see which module it is
//and append any items you need in the menu...
//TIP: for consistency, add a separator as the first item...
// if(type==mtProjectManager)
// {
// if(data)
// {
// if(data->GetKind()==FileTreeData::ftdkFile)
// {
// ProjectFile *f=data->GetProjectFile();
// if(f)
// {
// wxString name=f->file.GetFullPath();
// wxString ext=f->file.GetExt();
// if(IsPythonFile(name))
// {
// m_RunTarget=name;
// m_RunTargetSelected=true;
// menu->AppendSeparator();
//// menu->Append(ID_LangMenu_Run,_T("Python Run"),_T(""));
// menu->Append(ID_LangMenu_RunPiped,_T("Python Debug"),_T(""));
// }
// }
// }
// }
// }
// if(type==mtEditorManager) // also type==mtOpenFilesList - not sure how to find out which file has been right clicked.
// {
// EditorManager* edMan = Manager::Get()->GetEditorManager();
// wxFileName activefile(edMan->GetActiveEditor()->GetFilename());
// wxString name=activefile.GetFullPath();
// if(IsPythonFile(name))
// {
// m_RunTarget=name;
// m_RunTargetSelected=true;
// menu->AppendSeparator();
//// menu->Append(ID_LangMenu_Run,_T("Python Run"),_T(""));
// menu->Append(ID_LangMenu_RunPiped,_T("Python Debug"),_T(""));
//
// }
// }
// if(type==mtUnknown) // also type==mtOpenFilesList - not sure how to find out which file has been right clicked.
// {
// if(data->GetKind()==FileTreeData::ftdkFile) //right clicked on folder in file explorer
// {
// wxFileName f(data->GetFolder());
// wxString filename=f.GetFullPath();
// wxString name=f.GetFullName();
//// cbMessageBox(filename+_T(" ")+name);
// if(IsPythonFile(name))
// {
// m_RunTarget=filename;
// m_RunTargetSelected=true;
// menu->AppendSeparator();
//// menu->Append(ID_LangMenu_Run,_T("Python Run"),_T(""));
// menu->Append(ID_LangMenu_RunPiped,_T("Python Debug"),_T(""));
//
// }
// }
// }
}
bool PythonInterpreter::BuildToolBar(wxToolBar* toolBar)
{
// m_pTbar = toolBar;
// /* Loads toolbar using new Manager class functions */
// if (!IsAttached() || !toolBar)
// return false;
// wxString my_16x16=Manager::isToolBar16x16(toolBar) ? _T("_16x16") : _T("");
// Manager::AddonToolBar(toolBar,wxString(_T("py_debugger_toolbar"))+my_16x16);
// toolBar->Realize();
return true;
}