15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

#line 108 "wx_example.py"<br />

dc->BeginDrawing();<br />

dc->SetPen(wxPen(*red,4,wxSOLID));<br />

dc->DrawRectangle(5,5,50,50);<br />

dc->SetBrush(*grey_brush);<br />

dc->SetPen(wxPen(*blue,4,wxSOLID));<br />

dc->DrawRectangle(15, 15, 50, 50);<br />

"""<br />

inline(code,[’dc’,’red’,’blue’,’grey_brush’])<br />

dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL))<br />

dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))<br />

te = dc.GetTextExtent("Hello World")<br />

dc.DrawText("Hello World", 60, 65)<br />

dc.SetPen(wxPen(wxNamedColour(’VIOLET’), 4))<br />

dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])<br />

...<br />

SciPy Reference Guide, Release 0.8.dev<br />

Here, some of the Python calls to wx objects were just converted to C++ calls. There isn’t any benefit, it just demonstrates<br />

the capabilities. You might want to use this if you have a computationally intensive loop in your drawing code<br />

that you want to speed up. On windows, you’ll have to use the MSVC compiler if you use the standard wxPython<br />

DLLs distributed by Robin Dunn. Thats because MSVC and gcc, while binary compatible in C, are not binary compatible<br />

for C++. In fact, its probably best, no matter what platform you’re on, to specify that inline use the same<br />

compiler that was used to build wxPython to be on the safe side. There isn’t currently a way to learn this info from the<br />

library – you just have to know. Also, at least on the windows platform, you’ll need to install the wxWindows libraries<br />

and link to them. I think there is a way around this, but I haven’t found it yet – I get some linking errors dealing with<br />

wxString. One final note. You’ll probably have to tweak weave/wx_spec.py or weave/wx_info.py for your machine’s<br />

configuration to point at the correct directories etc. There. That should sufficiently scare people into not even looking<br />

at this... :)<br />

Keyword Option<br />

The basic definition of the inline() function has a slew of optional variables. It also takes keyword arguments that<br />

are passed to distutils as compiler options. The following is a formatted cut/paste of the argument section of<br />

inline’s doc-string. It explains all of the variables. Some examples using various options will follow.<br />

def inline(code,arg_names,local_dict = None, global_dict = None,<br />

force = 0,<br />

compiler=’’,<br />

verbose = 0,<br />

support_code = None,<br />

customize=None,<br />

type_factories = None,<br />

auto_downcast=1,<br />

**kw):<br />

inline has quite a few options as listed below. Also, the keyword arguments for distutils extension modules are<br />

accepted to specify extra information needed for compiling.<br />

Inline Arguments<br />

code string. A string of valid C++ code. It should not specify a return statement. Instead it should assign results that<br />

need to be returned to Python in the return_val. arg_names list of strings. A list of Python variable names that should<br />

1.12. Weave 97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!