Skip to content

Commit 59b7fa8

Browse files
committed
Added support for wxwidgets. Closes #27.
1 parent 646afca commit 59b7fa8

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

dependencies.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,72 @@ def check_pkgconfig(self):
135135
def found(self):
136136
return self.is_found
137137

138+
class WxDependency(Dependency):
139+
wx_found = None
140+
141+
def __init__(self, kwargs):
142+
Dependency.__init__(self)
143+
if WxDependency.wx_found is None:
144+
self.check_wxconfig()
145+
146+
if not WxDependency.wx_found:
147+
raise DependencyException('Wx-config not found.')
148+
self.is_found = False
149+
p = subprocess.Popen(['wx-config', '--version'], stdout=subprocess.PIPE,
150+
stderr=subprocess.PIPE)
151+
out = p.communicate()[0]
152+
if p.returncode != 0:
153+
mlog.log('Dependency wxwidgets found:', mlog.red('NO'))
154+
self.cargs = []
155+
self.libs = []
156+
self.is_found = False
157+
else:
158+
mlog.log('Dependency wxwidgets found:', mlog.green('YES'))
159+
self.is_found = True
160+
self.modversion = out.decode().strip()
161+
# wx-config seems to have a cflags as well but since it requires C++,
162+
# this should be good, at least for now.
163+
p = subprocess.Popen(['wx-config', '--cxxflags'], stdout=subprocess.PIPE,
164+
stderr=subprocess.PIPE)
165+
out = p.communicate()[0]
166+
if p.returncode != 0:
167+
raise RuntimeError('Could not generate cargs for wxwidgets.')
168+
self.cargs = out.decode().split()
169+
170+
p = subprocess.Popen(['wx-config', '--libs'], stdout=subprocess.PIPE,
171+
stderr=subprocess.PIPE)
172+
out = p.communicate()[0]
173+
if p.returncode != 0:
174+
raise RuntimeError('Could not generate libs for wxwidgets.')
175+
self.libs = out.decode().split()
176+
177+
def get_modversion(self):
178+
return self.modversion
179+
180+
def get_compile_args(self):
181+
return self.cargs
182+
183+
def get_link_args(self):
184+
return self.libs
185+
186+
def check_wxconfig(self):
187+
try:
188+
p = subprocess.Popen(['wx-config', '--version'], stdout=subprocess.PIPE,
189+
stderr=subprocess.PIPE)
190+
out = p.communicate()[0]
191+
if p.returncode == 0:
192+
mlog.log('Found wx-config:', mlog.bold(shutil.which('wx-config')),
193+
'(%s)' % out.decode().strip())
194+
WxDependency.wx_found = True
195+
return
196+
except Exception:
197+
pass
198+
WxDependency.wxconfig_found = False
199+
mlog.log('Found wx-config:', mlog.red('NO'))
200+
201+
def found(self):
202+
return self.is_found
203+
138204
class ExternalProgram():
139205
def __init__(self, name, fullpath=None, silent=False, search_dir=None):
140206
self.name = name
@@ -730,4 +796,5 @@ def find_external_dependency(name, kwargs):
730796
'Qt5': Qt5Dependency, # Qt people sure do love their upper case.
731797
'gnustep': GnuStepDependency,
732798
'appleframeworks': AppleFrameworks,
799+
'wxwidgets' : WxDependency,
733800
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <wx/wx.h>
4+
5+
class MyApp: public wxApp
6+
{
7+
public:
8+
virtual bool OnInit();
9+
};
10+
class MyFrame: public wxFrame
11+
{
12+
public:
13+
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
14+
private:
15+
void OnHello(wxCommandEvent& event);
16+
void OnExit(wxCommandEvent& event);
17+
void OnAbout(wxCommandEvent& event);
18+
wxDECLARE_EVENT_TABLE();
19+
};
20+
21+
enum {
22+
ID_Hello = 1
23+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
project('wxwidgets test', 'cpp')
2+
3+
add_global_arguments('-std=c++11', language : 'cpp')
4+
5+
wxd = dependency('wxwidgets')
6+
7+
wp = executable('wxprog', 'wxprog.cpp',
8+
dependencies : wxd)
9+
10+
test('wxtest', wp)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include"mainwin.h"
2+
3+
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
4+
EVT_MENU(ID_Hello, MyFrame::OnHello)
5+
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
6+
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
7+
wxEND_EVENT_TABLE()
8+
9+
bool MyApp::OnInit() {
10+
MyFrame *frame = new MyFrame( "Hello World", wxPoint(50, 50), wxSize(450, 340) );
11+
frame->Show( true );
12+
return true;
13+
}
14+
15+
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
16+
: wxFrame(NULL, wxID_ANY, title, pos, size) {
17+
wxMenu *menuFile = new wxMenu;
18+
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
19+
"Help string shown in status bar for this menu item");
20+
menuFile->AppendSeparator();
21+
menuFile->Append(wxID_EXIT);
22+
wxMenu *menuHelp = new wxMenu;
23+
menuHelp->Append(wxID_ABOUT);
24+
wxMenuBar *menuBar = new wxMenuBar;
25+
menuBar->Append( menuFile, "&File" );
26+
menuBar->Append( menuHelp, "&Help" );
27+
SetMenuBar( menuBar );
28+
CreateStatusBar();
29+
SetStatusText( "Welcome to wxWidgets!" );
30+
}
31+
32+
void MyFrame::OnExit(wxCommandEvent& event) {
33+
Close( true );
34+
}
35+
36+
void MyFrame::OnAbout(wxCommandEvent& event) {
37+
wxMessageBox( "This is a wxWidgets' Hello world sample",
38+
"About Hello World", wxOK | wxICON_INFORMATION );
39+
}
40+
41+
void MyFrame::OnHello(wxCommandEvent& event) {
42+
wxLogMessage("Hello world from wxWidgets!");
43+
}
44+
45+
#if 0
46+
wxIMPLEMENT_APP(MyApp);
47+
#else
48+
// Don't open a window because this is an unit test and needs to
49+
// run headless.
50+
int main(int, char **) {
51+
wxString name("Some app");
52+
wxPoint p(0, 0);
53+
wxSize s(100, 100);
54+
return 0;
55+
}
56+
57+
#endif

0 commit comments

Comments
 (0)