To draw graphic, which module to use?

Hi~
I have read most of modules and packages in wxpython, and many of them have
the function to draw shapes.
For now, I find wx.lib.plot, wx.lib.floatcanvas, wx.lib.ogl,
wx.GraphicsContext, wx.graphics, including wx itself, they all can draw
things. The introductions in doc are short so I can't have good
understanding of when and how to use these thing.
So, can you give me some advice on when and how to use these packages?
What's the advantage of each module for drawing. I hope you can give me a
specific description.

Thank you !

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/To-draw-graphic-which-module-to-use-tp5717074.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Gabrielle wrote:

Hi~
I have read most of modules and packages in wxpython, and many of them have
the function to draw shapes.
For now, I find wx.lib.plot, wx.lib.floatcanvas, wx.lib.ogl,
wx.GraphicsContext, wx.graphics, including wx itself, they all can draw
things. The introductions in doc are short so I can't have good
understanding of when and how to use these thing.
So, can you give me some advice on when and how to use these packages?
What's the advantage of each module for drawing. I hope you can give me a
specific description.

High level drawing of shape objects, with support for mouse interactions, hit testing, scaling and other manipulations, redrawing, etc.: FloatCanvas, OGL.

Lower level raster drawing that just moves bytes to the screen, leaving all the rest of the higher level features up to you: wx.DC and other DC classes.

Lower level vector (path based) drawing, supporting anti-aliasing, alpha blending and matrix manipulations: GraphicsContext and wx.lib.graphics (a GraphicsConext-like API using PyCairo for all platforms.)

BTW, the latter group (path-based vector drawing APIs) is probably the most similar to the HTML5 Canvas used by the flowchart tool you linked to in your other message.

···

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

BTW, the latter group (path-based vector drawing APIs) is probably the
most similar to the HTML5 Canvas used by the flowchart tool you linked
to in your other message.

Oops, I meant to say, "BTW, the latter group (path-based vector drawing APIs) plus some features of FloatCanvas, is probably the most similar..."

···

--
Robin Dunn
Software Craftsman

That's very helpful
I have other questions about the package wx.lib.ogl, and I hope you can
give me some advice.

I chose wx.lib.ogl to develop my project for drawing function. But I found
there are same methods in different classes. For example, the class Diagram
and ShapeCanvas in package wx.lib.ogl, they all have methods to delete
shapes, add shapes, rescale shapes and rotate shapes. So what should I do
now? Both classes can do things I want, and there is no specific
introduction for these classes, just some methods, I don't know how to
choose...Oh,it's always difficult for me to make a choice.

What's more, there is a demo I want to ask for your explaination.
   1 import wx
   2 import wx.lib.ogl as ogl
   3
   4 class AppFrame(wx.Frame):
   5 def __init__(self):
   6 wx.Frame.__init__( self,
   7 None, -1, "Demo",
   8 size=(300,200),
   9 style=wx.DEFAULT_FRAME_STYLE )
  10 sizer = wx.BoxSizer( wx.VERTICAL )
  11
  12
  13 canvas = ogl.ShapeCanvas( self )
  14 sizer.Add( canvas, 1, wx.GROW )
  15
  16 canvas.SetBackgroundColour( "LIGHT BLUE" )
  17
  18 diagram = ogl.Diagram()
  19 canvas.SetDiagram( diagram )
  20 diagram.SetCanvas( canvas )
  21
  22 shape = ogl.CircleShape( 20.0 )
  23 shape.SetX( 25.0 )
  24 shape.SetY( 25.0 )
  25 canvas.AddShape( shape )
  26 diagram.ShowAll( 1 )
  27
  28
  29 self.SetSizer(sizer)
  30 self.SetAutoLayout(1)
  31 self.Show(1)

About this demo, first question is, must I put a diagram onto canvas? I
tried not to set diagram,and it came an error. So why it's must to set
diagram on canvas? Can you tell me the steps to draw using high level
drawing package? I mean, what should I do first and next, for example, I
should set up a canvas, then put on a diagram.

Based on the last question, I want to know that's the difference between
canvas and shapeCanvas, Do you have some experience to use them? I found
canvas is the direct subclass of windows and shapeCanvas is subclass of
panel. I still have no idea which one should be used.

What's more, if I use wx.lib.ogl to draw, is that mean I don't need Device
Context anymore? But there is still some methods in wx.lib.ogl related to
DC, such as RecentreAll(self, dc) ,Redraw(self, dc) in class Diagram. Do you
know why?
Below is the introduction link of these two methods.
http://wxpython.org/docs/api/wx.lib.ogl.Diagram-class.html#RecentreAll

Another demo question is, why the circleShape is draggable? The demo didn't
add any attributes to make circle object draggable, just create it.
I searched , circleShape is subclass of ellipseShape which is the subclass
of Shape, which is the subclass of ShapeEvtHandler. But the introduction of
them is brief that I can't have a good understanding of them.
So could you explain why?

Waiting for your reply :slight_smile:

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/To-draw-graphic-which-module-to-use-tp5717074p5717154.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Gabrielle wrote:

I have other questions about the package wx.lib.ogl, and I hope you can
give me some advice.

You need to understand that "wx.lib.ogl" is a wrapper around the OpenGL
3D graphics library. OpenGL is extremely large, very flexible, and as a
result quite complicated. The Python interface can abstract some of
this, but it you try to use the abstraction without at least SOME
understanding the OpenGL framework that lives underneath, you will find
yourself in a lot of trouble.

I chose wx.lib.ogl to develop my project for drawing function. But I found
there are same methods in different classes. For example, the class Diagram
and ShapeCanvas in package wx.lib.ogl, they all have methods to delete
shapes, add shapes, rescale shapes and rotate shapes.

No, ShapeCanvas can add and remove, but it can't rescale or rotate.

So what should I do
now? Both classes can do things I want, and there is no specific
introduction for these classes, just some methods, I don't know how to
choose...Oh,it's always difficult for me to make a choice.

A Diagram contains other drawing objects, but it doesn't know how to
draw itself. To do that, it has to be associated with a ShapeCanvas.
So, you need both, but you'd do your manipulation in the more capable
Diagram object.

About this demo, first question is, must I put a diagram onto canvas? I
tried not to set diagram,and it came an error. So why it's must to set
diagram on canvas?

The Diagram knows how to do drawing, but it doesn't have a drawing
surface -- it isn't connected to a window. To do that, you use a
ShapeCanvas. The ShapeCanvas is the glue between the window and the
Diagram. That adds flexibility, because the Diagram can be associated
with several different kinds of canvas, should the need arise.

Can you tell me the steps to draw using high level
drawing package? I mean, what should I do first and next, for example, I
should set up a canvas, then put on a diagram.

You have the steps here, in this sample. Do you doubt them? Note that
I would not necessarily call wx.lib.ogl "high level".

Based on the last question, I want to know that's the difference between
canvas and shapeCanvas, Do you have some experience to use them? I found
canvas is the direct subclass of windows and shapeCanvas is subclass of
panel.

Which "canvas" do you mean here? In this sample, "canvas" is an object
of type "ShapeCanvas".

What's more, if I use wx.lib.ogl to draw, is that mean I don't need Device
Context anymore?

In general, that's true. Speaking directly about Windows, the native
Windows drawing system is called GDI. DCs are the main mechanism you
use to do drawing in GDI. When you decide to use OpenGL, you are
allowing OpenGL to do all of the drawing for you. You don't work with
GDI anymore. As far as GDI knows, your window is just a blank white
square. The drawing goes on behind its back, so to speak.

But there is still some methods in wx.lib.ogl related to
DC, such as RecentreAll(self, dc) ,Redraw(self, dc) in class Diagram. Do you
know why?

Yes, because even though you are using OpenGL to do your drawing, your
application is still a Windows application, and your window is still a
GDI window. OpenGL will take over the drawing, but you still have to
interface with GDI sometimes.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Thank you for your detailed explanation. That's helpful!

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/To-draw-graphic-which-module-to-use-tp5717074p5717207.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Tim Roberts wrote:

Gabrielle wrote:

I have other questions about the package wx.lib.ogl, and I hope you can
give me some advice.

You need to understand that "wx.lib.ogl" is a wrapper around the OpenGL
3D graphics library. OpenGL is extremely large, very flexible, and as a
result quite complicated. The Python interface can abstract some of
this, but it you try to use the abstraction without at least SOME
understanding the OpenGL framework that lives underneath, you will find
yourself in a lot of trouble.

No, there is an unfortunate name clash there. wx.lib.ogl is a Python reimplementation of the Object Graphics Library that was included in the original wx 20 years ago, not OpenGL.

A bit surprisingly, given the misunderstanding above, the rest of your comments were still mostly spot-on for OGL canvases and diagrams. :slight_smile:

···

--
Robin Dunn
Software Craftsman

You mean, wx.lib.ogl is a different thing comparing with OpenGL, but the
words about canvas and diagrams Tim said is right.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/To-draw-graphic-which-module-to-use-tp5717074p5717219.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Robin Dunn wrote:

Tim Roberts wrote:

You need to understand that "wx.lib.ogl" is a wrapper around the OpenGL
3D graphics library.

No, there is an unfortunate name clash there. wx.lib.ogl is a Python
reimplementation of the Object Graphics Library that was included in the
original wx 20 years ago, not OpenGL.

Hmm, I'm embarrassed.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Hi Robin

I have question.
I create a frame,and add a flatnotebook as a child of this frame, and then
add a shapecanvas as a child of flatnotebook. There is a toolbar in frame,
and I want to create a tool event so that when clicking this tool,
shapeCanvas can add a shape. But in implementation, the code has no error ,
everything works fine, but the shapeCanvas just can't show any shape.

I tried to fix it. If I add a shape in shapeCanvas class directly, it can
show this shape, and if I make shapeCanvas as the child of frame instead of
flatnotebook, the shapeCanvas can also response to the tool event correctly
and show the related shape. But when I close a tab page, the canvas will not
be closed.

Would you please have look at my code and give me some advice? I must solve
this problem as soon as possible and I really need your help.

Thanks very much

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/To-draw-graphic-which-module-to-use-tp5717074p5717295.html
Sent from the wxPython-users mailing list archive at Nabble.com.

hi

I think I solved my problem, I find GetCurrentPage in flatNotebook, and it
worked, thanks~

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/To-draw-graphic-which-module-to-use-tp5717074p5717302.html
Sent from the wxPython-users mailing list archive at Nabble.com.