Skip to content

Commit

Permalink
Merge pull request #1808 from astrofrog/screenshot
Browse files Browse the repository at this point in the history
Added a new GlueApplication.screenshot method
  • Loading branch information
astrofrog authored Jul 3, 2018
2 parents a9655c0 + 313a7e2 commit 1c8e0b8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ v0.14.0 (unreleased)
* Change 'Export Session' dialog to offer to save with relative paths to data
by default instead of absolute paths. [#1803]

* Added a new method ``screenshot`` on ``GlueApplication`` to save a
screenshot of the current view. [#1808]

* Show the active subset in the toolbar. [#1797]

* Refactored the viewer class base classes:
Expand Down
11 changes: 11 additions & 0 deletions glue/app/qt/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,17 @@ def _choose_merge(data, others, suggested_label):

return None, None

def screenshot(self, filename):
"""
Save a screenshot of the current application window to a file.
"""
image = QtGui.QImage(self.size(), QtGui.QImage.Format_RGB32)
painter = QtGui.QPainter(image)
flags = self.IgnoreMask | self.DrawWindowBackground | self.DrawChildren
self.render(painter, QtCore.QPoint(), QtGui.QRegion(), flags)
image.save(filename)
painter.end()

def __gluestate__(self, context):
state = super(GlueApplication, self).__gluestate__(context)
state['tab_names'] = self.tab_names
Expand Down
7 changes: 7 additions & 0 deletions glue/app/qt/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import absolute_import, division, print_function

import os
import sys

import pytest
Expand Down Expand Up @@ -460,6 +461,12 @@ def test_deselect_tool_on_viewer_change(self):

app.close()

def test_screenshot(self, tmpdir):
filename = tmpdir.join('screenshot.png').strpath
app = GlueApplication()
app.screenshot(filename)
assert os.path.exists(filename)


def test_logger_close():

Expand Down

0 comments on commit 1c8e0b8

Please sign in to comment.