•
•
•
•
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
![]() |
•
•
Join Date: Mar 2006
Posts: 56
Reputation:
Rep Power: 3
Solved Threads: 0
Hi, this is my code:
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!
# -*- 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()Thanks!
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,275
Reputation:
Rep Power: 8
Solved Threads: 167
This will give the mouse position within the whole scrolled canvas ...
python Syntax (Toggle Plain Text)
""" # -*- coding: cp1250 -*- """ # get coordinates of whole scrolled canvas 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) # hook left mouse button event self.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) def OnPaint(self, event): pass def OnLeftDown(self, event): """left mouse button is pressed""" device_pt = event.GetPosition() # tuple (x, y) # need to add current scrollbar value logic_pt to device_pt # if you want position relative to whole canvas logic_pt = self.canvas.CalcUnscrolledPosition(0, 0) #print device_pt, logic_pt adjusted_pt = (device_pt[0]+logic_pt[0], device_pt[1]+logic_pt[1]) self.okno.SetTitle('LeftMouse = ' + str(adjusted_pt)) if __name__ == "__main__": okno = wx.App(0) parent=wx.MDIParentFrame(None,size=wx.Size(500,500)) o=Okno(parent) parent.Show() okno.MainLoop()
Last edited by vegaseat : May 27th, 2007 at 12:45 pm. Reason: spelling
May 'the Google' be with you!
•
•
Join Date: Mar 2006
Posts: 56
Reputation:
Rep Power: 3
Solved Threads: 0
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
http://www.blujacker.wz.cz/coords.jpg
•
•
Join Date: Mar 2006
Posts: 56
Reputation:
Rep Power: 3
Solved Threads: 0
Lol, solved... i am really noob. The solution is:
python Syntax (Toggle Plain Text)
up_left_corner=self.canvas.CalcUnscrolledPosition(0, 0) dow_right_corner=self.canvas.CalcUnscrolledPosition(width_canvas, height_canvas)
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
- Simulate Mouse Move (C++)
- C++ Graphics (graphics.h) (C++)
- Can anybody give answers for these 2 queries ??!!?? (Visual Basic 4 / 5 / 6)
- how to make colors (C++)
- QuickSort (Computer Science and Software Design)
- Use Windows Update to Keep Your Computer Current (Windows tips 'n' tweaks)
Other Threads in the Python Forum
- Previous Thread: Putting an image into a Tkinter thingy
- Next Thread: Multi-line terminal commands



Linear Mode