User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 361,873 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,381 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:
Views: 1194 | Replies: 3 | Solved
Reply
Join Date: Mar 2006
Posts: 56
Reputation: Blujacker is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Blujacker Blujacker is offline Offline
Junior Poster in Training

wxCanvas-Get current coordinates

  #1  
May 27th, 2007
Hi, this is my code:
# -*- coding: cp1250 -*-
import  wx
class Okno:
    def __init__(self,parent=None,id=wx.ID_ANY,title="Graf"):
        self.okno=wx.MDIChildFrame(parent,title="Graf",id=-1)
        self.okno.Maximize()
        self.okno.SetAutoLayout(True)
        self.okno.SetBackgroundColour("#FCFCFE")       
        self.sizer = wx.FlexGridSizer(2,2,0,0)
        self.canvas = wx.ScrolledWindow(self.okno, id=wx.ID_ANY)
        self.canvas.EnableScrolling(True, True)        
        self.canvas.SetScrollbars(20, 20, 1000/20, 1000/20)
        self.sizer.Add(self.canvas, 1, wx.EXPAND)
        self.sizer.AddGrowableRow(0, 1)
        self.sizer.AddGrowableCol(0, 1)  
        self.okno.SetSizer(self.sizer)
        self.canvas.Bind(wx.EVT_PAINT, self.OnPaint)        
    
    def OnPaint(self, event):
        pass
if __name__ == "__main__":
    okno = wx.App(0)
    parent=wx.MDIParentFrame(None,size=wx.Size(500,500))
    o=Okno(parent)
    parent.Show()
    okno.MainLoop()
As you can see, its scrolled canvas and i need to get current coordinates of part of canvas which i can see (sory my english). For exapmle: If i run my code, that left up corner is (0,0) and down right corner is (500,500).

Thanks!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,275
Reputation: vegaseat is on a distinguished road 
Rep Power: 8
Solved Threads: 167
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Re: wxCanvas-Get current coordinates

  #2  
May 27th, 2007
This will give the mouse position within the whole scrolled canvas ...
  1. """
  2. # -*- coding: cp1250 -*-
  3. """
  4. # get coordinates of whole scrolled canvas
  5.  
  6. import wx
  7.  
  8. class Okno:
  9. def __init__(self,parent=None,id=wx.ID_ANY,title="Graf"):
  10. self.okno=wx.MDIChildFrame(parent,title="Graf",id=-1)
  11. self.okno.Maximize()
  12. self.okno.SetAutoLayout(True)
  13. self.okno.SetBackgroundColour("#FCFCFE")
  14. self.sizer = wx.FlexGridSizer(2,2,0,0)
  15. self.canvas = wx.ScrolledWindow(self.okno, id=wx.ID_ANY)
  16. self.canvas.EnableScrolling(True, True)
  17. self.canvas.SetScrollbars(20, 20, 1000/20, 1000/20)
  18. self.sizer.Add(self.canvas, 1, wx.EXPAND)
  19. self.sizer.AddGrowableRow(0, 1)
  20. self.sizer.AddGrowableCol(0, 1)
  21. self.okno.SetSizer(self.sizer)
  22. self.canvas.Bind(wx.EVT_PAINT, self.OnPaint)
  23.  
  24. # hook left mouse button event
  25. self.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
  26.  
  27. def OnPaint(self, event):
  28. pass
  29.  
  30. def OnLeftDown(self, event):
  31. """left mouse button is pressed"""
  32. device_pt = event.GetPosition() # tuple (x, y)
  33. # need to add current scrollbar value logic_pt to device_pt
  34. # if you want position relative to whole canvas
  35. logic_pt = self.canvas.CalcUnscrolledPosition(0, 0)
  36. #print device_pt, logic_pt
  37. adjusted_pt = (device_pt[0]+logic_pt[0], device_pt[1]+logic_pt[1])
  38. self.okno.SetTitle('LeftMouse = ' + str(adjusted_pt))
  39.  
  40. if __name__ == "__main__":
  41. okno = wx.App(0)
  42. parent=wx.MDIParentFrame(None,size=wx.Size(500,500))
  43. o=Okno(parent)
  44. parent.Show()
  45. okno.MainLoop()
Last edited by vegaseat : May 27th, 2007 at 12:45 pm. Reason: spelling
May 'the Google' be with you!
Reply With Quote  
Join Date: Mar 2006
Posts: 56
Reputation: Blujacker is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Blujacker Blujacker is offline Offline
Junior Poster in Training

Re: wxCanvas-Get current coordinates

  #3  
May 27th, 2007
Thanks for fast answer, but i need something else. I dont know how to say it in english, so i painted it:
http://www.blujacker.wz.cz/coords.jpg
Reply With Quote  
Join Date: Mar 2006
Posts: 56
Reputation: Blujacker is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Blujacker Blujacker is offline Offline
Junior Poster in Training

Re: wxCanvas-Get current coordinates

  #4  
May 28th, 2007
Lol, solved... i am really noob. The solution is:
  1. up_left_corner=self.canvas.CalcUnscrolledPosition(0, 0)
  2. dow_right_corner=self.canvas.CalcUnscrolledPosition(width_canvas, height_canvas)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Python Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 6:42 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC