Thanks. So What about a REPL? I really want that, so if it isn't there, I'll 
attempt to write it.

Pepijn

On Oct 26, 2011, at 6:02 PM, Hugo Parente Lima wrote:

> On Wednesday 26 October 2011 11:58:14 Pepijn de Vos wrote:
>> Hi,
>> 
>> I'm trying to get started with PySide, after some hacking on
>> https://bitbucket.org/3david/qtodotxt
>> 
>> disclaimer: I'm a little frustrated, but I mean well.
>> 
>> I read about the model-view architecture, so I want to start by developing
>> my model, which would update itself with a QFileSystemWatcher.
>> 
>> The event loop is severely interfering with my development process. Before
>> I start it, nothing works, after I start it, I can't use the REPL anymore.
>> 
>> My very modest goal for today was to test QFileSystemWatcher, because in my
>> hacking on QTodoTxt, it only notified once and then crashed. It's telling
>> that watching files has its own module on the Qt bug tracker.
>> 
>> Simple, right?
>> 
>> 1. open a file
>> 2. set up a watcher
>> 2. register a handler
>> 3. write to the file
>> 
>> But... the watcher only runs when I start the event loop. How would I write
>> to a file after that?
>> 
>> Best would be to run the event loop in the background, or have a REPL that
>> runs on the event loop. Couldn't find how to do it.
>> 
>> Second alternative would be to set up a Signal to invoke the write from the
>> event loop. How? How about...
>> 
>> s = Signal()
>> s.connect(write)
>> s.emit()
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> AttributeError: 'PySide.QtCore.Signal' object has no attribute 'emit'
> 
> Hi
> 
> Here is the code to do this:
> 
> from PySide.QtCore import *
> import tempfile
> import sys
> 
> def onFileChanged(path):
>    print("%s was changed!" % path)
>    QCoreApplication.instance().quit()
> 
> def writeOnMyFile():
>    global file
>    print("Writing on %s." % file.name)
>    file.write("Hello World\n")
>     # The file will not be modified until you call flush, close the file or 
> write contents enough.
>    file.flush()
> 
> app = QCoreApplication(sys.argv)
> 
> file = tempfile.NamedTemporaryFile()
> 
> watcher = QFileSystemWatcher()
> watcher.addPath(file.name)
> watcher.fileChanged.connect(onFileChanged)
> QTimer.singleShot(0, writeOnMyFile)
> sys.exit(app.exec_())
> 
> 
> Regards
> 
> 
>> You don't expect me to set up a push button to fire the event, right?
>> 
>> Okay, then maybe there is a test framework for PySide that understand the
>> event loop, like in Twisted. Maybe? Searching for it turned up nothing,
>> but at last I found
>> http://www.pyside.org/docs/pyside/PySide/QtTest/QTest.html No idea how to
>> use it though.
>> 
>> I'm sure this is all very simple to you, but I've been trying for hours to
>> do something simple, like testing a file watcher.
>> 
>> Pepijn
> 
> -- 
> Hugo Parente Lima
> INdT - Instituto Nokia de Tecnologia

_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to