Jörg wrote:

> This tells me that each line of input is processed by itself (?), so
> that one can't enter multiline strings.
> As the .vsz files saved by veusz itself rely on ImportString, I cannot
> process them with veusz_listen. I didn't look into it any further, so
> maybe I did something wrong? The documentation basically states, that
> all commands work with veusz_listen, and that ImportString is being used
> preferably for triple-quoted strings.
> As a workaround I changed my batch processing to a python script using
> the embedded veusz. However, with this setup I suffer from the problem
> of the script not exiting cleanly (which is known, according to the
> release notes).

Okay, I've changed the processing to be like the command line on the
program. It should execute when the block is closed now. Does this patch
help?

Jeremy
Index: veusz_listen.py
===================================================================
--- veusz_listen.py	(revision 718)
+++ veusz_listen.py	(working copy)
@@ -31,6 +31,7 @@
 
 import sys
 import os.path
+import codeop
 
 # Allow veusz to be run even if not installed into PYTHONPATH
 try:
@@ -63,6 +64,7 @@
         self.document = window.document
         self.plot = window.plot
         self.pickle = False
+        self.command_build = ''
 
         self.ci = document.CommandInterpreter(self.document)
         self.ci.addCommand('Quit', self.quitProgram)
@@ -95,7 +97,9 @@
     def dataReceived(self):
         """When a command is received, interpret it."""
 
-        line = sys.stdin.readline()
+        line = sys.stdin.readline()[:-1]
+        if not line:
+            return
 
         if self.pickle:
             # line is repr form of pickled string get get rid of \n
@@ -104,8 +108,29 @@
             sys.stdout.flush()
             
         else:
-            self.ci.run(line)
+            # code is more complex not to run commands immediately
+            command = line
+            if self.command_build:
+                newc = self.command_build + '\n' + command
+            else:
+                newc = command
 
+            # test whether command can be run by itself
+            try:
+                c = codeop.compile_command(newc)
+            except Exception:
+                c = 1
+            
+            if c is None or (len(command) != 0 and
+                             len(self.command_build) != 0 and
+                             (command[0] == ' ' or command[0] == '\t')):
+                # build up the expression until next time
+                self.command_build = newc
+            else:
+                # run code
+                self.ci.run( newc )
+                self.command_build = ''
+
 def run():
     '''Actually run the program.'''
     app = Application(sys.argv)

_______________________________________________
Veusz-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/veusz-discuss

Répondre à