Can I use pack once the main loop has been showed, or should I use something else to add /remove widgets to /from a vbox afterwards ?
I have this gtk.Window() that contains a vbox, where a menu, a treeview and a button are packed. At the push of this button, I want to display an image in a new container inside this window / vbox, and ideally, close said container at will.
(think image viewer with a file list, you click on an image file and a pane opens displaying it, if you click on another image file the new image is displayed in place of the old, and you can close the image pane)
My question is : How do you do that ? My trials so far led me to believe that once the vbox has been show()'d, you cant pack anything else into it..?
Has the "image" container have to exist prior to being displayed...?
What is the proper process to do this, in witch direction of the GTK manual should I look?
In GTK+ all widgets are hidden by default (which I think was a stupid design decision, but oh well). You usually call show_all() on a window, so indirectly show all widgets contained in it by the time of the call. If you add (pack, whatever) a widget later, don't forget to show() it manually.
Related
I have developed a Tkinter GUI and need to add a button in the GUI window top panel, next to the minimise, maximise and close buttons. The button then calls a function. How can this be done?
Tkinter doesn't have any support to do what you want. You'll have to find some sort of platform-specific library to alter what is shown in the window border.
Your only other option is to turn off the window border provided by your OS with overrideredirect, and then create your own border with whatever controls you want. This requires a lot of work because you also have to write the code for moving and resizing the window, but it's possible.
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.
I'm using python 2.7.5 on OSX 10.8. I'm learning PySide and trying to build a simple GUI.
I managed to use buttons (WOAAA!) used to chose a path or execute functions :
pathBtn = QtGui.QPushButton("FITS file path", self)
pathBtn.setToolTip('Choose the <b>path</b> to your FITS file')
pathBtn.clicked.connect(essai)
pathBtn.resize(pathBtn.sizeHint())
pathBtn.move(200, 100)
My problem is, when the program is running and I change the size of the window with the mouse cursor, the buttons don't move, don't adapt to the size variation.
I tried to find some answer (hell yeah google) and I understand that "QVBoxLayout" should do what I want (some kind of "dynamic" positionning, don't know if there's a specific name for that), but I didn't understand its syntax nor how to use it...
Any help appreciated!
In Qt widgets, layouts and the widget's size hints determine how things resize. The general procedure to layout a widget would be (for example):
dialog = QDialog()
layout = QVBoxLayout()
label = QLabel('This is a label')
edit = QLineEdit('This is a line edit box')
layout.addWidget(label)
layout.addWidget(edit)
dialog.setLayout(layout)
(*I cannot test this code here at work (no Qt/PySide), so consider this "pseudo code" :-)
This results in a dialog widget with a label and an edit box. If you resize the dialog widget, the layout and the resize properties of the widgets ensure that the label and edit box resize appropriately: horizontally both expand maximally, but vertically the edit will keep the same size while the label takes all the remaining space. This is because the resize hint of the edit box says it wants to keep its height (namely, one line of text).
If you do not specify a layout, your widgets (buttons, labels) don't do anything whenr resizing their parent widget, which is what you are observing. Hence, the solution is indeed the QVBoxLayout, use it as I described above.
By the way: for more complicated layouts, you probably want to use the Designer tool provided with Qt: this tool lets you see and test your GUI a priori.
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++