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
        createFilesBin(self._filesBinPath)
        self.filesList = os.listdir(self._filesBinPath)
        print self.filesList
        self.fileSysWatcher = QtCore.QFileSystemWatcher()

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

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

    @pyqtSlot("QString")   
    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):
        os.mkdir(lookInPath)

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

if __name__ == '__main__':
    main()

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

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

At first glance, the error means that the symmetric difference is empty and your code does not handle the case.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.