forked from spillz/codeblocks-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonInterpCtrl.h
More file actions
153 lines (131 loc) · 4.29 KB
/
PythonInterpCtrl.h
File metadata and controls
153 lines (131 loc) · 4.29 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
#ifndef PPCTRL_H
#define PPCTRL_H
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "xmlrpc_embedder.h"
#include "ShellCtrlBase.h"
#include "editormanager.h"
#include "cbstyledtextctrl.h"
#include <sdk.h>
class PythonInterpCtrl;
class PythonCodeCtrl: public cbStyledTextCtrl
{
public:
PythonCodeCtrl(wxWindow *parent, PythonInterpCtrl *py);
wxArrayString m_history_commands;
wxString m_history_working;
int m_history_position;
private:
void OnUserInput(wxKeyEvent& ke);
void OnCharAdded(wxScintillaEvent& ke);
PythonInterpCtrl *m_pyctrl;
DECLARE_EVENT_TABLE()
};
class PythonIOCtrl: public wxTextCtrl
{
public:
PythonIOCtrl(wxWindow *parent, PythonInterpCtrl *py);
void OnUserInput(wxKeyEvent& ke);
void LineInputRequest();
void OnTextChange(wxCommandEvent& e);
PythonInterpCtrl *m_pyctrl;
long m_line_entry_point;
bool m_line_entry_mode;
DECLARE_EVENT_TABLE()
};
// Allocates ports for xmlrpc connections (ensures unique port allocations)
// TODO: define port as an object to automate release
class PortAllocator: public std::map<int, bool>
{
public:
PortAllocator(const wxString &portlist=_T("9000;9001;9002"))
{
SetPorts(portlist);
}
void SetPorts(wxString portlist)
{ //TODO: If new ports overlap current then use current state of the port
this->clear();
wxString portstr=portlist.BeforeFirst(';');
while(portstr!=_(""))
{
long port;
if(portstr.ToLong(&port))
if(port>0)
(*this)[port]=false;
portlist=portlist.AfterFirst(';');
portstr=portlist.BeforeFirst(';');
}
}
wxString GetPorts()
{
wxString portlist;
for(PortAllocator::iterator it=this->begin();it!=this->end();it++)
portlist+=wxString::Format(_T("%i;"),it->first);
return portlist;
}
int RequestPort() //return the first free port
{
for(PortAllocator::iterator it=this->begin();it!=this->end();it++)
if(!(it->second))
{
it->second=true;
return it->first;
}
return -1; //no ports available
}
bool ReleasePort(int port) //release port, returns false if not found
{
PortAllocator::iterator it=this->find(port);
if(it==PortAllocator::end())
return false;
it->second=false;
return true;
}
};
namespace
{
ShellCtrlRegistrant<PythonInterpCtrl> reg(_T("Python Interpreter"));
}
class PythonInterpCtrl : public ShellCtrlBase
{
friend class PythonIOCtrl;
public:
PythonInterpCtrl() { m_pyinterp=NULL; }
PythonInterpCtrl(wxWindow* parent, int id, const wxString &name, ShellManager *shellmgr=NULL);
virtual ~PythonInterpCtrl() { if (m_pyinterp) delete m_pyinterp; }
virtual long LaunchProcess(const wxString &processcmd, const wxArrayString &options);
virtual void KillProcess();
virtual void SyncOutput(int maxchars=1000); //use this to respond to ShellManager request to gather output from the running process for display in the frame
virtual bool IsDead() {if (m_pyinterp) return m_pyinterp->IsDead(); return true;}
// long GetPid() {if(m_proc) return m_procid; else return -1;}
void OnUserInput(wxKeyEvent& ke);
void OnSize(wxSizeEvent& event);
void OnPyNotify(XmlRpcResponseEvent& event);
void OnLineInputRequest(wxCommandEvent& event);
void OnPyCode(wxCommandEvent& event);
void OnEndProcess(wxCommandEvent& event);
bool DispatchCode(const wxString &code);
bool BreakCode();
static PortAllocator m_portalloc;
void stdin_append(const wxString &data);
wxString stdin_retrieve();
protected:
bool RunCode(const wxString &codestr);
bool Continue();
bool SendKill();
private:
wxString stdin_data;
PythonIOCtrl *m_ioctrl;
PythonCodeCtrl *m_codectrl;
wxSplitterWindow *m_sw;
XmlRpcInstance *m_pyinterp;
wxString m_code; //currently running code
int m_killlevel;
int m_port;
// void OnEndProcess(wxProcessEvent &event);
DECLARE_DYNAMIC_CLASS(PythonInterpCtrl)
DECLARE_EVENT_TABLE()
};
#endif // PPCTRL_H