How to click on QTextEdit with cursor in PyQT5 code - python

I have a QTextEdit acting as a input field of sorts so whenever you click the post button, it posts whatever is in that QTextEdit. However after I hit post, the text edit deselects which is annoying to have to keep clicking on it before I type more. Is there a method or way in PyQT5 to click on that text box automatically in my code without having to manually move my mouse?
I looked into QTextCursor but that appears to be more for the actual text inside of the text box instead of the box itself. If there's a way to do this, I would greatly appreciate it, thank you!

Related

How to add an extra checkbox to a messagebox in tkinter?

I cannot resolve the following problem for ages. How to add an extra checkbox to a standard message box in Tkinter?
I watched many different videos on youtube on how to create a custom message box with tk.Toplevel, however, it works differently than a classic message box.
Basically, what I need to get is to add a checkbox like "don't ask me again" for a specific warning message. I don't believe that I need to go with the whole new message box just because of a little checkbox.
Checkbox that I want to have
Custom checkbox with TopLevel does not work properly for me. It does not pause the program (in my case, the message box pops up inside of the while loop and, depending on the response, should either break the loop or continue the execution). With the toplevel widget it just throws numerous message boxes without pausing.
I hope someone will be able to help me.

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.

How to use checkable auto-exclusive buttons

I hope find an answer. I have created an application with Python and PyQt4, and I have made the buttons checkable to select a file or folder from the treeview, and all button are auto-exclusive. The problem is when I choose another tab and check a button from there, the button in the first tab is still checked and I can't call setchecked(False). Any idea how to solve this problem ?
archive with the code and the ui used : sorry i don't know how to insert the code here .
enter link description here

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.

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.

Categories