from PySide import QtGui
class SingletonType(type):
_instance = None
def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(SingletonType, cls).__call__(*args, **kwargs)
return cls._instance
class MainWindow(QtGui.QMainWindow):
__metaclass__ = SingletonType
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle('Singleton Window')
self.resize(640, 405)
when I run this code the error will show up like this.
# Error: ImportError: file <maya console> line 1: No module named PySide
My pycharm is already getting maya's PySide2, QtGui, QtCore and QtWidgets.
Hi! @stuzzz Thanks for the reply.
I tried to import PySide2 like this.
import PySide2
print('PySide2')
It shows PySide2 so I think I was able to import it. but when I tried that command in 1 comes error.
# Error: NameError: file <maya console> line 12: name 'QtGui' is not defined #
so I tried. but come error again.
import PySide2
import QtGui
# Error: ImportError: file <maya console> line 2: No module named QtGui #
Have you tried the above command? Did it work?
thank you. I did but its show the error
# Error: AttributeError: file <maya console> line 12: 'module' object has no attribute 'QMainWindow'
I tried two patterns.
import PySide2
from PySide2 import QtGui
class SingletonType(type):
_instance = None
def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(SingletonType, cls).__call__(*args, **kwargs)
return cls._instance
class MainWindow(QtGui.QMainWindow):
__metaclass__ = SingletonType
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle('Singleton Window')
self.resize(640, 405)
from PySide2 import QtCore, QtGui, QtWidgets
import maya.cmds as cmds
class SingletonType(type):
_instance = None
def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(SingletonType, cls).__call__(*args, **kwargs)
return cls._instance
class MainWindow(QtGui.QMainWindow):
__metaclass__ = SingletonType
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle('Singleton Window')
self.resize(640, 405)
I'm sorry to bother you but could you please try this code?
You've made a mistake here:
class MainWindow(QtGui.QMainWindow):
class MainWindow(QtWidgets.QMainWindow):
Then there is an error concerning your metaclass design. If not sure to know what you try to achieve ...
Can't find what you're looking for? Ask the community or share your knowledge.