PyGtk - Can't open the same window twice - pygtk

I've been using PyGtk to make an indicator that will show a preferences window when a button is pressed. The window is built once and opened using show_all() on a button press. When opened a second time, however, there widgets in the window disappear. Is there a way I can show and close the same window multiple times? The following code will reproduce the problem after closing it for the first time
#! /usr/bin/python
import gtk
def show():
window.show_all()
return True
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
gtk.timeout_add(2000, show)
gtk.main()

You need to hide the window instead of closing it.
Adding the following code will hide the window when the close button is clicked.
def hide_window(window, event):
window.hide()
return True
window.connect('delete-event', hide_window)
From the PyGTK FAQ:
http://faq.pygtk.org/index.py?req=show&file=faq10.021.htp

Related

Application closed entirely when closing a pyopengl window

I have a GUI developed with pyside2, i have a button in this GUI, when clicking on it, a pyopengl window appears and showing what is needed. The problem is that when closing this window, the entire GUI closed. I want to continue using the GUI after closing the opengl window.
I'm using GLUT to create the window.
my_GUI_mainwindow.py:
import pyopengl
...
...
...
self.Btn.clicked.connect(self.opengl)
def opengl(self):
pyopengl(file_m)
my_pyopengl.py:
glutInit()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
glutInitWindowSize(pyopengl.g_Width, pyopengl.g_Height)
glutCreateWindow(self.fileName)
self.init()
glutReshapeFunc(self.reshape)
glutDisplayFunc(self.display)
glutMouseFunc(self.mouse)
glutMotionFunc(self.motion)
glutKeyboardFunc(self.keyboard)
glutMainLoop()

Not able to switch pop up window having different action points

I am unable to switch pop-up using selenium on "http://www.azurespeed.com/Azure/UploadLargeFile" after clicking "Start Testing". It is not a frame, alert or window. I want to click on "Choose file" button. I believe it is not a window pop-up as it is present on DOM.
Yes, you are right. It is present in DOM, you can locate the respective element and perform click action.
Code - driver.findElement(By.xpath("//*[#id='file-input']")).click();
After execution of above code window file upload pop up will open.
you need to wait until upload popup appear then for file input use send_keys() to set the value
driver.find_element_by_css_selector('a[data-target="#upload-modal"]').click()
# wait until upload dialog appear
file_input = WebDriverWait(driver, 5).until(
lambda d: d.find_element_by_id('upload-modal').is_displayed()
)
file_input = driver.find_element_by_css_selector('#file-input')
file_input.send_keys('/path/to/file.ext')

Set focus to child window in PyGtk

I am writing a simple application in python using PyGObject and glade. The application has a main window and a functional window (Generate logs, also a Window object) which opens up on clicking a menu item.
The Generate logs window is supposed to:
Show options to generate log for a particular date
Be minimizable and should close automatically when the task is complete (OR)
Be able to be closed manually if the user wishes so
The problem is, once I show up the Generate logs window, I am directly able to select the main window as well. Then, I can go to the menu and bring up as many Generate logs windows as I want.
I have tried several options (Is Focus, setting up main window as Transient parent etc) but nothing worked. How can I fix this?
First you say PyGTK, then you say PyGObject, this are 2 different things. I'm going to answer for PyGTK (my sources are from GTK+ 2 docs) since it's in the title and maybe people looking for that will end up here. But never fear, because for this question, the answer is practically (I think exactly) the same for both.
What I understand is that you want you "Generate log" window to be modal. That means other windows can't be used while your modal window is up, just like a Dialog window. Also you should set the main window to be the parent of your modal window, since this helps the OS Window Manager i.e. keep the dialog on top of the main window.
Yo can do both of this things directly from Glade (if you've created both windows in the same project, not always the case) selecting the Modal atribute to True and the Transient for Window attribute to your main window, in the General Properties section of your Generate log window.
Also you can do it programmatically using the set_modal() and the set_transient_for(parent_window) method of your child window.
Let's say your parent window is called main_window and the child window is generate_log_window, then you can do it like this:
generate_log_window.set_modal(gtk.TRUE)
generate_log_window.set_transient_for(main_window)
If you want it to show center top of your main window, do this
generate_log_window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
To your second point, the ability to minimize can be set from Glade.
Sources:
GTK+ 2 GtkWindow reference set_modal
GTK+ 2 GtkWindow reference set_transient_for
PyGTK FAQ: How do I get my windows to show up where I want
PyGTK FAQ: How do I make a dialog block the whole application, so the user is forced to answer it?
create several windows (see your other post).
Upload them in init
Show them with "signals" in glade using "show" and "hide"
class GUIxxxx
#...
def action1(self, widget, data=None):
self.window1.show()
def action2(self, widget, data=None):
# do something here
self.window1.hide()

GTK builder: Empty dialog window after WM-kill

I used glade to build my GUI.
Now i have a transient top level dialog window that pops up. If i kill this dialog window with a window manager shortcut, it gets deleted/destroyed. I catch those signals an do a dialog_window.hide() but if i reopen the dialog window an empty window appears.
Am i missing some glade settings?
Or do i have to rebuild the dialog window each time? - When yes, how?
Here is my glade-file: http://codepad.org/dP7NOlob
The window i'm talking about is named edit_account_window
If the WindowManager kills the window all widgets get deleted, so the window needs to be rebuild. This can be done like this:
def buildFooWindow(self):
self.builder.add_objects_from_file( 'glade_file_path', ['foo_window'] )
self.builder.connect_signals({'foo_window_cancel': self.fooWindowCancel})
So you have to call this function each time you want to show the window.

simplemodal close function

I love the osx version of the simple modal. However, I would like to do some data editing in the opened modal box.
Now when the user clicked outside of the modal, it'll close. So if the user accidentally clicked the outside of the modal, their information will be lost.
How do I disable closing when click outside of the modal? thanks!
Go to Line 28 of the file "osx.js" that is included in Simple Modal OSX Style Dialog. Change overlayClose: true to overlayClose: false.