I think I have created a problem for myself....
I have two functions and a global file descriptor(file object)
def fileController():
global fd
fName = ui.fileEdit.text()
if ui.lineByLine.isChecked:
ui.fileControl.setText('Next Line')
ui.fileControl.clicked.connect(nextLine)
fd = open(fName, 'r')
def nextLine():
global fd
lineText = fd.readline()
print lineText
def main():
app = QtGui.QApplication(sys.argv)
global ui
ui = uiClass()
ui.fileControl.clicked.connect(fileController)
ui.lineByLine.stateChanged.connect(lineByLineChange)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
when nextLine() is called, it returns the first line.
if it is called again it returns the first line and the second line.
if it is called yet again it returns the first line and the second line and the third line.
etc. etc.
could the file descriptor being a global variable cause this?
complete un-redacted code can be found here
all help is appreciated!
EDIT: included more of the code for context
EDIT2: added link to github project file
SOLVED: problem was that:
ui.fileControl.clicked.connect(nextLine)
does not disconnect the previous signal. so every time file Control() was clicked a "signal and slot" was added so that newLine() was called multiple times. And as fileController was still being called the file was being reopened. So I saw the behaviour above. Thanks for all the advice!