Can pyside-uic Compile a ui file with QButtonGroups - python

Ive got a .ui file made in designer and as soon as i group some radio buttons together, pyside-uic fails to compile the file and return with an unexpected error.
Is there a way around this or am i missing something when adding these groups. Im picking the buttons i need, right clicking and creating a button group from there.
Here is the most basic version of the ui, and this even crashes for me.
http://pastebin.com/0NYHPBUD

after debugging pysideuic, i figured that in module uiparser.py in line 212 the generator fails, because it treats a string like an object.
By changing the source (https://github.com/PySide/Tools/pysideuic/uiparser.py) from:
bg_name = bg_i18n.string
to:
bg_name = bg_i18n
the generator will be working fine.
After further investigation it seems that the implementation of the QButtonGroup changed.
It used to be a Widget.
regards
Ben

Related

How to add function for QT-Designer Push Button

I am working on QT Designer to build GUI App. I want to ask how add command for push button.
For example I want to apply this action :
self.NfmtLoginButton.clicked.connect(lambda: SecondScript.printme(self.NfmtPasswordEntry.text()))
Is it possible through the QT Designer. to be permanently saved. and no need to add all the commands again when generating new python script file from UI file.
No, it's not possible, but that should not be a problem, as the files generated using pyuic should never, ever be modified (the warning in those files is not to be undertaken).
Those files should always be left unmodified and only updated again with pyuic, as they are only meant to be imported in the actual program file, as explained in the official guidelines about using Designer (the "multiple inheritance approach is generally the most suggested).

WxPython Choice Field Invisible just on Mac

I am developing a cross platform app in Python using wxPython. The app is fully developed, and the graphics toolkit is set in stone, at least for the time being.
On Windows, everything looks great. On Linux, everything looks pretty good. On Mac, I am having trouble with a combobox/choice being hidden in the toolbar, even though it shows up fine on Windows.
Here is a snapshot of my app on Linux, noting the entire "CoeffConv ..." section is part of the perfectly displayed combobox:
And here is a snapshot of the same exact codebase on Mac:
I've tried with wx.ComboBox and wx.Choice with the same effect. I've made sure to call Realize() after I've added my toolbar items. I've made sure AddControl is called to actually add the object to the toolbar. It's definitely trying to render because the spacing is exactly what I would expect, given the contents of the choice field.
In fact, if I don't call AddControl, but I create the choice field with the toolbar as the parent, the box gets rendered but things aren't arranged properly due to the missing AddControl call:
As another check, I created a super simple toolbar with choice demo, and it works just fine:
So, here's the summary of things I know:
On Windows, the choice field works perfect, indicating the code isn't necessarily wrong.
On Linux, the choice field works perfect, supporting the idea that the code is actually OK.
On Mac, the choice field is present it seems, but somehow invisible, implying this is a problem with the Mac, or the Python distribution on Mac, or the combobox control in the wxPython distribution on Mac.
On Mac, I can get the choice to render (improperly but still) without an AddControl call, indicating the combobox can render properly, but something is goofy about the placement when added to the toolbar
However, On Mac, I can get a toolbar/choice to render totally fine in a dummy example, indicating it's something about my implementation...but I can't figure out what would cause it as I'm trying to make the exact same calls to the wx objects as in the dummy example.
I can't get the dummy example to reproduce the problem, but I'll keep trying. I'm happy to report out some object properties if they would be helpful in diagnosing. If someone has a clue for what could cause it to not show up, I'd really appreciate it!
While I couldn't find the root as to why it didn't work on Mac, I did find an issue that could help others.
First a little more background. In the app, we have multiple toolbars. Because of that, we are creating toolbars using plain wx.ToolBar objects and adding them to the app frame using sizers. This is in contrast to the more standard method of using self.CreateToolBar() which only allows a frame to have a single toolbar.
When I make a single change to the code to use the more natural CreateToolBar interface, the combobox immediately shows up. When I do that, the second toolbar is messed up, but at least the initial toolbar works perfectly. I'll be investigating how to get multiple toolbars on Mac, but it's a step in the right direction.
It's been a while, but there's another solution to this for wxPython 4 if you can't use CreateToolBar():
The widgets do get added to the bar and reserve the correct amount of space, but they fail to draw properly. You can resolve this by calling control.Hide() followed by control.Show() on each widget control, which then makes them draw properly.

Access individual button inside Qt's QDialogButtonBox

Long story short. I have one python module generated from ui file, let's say dialog.py this form contains QDialogButtonBox widget
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
The question is how can I access individual button inside this buttonBox?
I have tried using ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) but it did not work, the program crashed instead.
http://pyqt.sourceforge.net/Docs/PyQt4/qdialogbuttonbox.html#button
The only thing I was able to come up is this:
ui.buttonBox.buttons()[0].setEnabled(False)
note plural buttons and it works but I am not sure if this is portable and right way.
Here is original Qt link since this is pyqt5
http://doc.qt.io/qt-5.6/qdialogbuttonbox.html#button
Regards.
The only thing I can say is that I am an idiot ;-)
I forgot to import QDialogButtonBox in this module and instead run python script directly using interpreter I ran it through 'sublime text' (text editor) build menu which gave me this message:
[Finished in 3.1s with exit code -6]
So the answer is that there was no QDialogButtonBox symbol imported which I'd have known if I run it with python interpreter.

How to close a QFileDialog.getOpenFileName in QTest?

I am developing an application in Python 3.5, using PyQt4, and I want to test it with unit test using QTest. So far I managed to do whatever I want with QTest except for this problem :
My window as a folder button, when you click it, a File Dialog open to choose a folder (classic). This is (more or less) written like that in my code :
self.file_dialog = QtGui.QFileDialog()
[...]
tmp_path = self.file_dialog.getOpenFileName(self, caption='toto', filter="*.csv")
My problem is that in QTest, I can't find a way to close this dialog when it shows up.
I already tried calling its close() or reject() method (directly or with a single shot timer), but none of these seems to work...
Is there any solution I didn't thought of ? I wouldn't mind closing all windows if that's necessary (but I can't do that either)
Thanks !
As far I have understood, you should not use the static methods (such as getOpenFileName) in tests, because you cannot control the opening of the dialog window. You should instead use the constructor, set the options you need and then call self.file_dialog.exec_() only in the real code (not in the tests).

pyqt embed in photoshop

This is complex to explain, I hope this will not end up being a vague question getting vague answers.
If this is not the right place to ask this, you may help me to find the proper one.
I have a plugin for Photoshop based on the Listener, so it captures any input from the user.
The plugin creates a python module (called here "ps") containing basically the hInstance and the hwnd of the photoshop window.
Then this plugin, using plain python commands in the plugin for the module like those
PyRun_SimpleString("import Photoshop");
PyRun_SimpleString("Photoshop.showTools()");
will load a special module (here called "Photoshop") that will initialize pyqt and using the QtWinMigrate and the ps module to get the hInstance like this: QMfcApp.pluginInstance(ps.GetPluginInstance()), will start pyqt in photoshop. Here an example code of the Photoshop module using the ps module:
from PyQt4.QtWinMigrate import QMfcApp
from PyQt4.QtGui import QPushButton
import ps #this is implemented in the photoshop plugin (based on the Listener plugin)
#create the plugin instance here
app=QMfcApp.pluginInstance(ps.GetPluginInstance())
def showTools():
box = QPushButton()
box.show()
app.exec_()
Again then, the sequence is like this:
When the plugin starts in photoshop "ps" module is created, then it will load the "Photoshop" module that will load and bind properly pyqt. In the "Photoshop" module I can load any python module, widgets are properly working and everything works really well inside Photoshop.
But now the problem is: using Wacom tablets in Photoshop loose stroke sensitivity, the driver works and everything else works but the pressure sensitivity.
Apparently QMfcApp.pluginInstance will install an event filter to drive the Qt event loop while photoshop still owns the event loop. ( http://doc.qt.digia.com/solutions/4/qtwinmigrate/qmfcapp.html )
and on the paper looks fine to me.. but I could not manage to solve this by myself and I tried, more or less carefully, different approaches:
the listener plugin is not the problem. If Listener plugin runs but python is not initialized sensitivity works fine.
python itself is not a problem. If the listener starts python without gui nor pyqt, then works fine.
as soon as I call pluginInstance which should create the QApplication the issue starts and pressure is lost from the tablet. Even with the small code I wrote before.
Someone may have put pyqt as a plugin somewhere else, since the only purpose of QMfcApp is apparently this one. There is something I can configure to make it work? Is a known issue?
I would rather keep the approach (instead of connecting to photoshop externally like with COM)
I am not able to post the entire code here but let me know if you need something.. I probably can show more.
Thanks a lot for your help

Categories