Skip to content

Commit

Permalink
Refs #10563 Add "widget" option to interface directive
Browse files Browse the repository at this point in the history
This option allows you to specify a widget's name to screenshot just
that widget.
  • Loading branch information
Harry Jeffery committed Nov 19, 2014
1 parent c9b5340 commit 74561d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Code/Mantid/docs/sphinxext/mantiddoc/directives/interface.py
Expand Up @@ -13,6 +13,7 @@ class InterfaceDirective(BaseDirective):
"""

required_arguments, optional_arguments = 1, 0
option_spec = {"widget" : str}

def run(self):
"""
Expand All @@ -30,14 +31,14 @@ def execute(self):
"""
Called by Sphinx when the ..interface:: directive is encountered
"""
picture = self._create_screenshot()
picture = self._create_screenshot(widget_name = self.options.get("widget", None))
self._insert_screenshot_link(picture)
return []

def interface_name(self):
return self.arguments[0]

def _create_screenshot(self):
def _create_screenshot(self, widget_name = None):
"""
Creates a screenshot for the named interface in the "images/screenshots"
subdirectory.
Expand All @@ -58,7 +59,7 @@ def _create_screenshot(self):
os.makedirs(screenshots_dir)

try:
picture = custominterface_screenshot(self.interface_name(), screenshots_dir)
picture = custominterface_screenshot(self.interface_name(), screenshots_dir, widget_name = widget_name)
except RuntimeError, exc:
env = self.state.document.settings.env
env.warn(env.docname, "Unable to generate screenshot for '%s' - %s" % (self.interface_name(), str(exc)))
Expand Down
9 changes: 7 additions & 2 deletions Code/Mantid/docs/sphinxext/mantiddoc/tools/screenshot.py
Expand Up @@ -60,7 +60,7 @@ def algorithm_screenshot(name, directory, version = -1, ext = ".png"):

#--------------------------------------------------------------------------

def custominterface_screenshot(name, directory, ext = ".png"):
def custominterface_screenshot(name, directory, ext = ".png", widget_name = None):
"""
Takes a snapshot of a custom interface and saves it as an image
named "name.png"
Expand All @@ -79,11 +79,16 @@ def custominterface_screenshot(name, directory, ext = ".png"):

import mantidqtpython as mantidqt
from mantidplot import threadsafe_call
from PyQt4.QtGui import QWidget

iface_mgr = mantidqt.MantidQt.API.InterfaceManager()
# threadsafe_call required for MantidPlot
dlg = threadsafe_call(iface_mgr.createSubWindow, name, None)

picture = Screenshot(dlg, name.replace(' ','_') + "_interface" + ext, directory)
if widget_name:
widget = dlg.findChild(QWidget, widget_name)
picture = Screenshot(widget, name.replace(' ','_') + "_" + widget_name + "_widget" + ext, directory)
else:
picture = Screenshot(dlg, name.replace(' ','_') + "_interface" + ext, directory)
threadsafe_call(dlg.close)
return picture

0 comments on commit 74561d7

Please sign in to comment.