python tkinter full frame vs message box focus - python

I am creating a full-frame (no decorations) window with code like this (in python 3.2 using tkinter):
self.root = Tk()
self.W, self.H = self.root.winfo_screenwidth(), self.root.winfo_screenheight()
self.root.overrideredirect(1) # full screen, no menu or borders
self.root.geometry("%dx%d+0+0" % (self.W, self.H))
When I try to open a file dialog or message box, they appear UNDER the full frame window. I can verify this by calling a withdraw() on the main window before I open one of the dialogs. For example,
file = tkinter.filedialog.askopenfilename(parent=self.root) # UNDER main window
On windows I don't have a problem with this, only on fedora 14 and ubuntu 12.04 have I noticed it. (I haven't tested on Mac). I'm passing a parent to the dialogs but they don't seem to be paying attention. Can someone help me understand what I'm doing wrong? Thanks.

Calling .overrideredirect(1) on a window has a different meanings on Windows and X11. On Windows, it tells the OS to disable drawing of the window border. On X11, it tells the window manager to completely ignore the window. Realistically, it should have the same effect on Windows that it does on X11, but this is not the case.
The reason why calling .overrideredirect(1) causes the window to stay on top is because X11 does not have any control over it (as the displaying of the window is not handled by the window manager). The program window and the window manager are completely independent, so implementing standard window stacking would not make sense.
With only tkinter, there is nothing you can do to prevent this behaviour, because tkinter is not really the source of the problem. There may be a way to use X11 Python bindings to show the window without a frame, but this would result in platform specific code.
You may want to rethink removing the window border. Is there a possible alternative? A fullscreen window including the window border is a fine option. Removing window borders is not a good idea at the best of times due to accessibility reasons (no way to move, minimize, maximize, etc.). Also, personally, as a Linux user, I have my window borders customized with all kinds of features (e.g. window tabbing, shade button), and use them quite frequently. Removing the window border would prevent such features from being used.

Related

Python GTK+ 3: Is it possible to make background window invisible?

basically I have this window with a bunch of buttons but I want the background of the window to be invisible/transparent so the buttons are essentially floating. However, GTK seems to be pretty limited with CSS and I haven't found a way to do it yet. I've tried making the main window opacity 0 but that doesn't seem to work. Is this even possible and if so how can I do it? Thanks.
Edit: Also, I'm using X11 forwarding.
For transparency Xorg requires a composite manager running on the X11 server. The compmgr program from Xorg is a minimal composite manager.

pygtk window moves when resized

Setup:
OS: Ubuntu Precise (12.04) amd64
Python: 2.7.3
GTK: 2.24.0
WindowManager: metacity and FVWM2 both exhibit the same behavior
I have a small pygtk app that contains (among other widgets) a treeview. The window has resizable=False so as the treeview is expanded/collapsed, the window automatically resizes to fit the content. This all works just fine.
The problem is that when the window resizes, it stays centered on where it was. I want the top-left corner of the window to stay in the same spot when the window resizes.
I've found that calling parse_geometry() with a +x+y position will induce the desired behavior. But that's not always an option. In the typical case, I want the window to open where the mouse is, not in a fixed location.
I suspect I need to set gtk.gdk.HINT_USER_POS, but as best I can tell, pygtk's version of set_geometry_hints() doesn't allow me to pass GdkWindowHints like the C and Perl interfaces do.
How can I make the window's top-left corner stay still as the contents cause the window to change size?
Update:
Since parse_geometry() sets the bit for me, just before gtk.main(), I call
gobject.timeout_add(500, self.fix_window)
The callback is:
def fix_window(self):
self.window.parse_geometry("+%d+%d" % self.window.get_position())
While this works, it's ugly so I'd still appreciate a better alternative.

Putting Webkit onto the Nautilus desktop (on Ubuntu Maverick) with PyGTK

I can get what I think is the Nautilus desktop window by using this code:
screen = wnck.screen_get_default()
while gtk.events_pending():
gtk.main_iteration()
for window in screen.get_windows():
if window.get_name() == 'x-nautilus-desktop':
xid = window.get_xid()
wrapped_window = gtk.gdk.window_foreign_new(xid)
but when I try to do wrapped_window.add() I get the error that the Window Object does not have the add method.
I know this can be done since someone already has a youtube video demoing the effect at http://www.youtube.com/watch?v=NOlIfhXQX9g but I can't figure out how to get the background window and put a widget on it.
Anyone know how to do it?
You're mixing up gtk.Window and gtk.gdk.Window. They are not the same. The former is a toplevel desktop window and functions as a container for GTK widgets; the latter is an abstraction of an area of the screen which can be drawn on top of, and is not a container.
You can't get an application's GTK widgets using libwnck. How to achieve the effect you want I don't know, but I think you need to look more into extending the window manager, since that is what manages the desktop.

How do I get a windows border like this in Tkinter?

Is there any way to get a border like this in Tkinter? Notice how it lacks the buttons on the top right. Also I don't want this program to show in the task bar.
This is in windows 7, btw.
Tk (and thus, Tkinter) has a command for removing all window manager decoration. This command in tkinter is the "wm_overrideredirect" method of toplevel windows. Pass it a parameter of True to remove the window manager decorations. You can then draw whatever borders you want, usually by packing a canvas over the entire window and drawing on the canvas.
However, when I experiment with this on my Mac, the window appears properly but won't take focus. Perhaps this is a bug in Tkinter. I don't see the same problem with identical code in Tcl.
The WS_DLGFRAME window style should give you a window without a titlebar and WS_EX_TOOLWINDOW is normally also used for a window like this so it is not visible in the taskbar (Or with a hidden parent window like control panel dialogs before Vista) You can figure out the exact window styles with a tool like Spy++ (Visual Studio) or WinSpy++

Which display manager for a non interactive Python app and mplayer?

I am developing an application that will run on Linux to run fullscreen all the time (no menus or trays or anything will be visible).
The application is going to be developed in Python, not that that matters as far as the window manager, but what I am having a hard time with is choosing a window manager.
I need something with the smallest possible footprint, that will let me run a graphical Python app and have an mplayer window at the same time, at widescreen resolutions (widescreen, 16:10,16:9, etc). Other than that, it doesn't need a lot of features, but the end footprint size is the most important thing I'll be looking at.
What window manager would you recommend?
EDIT: There won't be any interaction with the application needed.
You don't actually need any window manager or display manager. All you need to do is open your initial window with the same geometry as the root window. I suppose you could even draw directly into the root window if you wanted.
If you are using some display library it probably has an easy way to open a full screen window. For example using a recent enough version of SDL through pygame you can do
pygame.display.init()
surface = pygame.display.set_mode((0,0),pygame.FULLSCREEN,0)
to get a window that fills the entire screen. This will work even if there is no window manager running.
As for mplayer, it accepts the -geometry flag, so you can use something like mplayer -geometry 640x480+20+20 to display the mplayer window 20 pixels from the top 20 pixels from the left and with a size of 640x480 pixels.
You probably meant window manager. Display manages are KDM, GDM and the like. Windoe managers, to name, GNOME, Xfce, KDE, ratpoison, fvwm, twm, blackbox are a few. ratpoison gives full screen to the application that is in the foreground but demands heavy keyboard interaction (hence the name ratpoison) and no mouse interaction at all.
I assume you'll be running both your python GUI and mplayer in some sort of geometries combination that shows both at the same time, filling the screen.
As commented, you should not need a window manager to achieve that. You could have your python GUI app get command-line parameters for setting its window geometry and also call fullscreen mplayer with the -geometry parameter. That should fill the screen as expected, without any window decorations.
Now you could have the startx script called for the user running it all and have a custom ~/.xinitrc script doing something like:
#!/bin/sh
exec python my_gui_app --whatever-sets-geom &
exec mplayer -fs video.avi
If yout pyhon app will instead be launching mplayer then just leave the first 'exex' call (remove the '&') and have it call mplayer as desired with the expected dimensions in '-fs' mode.
Please note you may need to use something like the 'xset' program to disable monitor blanking due to energy savings, hide the cursor (although IIRC that's something mplayer does for its own window), and things like that.
Also, somethimes running, for example, GTK apps on a bare X display may end up using an "ugly" theme, so you may need to have the toolkit style configuration taken care of someway.
I am doing something similar on my "set-top box" and I don't use any window manager.
It boots debian, and from inittab I auto-login the user that runs the display. That user's .profile starts X, which runs .xinitrc, which starts my python app that runs as a network server in front of mplayer (running mplayer in -slave mode).
My python app does not have a GUI element - only mplayer runs on the X display. But in your case, it should be no different. As I mentioned in a comment to another answer, you may want to look into how you can reparent mplayer's window to give you greater control over its placement and/or movement/size.
Doing it this way avoided a display manager and a window manager. This simplifies the solution, boots faster and uses a smaller footprint (it runs of an SD card, with heaps of room to spare).
I realize this is an old question, but I use openbox on my system, I have created a custom config file that disables all mouse keyboard shortcuts, and removes borders etc on the applications.
In the openbox config i even created some secret shortcuts that can run fx. an xterm for debugging live on the box.
The openbox documentation was very helpful in figuring everything out, I did the config in about 30 minutes.

Categories

Resources