Hi PythonOCC Team,

     I'm having trouble viewing shapes from the python command prompt in
the new pythonocc-0.6 alpha distribution.  I used to use pythonocc-0.5,
with this same code, and it didn't have this problem.
     I stripped my code down to the bare minimum to replicate the error.
(So, technically, I haven't verified this exact code works on pythonocc-0.5.)
It closely follows the wxPython examples, viewer.py and viewer_basics.py.
A transcript of what happens from the python prompt follows.  When I start
a view, the view window appears, and I can interact with it.  When I close
the view and start a second view, or when I keep the view open and start a
second view, I get a "Cannot connect to server" error.  A transcript and
source code follow.  If you comment out all the lines with "self.canvas"
in the simple_display.py file, you'll remove pythonocc from the canvas and
you'll see what should happen.
     I'm using Debian 6.0 Linux.  Any help would be appreciated.  It may
be a pythonocc-0.6 bug.

Thanks,
Charles

-------- The Transcript --------

(I had to replace >>> with --- because gmane thought I was top-posting.)

my_computer> python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
--- import display
--- display.view()
---  ###### 3D rendering pipe initialisation #####
Display3d class initialization starting ...
Graphic device created.
Xw_Window created.
Viewer created.
Interactive context created.
Display3d class successfully initialized.
 ########################################

--- 
--- display.view()
---  ###### 3D rendering pipe initialisation #####
Display3d class initialization starting ...
Traceback (most recent call last):
  File "simple_display.py", line 31, in add_view
    View()
  File "simple_display.py", line 54, in __init__
    self.canvas.InitDriver()
  File "/usr/local/lib/python2.6/dist-packages/OCC/Display/wxDisplay.py", line 
151, in InitDriver
    self._display.Create()
  File "/usr/local/lib/python2.6/dist-packages/OCC/Display/OCCViewer.py", line 
84, in Create
    self.Init(self._window_handle)
RuntimeError: Aspect_GraphicDeviceDefinitionError
Cannot connect to server ''


-------- The display.py file --------

class MainThread(object):

    def start(self):
        self.app = None
        import thread
        thread.start_new_thread(self.run, ())

    def run(self):
        import simple_display

        self.app = simple_display.SecondThreadApp(0)
        self.app.MainLoop()

    def add_view(self):
        import simple_display

        while not self.app: # Wait for app to be up and running
            pass
        evt = simple_display.AddView()
        simple_display.wx.PostEvent(self.app.catcher, evt)

app = MainThread()
app.start()

def view():
    app.add_view()


-------- The simple_display.py file --------

from OCC.Display.wxDisplay import wxViewer3d

import wx

# The following lines came from the wxPython examples (viewer.py and
# viewer_basics.py).

wx_EVT_ADD_VIEW = wx.NewEventType()
EVT_ADD_VIEW = wx.PyEventBinder(wx_EVT_ADD_VIEW, 1)

class AddView(wx.PyEvent):
    def __init__(self):
        wx.PyEvent.__init__(self)
        self.SetEventType(wx_EVT_ADD_VIEW)

class HiddenCatcher(wx.Frame):
    """
        The "catcher" frame in the second thread.
        It is invisible.  It's only job is to receive
        Events from the main thread, and create
        the appropriate windows.
    """
    def __init__(self):
        wx.Frame.__init__(self, None, -1, '')
        self.Bind(EVT_ADD_VIEW, self.add_view)

    def add_view(self, evt):
        View()

class SecondThreadApp(wx.App):
    """
        wxApp that lives in the second thread.
    """
    def OnInit(self):
        catcher = HiddenCatcher()
        #self.SetTopWindow(catcher)
        self.catcher = catcher
        return True

# Now my class follows

class View(object):
    """
    A frame for displaying pythonOCC models.
    """
    def __init__(self):
        self.frame = wx.Frame(None, -1, 'Test Viewer', size = (640, 480))
        self.canvas = wxViewer3d(self.frame)
        self.frame.Show(True)
        wx.SafeYield()
        self.canvas.InitDriver()
        self.canvas.SetFocus()

    def exit(self, event = None):
        self.frame.Destroy()



_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to