Gettin started with PyQt, wxPython and pythonOCC

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()