a graphics issue I can not figure out

Nathan smith <[email protected]>
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
Hi Group,

I have recently been playing around with the drawing tools available in 
wx python.

My goal was to create a grid and then plot some lines upon it.

I have got the grid working, but I can not seem to position a triangle 
correctly.

Here is some code which I have explained best I can:

Note in the below code the variable g just refers to a way I store 
global variables.

class Mywin(wx.Frame):
  def __init__(self, parent, title):

   super(Mywin, self).__init__(parent, title = title,size = (350,250), 
style=wx.DEFAULT_FRAME_STYLE)
   self.Maximize()
   g.center_point=self.GetClientSize()
   g.center_point=[g.center_point.x/2, g.center_point.y/2]

# this is the screen where the graph is drawn. Called from a main menu 
hence the first line.

  def graph(self):
   self.mainpanel.Hide()
   self.Bind(wx.EVT_PAINT, self.onpaint)
   self.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
   self.SetBackgroundColour('WHITE')
   self.Layout()
   self.Fit()
   self.Show()
   self.SetFocus()

# the paint function. to give you an example of what is in the g.lines 
variable it is something like this:

g.lines=[[[1, 1], [5, 1], wx.Colour(255, 0, 0, 255), 100], [[1, 1], [1, 
5], wx.Colour(255, 0, 0, 255), 100], [[1, 5], [5, 1], wx.Colour(255, 0, 
0, 255), 100]]

  def onpaint(self, event):
   self.dc = wx.PaintDC(self)
   self.dc.Clear()
   self.pen = wx.Pen(wx.BLACK_PEN)
   self.dc.SetPen(self.pen)
   p1=[g.center_point[0]-(38*6), g.center_point[1]-(38*6)]
   p2=[g.center_point[0]+(38*5), g.center_point[1]-(38*6)]
   for x in range(11):
    self.dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
    p1 = [p1[0],p1[1]+38]
    p2 = [p2[0],p2[1]+38]
   p1=[g.center_point[0]-(38*6), g.center_point[1]-(38*6)]
   p2=[g.center_point[0]-(38*6), g.center_point[1]+(38*5)]
   for x in range(11):
    self.dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
    p1 = [p1[0]+38,p1[1]]
    p2 = [p2[0]+38,p2[1]]
   bl=[g.center_point[0]-(38*6), g.center_point[1]-(38*6)] # this is the 
bottom left corner coordinates and from this we work out where the user 
selected the line to go. (lines are made by using the arrow keys and such.)

   for x in g.lines:
     self.pen.SetColour(wx.Colour(x[2]))
     self.pen.SetStyle(x[3])
     self.dc.DrawLine(bl[0]+(x[0][0]*38)+10, bl[1]+(x[0][1]*38)+10,  
bl[0]+(x[1][0]*38)+10, bl[1]+(x[1][1]*38)+10)


When ever I do this using the coordinates specified, it always puts the 
triangle in the top left, rather than the bottom left.

I am doing *38 to compensate for the pixel to cm conversion.

then +10 because I have this weird feeling if I draw directly over the 
grid lines wx python will not show it?


Any help here would be appreciated.

thanks'

Nathan


-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/63cf31d1-f147-b066-92ed-f66a7d21038b%40gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.