close button in pygtk about dialog not closing dialog - python

I'm drawing an interface for a pygtk application using glade, and I've made an about dialog. I'm having trouble with the close button in the about dialog. The close button in the credits operates as expected, but in the about dialog the button does nothing, so it has to be closed with the windows manager. I went to select the button by clicking on it and by expanding the items contained in the GtkHButtonBox, but I can't expand it in the top right section, and if I click on it it just selects the GtkHButtonBox. I've looked it up and found
GtkAboutDialog Close Button Bug and
About Dialog
I tried following those instructions, but thought they seemed a bit funny since it puts destroy immediately after show, and that's exactly what it's doing, it just destroys it straight away after showing it. I also looked in the pygtk tutorial but that hasn't been updated since 2005, so doesn't have anything about the about dialog.
filename = "sudoku_gui.glade"
builder = gtk.Builder()
builder.add_from_file(filename)
builder.connect_signals(self)
aboutWindow = builder.get_object('about_Sudoku')
aboutWindow.show()
Please help me with it, I'll be much appreciated.
Solution:
Because the solution doesn't directly provide the detail needed, I'll put it in here for reference. The last line should be changed to
aboutWindow.run()
not show(), then add
aboutWindow.destroy()
which will close the dialog when the close button is clicked.

Try this page : http://zetcode.com/tutorials/pygtktutorial/dialogs/
Hope this helps.

Related

How to keep an urwid.Edit always in focus?

I have programmed with python+urwid a ircII-like screen, where I have a text flow the entire screen of the terminal, plus an editable text at the bottom as the prompt, to let the user insert commands and press enter.
The main body of the screen is an urwid.SimpleFocusListWalker and for each line of new text (e.g. command response) a new urwid.Text is created.
This code shows how I create the layout.
self._widgetPromptText = urwid.Edit(self._textPrompt, initial_text)
self._widgetLinesList = urwid.SimpleFocusListWalker([])
self._widgetBufferListBox = urwid.ListBox(self._widgetLinesList)
self._w = urwid.Frame(header=self._widgetHeader,
body=self._widgetBufferListBox,
footer=self._widgetPromptText,
focus_part="footer")
Ok, now the problem is that when my terminal window loses focus, and I click on it again, by clicking the title bar of the xterm window, OR by directly clicking the bottom urwid.Edit that acts as the user's input for commands, everything is fine.
BUT, if I click on the screen of the xterm window, the bottom urwid.Edit loses focus, so it also loses the cursor. I have to click again on the urwid.Edit to get the cursor appearing again, and be able to write.
It seems that when with the mouse I click the screen, urwid leave focus from the bottom urwid.Edit and gives it to the urwid.SimpleFocusListWalker or the urwid.ListBox, without the possibility of giving back focus to the urwid.Edit, unless I click with the mouse on it.
I definitely don't want this!
How I can tell urwid to not give focus to the urwid.SimpleFocusListWalker or the urwid.ListBox, or simply to give focus to the urwid.Edit when one of them gets it?
More importantly, I wish to be possible to tell urwid to never leave focus from the urwid.Edit I use to write commands.
Any help?!
Uhm, it seems I have been able to solve the error by adding this code to my class:
def mouse_event(self, size, event, button, col, row, focus):
pass
Now, when I click on the surface of the terminal, the cursor doesn't disappear anymore.
That's exactly what I was looking for.

Have a popupmenu appear on a popupmenu on right-click

I have a wx Popupmenu appear when I left-click on a toolbar LabelTool. I already have a binding to have a handler run when I left click an item in the menu, but I want another popup menu to appear when I right click an item in the original popup menu. I've already tried binding it to wx.EVT_RIGHT_DOWN but it doesn't do it. Whenever I try right clicking on a menu object, it seems it still calls the wx.EVT_MENU, which calls the same handler as a left-click would. How would I implement this?
As far as I can tell, that is not supported. Besides, no user is going to expect that they need to right click on a context menu anyway. You should rethink your design so it's more intuitive. Perhaps by using a sub-menu instead of a secondary popup menu

Pygtk : i would like an example of creating a dialog box (instantiate, run, hide) , mine doesn't disappear after OK

Is there any clear example of how to use message Dialog box ? i tried to implement mine but it crashes the program. When it comes up and i click OK, it doesn't disappear, it becomes a little tiny window still hanging in the middle of the screen, that leaves me no option but CTRL-Z.
I am using glade to read my file, the glade file has the main window and other small windows some of which are window plots and others are Message dialog boxes.
Just a pseudcode is helpful
again, i have a main class, which retrieves all the objects that are needed from the glade file, then class the appropriate class handler signals.

How do you switch between two windows in PyQt?

I want to make a new PyQt window show up and hide the current window when I click a button. After playing around for hours, I haven't found a good way to do this.
When I try to show a new QDialog and hide the current one, the program closes. It works if another window is open. I believe this is because it is viewing the last window as closing and terminates, or maybe the new QDialog is falling off the stack.
My current method involves storing the QDialog as a variable in the current dialog, then showing it and hiding current dialog. This seems like a total hack, though.
Example below:
def _createQuestion(self):
# initialization of the UI and everything goes on in the constructor
self.dialog = QuestionBanks()
self.dialog.show()
self.hide()
Is there a better way of switching a single window to a distinct different single window in PyQt4?

How to change the OSX menubar in wxPython without any opened window?

I am writing a wxPython application that remains open after closing all of its windows - so you can still drag & drop new files onto the OSX dock icon (I do this with myApp.SetExitOnFrameDelete(False)).
Unfortunately if I close all the windows, the OSX menubar will only contain a "Help" menu. I would like to add at least a File/Open menu item, or just keep the menubar of the main window. Is this somehow possible in wxPython?
In fact, I would be happy with a non-wxPython hack as well (for example, setting the menu in pyobjc, but running the rest of the GUI in wxPython). wxPython development in OSX is such a hack anyway ;)
UPDATE: I managed to solve this problem using the tip from Lyndsey Ferguson. Here's what I have done:
On startup I create a window which I show and hide immediately. I set its position to (-10000,-10000) so that it does not flicker on the screen (aargh, what a dirty hack!)
I create an empty EVT_CLOSE event handler in that window so that it cannot be closed.
It seems that destroying a window resets the OSX menu, but hiding does not... So when the last window is closed, I need to show and hide this window again (hiding is necessary so that the user cannot switch to this window using the Window menu or Cmd-`)
Yeah, this is really ugly... I will be very grateful if someone comes up with a prettier solution.
UPDATE 2: Actually it can be solved in a much easier way: if we do not close the last window, only hide it. And ensure that it does not respond to menu events anymore.
Nowadays you can use wx.MenuBar.MacSetCommonMenuBar() to set the menu bar (which you have to create) that should be used when no windows are open.
If you just want a default macOS menu bar to be used (with the application and Window menus already there), this appears to be the minimal code:
menubar = wx.MenuBar()
wx.MenuBar.MacSetCommonMenuBar(menubar)
This will let your app respond to Command+Q out-of-the-box, too.
The wx.MenuItem IDs wx.ID_ABOUT and wx.ID_EXIT are special as menu items with those IDs are moved to the macOS Application menu. The docs actually refer to the application menu as the "Apple" menu (e.g. the menu described in the wx.MenuBar.OSXGetAppleMenu() function's docs is the application menu), possibly for historical reasons.
Can you create a hidden window that is offscreen somewhere? It is a hack, but I remember having to do a lot of hacks to make my wxPython-based application work correctly on Mac OS X.
Note:You'll have to disable the close button and set up that hidden window so that it doesn't show up in the Window menu.
Aside:Have you considered factoring out your GUI portion of your Python application and using PyObjC on Mac OS X? You'll get more native behaviours...

Categories