473,225 Members | 577 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,225 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 7130
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.