Reputation: 11
I keep getting this error and I'm kind of stuck. I know that it has something to do with the last bit of code but, other than that, I'm mostly confused and I'm not really sure how to go about fixing it/implementing fixes.
The section that calls Panel (part of a visual options menu):
self.AutojoinMemosPanel = GUI.Options.Panels.AutojoinMemos.Panel(self.config,self)
self.pages.addWidget(self.AutojoinMemosPanel)
Panel:
from PyQt4 import QtCore
from PyQt4 import QtGui
class MemoEntryItem(QtGui.QListWidgetItem):
def __init__(self,MemoName):
QtGui.QListWidgetItem.__init__(self,MemoName)
self.MemoName = MemoName
class Panel(QtGui.QWidget):
def __init__(self,Config,userprofile):
QtGui.QWidget.__init__(self)
self.Config = Config
self.AutoIdentifyCheck = QtGui.QCheckBox("Automatically identify with nickserv")
self.PasswordLabel = QtGui.QLabel("Password:")
self.PasswordEntry = QtGui.QLineEdit()
self.PasswordEntry.setEchoMode(QtGui.QLineEdit.Password)
self.TitleLabel = QtGui.QLabel("Memos to join on startup:")
self.MemosList = QtGui.QListWidget()
self.MemoNameEntry = QtGui.QLineEdit()
self.RemoveButton = QtGui.QPushButton("REMOVE")
self.AddButton = QtGui.QPushButton("ADD")
Layout = QtGui.QVBoxLayout(self)
Layout.setAlignment(QtCore.Qt.AlignTop)
Layout.addWidget(self.AutoIdentifyCheck)
NickservPasswordLayout = QtGui.QHBoxLayout()
NickservPasswordLayout.addWidget(self.PasswordLabel)
NickservPasswordLayout.addWidget(self.PasswordEntry)
Layout.addLayout(NickservPasswordLayout)
Layout.addWidget(self.TitleLabel)
Layout.addWidget(self.MemosList)
Layout.addWidget(self.MemoNameEntry)
AddRemoveButtonLayout = QtGui.QHBoxLayout()
AddRemoveButtonLayout.addWidget(self.RemoveButton)
AddRemoveButtonLayout.addWidget(self.AddButton)
Layout.addLayout(AddRemoveButtonLayout)
self.connect(self.RemoveButton,QtCore.SIGNAL("clicked()"),self,QtCore.SLOT("RemoveSelectedMemo()"))
self.connect(self.AddButton,QtCore.SIGNAL("clicked()"),self,QtCore.SLOT("AddMemoFromTextEntry()"))
if self.Config.userprofile.userprofile.get("AutoIdentify",False):
self.AutoIdentifyCheck.setChecked(True)
self.PasswordEntry.setText(self.Config.userprofile.userprofile.get("NickservPassword",""))
for MemoName in self.Config.config.get("AutojoinMemos",[]):
self.AddMemoEntry(MemoName)
@QtCore.pyqtSlot()
def RemoveSelectedMemo(self):
self.MemosList.takeItem(self.MemosList.currentRow())
@QtCore.pyqtSlot()
def AddMemoFromTextEntry(self):
MemoName = str(self.MemoNameEntry.text()).strip()
if (MemoName != ""):
self.AddMemoEntry(MemoName)
self.MemoNameEntry.setText("")
def AddMemoEntry(self,MemoName):
self.MemosList.addItem(MemoEntryItem(MemoName))
def SaveOptions(self):
MemosListed = []
for MemoIndex in range(self.MemosList.count()):
MemoItem = self.MemosList.item(MemoIndex)
MemosListed.append(MemoItem.MemoName)
self.Config.set("AutojoinMemos",MemosListed)
self.Config.userprofile.userprofile["AutoIdentify"] = self.AutoIdentifyCheck.isChecked()
self.Config.userprofile.userprofile["NickservPassword"] = str(self.PasswordEntry.text())
self.Config.userprofile.save()
Any help?
Upvotes: 1
Views: 4437
Reputation: 21667
At first thought, one of two things could be happening here. Upon deeper inspection, there's only one.
Let's assume, since you didn't state explicitly, that the problematic line is:
if self.Config.userprofile.userprofile.get("AutoIdentify",False):
Then when you get the error
AttributeError: 'NoneType' object has no attribute 'userprofile'
means that you are trying to access an attribute which does not exist (which is the meaning behind has no attribute 'userprofile'
), and that the object you're checking an attribute for doesn't exist, since the type of an object that doesn't exist is NoneType
(which is the meaning behind 'NoneType' object
).
So to debug, you want to look for possibilities where the object accessing userprofile
could be None
(i.e. not assigned or null). This is possible at
self.Config.userprofile #1
and
self.Config.userprofile.userprofile #2
In #1, if the value of Config is None
, then self.Config.userprofile
will throw that AttributeError because Config
is a NoneType
object, and thus has no attributes--let alone a userprofile
attribute.
In #2 if the value of userprofile
of self.Congig
is None
, then self.Config.userprofile.userprofile
will throw that AttributeError because userprofile
is a NoneType
object and therefore has no attributes either.
However, you can eliminate one of these two options.
Think about it, #2 could never throw this error because if the attribute userprofile
of the object self.Config
was None
(as expained above), then you would first throw a different error:
AttributeError: 'Config' object has no attribute 'userprofile'
If Config
object did have an attribute userprofile
then you would get the error:
AttributeError: 'userprofile' object has no attribute 'userprofile'
Therefore, Config
must be None
, which means you're not passing Config
in with a value to __init__
.
Hope this helps to fix your issue and to debug better on your own!
Upvotes: 3