RE: [wxPython] wxFrame, non titlebar, moveable
I’ve been studying this because I’ll need something similar soon.
I can’t find any documentation on the Dragging() method of the wxEvent object (used in the OnMouseMove handler).
But also, why do you need it if you are keeping your own button state record (self.leftDown)?
Dale Strickland-Clark
Riverhall Systems Ltd. Custom database and Web applications.
Offices: London & Wokingham
···
-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Thu, 2002 January 24 00:33
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] wxFrame, non titlebar, moveable
I’m trying to figure out the right style settings to make a wxFrame that
lacks a titlebar but is moveable. Anyone have any good examples?
As luck would have it I had need of one of those this morning. The code is
below. BTW, without the titlebar the frame itself is not moveable, but you
can let the contents of the window be sensitive to mouse dragging and let it
move the frame.
from wxPython.wx import *
class TestFrame(wxFrame):
def __init__(self):
wxFrame.__init__(self, None, -1, "window title",
style=wxSIMPLE_BORDER)
panel = TestPanel(self)
self.SetSize((450, 25))
class TestPanel(wxPanel):
def __init__(self, parent):
wxPanel.__init__(self, parent, -1)
self.leftDown = false
self.parentFrame = parent
while self.parentFrame.GetParent() is not None:
self.parentFrame = self.parentFrame.GetParent()
EVT_LEFT_DOWN(self, self.OnLeftDown)
EVT_LEFT_UP(self, self.OnLeftUp)
EVT_MOTION(self, self.OnMouseMove)
EVT_RIGHT_UP(self, self.OnRightUp)
def OnRightUp(self, evt):
self.parentFrame.Close()
def OnLeftDown(self, evt):
self.CaptureMouse()
self.leftDown = true
pos = self.ClientToScreen(evt.GetPosition())
origin = self.parentFrame.GetPosition()
dx = pos.x - origin.x
dy = pos.y - origin.y
self.delta = wxPoint(dx, dy)
def OnLeftUp(self, evt):
self.ReleaseMouse()
self.leftDown = false
def OnMouseMove(self, evt):
if evt.Dragging() and self.leftDown:
pos = self.ClientToScreen(evt.GetPosition())
fp = (pos.x - self.delta.x, pos.y - self.delta.y)
self.parentFrame.Move(fp)
app = wxPySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
–
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!
wxpython-users mailing list