[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?

···

----------
Keith J. Farmer
kfarmer@thuban.org
http://www.thuban.org

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!