name 'QtGui' is not defined - but it is!

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
AleksClark
Posts: 2
Joined: Fri Jan 06, 2017 2:21 pm

name 'QtGui' is not defined - but it is!

Post by AleksClark »

Running the latest git version, I'm getting "name 'QtGui' not defined" when trying to open the OpenSCAD workbench. Fine, one might assume something about pyside...except it's installed, and defined, as shown in the console (I ran the console command /prior/ to attempting to open the OpenSCAD workbench).

Image
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: name 'QtGui' is not defined - but it is!

Post by DeepSOIC »

I can confirm. I can't activate OpenSCAD workbench too.

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.9422 (Git)
Build type: Debug
Branch: (HEAD detached at FC/master)
Hash: 6378f611582b47840d771cdc23324a66c67d0e22
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0

In contrast, here it works fine:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.8361 (Git)
Build type: Release
Branch: DeepSOIC10
Hash: 4ac7673e543274bcae856872033a114c7b60481b
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: name 'QtGui' is not defined - but it is!

Post by wmayer »

No problem here. Can you run this Python command in the console, please?

Code: Select all

Gui.activateWorkbench("OpenSCADWorkbench")
When it fails it should show the call stack which nay give some more hints about the reason.
AleksClark
Posts: 2
Joined: Fri Jan 06, 2017 2:21 pm

Re: name 'QtGui' is not defined - but it is!

Post by AleksClark »

I ran it, but didn't get a backtrace. Is there a debug mode or somesuch?
User avatar
easyw-fc
Veteran
Posts: 3630
Joined: Thu Jul 09, 2015 9:34 am

Re: name 'QtGui' is not defined - but it is!

Post by easyw-fc »

wmayer wrote:No problem here. Can you run this Python command in the console, please?

Code: Select all

Gui.activateWorkbench("OpenSCADWorkbench")
When it fails it should show the call stack which nay give some more hints about the reason.
I get only these warnings:

Code: Select all

Cannot find icon: python
Cannot find icon: python
here some more test results
viewtopic.php?f=3&t=19613&start=10#p151845
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: name 'QtGui' is not defined - but it is!

Post by wmayer »

AleksClark wrote:I ran it, but didn't get a backtrace. Is there a debug mode or somesuch?
When deleting my user config file then I can confirm the issue. And yes there is no stack trace but pops up the error dialog even when typing the command into the Python console.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: name 'QtGui' is not defined - but it is!

Post by wmayer »

OK, I found it: git commit bf5dcbd
User avatar
easyw-fc
Veteran
Posts: 3630
Joined: Thu Jul 09, 2015 9:34 am

Re: name 'QtGui' is not defined - but it is!

Post by easyw-fc »

wmayer wrote:OK, I found it: git commit bf5dcbd
it is fine in FC 9546, but I still miss two icons

Code: Select all

Cannot find icon: python
Cannot find icon: python
Image
thx
Maurice
mlampert
Veteran
Posts: 1772
Joined: Fri Sep 16, 2016 9:28 pm

Re: name 'QtGui' is not defined - but it is!

Post by mlampert »

wmayer wrote:OK, I found it: git commit bf5dcbd
A similar pattern is used all over the place and I'm sure it is correct, or what the correct pattern /should/ look like. As an example I use the code from SplitFeatures.py because it currently breaks running the Path unit tests from the command line:

Code: Select all

if FreeCAD.GuiUp:
    import FreeCADGui
    from PySide import QtCore, QtGui

#-------------------------- translation-related code ----------------------------------------
#(see forum thread "A new Part tool is being born... JoinFeatures!"
#http://forum.freecadweb.org/viewtopic.php?f=22&t=11112&start=30#p90239 )
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except Exception:
    def _fromUtf8(s):
        return s
try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)
Specifically QtGui is only loaded if GuiUp is true - which it isn't if the tests are run from the command line - yet the code still uses QtGui to do the translation. git commit bf5dcbd does a similar thing, loading QtGui in the try block, but still using it in the except block. There are a few variations in different sources including importing QtGui unconditionally.

Question: How should this pattern properly be implemented so it works for translation in all cases including running code from the command line?

Second question: Would it make sense to implement "translate(...)" in FreeCAD proper so every python script can just use it instead of having to duplicate the same code everywhere?
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: name 'QtGui' is not defined - but it is!

Post by wmayer »

Second question: Would it make sense to implement "translate(...)" in FreeCAD proper so every python script can just use it instead of having to duplicate the same code everywhere?
Actually I don't see any need to implement a translate() function. It would suffice to directly use QCoreApplication.translate where the third and fourth parameter is omitted to be source compatible with Qt5.
Post Reply