When I make a pygame window (I believe it uses SDL), it launches as a popup window, as I want, since then it doesn't affect the layout or visibility of elements. But if I launch a simple program using GTK and Cairo, it doesn't launch as a popup. Is there some specific env flag, signal, etc. that needs to be used to launch a window as a popup rather than a tiled window?
pygame hello world code
cairo+gtk code, GTK Window section, past mid point of page
To do this in GTK, you need to call
gtk_window_set_type_hint((GtkWindow*)windowname, GDK_WINDOW_TYPE_HINT_DIALOG);
https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-set-type-hint
i3 will take window hints, and if a window tells i3 it is a dialog window, it will make it float automatically.
Get the WM_CLASS class or instance for the window with xprop and set floating enable for the window.
For example I have this in my i3 config
for_window [instance="Game of Life"] floating enable
Related
I am working on a Frameless window for modern GUI with Tkinter. I have implemented a drag window feature but It is also working when window is behind of the taskbar, it is a big problem when I am trying to recover my window from behind of taskbar. So I want to disable the drag feature when the mouse reaches on taskbar's border.
def drag(event):
act = str(event.type)
if act == 'Motion':
global _app
#_app is a reference to root in other py file
t = _app.geometry().split('+')[1:]
xval = int(t[0])
yval = int(t[1])
_app.geometry('+'+
str(xval + event.x -400)+
'+'+str(yval + event.y -20))
#window size is fixed i.e. 800x480
When you makes a window border-less using overrideredirect() method, then this method says to operating system's windows manager to just ignore your tkinter's GUI window.
When you do this then the windows manager now takes no any responsibility for your GUI window. Each and every task like window dragging, minimization and maximization, closing event etc should be handled by you manually.
Now to solve you dragging problem on windows taskbar there are two ways.
1) As I told you before that do everything manually, then you should to locate your windows taskbar manually and then modify your drag function to prevent your mouse motion after the borders of your taskbar.
2) The simplest way is to make your GUI window a top level window by which you will able to drag your window onto the taskbar without any window hiding problem.
To make the window top level you should just set an Attribute i.e. topmost = True.
root.attributes('-topmost',1)
I'd like to know how I can have my window as a priority over other application windows.
For instance, even if my window was on top of an existing application window, and I happened to click on the existing application window, I don't want my window to hide behind the existing window, I want it to stay visible (in the foreground) at all times. Is this possible?
(Using overrideredirect, by the way)
For windows you can use topmost
root.wm_attributes("-topmost", 1)
I have a ctrl+f dialog and when I press the window, it causes the main window to lose focus. Is there a way to have both windows have focus?
Kind of, but not really. Only one window can claim focus on the desktop/operating system level. You want this to be your application or main PyQT object. Then, what you want to do is define a new window type (QObject) that will be treated like a toolbox/dialog within the parent application. This will set a child-like focus attribute. Your application will retain focus on the desktop level, and now you have another inner-focus attribute for windows spawned from within your app.
QtGui QStyleOptionToolBox
StackOverflow: pyqt popup window
My python application launches a subprocess that creates a pyglet window. When the pyglet window opens, it is in front of all other windows, and takes keyboard focus. I'd like my pyglet window to open in the background, and not take focus. Is this possible?
Stripped-down version of the code I'm using:
import pyglet
pyglet.window.Window()
pyglet.app.run()
I'm using Windows 7, in case that makes a difference..
Reversing focus is OS specific:
pyglet does not provide OS specific window control. So most likely you will have to use an ad-hoc trick for quick&dirty solutions or try to approach it with extensions like pywin32 using Windows API and/or COM to list through the stack of taskbar applications to reverse stealing of focus. You can also try to create your own window (container - which you can manipulate) first - in order to delegate its context to pyglet.
Delaying stealing of focus
On the other hand if according to your program logic you just want to delay actual showing of you application you can play with visibility:
import pyglet
w = pyglet.window.Window()
w.set_visible(False)
pyglet.app.run()
So if you don't want to play with delegation of window context, you can probably do the following:
start your application w/o showing the window
find the focus of the current active window by getting its handle/id
show your window
give back the focus to the previous window
The above assumes working with windows API. I think MSDN had examples on focus changing.. If you know PID of your current window (main application) this should simplify the step 2.
I am thinking this might be more of a windows / window manager issue than your app - will something like this http://pcsupport.about.com/od/windowsxp/ht/stealingfocus02.htm help ??
I am writing a wxPython application that remains open after closing all of its windows - so you can still drag & drop new files onto the OSX dock icon (I do this with myApp.SetExitOnFrameDelete(False)).
Unfortunately if I close all the windows, the OSX menubar will only contain a "Help" menu. I would like to add at least a File/Open menu item, or just keep the menubar of the main window. Is this somehow possible in wxPython?
In fact, I would be happy with a non-wxPython hack as well (for example, setting the menu in pyobjc, but running the rest of the GUI in wxPython). wxPython development in OSX is such a hack anyway ;)
UPDATE: I managed to solve this problem using the tip from Lyndsey Ferguson. Here's what I have done:
On startup I create a window which I show and hide immediately. I set its position to (-10000,-10000) so that it does not flicker on the screen (aargh, what a dirty hack!)
I create an empty EVT_CLOSE event handler in that window so that it cannot be closed.
It seems that destroying a window resets the OSX menu, but hiding does not... So when the last window is closed, I need to show and hide this window again (hiding is necessary so that the user cannot switch to this window using the Window menu or Cmd-`)
Yeah, this is really ugly... I will be very grateful if someone comes up with a prettier solution.
UPDATE 2: Actually it can be solved in a much easier way: if we do not close the last window, only hide it. And ensure that it does not respond to menu events anymore.
Nowadays you can use wx.MenuBar.MacSetCommonMenuBar() to set the menu bar (which you have to create) that should be used when no windows are open.
If you just want a default macOS menu bar to be used (with the application and Window menus already there), this appears to be the minimal code:
menubar = wx.MenuBar()
wx.MenuBar.MacSetCommonMenuBar(menubar)
This will let your app respond to Command+Q out-of-the-box, too.
The wx.MenuItem IDs wx.ID_ABOUT and wx.ID_EXIT are special as menu items with those IDs are moved to the macOS Application menu. The docs actually refer to the application menu as the "Apple" menu (e.g. the menu described in the wx.MenuBar.OSXGetAppleMenu() function's docs is the application menu), possibly for historical reasons.
Can you create a hidden window that is offscreen somewhere? It is a hack, but I remember having to do a lot of hacks to make my wxPython-based application work correctly on Mac OS X.
Note:You'll have to disable the close button and set up that hidden window so that it doesn't show up in the Window menu.
Aside:Have you considered factoring out your GUI portion of your Python application and using PyObjC on Mac OS X? You'll get more native behaviours...