It seems like the slotDirChanged is getting executed twice, becuase everything seems to be working fine,

import datetime
from PyQt4 import QtGui,QtCore
from PyQt4.QtCore import pyqtSlot
import sys
import os

class WatchFilesBin(QtGui.QMainWindow):
    def __init__(self, lookinpath=None):
        super(WatchFilesBin, self).__init__()
        self._filesBinPath = lookinpath
        self.filesList = os.listdir(self._filesBinPath)
        print self.filesList
        self.fileSysWatcher = QtCore.QFileSystemWatcher()

    def watchMyNodesBin(self):
        QtCore.QObject.connect(self.fileSysWatcher,QtCore.SIGNAL("directoryChanged(QString)"), self,       

    def recievedNodes(self):
        newUsrFile = list(set(self.filesList).symmetric_difference(os.listdir(self._filesBinPath)))[0]
        if not newUsrFile in self.filesList:
            return newUsrFile

    def slotDirChanged(self, userNodes):
        newFiles = self.recievedNodes()
        print newFiles
        if newFiles:
            userName = newFiles.split(".")[0]
            retValue = MessageBox(userName=userName)._messageBox()
            print retValue

class MessageBox(QtGui.QDialog):
    def __init__(self, userName, parent=None):
        super(MessageBox, self).__init__(parent)
        self._userName = userName

    def _messageBox(self):
        msgBox = QtGui.QMessageBox()
        msgBox.setText('Recieved Files from %s' % self._userName)
        msgBox.addButton(QtGui.QPushButton('Accept'), QtGui.QMessageBox.YesRole)
        msgBox.addButton(QtGui.QPushButton('Regect'), QtGui.QMessageBox.RejectRole)
        return msgBox.exec_()

def createFilesBin(lookInPath):
    if not os.path.exists(lookInPath):

def main():
    usr = os.getenv('USER')
    fileBin = os.path.join("/Users/",usr,"recievedFiles")
    if not os.path.exists(fileBin):
    app = QtGui.QApplication(sys.argv)
    window =  WatchFilesBin(fileBin)

if __name__ == '__main__':

Is ther any way error can be avoided? what I am doing wrong ?

Traceback (most recent call last):
  File "/Users/krystosan/Developments/", line 34, in slotDirChanged
    newNodes = self.recievedNodes()
  File "/Users/krystosan/Developments/", line 26, in recievedNodes
    newUsrNodeFile = list(set(self.filesList).symmetric_difference(os.listdir(self._filesBinPath)))[0]
IndexError: list index out of range

Edited 3 Years Ago by krystosan: typo

well I dont think so that is the case could you try comment out this

        print newFiles
        #if newFiles:
            #userName = newFiles.split(".")[0]
            #retValue = MessageBox(userName=userName)._messageBox()
            #print retValue

from slotDirChanged and change the method to

    def recievedNodes(self):
        print "Hello"
        return "Test"

whats strange earlier i was testing on CentOS this above method was executing twice but on MacOSx it executes just once.

This article has been dead for over six months. Start a new discussion instead.