Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grabWindowPixmap() broken for QCDATWidget #1276

Closed
remram44 opened this issue May 5, 2015 · 7 comments
Closed

grabWindowPixmap() broken for QCDATWidget #1276

remram44 opened this issue May 5, 2015 · 7 comments

Comments

@remram44
Copy link
Contributor

@remram44 remram44 commented May 5, 2015

The saveToPNG() implementation in QCDATWidget doesn't correctly handle the case where the filename argument is None, which makes VCS fail.

Traceback (most recent call last):
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/spreadsheet/spreadsheet_tabcontroller.py", line 426, in exportSheetToSingleImageActionTriggered
    self.currentWidget().exportSheetToImage(filename)
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/spreadsheet/spreadsheet_tab.py", line 543, in exportSheetToImage
    pix = widget.grabWindowPixmap()
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/uvcdat_cdms/vtk_classes.py", line 836, in grabWindowPixmap
    uchar = self.saveToPNG(None)  # crashes
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/uvcdat_cdms/init.py", line 1511, in saveToPNG
    self.canvas.png(filename)
  File "/home/remram/uvcdat-builds/builds/32f3893f053107374d2b4b8fb0feee5efbcaedee/install/lib/python2.7/site-packages/vcs/Canvas.py", line 4783, in png
    return self.backend.png(file,width,height,units,draw_white_background, **args )
  File "/home/remram/uvcdat-builds/builds/32f3893f053107374d2b4b8fb0feee5efbcaedee/install/lib/python2.7/site-packages/vcs/VTKPlots.py", line 1577, in png
    if not file.split('.')[-1].lower() in ['png']:
AttributeError: 'NoneType' object has no attribute 'split'

I'm not sure what is expected here.

@remram44 remram44 added the Bug label May 5, 2015
@remram44
Copy link
Contributor Author

@remram44 remram44 commented May 5, 2015

Options are: make VisTrails feed a temporary filename to VCS, or directly get an in-memory buffer from VCS.

@remram44
Copy link
Contributor Author

@remram44 remram44 commented Jun 11, 2015

Traceback as of 2.2.0-45, vistrails 2.2.0-12

Traceback (most recent call last):
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/spreadsheet/spreadsheet_tabcontroller.py", line 426, in exportSheetToSingleImageActionTriggered
    self.currentWidget().exportSheetToImage(filename)
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/spreadsheet/spreadsheet_tab.py", line 543, in exportSheetToImage
    pix = widget.grabWindowPixmap()
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/uvcdat_cdms/vtk_classes.py", line 836, in grabWindowPixmap
    uchar = self.saveToPNG(None)
  File "/home/remram/Documents/programming/uvcdat-vistrails/vistrails/packages/uvcdat_cdms/init.py", line 1511, in saveToPNG
    self.canvas.png(filename)
  File "/home/remram/uvcdat-builds/builds/9f25d777ca82a9bd383f232c26b579e4912c88e8/install/lib/python2.7/site-packages/vcs/Canvas.py", line 4787, in png
    return self.backend.png(file,width,height,units,draw_white_background, **args )
  File "/home/remram/uvcdat-builds/builds/9f25d777ca82a9bd383f232c26b579e4912c88e8/install/lib/python2.7/site-packages/vcs/VTKPlots.py", line 857, in png
    if not file.split('.')[-1].lower() in ['png']:
AttributeError: 'NoneType' object has no attribute 'split'

Second attempt at exporting causes segmentation fault:

QPaintDevice: Cannot destroy paint device that is being painted

@remram44
Copy link
Contributor Author

@remram44 remram44 commented Jun 11, 2015

@doutriaux1 Is rendering to a memory buffer going to be supported in vcs? It looks like VCS plots have never been exportable in the spreadsheet since their introduction in 2011.

@rexissimus
Copy link
Member

@rexissimus rexissimus commented Jun 11, 2015

This seems to work:

diff --git a/Packages/vcs/Lib/VTKPlots.py b/Packages/vcs/Lib/VTKPlots.py
index 1c1f112..bd894b0 100644
--- a/Packages/vcs/Lib/VTKPlots.py
+++ b/Packages/vcs/Lib/VTKPlots.py
@@ -851,17 +851,18 @@ def gif(self,filename='noname.gif', merge='r', orientation=None, geometry='1600x

   def png(self, file, width=None,height=None,units=None,draw_white_background = True, **args ):

+@ -854,13 +1583,14 @@ def png(self, file, width=None,height=None,units=None,draw_white_background = Tr
         if self.renWin is None:
           raise Exception,"Nothing to dump aborting"

-        if not file.split('.')[-1].lower() in ['png']:
-            file+='.png'
-
-        try:
-          os.remove(file)
-        except:
-          pass
+        if file is not None:
+            if not file.split('.')[-1].lower() in ['png']:
+                file+='.png'

+            try:
+              os.remove(file)
+            except:
+              pass

         #if width is not None and height is not None:
         #  self.renWin.SetSize(width,height)
@@ -883,8 +884,16 @@ def png(self, file, width=None,height=None,units=None,draw_white_background = Tr

         writer = vtk.vtkPNGWriter()
         writer.SetInputConnection(imgfiltr.GetOutputPort())
-        writer.SetFileName(file)
+
+        if file is not None:
+            writer.SetFileName(file)
+        else:
+            writer.WriteToMemoryOn()
         writer.Write()
+        if file is not None:
+            return file
+        else:
+            return writer.GetResult()

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Jun 11, 2015

@remram44 I believe that's what bg=1 is for.

@remram44
Copy link
Contributor Author

@remram44 remram44 commented Jun 11, 2015

Is it something cdat used to have?

@doutriaux1
Copy link
Contributor

@doutriaux1 doutriaux1 commented Jun 11, 2015

still does x.plot(data,bg=1)

@remram44 remram44 removed their assignment Oct 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants