471,357 Members | 1,083 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

Move windows without title bar (wxPython)

Hi evrebody!
Currently I am using wxPython to make my own program !
My program have no taskbar so I would like to know how to do this:
When an user click on right mouse button, and he keep down this button , he can move the program windows anywhere.

I have this:
Expand|Select|Wrap|Line Numbers
  1. self.Bind(wx.EVT_RIGHT_DOWN, self.OnMoveFen)
So I don't know how to write OnMoveFen function... Can you help me please ?
Thank you :-)

EDIT: Can you delete this topic, I do an error
Aug 28 '07 #1
5 6958
Hi evrebody!
Currently I am using wxPython to make my own program !
My program have no taskbar so I would like to know how to do this:
When an user click on right mouse button, and he keep down this button , he can move the program windows anywhere.

I have this:
Expand|Select|Wrap|Line Numbers
  1. self.Bind(wx.EVT_RIGHT_DOWN, self.OnMoveFen)
So I don't know how to write OnMoveFen function... Can you help me please ?
Thank you :-)
Aug 28 '07 #2
bartonc
6,596 Expert 4TB
I'm guessing that you mean "title bar"...

I'd say that you probably want to catch

EVT_MOTION

Then, in the handler:
Expand|Select|Wrap|Line Numbers
  1. if event.m_leftDown:
  2.     x, y = event.GetPosition()
Then calculate the new position of the window based on the difference from the last motion event. You could later limit the area of the window that responds this way (or not).
Aug 29 '07 #3
So I have do this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. self.Bind(wx.EVT_MOTION , self.OnMoveFen)
  3.  
  4. def OnMoveFen(self, event):
  5.         if wx.MouseEvent.LeftIsDown == True:
  6.             pt = wx.Point
  7.             self.Move(pt)
But when I push down my left button nothing do... can you help me please...
Aug 29 '07 #4
bartonc
6,596 Expert 4TB
So I have do this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. self.Bind(wx.EVT_MOTION , self.OnMoveFen)
  3.  
  4. def OnMoveFen(self, event):
  5.         if wx.MouseEvent.LeftIsDown == True:
  6.             pt = wx.Point
  7.             self.Move(pt)
But when I push down my left button nothing do... can you help me please...
Hopefully, this example will help you learn some of the fundamentals of OOP and event programming. You really need a basic understanding of object creation and have fallen into some basic misunderstandings.
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4.  
  5. def create(parent):
  6.     return Frame1(parent)
  7.  
  8. [wxID_FRAME1] = [wx.NewId() for _init_ctrls in range(1)]
  9.  
  10. class Frame1(wx.Frame):
  11.     def _init_ctrls(self, prnt):
  12.         # generated method, don't edit
  13.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(22, 22),
  14.                 size=wx.Size(400, 250), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  15.         self.SetClientSize(wx.Size(392, 223))
  16.         self.Bind(wx.EVT_MOTION, self.OnFrame1Motion)
  17.         self.Bind(wx.EVT_LEFT_DOWN, self.OnFrame1LeftDown)
  18.  
  19.     def __init__(self, parent):
  20.         self._init_ctrls(parent)
  21.  
  22.         self.lastMousePos = wx.Point(0, 0)
  23.  
  24.  
  25.     def OnFrame1Motion(self, event):
  26.         if event.LeftIsDown():
  27.             x, y = event.GetPosition()
  28.             deltaX = x - self.lastMousePos[0]
  29.             deltaY = y - self.lastMousePos[1]
  30.             self.lastMousePos = wx.Point(x, y)
  31.             x, y = self.GetPosition()
  32.             self.Move(wx.Point(x + deltaX, y + deltaY))
  33.         event.Skip()
  34.  
  35.     def OnFrame1LeftDown(self, event):
  36.         self.lastMousePos = event.GetPosition()
  37.         event.Skip()
  38.  
  39.  
  40. if __name__ == "__main__":
  41.     app = wx.PySimpleApp()
  42.     frame = create(None)
  43.     frame.Show()
  44.     app.MainLoop()
  45.  
It's a little rough around the edges, but contains the basic idea.
Aug 29 '07 #5
I realize this is 7 years old, but in case someone else comes across this, an improvement on the implementation above is the following:

Expand|Select|Wrap|Line Numbers
  1. import wx
  2.  
  3. def create(parent):
  4.     return Frame1(parent)
  5.  
  6. [wxID_FRAME1] = [wx.NewId() for _init_ctrls in range(1)]
  7.  
  8. class Frame1(wx.Frame):
  9.     def _init_ctrls(self, prnt):
  10.         # generated method, don't edit
  11.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(22, 22),
  12.                 size=wx.Size(400, 250), style=wx.NO_BORDER, title='Frame1')
  13.         self.Bind(wx.EVT_MOTION, self.OnFrame1Motion)
  14.         self.Bind(wx.EVT_LEFT_DOWN, self.OnFrame1LeftDown)
  15.  
  16.     def __init__(self, parent):
  17.         self._init_ctrls(parent)
  18.         self.lastMousePos = wx.Point(0, 0)
  19.  
  20.     def OnFrame1Motion(self, event):
  21.         if event.LeftIsDown():
  22.             windowX = self.lastMousePos[0]
  23.             windowY = self.lastMousePos[1]
  24.             screenX = wx.GetMousePosition()[0]
  25.             screenY = wx.GetMousePosition()[1]
  26.             self.Move(wx.Point(screenX - windowX, screenY - windowY))
  27.         event.Skip()
  28.  
  29.     def OnFrame1LeftDown(self, event):
  30.         self.lastMousePos = event.GetPosition()
  31.         event.Skip()
  32.  
  33.     def closeWindow(self, e):
  34.         self.Destroy() #prevent memory leak
  35.  
  36. if __name__ == "__main__":
  37.     app = wx.App()
  38.     frame = create(None)
  39.     frame.Show()
  40.     app.MainLoop()
  41.  
  42.  
This now drags the window correctly, and at the same speed the mouse moves. Consider adding an 'x' button or option to close the window for the user. Alt-F4 on windows will close it in its current state.
Feb 16 '16 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Stéphane Ninin | last post: by
4 posts views Thread by Zach Shutters | last post: by
10 posts views Thread by Robert | last post: by
1 post views Thread by Todd7 | last post: by
2 posts views Thread by Rich Churcher | last post: by
7 posts views Thread by John Salerno | last post: by
3 posts views Thread by Tom Brown | last post: by
2 posts views Thread by timw.google | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.