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.
Related
I am trying to make my GUI icon go bigger.
I tried this:
MainWindow.setWindowIcon(QtGui.QIcon('Logo1.png'))
MainWindow.setIconSize(QtCore.QSize(128,128))
When 'Logo1.png' is 128x128
When I change numbers SetIconSize line, like this:
MainWindow.setIconSize(QtCore.QSize(500,500))
It doesn't show on my GUI.
My questions are:
Does this happen because I need my logo to be smaller something like 28X28?
If I need a specific size, what size is it and how do I make my logo this size?
Even if I do need a specific size, why wont setIconSize change my icon size?
The iconSize property documentation of QMainWindow explains that:
[The] size of toolbar icons in this mainwindow.
As you can see, it has nothing to do with the windowIcon.
It is up to the underlying OS and its window manager to decide the size of the icon, whether its shown in the window decoration (tipically in the title bar), the task manager/window switcher or anything else, and you don't have any control over it through Qt.
The only "exception" is when drawing client-side windows: windows for which the whole decoration is drawn by the program (the title bar with its system buttons and icon, the frame around the window, etc.).
That is, though, something that is usually discouraged as it's hard to achieve without facing various difficulties (both with drawing and interaction); it also makes the window appearance inconsistent with the whole system and could also create issues with accessibility for visually impaired people.
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.
I am trying to rebuild the functionality of the desktop's "highlight to select" feature so that I can use it in my own app. When I say "highlight to select" I mean the selection box that shows up if you click and drag on your desktop (native to all main-stream OS).
I've been working for hours trying to recreate it, and simply can't find a way. I've tried PyGTK, Xlib for python, and a couple other weird hacks. All of which have their own problems that won't allow me to move forward.
I generally don't ask for straight up example code without providing some sort of starting point, but in this project I don't even know where to start. How would you do this?
Here's the requirements:
Must draw on the root window (or a transparent layer that "appears" to be the root)
Must return the coordinates of the selection (x, y, height width)
Update: Forgot some details.
I am using Ubuntu 10.10
I have dual monitors (though, I don't think that should matter)
I don't mind downloading any extra libraries that are necessary
I don't know if this is what you're looking for, but what if you created another window in your module, and have your code show it when you release drag? You could fetch the cursor's current position, and have it draw the window there.
This should help you get the mouse position on the root window.
So, your code may look a little like this (this is untested code!) I'm only showing the relevant portions of what goes inside __ init __.
def __init__(self):
...
#Some of your code here.
...
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
#Note that I am creating a popup window separately.
popwin = gtk.Window(gtk.WINDOW_POPUP)
#I am setting "decorated" to False, so it will have no titlebar or window controls.
#Be sure to compensate for this by having another means of closing it.
popwin.set_decorated(False)
def ShowPopup():
#You may need to put additional arguments in above if this is to be an event.
#For sake of example, I'm leaving this open ended.
#Get the cursor position.
rootwin = widget.get_screen().get_root_window()
curx, cury, mods = rootwin.get_pointer()
#Set the popup window position.
popwin.move(curx, cury)
popwin.show()
def HidePopup():
#This is just an example for how to hide the popup when you're done with it.
popwin.hide()
...
#More of your code here.
...
#Of course, here is the code showing your program's main window automatically.
win.show()
A very simplistic approach, but it should give the appearance of what you're wanting.
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.
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++