[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyQt] Python generated file changes not detected by QFileSystemModel
From:       Mads Ipsen <madsipsen () gmail ! com>
Date:       2012-05-22 9:51:38
Message-ID: 4FBB61AA.8050501 () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

Here's the problem:

 1. Set up a QFileSystemModel, call setRootPath() and hook up to the
    dataChanged signal.
 2. Open a new file from Python and write some text into it. Then close it.
 3. Reopen the file in append mode and write some more text into it.
    Then close it.
 4. Open a file in an external editor. Write some stuff. Save. Write
    more stuff. Save.

If you do (3), the dataChanged signal is NOT emitted. However, if you do 
(4), the dataChanged signal IS emitted.

Any clues? An attached file that reproduces the issue is attached.

Best regards,

Mads


-- 
+-----------------------------------------------------+
| Mads Ipsen                                          |
+----------------------+------------------------------+
| Gåsebæksvej 7, 4. tv |                              |
| DK-2500 Valby        | phone:          +45-29716388 |
| Denmark              | email:  mads.ipsen@gmail.com |
+----------------------+------------------------------+



[Attachment #5 (text/html)]

<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <font face="Consolas">Hi,<br>
      <br>
      Here's the problem:<br>
      <br>
    </font>
    <ol>
      <li><font face="Consolas">Set up a QFileSystemModel, call
          setRootPath() and hook up to the dataChanged signal.</font></li>
      <li><font face="Consolas">Open a new file from Python and write
          some text into it. Then close it.</font></li>
      <li><font face="Consolas">Reopen the file in append mode and write
          some more text into it. Then close it.</font></li>
      <li><font face="Consolas">Open a file in an external editor. Write
          some stuff. Save. Write more stuff. Save.</font></li>
    </ol>
    <p>If you do (3), the dataChanged signal is NOT emitted. However, if
      you do (4), the dataChanged signal IS emitted.<br>
    </p>
    <p>Any clues? An attached file that reproduces the issue is
      attached.<br>
    </p>
    <p>Best regards,<br>
    </p>
    <p>Mads<br>
    </p>
    <font face="Consolas"><br>
    </font>
    <pre class="moz-signature" cols="72">-- 
+-----------------------------------------------------+
> Mads Ipsen                                          |
+----------------------+------------------------------+
> G&aring;seb&aelig;ksvej 7, 4. tv |                              |
> DK-2500 Valby        | phone:          +45-29716388 |
> Denmark              | email:  <a class="moz-txt-link-abbreviated" \
> href="mailto:mads.ipsen@gmail.com">mads.ipsen@gmail.com</a> |
+----------------------+------------------------------+

</pre>
  </body>
</html>


["fsm-2.py" (text/x-python)]

import sys
import os

from PyQt4 import QtGui, QtCore

class Widget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)
        self._view = QtGui.QListView()
        layout.addWidget(self._view)
        
        # Add the model
        self._model = QtGui.QFileSystemModel()
        self._model.setRootPath(QtCore.QDir().rootPath())
        self._model.setReadOnly(False)
        self._model.setFilter(QtCore.QDir.AllDirs | QtCore.QDir.AllEntries)        
        self._view.setModel(self._model)

        # Root path
        path = os.path.dirname(os.path.abspath(__file__))
        self._model.setRootPath(path)

        # Set a root index
        index = self._model.index(path)
        self._view.setRootIndex(index)

        # Generate a file with some text
        print 'Making file'
        f = open('foo.dat', 'w')
        f.write('Some stuff\n')
        f.close()

        self.connect(self._model, QtCore.SIGNAL('dataChanged(const QModelIndex &, \
const QModelIndex &)'), self.dataChanged)

        # Append more text - this should trigger a signal call
        print 'Modifying file'
        f = open('foo.dat', 'w+')
        f.write('Some more stuff\n')
        f.close()

    def dataChanged(self, index_0, index_1):
        print 'dataChanged', self._model.filePath(index_0), \
self._model.filePath(index_1)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)

    widget = Widget()
    widget.show()

    sys.exit(app.exec_())



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic