Created
March 4, 2018 02:40
-
-
Save VintageAppMaker/9bac94c5666f1974b1b16c9f8af870aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*************************************************************** | |
* Name: wxTestMain.h | |
* Purpose: Defines Application Frame | |
* Author: () | |
* Created: 2012-11-05 | |
* Copyright: () | |
* License: | |
**************************************************************/ | |
#ifndef WXTESTMAIN_H | |
#define WXTESTMAIN_H | |
#ifndef WX_PRECOMP | |
#include <wx/wx.h> | |
#endif | |
#include "wxTestApp.h" | |
#include <wx/tglbtn.h> | |
#include <wx/gdicmn.h> | |
#include <wx/font.h> | |
#include <wx/colour.h> | |
#include <wx/settings.h> | |
#include <wx/textctrl.h> | |
#include <wx/listbox.h> | |
#include <wx/sizer.h> | |
#include <wx/dialog.h> | |
#include <wx/button.h> | |
#include <wx/statline.h> | |
class wxTestDialog: public wxDialog | |
{ | |
public: | |
wxTestDialog(wxDialog *dlg, const wxString& title); | |
~wxTestDialog(); | |
protected: | |
wxButton* m_btnSearch; | |
wxTextCtrl* m_textCtrl1; | |
public: | |
wxListBox* m_listBox1; | |
void OnDblClick(wxCommandEvent &event); | |
void OnSearch(wxCommandEvent &event); | |
private: | |
void OnClose(wxCloseEvent& event); | |
void OnQuit(wxCommandEvent& event); | |
DECLARE_EVENT_TABLE() | |
private: | |
void PythonExcute_Search(char* szName); | |
void PythonExcute_Kill(int pid); | |
}; | |
#endif // WXTESTMAIN_H | |
#ifdef WX_PRECOMP | |
#include "wx_pch.h" | |
#endif | |
#ifdef __BORLANDC__ | |
#pragma hdrstop | |
#endif //__BORLANDC__ | |
#include "wxTestMain.h" | |
#include <Python.h> | |
/* | |
일반처리 | |
*/ | |
#define MAX_QUEUE_SIZE 1024 | |
static wxTestDialog* m_dlg = NULL; | |
static int PID_LIST[MAX_QUEUE_SIZE]; | |
static int nIndx = 0; | |
// message 출력 | |
void AppendMessage(char* szMessage) | |
{ | |
wxString sMessage(szMessage, wxConvUTF8); | |
m_dlg->m_listBox1->Append( sMessage ); | |
} | |
/* | |
python 관련 함수 | |
*/ | |
static PyObject* AddProcInfo(PyObject *self, PyObject *args) | |
{ | |
char* sname; | |
int pid; | |
if(!PyArg_ParseTuple(args, "si", &sname, &pid)) | |
return NULL; | |
PID_LIST[nIndx++] = pid; | |
AppendMessage(sname); | |
return Py_BuildValue("i", 0); | |
} | |
static struct PyMethodDef methods[] = | |
{ | |
{"AddProcInfo", AddProcInfo, METH_VARARGS}, | |
{NULL, NULL} | |
}; | |
void initpylib() | |
{ | |
Py_Initialize(); | |
PyObject* sysPath = PySys_GetObject((char*)"path"); | |
PyObject* curDir = PyString_FromString("."); | |
PyList_Append(sysPath, curDir); | |
Py_InitModule3("uilib", methods, "this is ui app"); | |
} | |
void InitPIDList() | |
{ | |
memset(PID_LIST, 0, MAX_QUEUE_SIZE); | |
nIndx = 0; | |
} | |
//helper functions | |
enum wxbuildinfoformat { | |
short_f, long_f }; | |
wxString wxbuildinfo(wxbuildinfoformat format) | |
{ | |
wxString wxbuild(wxVERSION_STRING); | |
if (format == long_f ) | |
{ | |
#if defined(__WXMSW__) | |
wxbuild << _T("-Windows"); | |
#elif defined(__WXMAC__) | |
wxbuild << _T("-Mac"); | |
#elif defined(__UNIX__) | |
wxbuild << _T("-Linux"); | |
#endif | |
#if wxUSE_UNICODE | |
wxbuild << _T("-Unicode build"); | |
#else | |
wxbuild << _T("-ANSI build"); | |
#endif // wxUSE_UNICODE | |
} | |
return wxbuild; | |
} | |
// ui 관련 상수정의 | |
enum{ | |
ID_LST_PROC = wxID_HIGHEST + 1 , // declares an id which will be used to call our button | |
ID_BTN_SEARCH | |
}; | |
BEGIN_EVENT_TABLE(wxTestDialog, wxDialog) | |
EVT_CLOSE( wxTestDialog::OnClose ) | |
EVT_BUTTON ( ID_BTN_SEARCH, wxTestDialog::OnSearch ) // search 버튼 클릭 이벤트(매크로로 정의함) | |
END_EVENT_TABLE() | |
wxTestDialog::wxTestDialog(wxDialog *dlg, const wxString &title) | |
: wxDialog(dlg, -1, title) | |
{ | |
// 일반함수에서 개체를 사용하고자 함이다. | |
m_dlg = this; | |
this->SetSizeHints( wxDefaultSize, wxDefaultSize ); | |
wxBoxSizer* bSizer1; | |
bSizer1 = new wxBoxSizer( wxVERTICAL ); | |
m_btnSearch = new wxButton( this, ID_BTN_SEARCH, wxT("검색"), wxDefaultPosition, wxSize( 150,-1 ), 0 ); | |
bSizer1->Add( m_btnSearch, 0, wxALL | wxEXPAND, 5 ); | |
m_textCtrl1 = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 280,-1 ), 0 ); | |
bSizer1->Add( m_textCtrl1, 0, wxALL | wxEXPAND, 5 ); | |
m_listBox1 = new wxListBox( this, ID_LST_PROC, wxDefaultPosition, wxSize( 280,280 ), 0, NULL, 0 ); | |
bSizer1->Add( m_listBox1, 0, wxALL | wxEXPAND, 5 ); | |
// listbox의 item이 더블클릭된 경우 호출되어질 이벤트 핸들러 등록 | |
Connect(ID_LST_PROC, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler(wxTestDialog::OnDblClick)); | |
this->SetSizer( bSizer1 ); | |
this->Layout(); | |
InitPIDList(); | |
} | |
wxTestDialog::~wxTestDialog() | |
{ | |
} | |
void wxTestDialog::OnDblClick(wxCommandEvent &event) | |
{ | |
int sel = m_listBox1->GetSelection(); | |
PythonExcute_Kill( PID_LIST[sel] ); | |
if(sel > -1){ | |
//m_listBox1->Delete(sel); | |
m_listBox1->Clear(); | |
InitPIDList(); | |
wxString wxname = m_textCtrl1->GetValue(); | |
PythonExcute_Search((char*)wxname.mb_str().data()); | |
} | |
} | |
void wxTestDialog::OnSearch(wxCommandEvent &event) | |
{ | |
m_listBox1->Clear(); | |
wxString wxname = m_textCtrl1->GetValue(); | |
InitPIDList(); | |
PythonExcute_Search((char*)wxname.mb_str().data()); | |
} | |
void wxTestDialog::OnClose(wxCloseEvent &event) | |
{ | |
Destroy(); | |
} | |
void wxTestDialog::PythonExcute_Search(char* szName) | |
{ | |
const char* SCRIPT_SEARCH = "ProcessManager"; | |
// python 초기화 | |
initpylib(); | |
PyObject* name = PyString_FromString( SCRIPT_SEARCH ); | |
PyObject* ScriptModule = PyImport_Import( name ); | |
Py_DECREF(name); | |
if (!ScriptModule) | |
{ | |
PyErr_Print(); | |
return; | |
} | |
PyObject* SearchFunc = PyObject_GetAttrString(ScriptModule, "SearchFunc"); | |
Py_DECREF(ScriptModule); | |
if (!SearchFunc) | |
{ | |
PyErr_Print(); | |
return; | |
} | |
PyObject* args = Py_BuildValue("(s)", szName ); | |
if (!args) | |
{ | |
PyErr_Print(); | |
Py_DECREF(SearchFunc); | |
return; | |
} | |
PyObject* resultObj = PyObject_CallObject(SearchFunc, args); | |
Py_DECREF(SearchFunc); | |
Py_DECREF(args); | |
if (!resultObj) | |
{ | |
PyErr_Print(); | |
return; | |
} | |
Py_DECREF(resultObj); | |
Py_Finalize(); | |
} | |
void wxTestDialog::PythonExcute_Kill(int pid) | |
{ | |
const char* SCRIPT_SEARCH = "ProcessManager"; | |
// python 초기화 | |
initpylib(); | |
PyObject* name = PyString_FromString( SCRIPT_SEARCH ); | |
PyObject* ScriptModule = PyImport_Import( name ); | |
Py_DECREF(name); | |
if (!ScriptModule) | |
{ | |
PyErr_Print(); | |
return; | |
} | |
PyObject* DeleteFunc = PyObject_GetAttrString(ScriptModule, "DeleteFunc"); | |
Py_DECREF(ScriptModule); | |
if (!DeleteFunc) | |
{ | |
PyErr_Print(); | |
return; | |
} | |
PyObject* args = Py_BuildValue("(i)", pid ); | |
if (!args) | |
{ | |
PyErr_Print(); | |
Py_DECREF(DeleteFunc); | |
return; | |
} | |
PyObject* resultObj = PyObject_CallObject(DeleteFunc, args); | |
Py_DECREF(DeleteFunc); | |
Py_DECREF(args); | |
if (!resultObj) | |
{ | |
PyErr_Print(); | |
return; | |
} | |
Py_DECREF(resultObj); | |
Py_Finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment