Have a popupmenu appear on a popupmenu on right-click - python

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

Related

tkinter disable right click on a pop-up menu

I have a pop-up menu that comes up when I right click on a widget in tkinter
def popup(event):
self.popup_menu.tk_popup(event,x, event.y, 0)
popup_menu = tk.Menu(widget, tearoff=False)
popup_menu.add_command(label='whatever', command=lambda: print('whatever'))
...
bind('<Button-3>', popup)
It pops up fine, but a command runs even when it is right clicked. I would like to make the command run only when it is left clicked, to prevent weird behavior when releasing the right button.
I've looked through the options here, and there's not too much information elsewhere about pop-up menues. If anyone knows how to disable right-click or a work around pop-up where I can control things like that.
EDIT: my current work around is binding the popup to the release of the right button, so the release can't trigger an event. bind('<ButtonRelease-3>', popup)'

Turn QPushButton on and off

I have an app in PyQt with a few buttons to shift between modes of the application.
I have the clicked() signals of the buttons linked to the appropriate methods. My problem is that there are other ways to change modes (for instance, loading settings will automatically move the user to their default mode), and I'm using the QPushButtons as indicators of the "active mode". This was previously accomplished by having two icons for each button, one for the button being off and the other for the button being on. It's all been designed in QtDesigner, so clicking on one button turns it on (and turns the other buttons off) and changes the icons appropriately. And when the mouse is released, that button stays on.
The button stays on until another button is pressed.
I'm trying to figure out how I can change a button from "on" to "off" without the user actually pressing the button, so I can change modes appropriately.
The Qt docs make reference to the property I'm looking for but I can't find any more details than the fact that these states exist:
The most important modes or states are:
Available or not (grayed out, disabled).
Standard push button, toggling push button or menu button.
On or off (only for toggling push buttons).
Default or normal. The default button in a dialog can generally be "clicked" using the
Enter or Return key.
Auto-repeat or not.
Pressed down or not.
(http://qt-project.org/doc/qt-5/QPushButton.html)
To be more specific, I'm looking for a way to see the state of a QPushButton; to see whether it is "On" or "Off", and I'm looking for a way to change that state.
EDIT: I found the appropriate method QPushButton.isOn() but the problem is that it's in Qt3. (I'm using Qt5, where this method no longer exists). Clearly it's obsolete now, would anyone happen to know what replaced it?
http://doc.qt.digia.com/3.2/qpushbutton.html#isOn
QPushButton inherits from QAbstractButton and and therefore has the following methods: isChecked, setChecked and isCheckable, setCheckable. This way you can convert the button into a toggle button and ask/set the state. There is also setAutoRepeat and autoRepeat which controls the auto repeat programmatically.
Especially instead of isOn use isChecked.
Furthermore it also inherits from QWidget which has methods isEnabled and setEnabled. With this you can activate/de-active the button which is shown by graying out the button as well as by prohibiting clicks on the button.
Basically just study the documentation for QAbstractButton and QWidget to see how you can programmatically interact with a QPushButton to enable/disable it.

How to get clicks on disabled buttons with wxpython?

I have a disabled button, and it does not receive clicks when I use EVT_BUTTON on it. Is there a way to receive clicks even when it has been Disabled()?
The whole point of disabling a button is so that the EVT_BUTTON event is not fired. I'm sure you could create create an ugly hack using EVT_LEFT_DOWN and detecting where the mouse is in your app as a workaround, but why bother? This is intended behavior.
Perhaps wxpython has a mechanism similar to pygtk.
In pygtk you create a input-only (that is transparent) window over the widget you want to get clicks for and get your clicks there.

close button in pygtk about dialog not closing dialog

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.

wxPython: Change a buttons text in a wx.FileDialog

I have a wx.FileDialog (with the wx.FD_OPEN flag) & I would like to know if I can (& how) I could change the button in the bottom right of the FileDialog from "Open" to "Create" or "Delete", etc.
What I am doing is I have a button with the text "Delete Portfolio", when pressed it opens a FileDialog & allows the user to select a portfolio file(.db) to delete. So instead of the File Dialog's bottom right confirm button displaying "Open" I would like to be able to change the text to "Confirm" or "Delete" or whatever.
Is this possible, its a rather superficial thing to do, but if the button says open when the user wants to select a file to delete, it can be a little confusing even if the title of the dialog says "please select a file to delete"
Yeah, I agree with Arafangion. wxPython uses the native widgets and can only manipulate them in whatever way that native widgets allow. You would need to create a custom dialog to do this.
If you are using the native controls, which wx tends to use, then you probably can't.

Categories