Skip to content

Commit

Permalink
Merge branch 'continue-dialog' into 'v2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Apr 23, 2014
2 parents 9b35068 + c566477 commit 0728902
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 73 deletions.
11 changes: 11 additions & 0 deletions vistrails/packages/dialogs/__init__.py
Expand Up @@ -35,7 +35,18 @@
"""dialogs provides modules for user-based interaction on execution.
Users can then enter file names, numbers, strings, etc."""

from vistrails.core.packagemanager import get_package_manager


identifier = 'org.vistrails.vistrails.dialogs'
name = 'Dialogs'
version = '0.9.2'
old_identifiers = ['edu.utah.sci.vistrails.dialogs']


def package_dependencies():
pm = get_package_manager()
if pm.has_package('org.vistrails.vistrails.spreadsheet'):
return ['org.vistrails.vistrails.spreadsheet']
else:
return []
63 changes: 63 additions & 0 deletions vistrails/packages/dialogs/continue_prompt.py
@@ -0,0 +1,63 @@
from PyQt4 import QtCore, QtGui

from vistrails.core.configuration import get_vistrails_configuration
from vistrails.core.modules import basic_modules
from vistrails.core.modules.vistrails_module import Module, ModuleError

from vistrails.packages.spreadsheet.basic_widgets import SpreadsheetCell
from vistrails.packages.spreadsheet.spreadsheet_cell import QCellContainer


class PromptWindow(QtGui.QDialog):
def __init__(self, widget, label=None):
QtGui.QDialog.__init__(self)
self.setWindowTitle("Check intermediate results")
self.setLayout(QtGui.QVBoxLayout())
self.layout().addWidget(widget)
if label is not None:
self.layout().addWidget(QtGui.QLabel(label))
buttons = QtGui.QDialogButtonBox(
QtGui.QDialogButtonBox.Yes | QtGui.QDialogButtonBox.No)
self.connect(buttons, QtCore.SIGNAL('accepted()'),
self, QtCore.SLOT('accept()'))
self.connect(buttons, QtCore.SIGNAL('rejected()'),
self, QtCore.SLOT('reject()'))
self.layout().addWidget(buttons)


class PromptIsOkay(Module):
_input_ports = [('label', basic_modules.String,
{'optional': True}),
('carry_on', basic_modules.Boolean,
{'optional': True, 'defaults': "['False']"}),
('cell', SpreadsheetCell)]
_output_ports = [('result', basic_modules.Boolean)]

def compute(self):
vt_configuration = get_vistrails_configuration()
if not getattr(vt_configuration, 'interactiveMode', False):
self.setResult('result', True)
return

cell = self.getInputFromPort('cell')
label = self.forceGetInputFromPort('label', None)

# FIXME : This should be done via the spreadsheet, removing it properly
# and then sending a new DisplayCellEvent
# However, there is currently no facility to remove the widget from
# wherever it is
oldparent = cell.parent()
assert isinstance(oldparent, QCellContainer)
ncell = oldparent.takeWidget()
assert ncell == cell
dialog = PromptWindow(cell, label)
result = dialog.exec_() == QtGui.QDialog.Accepted
oldparent.setWidget(cell)

self.setResult('result', result)

if not result and not self.getInputFromPort('carry_on'):
raise ModuleError(self, "Execution aborted")


_modules = [PromptIsOkay]
83 changes: 35 additions & 48 deletions vistrails/packages/dialogs/init.py
Expand Up @@ -32,17 +32,18 @@
## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
###############################################################################

from vistrails.core.modules import basic_modules
from vistrails.core.modules.vistrails_module import Module, ModuleError
import vistrails.core.modules
import vistrails.core.modules.basic_modules
import vistrails.core.modules.module_registry
import vistrails.core.system
import vistrails.gui.application
from PyQt4 import QtCore, QtGui
from vistrails.core.packagemanager import get_package_manager
from PyQt4 import QtGui

##############################################################################

class Dialog(Module):
_input_ports = [('title', basic_modules.String,
{'optional': True}),
('cacheable', basic_modules.Boolean,
{'optional': True, 'defaults': "['False']"})]

def __init__(self, *args, **kwargs):
super(Dialog,self).__init__(*args, **kwargs)
Expand All @@ -51,30 +52,26 @@ def __init__(self, *args, **kwargs):
def is_cacheable(self):
return self.cacheable_dialog


class TextDialog(Dialog):
_input_ports = [('label', basic_modules.String,
{'optional': True, 'defaults': "['']"}),
('default', basic_modules.String,
{'optional': True, 'defaults': "['']"})]
_output_ports = [('result', basic_modules.String)]

password = False

def compute(self):
if self.hasInputFromPort('title'):
title = self.getInputFromPort('title')
else:
title = 'VisTrails Dialog'
if self.hasInputFromPort('label'):
label = self.getInputFromPort('label')
else:
label = ''
if self.password:
label = 'Password'
label = self.getInputFromPort('label')

if self.hasInputFromPort('default'):
default = self.getInputFromPort('default')
else:
default = ''

if self.hasInputFromPort('cacheable') and self.getInputFromPort('cacheable'):
self.cacheable_dialog = True
else:
self.cacheable_dialog = False
default = self.getInputFromPort('default')

self.cacheable_dialog = self.getInputFromPort('cacheable')

mode = QtGui.QLineEdit.Normal
if self.password:
Expand All @@ -89,24 +86,25 @@ def compute(self):


class PasswordDialog(TextDialog):
_input_ports = [('label', basic_modules.String,
{'optional': True, 'defaults': "['Password']"})]

password = True


class YesNoDialog(Dialog):
_input_ports = [('label', basic_modules.String,
{'optional': True, 'defaults': "['Yes/No?']"})]
_output_ports = [('result', basic_modules.Boolean)]

def compute(self):
if self.hasInputFromPort('title'):
title = self.getInputFromPort('title')
else:
title = 'VisTrails Dialog'
if self.hasInputFromPort('label'):
label = self.getInputFromPort('label')
else:
label = 'Yes/No?'
label = self.getInputFromPort('label')

if self.hasInputFromPort('cacheable') and self.getInputFromPort('cacheable'):
self.cacheable_dialog = True
else:
self.cacheable_dialog = False
self.cacheable_dialog = self.getInputFromPort('cacheable')

result = QtGui.QMessageBox.question(
None,
Expand All @@ -117,23 +115,12 @@ def compute(self):
self.setResult('result', result)


##############################################################################

def initialize(*args, **keywords):
reg = vistrails.core.modules.module_registry.get_module_registry()
basic = vistrails.core.modules.basic_modules

reg.add_module(Dialog, abstract=True)
reg.add_input_port(Dialog, "title", basic.String)
reg.add_input_port(Dialog, "cacheable", basic.Boolean)

reg.add_module(TextDialog)
reg.add_input_port(TextDialog, "label", basic.String)
reg.add_input_port(TextDialog, "default", basic.String)
reg.add_output_port(TextDialog, "result", basic.String)
_modules = [(Dialog, {'abstract': True}),
TextDialog, PasswordDialog,
YesNoDialog]

reg.add_module(PasswordDialog)

reg.add_module(YesNoDialog)
reg.add_input_port(YesNoDialog, "label", basic.String)
reg.add_output_port(YesNoDialog, "result", basic.Boolean)
pm = get_package_manager()
if pm.has_package('org.vistrails.vistrails.spreadsheet'):
from .continue_prompt import _modules as continue_modules
_modules.extend(continue_modules)
22 changes: 6 additions & 16 deletions vistrails/packages/spreadsheet/basic_widgets.py
Expand Up @@ -80,6 +80,7 @@ def registerWidget(reg, basicModules, basicWidgets):

reg.add_module(SpreadsheetCell)
reg.add_input_port(SpreadsheetCell, "Location", CellLocation)
reg.add_output_port(SpreadsheetCell, "Widget", SpreadsheetCell)

reg.add_module(SingleCellSheetReference)
reg.add_input_port(SingleCellSheetReference, "SheetName",
Expand Down Expand Up @@ -216,21 +217,6 @@ def createDisplayEvent(self, cellType, inputPorts):
e.cellType = cellType
e.inputPorts = inputPorts
return e

def display(self, cellType, inputPorts):
""" display(cellType: python type, iputPorts: tuple) -> None
Dispatch the cellType to the spreadsheet with appropriate input data
to display it
Keyword arguments:
cellType --- widget type, this is truely a python type
inputPorts --- a tuple of input data that cellType() will understand
"""
if spreadsheetController.echoMode():
return self.displayAndWait(cellType, inputPorts)
e = self.createDisplayEvent(cellType, inputPorts)
spreadsheetController.postEventToSpreadsheet(e)

def displayAndWait(self, cellType, inputPorts):
""" displayAndWait(cellType: python type, iputPorts: tuple)
Expand All @@ -247,7 +233,11 @@ def displayAndWait(self, cellType, inputPorts):
spreadsheetWindow = spreadsheetController.findSpreadsheetWindow()
if spreadsheetWindow.echoMode == False:
spreadsheetWindow.configShow(show=True)
return spreadsheetWindow.displayCellEvent(e)
self.cellWidget = spreadsheetWindow.displayCellEvent(e)
self.setResult('Widget', self.cellWidget)
return self.cellWidget

display = displayAndWait

class SingleCellSheetReference(SheetReference):
"""
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/spreadsheet/widgets/iebrowser/iecell.py
Expand Up @@ -61,7 +61,7 @@ def compute(self):
else:
fileValue = None
urlValue = None
self.display(IECellWidget, (urlValue, fileValue))
self.displayAndWait(IECellWidget, (urlValue, fileValue))

class IECellWidget(QCellWidget):
"""
Expand Down
Expand Up @@ -60,7 +60,7 @@ def compute(self):
fileValue = window.file_pool.make_local_copy(file_to_display.name)
else:
fileValue = None
self.cellWidget = self.displayAndWait(ImageViewerCellWidget, (fileValue, ))
self.displayAndWait(ImageViewerCellWidget, (fileValue, ))

class ImageViewerCellWidget(QCellWidget):
"""
Expand Down
4 changes: 2 additions & 2 deletions vistrails/packages/spreadsheet/widgets/richtext/richtext.py
Expand Up @@ -75,7 +75,7 @@ def compute(self):
else:
raise ModuleError(self, "'%s' format is unknown" % text_format)

self.cellWidget = self.displayAndWait(RichTextCellWidget, (html,))
self.displayAndWait(RichTextCellWidget, (html,))


class XSLCell(SpreadsheetCell):
Expand All @@ -97,7 +97,7 @@ def compute(self):
if html is None:
raise ModuleError(self, "Error applying XSL")

self.cellWidget = self.displayAndWait(RichTextCellWidget, (html,))
self.displayAndWait(RichTextCellWidget, (html,))


class RichTextCellWidget(QCellWidget):
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/spreadsheet/widgets/svg/svg.py
Expand Up @@ -62,7 +62,7 @@ def compute(self):
fileValue = window.file_pool.make_local_copy(file_to_display.name)
else:
fileValue = None
self.display(SVGCellWidget, (fileValue,))
self.displayAndWait(SVGCellWidget, (fileValue,))

### SVG Cell widget type
class SVGCellWidget(QCellWidget):
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/spreadsheet/widgets/webview/webview.py
Expand Up @@ -61,7 +61,7 @@ def compute(self):
else:
fileValue = None
urlValue = None
self.display(WebViewCellWidget, (urlValue, fileValue))
self.displayAndWait(WebViewCellWidget, (urlValue, fileValue))

class WebViewCellWidget(QCellWidget):
"""
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/tabledata/viewer.py
Expand Up @@ -11,7 +11,7 @@ class TableCell(SpreadsheetCell):

def compute(self):
table = self.getInputFromPort('table')
self.cellWidget = self.displayAndWait(TableCellWidget, (table,))
self.displayAndWait(TableCellWidget, (table,))


class TableCellWidget(QCellWidget):
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/vtk/vtkcell.py
Expand Up @@ -89,7 +89,7 @@ def compute(self):
iHandlers = self.forceGetInputListFromPort('InteractionHandler')
iStyle = self.forceGetInputFromPort('InteractorStyle')
picker = self.forceGetInputFromPort('AddPicker')
self.cellWidget = self.displayAndWait(QVTKWidget, (renderers, renderView, iHandlers, iStyle, picker))
self.displayAndWait(QVTKWidget, (renderers, renderView, iHandlers, iStyle, picker))

AsciiToKeySymTable = ( None, None, None, None, None, None, None,
None, None,
Expand Down
2 changes: 1 addition & 1 deletion vistrails/packages/vtk/vtkviewcell.py
Expand Up @@ -79,7 +79,7 @@ def compute(self):
renderView = self.forceGetInputFromPort('SetRenderView')
if renderView==None:
raise ModuleError(self, 'A vtkRenderView input is required.')
self.cellWidget = self.displayAndWait(QVTKViewWidget, (renderView,))
self.displayAndWait(QVTKViewWidget, (renderView,))

AsciiToKeySymTable = ( None, None, None, None, None, None, None,
None, None,
Expand Down

0 comments on commit 0728902

Please sign in to comment.