wxPython: Change a buttons text in a wx.FileDialog - python

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.

Related

Tkinter navigate page to page with the same background

I don't know How structure the GUI of my program...
I don't have big experience with GUI programming, i know all the widgets, the
geometry managers, the "object-oriented" method in Tkinter, but i don't understand
how combine all this things...
I want to create a program with an image in background where there is a button and if i press this button i switch in another page and the button disappears
Like this : https://moqups.com/iampirla#gmail.com/wyM7CyET/p:a80e8d902
How i can structure my code to do this?
You could use pack_forget() this removes the widget although allows you to use it later if you wish. You could do the first page and then use some code like below. To clear the page. This could then reference the next thing you wish to do using in this example question().
def answred():
nameLabel.pack_forget()
nameEntry.pack_forget()
nameButton.pack_forget()
classQuestion.pack_forget()
button1.pack_forget()
button2.pack_forget()
button3.pack_forget()
question()
You could this but not remove the background widgets

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

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.

PyQt Button Selection

I have a PyQt GUI set up that has a selection of QPushButtons and a QLineEdit text box (among other things). The text box is set up so as to call a function upon returnPressed(). My problem is that when I click on the text box and put in text, one of the buttons becomes selected which means that when I press enter in the text box it activates both the button and the text box function.
Is there a way around this? Some way to stop any buttons from being selected while the text box is being edited?
The code is fairly long so I can't add it here but if there are any questions regarding layout or anything that may be relevant, please ask.
Thank you for any help you can offer
From your question and comments, I'm guessing that the buttons and line-edit are in a QDialog, and that the selection/highlighting occurs due to the default/autoDefault property of buttons.
Normally, these properties will be set to False, but in a QDialog they are automatically set to True. The button that is the current default gets an additional frame drawn around it (even when it doesn't have the keyboard focus), and is activated whenever the return key is pressed.
You can of course prevent this behaviour by simply doing:
button.setDefault(False)
button.setAutoDefault(False)
for each button in the dialog.

Create button to browse folders and select a file in python

I'm developing a python widget using tkinter where I need a button which will operate like any of the open button we see today. Basically I want it to help users to browse a file, select it and click ok. What i want is , as soon as the user clicks 'ok', it'll copy the file from that location and save it into a particular location in a particular name, which will be then used by rest of my widget.
Thanks in advance.
Take a look at the various widgets in tkFileDialog. They could be very useful. Particularly, you might want askopenfilename which will pop up a dialog where you can browse for a particular file -- When the user hits OK it returns a filename which you can do whatever you want with.

Categories