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.
Related
I'd like to write a handler for the event after the window is moved in Windows / Linux.
I need such a function to reset the behaviour of my app because dragging of the window will stop/pause all Clock.schedules and after the window is released the animation with the schedule is not starting properly.
The wrong behaviour during window move is no problem but afterwards the app should restart correctly.
Something simillar to this code for window resize:
class DemoApp(App):
def build(self):
def win_cb(window, width, height):
print 'resizing'
Window.bind(on_resize=win_cb)
Is there something like on_move? I haven't seen anything like that in the api-documentation
No, there is no way to get the current window position in Kivy. It may be possible by directly utilizing the window backend (i.e. pygame) but this is not cross-platform compatible and is quite hacky.
However, you're definitely having some other problem here. Animations and Clock schedules both work fine for me while moving and resizing the window. You might want to post another question asking why your schedules are getting screwed up, because this is not expected behavior.
I wanted to ask if it is possible to draw a child window inside a parent window so that it will only be able to move inside the parent window and won't be able to move out of the parent window bounds.
If you mean having actual windows with title bar, menu, status bar etc. inside the parent window then the answer is:
No, Tcl/Tk and by extension Tkinter does not support this with its standard widgets.
There have been efforts in the past to implement widgets which emulate MDI as you can see on the TCL wiki, but most of them are over a decade old. You will probably have to implement it yourself or choose a different GUI toolkit if you really need to implement this kind of UI design.
If you do it yourself, you can use the Frame widget as the subwindow, and use place to put it in the containing window. Or, you can create it as an object on a canvas. You'll have to write all of the code to give the inner window borders and a title bar, and to manage moving it around, iconifying it, etc.
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.
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.
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++