Hi,
I've been attempting to create a simple wxPy application that involves wx.lib.ogl shapes. At this point, after puzzling over the code I've been attempting to build for several days, I'm just wondering if it's even possible to do what I want to do before I continue...
[My environment: OS X 10.3.9, Python 2.3, wx-2.6-mac-ansi... not sure how to find exact version/download of wxpython i have]
I'd like to build a simple window, a ShapeCanvas, which is initialized with two RectangleShapes. When a mouse left-clicks and drags from one rectangle to the other, I'd like a line (a LineShape) to be drawn from one shape to the next, connecting the two shapes into a graph.. two nodes connected by an edge. If the cursor that is dragging a line (anchored at the first shape) never reaches the 2nd shape, the line would disappear when the left mouse button is lifted. But as the mouse cursor is being dragged, whether or not it reaches the 2nd shape, the line is visible, connecting the 1st shape with the mouse cursor.
What I'm having trouble with is the following..
1) As far as I can tell, when a LineShape is drawn, it needs two Shape objects to connect in order to be drawn. e.g.,
line = ogl.LineShape()
fromShape.AddLine(line, toShape)
In the case of drawing a LineShape dynamically, it seems rather than dealing with shapes objects, the inputs to AddLine would need to be x,y coordinates of the location of the mouse cursor rather than with Shape objects. Is it possible to draw a LineShape line without giving it shapes, but x,y coordinates instead?
2) Event handling. I'm unclear what exactly needs to be designed for event handling. I do know that the bulk of the coding complexity is within the evt handing methods.. but i'm unsure what exactly has to occur where. Below is pseudocode for what I think the framework should be in general for the program. I would post real code but I'm afraid what i have is way off base and might do more harm than good to post at this time.
···
#--------
# pseudo code for connecting two Shapes with a LineShape
import wx
import wx.lib.ogl as ogl
class MyShapeCanvas(ogl.ShapeCanvas):
def __init__:
# 1) create ogl.Diagram and set Canvas to diagram obj
# 2) create two RectangleShapes and add to diagram
# 3) create MyEvtHandler obj and add RectangleShapes to it
class MyEvtHandler(ogl.ShapeEvtHandler):
def __init__:
def OnBeginDragLeft(self,x,y,keys):
# 1) create line object
# 2) get mouse cursor x,y (wx.GetMouseState.GetX())
# 3) if mouse cursor is on a shape (line.HitTest?)
# pass in shape to line as shape to start line from
def OnDragLeft(self,draw,x,y,keys):
# create line object for each move of the cursor...
# passing in shape coordinates from shape discovered in
# OnBeginDragLeft as the line start and mouse
# cursor position as line end
def OnEndDragLeft(self,draw,x,y,keys):
# if drag ends and mouse button is lifted on top of the 2nd
# shape, set line start as shape coordinates from
# shape discovered in OnBeginDragLeft, and line end
# as 2nd shape's x,y
def OnPaint():
# ???
def OnMotion():
# ???
#--------
Suggestions on any or all of part of this greatly appreciated!!
-Genevieve