In this sample, we will set up a simple application that:
- create a menu and 2 menus items,
- these 2 menu items create a box for the first one, and a cylinder for the second one,
- for both wxPython and PyQt
We first call the SimpleGui module, that provides a simple interface to design GUI for both PyQt, wxPython and python-xlib:
from OCC.Display.SimpleGui import *
If you want to use wxPython, just set the backend as following:
set_backend('wx')
If you want to use rather PyQt, just replace the previous line with
set_backend('qt')
or, for python-xlib:
set_backend('X')
The next step is to init the display functions:
display, start_display, add_menu, add_function_to_menu = init_display()
Let’s now define the two functions that create and display a box and a cylinder:
def simple_test(event=None):
display.Test()
def simple_cylinder(event=None):
from OCC.BRepPrimAPI import BRepPrimAPI_MakeCylinder
s = BRepPrimAPI_MakeCylinder(60, 200)
display.DisplayShape(s.Shape())
Now we create a menu named ‘simple test’ and add the two functions into submenus:
add_menu('simple test')
add_function_to_menu('simple test',simple_test)
add_function_to_menu('simple test',simple_cylinder)
Finally, ask the display to be rendered:
display.View_Iso() display.FitAll() # display loop start_display()
Where is the /samples/Level2/Display folder? On Win XP, I’m looking in the folder C:\Python26\Lib\site-packages\OCC, but I don’t see any samples.
@Ethan pythonOCC-0.4 was not packaged with examples. You should download/install the 0.5 release: the Windows installer comes with examples.
OK! I’m not sure why I pulled 0.4. I’ll have a go with 0.5.