ogl.shapecanvas placing

Hello,

I am trying to use the OGL demo code to display a circle shape. I placed the
TestWindow class derived from ogl.shapecanvas inside a wx.Frame, and it worked
fine.

But I wish to use a SplitterWindow in the frame and place the ogl.shapecanvas
class (TestWindow) on Window2. Now, the shapecanvas does not show up. It is
displayed as a small square on the top left corner of the 2nd window.

Please see my code below. Any help will be very appriciated.

Thanks.

Lokesh

#Boa:Frame:Frame1

import wx
import wx.lib.ogl as ogl

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1SPLITTERWINDOW1, wxID_FRAME1WINDOW1,
wxID_FRAME1WINDOW2,
] = [wx.NewId() for _init_ctrls in range(4)]

class MyEvtHandler(ogl.ShapeEvtHandler):
    #def __init__(self, log, frame):
    def __init__(self, frame):
        ogl.ShapeEvtHandler.__init__(self)
        
    def OnLeftClick(self, x, y, keys=0, attachment=0):
        shape = self.GetShape()
        print 'Shape selected: ', shape
        canvas = shape.GetCanvas()
        dc = wx.ClientDC(canvas)
        canvas.PrepareDC(dc)
        if shape.Selected():
            shape.Select(False, dc)
            #canvas.Redraw(dc)
            canvas.Refresh(False)
        else:
            redraw = False
            shapeList = canvas.GetDiagram().GetShapeList()
            toUnselect = []

            for s in shapeList:
                if s.Selected():
                    # If we unselect it now then some of the objects in
                    # shapeList will become invalid (the control points are
                    # shapes too!) and bad things will happen...
                    toUnselect.append(s)

            shape.Select(True, dc)

            if toUnselect:
                for s in toUnselect:
                    s.Select(False, dc)

                canvas.Redraw(dc)
                canvas.Refresh(False)

    def OnEndDragLeft(self, x, y, keys=0, attachment=0):
        shape = self.GetShape()
        ogl.ShapeEvtHandler.OnEndDragLeft(self, x, y, keys, attachment)

        if not shape.Selected():
            self.OnLeftClick(x, y, keys, attachment)

    def OnSizingEndDragLeft(self, pt, x, y, keys, attch):
        ogl.ShapeEvtHandler.OnSizingEndDragLeft(self, pt, x, y, keys, attch)

    def OnMovePost(self, dc, x, y, oldX, oldY, display):
        shape = self.GetShape()
        ogl.ShapeEvtHandler.OnMovePost(self, dc, x, y, oldX, oldY, display)
        if "wxMac" in wx.PlatformInfo:
            shape.GetCanvas().Refresh(False)

class TestWindow(ogl.ShapeCanvas):
    #def __init__(self, parent, log, frame):
    def __init__(self, parent, frame):
        ogl.ShapeCanvas.__init__(self, parent)

        self.frame = frame
        self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE)
        self.diagram = ogl.Diagram()
        self.SetDiagram(self.diagram)
        self.diagram.SetCanvas(self)
        self.shapes = []
        self.save_gdi = []
        
        self.MyAddShape(
            ogl.CircleShape(80),
            75, 110, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle"
            )
            
    def MyAddShape(self, shape, x, y, pen, brush, text):
        # Composites have to be moved for all children to get in place
        if isinstance(shape, ogl.CompositeShape):
            dc = wx.ClientDC(self)
            self.PrepareDC(dc)
            shape.Move(dc, x, y)
        else:
            shape.SetDraggable(True, True)
        shape.SetCanvas(self)
        shape.SetX(x)
        shape.SetY(y)
        if pen: shape.SetPen(pen)
        if brush: shape.SetBrush(brush)
        if text:
            for line in text.split('\n'):
                shape.AddText(line)
        #shape.SetShadowMode(ogl.SHADOW_RIGHT)
        self.diagram.AddShape(shape)
        shape.Show(True)

        evthandler = MyEvtHandler(self.frame)
        evthandler.SetShape(shape)
        evthandler.SetPreviousHandler(shape.GetEventHandler())
        shape.SetEventHandler(evthandler)

        self.shapes.append(shape)
        return shape

    def OnBeginDragLeft(self, x, y, keys):
        self.log.write("OnBeginDragLeft: %s, %s, %s\n" % (x, y, keys))

    def OnEndDragLeft(self, x, y, keys):
        self.log.write("OnEndDragLeft: %s, %s, %s\n" % (x, y, keys))
        
class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(482, 193), size=wx.Size(555, 417),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(539, 381))

        self.splitterWindow1 = wx.SplitterWindow(id=wxID_FRAME1SPLITTERWINDOW1,
              name='splitterWindow1', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(539, 381), style=wx.SP_3D)

        self.window1 = wx.Window(id=wxID_FRAME1WINDOW1, name='window1',
              parent=self.splitterWindow1, pos=wx.Point(0, 0), size=wx.Size(200,
              381), style=0)
        self.window1.SetBackgroundColour(wx.Colour(255, 255, 128))

        self.window2 = wx.Window(id=wxID_FRAME1WINDOW2, name='window2',
              parent=self.splitterWindow1, pos=wx.Point(204, 0),
              size=wx.Size(335, 381), style=0)
        self.window2.SetBackgroundColour(wx.Colour(128, 255, 255))
        self.splitterWindow1.SplitVertically(self.window1, self.window2, 200)

    def __init__(self, parent):
        self._init_ctrls(parent)
        ogl.OGLInitialize()
        win = TestWindow(self.window2, self.window2)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()

Lokesh Batra schrieb:

        self.window2 = wx.Window(id=wxID_FRAME1WINDOW2, name='window2',
              parent=self.splitterWindow1, pos=wx.Point(204, 0),
              size=wx.Size(335, 381), style=0)
        self.window2.SetBackgroundColour(wx.Colour(128, 255, 255))
        self.splitterWindow1.SplitVertically(self.window1, self.window2, 200)

    def __init__(self, parent):
        self._init_ctrls(parent)
        ogl.OGLInitialize()
        win = TestWindow(self.window2, self.window2)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Lokesh,

just a quick hint to get you going:

in class Frame1 change statement
self.window2 = wx.Window(id=wxID_FRAME1WINDOW2, name='window2',
              parent=self.splitterWindow1, pos=wx.Point(204, 0),
              size=wx.Size(335, 381), style=0)

to

self.window2 = TestWindow(self.splitterWindow1, self)

and the init Method to:

def __init__(self, parent):
        ogl.OGLInitialize()
        self._init_ctrls(parent)

delete the line:
win = TestWindow(self.window2, self.window2)

the splitter needs a referenz to your OGL-Canvas and you need to run ogl.OGLInitialize before you initalize the OGL-Canvas. Hope this helps.

Jürgen

I read somewhere that OGL is dead,
and no longer included in the wxPython distro.
Is that correct ?

cheers,
Stef

Jürgen Kareta wrote:

···

Lokesh Batra schrieb:

        self.window2 = wx.Window(id=wxID_FRAME1WINDOW2, name='window2',
              parent=self.splitterWindow1, pos=wx.Point(204, 0),
              size=wx.Size(335, 381), style=0)
        self.window2.SetBackgroundColour(wx.Colour(128, 255, 255))
        self.splitterWindow1.SplitVertically(self.window1, self.window2, 200)

    def __init__(self, parent):
        self._init_ctrls(parent)
        ogl.OGLInitialize()
        win = TestWindow(self.window2, self.window2)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Lokesh,

just a quick hint to get you going:

in class Frame1 change statement
self.window2 = wx.Window(id=wxID_FRAME1WINDOW2, name='window2',
             parent=self.splitterWindow1, pos=wx.Point(204, 0),
             size=wx.Size(335, 381), style=0)

to
self.window2 = TestWindow(self.splitterWindow1, self)

and the init Method to:

def __init__(self, parent):
       ogl.OGLInitialize()
       self._init_ctrls(parent)

delete the line:
win = TestWindow(self.window2, self.window2)

the splitter needs a referenz to your OGL-Canvas and you need to run ogl.OGLInitialize before you initalize the OGL-Canvas. Hope this helps.

Jürgen

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Lokesh Batra wrote:

which class is most popular nowdays for 2D graphics ?

There are three options:

Write it all yourself with wx.DCs and/or wx.GraphicsContext

OGl, which I think is alive and well, in it's Python version (the older, C++ version may not be maintained anymore)

FloatCanvas:
  - wx.lib.floatcanvas
  - FloatCanvas - wxPyWiki

Which is best for you depends on what you need to do. If you describe your problem, we can advise. FloatCanvas is my baby, so I can help with that. There is also a mailing list here:

http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas

and a TRAC project here:

http://morticia.cs.dal.ca/FloatCanvas/

But it's down at the moment -- I'll try to find out why.

Note that FloatCanvas is getting a major re-write right now as a Google Summer of Code projects. This is good, as we should have a more feature-full and flexible version at the end, but my be an issue for you, as the API is going to change (how much, we don't' know yet). However, the old one won't suddenly stop working.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Stef Mientki wrote:

I read somewhere that OGL is dead,
and no longer included in the wxPython distro.
Is that correct ?

Only the C++ version. The Python version is maintained, mostly by users who track down the problems they run into and send me the patches.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!