473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 7155
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

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

Similar topics

7
by: Stéphane Ninin | last post by:
Hello world, I am fighting with what is probably a stupid problem. In a wxpython GUI, here is a method which must read a file, and if the file is not correctly formed rename it and create a...
4
by: Zach Shutters | last post by:
I am new to python and working my way through the van Rossum tutorial. I am cursios though about if you can program windows with python? I know I shouldn't worry about this right now but I am...
25
by: TPJ | last post by:
GUI's etc: PyGtk on Windows "(...) So if someone develops mainly for X and just wants to make sure that it is not impossible to run on Windows, you can use PyGTK. (...)", July 2nd, 1999 pyGTK...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
1
by: Todd7 | last post by:
I am writing a python program to load a pdf file into an IEHtmlWindow which displays it through adobe acrobat reader 7. Depending on the buttons the user clicks, the program moves it to another...
2
by: Rich Churcher | last post by:
Is there a way using any of the Python UI toolkits to generate popup menus outside the context of an application? For example, middle-clicking on the desktop shows a list of shortcuts to choose...
7
by: John Salerno | last post by:
I was reading in the wxPython wiki that most of the time you don't have to include the id parameter at all, and you can just use keyword arguments for other parameters. But I'm having trouble...
3
by: Tom Brown | last post by:
Hey people, I've written a python app that r/w eight serial ports to control eight devices using eight threads. This all works very nicely in Linux. I even put a GUI on it using PyQt4. Still...
2
by: timw.google | last post by:
The subject line says it all. Is there a way to install wxPython on a Windows machine without admin privs? I love the way python doesn't need admin to install locally, and I'd like to try wxPython...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.