Skip to content

Commit

Permalink
Add more configuration functionality
Browse files Browse the repository at this point in the history
Add system-specific settings and widgets for thumbnail cache clearing
and linux file extension handling.
  • Loading branch information
dakoop committed May 10, 2014
1 parent 438a07d commit d77cebc
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 94 deletions.
45 changes: 35 additions & 10 deletions vistrails/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
webRepositoryUser: Web repository username
repositoryLocalPath: Local package repository directory
repositoryHTTPURL: Remote package repository URL
handlerDontAsk: Do not ask about extension handling at startup
"""

_documentation = """
Expand Down Expand Up @@ -478,10 +479,10 @@ def __init__(self, name, sub_fields):
ConfigField('defaultFileType', system.vistrails_default_file_type(), str,
widget_type="combo",
widget_options={"allowed_values": [".vt", ".xml"],
"label": "Default File Type/Extension:"}),
"label": "Default File Type/Extension"}),
ConfigField('debugLevel', 0, int, widget_type="combo",
widget_options={"allowed_values": [0,1,2],
"label": "Show alerts for:",
"label": "Show alerts for",
"remap": {0: "Critical Errors Only",
1: "Critical Errors and Warnings",
2: "Errors, Warnings, and " \
Expand Down Expand Up @@ -520,12 +521,11 @@ def __init__(self, name, sub_fields):
"Thumbnails":
[ConfigFieldParent('thumbs',
[ConfigField('autoSave', True, bool, ConfigType.ON_OFF),
# FIXME add clear button for cache in preferences dialog!
ConfigField('mouseHover', False, bool, ConfigType.ON_OFF),
ConfigField('tagsOnly', False, bool, ConfigType.ON_OFF),
ConfigField('cacheDirectory', os.path.join("$DOT_VISTRAILS", "thumbs"),
ConfigPath, ConfigType.NORMAL),
ConfigField('cacheSize', 20, int)])],
ConfigField('cacheSize', 20, int, widget_type='thumbnailcache')])],
"Packages":
[ConfigField('enablePackagesSilently', False, bool, ConfigType.ON_OFF),
ConfigField('installBundles', True, bool, ConfigType.ON_OFF),
Expand Down Expand Up @@ -558,7 +558,6 @@ def __init__(self, name, sub_fields):
ConfigField('runningJobsList', None, str, ConfigType.STORAGE),
ConfigField('isInServerMode', False, bool, ConfigType.INTERNAL),
ConfigField('isRunningGUI', True, bool, ConfigType.INTERNAL),
ConfigField('handlerDontAsk', False, bool, ConfigType.INTERNAL),
ConfigField('spawned', False, bool, ConfigType.INTERNAL),
ConfigField('rootDirectory', None, ConfigPath, ConfigType.INTERNAL)],
"Jobs":
Expand All @@ -571,12 +570,20 @@ def __init__(self, name, sub_fields):
# FIXME make sure that the platform-specific configs are added!
mac_config = {
"Interface":
[('useMacBrushedMetalStyle', True, bool, ConfigType.ON_OFF)]
[ConfigField('useMacBrushedMetalStyle', True, bool, ConfigType.ON_OFF)]
}

win_config = { }

linux_config = { }
linux_config = {
"General":
[ConfigField('handlerCheck', None, str, ConfigType.INTERNAL,
widget_type="linuxext",
widget_options={'label': 'Extension Handler'}),
ConfigField('handlerDontAsk', None, bool)]
}

all_configs = [base_config, mac_config, win_config, linux_config]

def build_config_obj(d):
new_d = {}
Expand All @@ -600,8 +607,25 @@ def build_config_obj(d):
new_d[field.name] = v
return ConfigurationObject(**new_d)

def get_system_config():
config = {}
config.update(base_config)
if system.systemType in ['Windows', 'Microsoft']:
sys_config = win_config
elif system.systemType in ['Linux']:
sys_config = linux_config
elif system.systemType in ['Darwin']:
sys_config = mac_config
for category, fields in sys_config.iteritems():
if category not in base_config:
config[category] = fields
else:
config[category].extend(fields)
return config

def default():
retval = build_config_obj(base_config)
config = get_system_config()
retval = build_config_obj(config)
return retval

def parse_documentation():
Expand Down Expand Up @@ -657,8 +681,9 @@ def set_field_labels(fields, prefix=""):
if label is not None and 'label' not in field.widget_options:
field.widget_options['label'] = label

for field_list in base_config.itervalues():
set_field_labels(field_list)
for config in all_configs:
for field_list in config.itervalues():
set_field_labels(field_list)

class VisTrailsHelpFormatter(argparse.HelpFormatter):
def add_usage(self, usage, actions, groups, prefix=None):
Expand Down
181 changes: 97 additions & 84 deletions vistrails/gui/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,8 @@ def set_value(self, value):
value = ""
self.setText(unicode(value))

class QConfigurationPathEdit(QtGui.QWidget, QConfigurationWidgetItem):
def __init__(self, key, field, callback_f,
button_cls=QDirectoryChooserToolButton,
parent=None):
class QConfigurationLineEditButton(QtGui.QWidget, QConfigurationWidgetItem):
def __init__(self, key, field, callback_f, button, parent=None):
QtGui.QWidget.__init__(self, parent)
QConfigurationWidgetItem.__init__(self, key, field, callback_f)

Expand All @@ -321,12 +319,15 @@ def __init__(self, key, field, callback_f,
self.line_edit.setMinimumWidth(200)
layout.addWidget(self.line_edit)

button = button_cls(self, self.line_edit)
layout.addWidget(button)
if button is not None:
layout.addWidget(button)
self.setLayout(layout)

self.line_edit.editingFinished.connect(self.value_changed)

def add_button(self, button):
self.layout().addWidget(button)

def value_changed(self):
QConfigurationWidgetItem.value_changed(self, self.line_edit.text())

Expand All @@ -335,6 +336,83 @@ def set_value(self, value):
value = ""
self.line_edit.setText(unicode(value))

class QConfigurationPathEdit(QConfigurationLineEditButton):
def __init__(self, key, field, callback_f,
button_cls=QDirectoryChooserToolButton, parent=None):
QConfigurationLineEditButton.__init__(self, key, field, callback_f,
None, parent)
button = button_cls(self, self.line_edit)
self.add_button(button)

class QConfigurationThumbnailCache(QConfigurationLineEditButton):
def __init__(self, key, field, callback_f, parent=None):
button = QtGui.QPushButton("Clear...")
button.setAutoDefault(False)
button.clicked.connect(self.clear_clicked)
QConfigurationLineEditButton.__init__(self, key, field, callback_f,
button, parent)

def clear_clicked(self, checked=False):
cache_dir = get_vistrails_configuration().thumbs.cacheDirectory
res = show_question('VisTrails',
("All files in %s will be removed. "
"Are you sure? " % cache_dir),
buttons = [YES_BUTTON,NO_BUTTON],
default = NO_BUTTON)
if res == YES_BUTTON:
ThumbnailCache.getInstance().clear()

class QConfigurationLabelButton(QtGui.QWidget, QConfigurationWidgetItem):
def __init__(self, key, field, callback_f, label=None, button=None,
parent=None):
QtGui.QWidget.__init__(self, parent)
QConfigurationWidgetItem.__init__(self, key, field, callback_f)

layout = QtGui.QHBoxLayout()
layout.setMargin(0)
layout.setSpacing(5)

if label is not None:
self.label = label
layout.addWidget(self.label)

if button is not None:
self.button = button
layout.addWidget(self.button)
self.setLayout(layout)

def add_button(self, button):
self.button = button
self.layout().addWidget(self.button)

def add_label(self, label):
self.label = label
self.layout().insertWidget(0, self.label)

def set_value(self, value):
# nothing to do here
pass

class QConfigurationLinuxHandler(QConfigurationLabelButton):
def __init__(self, key, field, callback_f, parent=None):
from vistrails.gui.application import linux_default_application_set
if linux_default_application_set():
label = QtGui.QLabel(".vt, .vtl handlers installed")
button = None
else:
label = QtGui.QLabel(".vt, .vtl handlers not installed")
button = QtGui.QPushButton("Install...")
button.setAutoDefault(False)
button.clicked.connect(self.install_clicked)
QConfigurationLabelButton.__init__(self, key, field, callback_f,
label, button, parent)

def install_clicked(self, checked=False):
from vistrails.core.application import get_vistrails_application
app = get_vistrails_application()
if app.ask_update_default_application(False):
self.label.setText(".vt, .vtl handlers installed")

class QConfigurationComboBox(QtGui.QComboBox, QConfigurationWidgetItem):
def __init__(self, key, field, callback_f, parent=None):
QtGui.QComboBox.__init__(self, parent)
Expand All @@ -353,16 +431,20 @@ def __init__(self, key, field, callback_f, parent=None):
for entry in entries:
self.addItem(entry)

self.currentIndexChanged[unicode].connect(self.value_changed)
self.currentIndexChanged[int].connect(self.value_changed)

def set_value(self, value):
options = self.get_widget_options()
print "SETTING VALUE:", value
if value is not None and "allowed_values" in options:
if "remap" in options:
remap = options["remap"]
cur_text = remap[value]
print "USING REMAP:", remap
else:
print "NO REMAP"
cur_text = value
print "CUR TEXT:", value
self.setCurrentIndex(self.findText(cur_text))
else:
self.setCurrentIndex(-1)
Expand All @@ -389,68 +471,6 @@ def __init__(self, parent, persistent_config, temp_config, cat_fields):
spacer_widget.setLayout(spacer_layout)
layout.addRow("", spacer_widget)

self.create_default_handler_button(self, layout)

def create_default_handler_button(self, parent, layout):
if vistrails.core.system.systemType == 'Linux':
from vistrails.gui.application import linux_default_application_set
from vistrails.core.application import get_vistrails_application

group = QtGui.QGroupBox(u"Open .vt .vtl files with VisTrails")
layout.addWidget(group)
layout2 = QtGui.QHBoxLayout()
group.setLayout(layout2)

if linux_default_application_set():
label = u".vt .vtl has a handler set"
else:
label = u".vt .vtl has no handler"
self._handler_status = QtGui.QLabel(label)

def set_dont_ask(state):
self._configuration.handlerDontAsk = bool(state)
self._temp_configuration.handlerDontAsk = bool(state)
self.emit(QtCore.SIGNAL('configuration_changed'),
'handlerDontAsk', bool(state))
self._handler_dont_ask = QtGui.QCheckBox(u"Don't ask at startup")
self.connect(self._handler_dont_ask,
QtCore.SIGNAL('stateChanged(int)'),
set_dont_ask)

def install():
app = get_vistrails_application()
if app.ask_update_default_application(False):
self._handler_status.setText(u".vt .vtl has a handler set")
install_button = QtGui.QPushButton(u"Install handler")
self.connect(install_button, QtCore.SIGNAL('clicked()'),
install)

layout2.addWidget(self._handler_status)
layout2.addWidget(self._handler_dont_ask)
layout2.addWidget(install_button)

def update_state(self, persistent_config, temp_config):
""" update_state(configuration: VistrailConfiguration) -> None
Update the dialog state based on a new configuration
"""

self._configuration = persistent_config
self._temp_configuration = temp_config

#Default handler
if vistrails.core.system.systemType == 'Linux':
from vistrails.gui.application import \
linux_default_application_set, linux_update_default_application

if linux_default_application_set():
self._handler_status.setText(u".vt .vtl has a handler set")
else:
self._handler_status.setText(u".vt .vtl has no handler")

self._handler_dont_ask.setChecked(
self._configuration.check('handlerDontAsk'))

def process_fields(self, layout, fields, category, parent_fields=[],
prev_field=None, prefix=""):
for field in fields:
Expand Down Expand Up @@ -532,6 +552,12 @@ def add_field(self, base_layout, field, category="", startup_only=False,
elif widget_type == "pathedit":
widget = QConfigurationPathEdit(config_key, field,
self.field_changed)
elif widget_type == "thumbnailcache":
widget = QConfigurationThumbnailCache(config_key, field,
self.field_changed)
elif widget_type == "linuxext":
widget = QConfigurationLinuxHandler(config_key, field,
self.field_changed)
else:
config_val = bool(config_val)
widget = QConfigurationCheckBox(config_key, field,
Expand All @@ -542,7 +568,7 @@ def add_field(self, base_layout, field, category="", startup_only=False,
if not label_text and category:
label_text = category
if label_text:
label = QtGui.QLabel(label_text)
label = QtGui.QLabel(label_text + ":")
label_layout.addWidget(label)

base_layout.addRow(label_widget, widget)
Expand Down Expand Up @@ -609,17 +635,4 @@ def thumbs_cache_directory_changed(self):
else:
show_warning('VisTrails', 'The directory specified does not exist.')
self._thumbs_cache_directory_edt.setText(old_folder)

def clear_thumbs_cache_pressed(self):
"""clear_thumbs_cache_pressed() -> None
Will delete all files in thumbs.cacheDirectory if user clicks yes
"""
res = show_question('VisTrails',
"All files in %s will be removed. Are you sure? " % (
self._temp_configuration.thumbs.cacheDirectory),
buttons = [YES_BUTTON,NO_BUTTON],
default = NO_BUTTON)
if res == YES_BUTTON:
self._cache.clear()


0 comments on commit d77cebc

Please sign in to comment.