コード例 #1
0
    def onBrowseClicked(control_instance):
        """ Browse the file system and update the control instance accordingly.

        If a valid file path has already been entered the file dialogue will
        automatically point to the file folder, otherwise the current working
        directory is used.

        Parameters
        ----------
        control_instance: QWidget (mandatory)
            the file widget item
        """
        # Get the current file path
        current_control_value = os.getcwd()
        if FileControlWidget.is_valid(control_instance):
            current_control_value = unicode(control_instance.path.text())

        # get widget via a __self__ in a method, because control_instance may
        # be a weakproxy.
        widget = control_instance.__repr__.__self__
        # Create a dialog to select a file
        if control_instance.output:
            fname = qt_backend.getSaveFileName(
                widget, "Output file", current_control_value, "", None,
                QtGui.QFileDialog.DontUseNativeDialog)
        else:
            fname = qt_backend.getOpenFileName(
                widget, "Open file", current_control_value, "", None,
                QtGui.QFileDialog.DontUseNativeDialog)

        # Set the selected file path to the path sub control
        control_instance.path.setText(unicode(fname))
コード例 #2
0
    def load_list(controller_widget, control_name, control_instance):
        controller_widget = get_ref(controller_widget)
        control_instance = get_ref(control_instance)

        # get widget via a __self__ in a method, because control_instance may
        # be a weakproxy.
        widget = control_instance.__repr__.__self__

        fname = qt_backend.getOpenFileName(
            widget, "Open file", "", "", None,
            QtGui.QFileDialog.DontUseNativeDialog)
        if fname:
            parent_controller = controller_widget.controller
            elem_trait = parent_controller.trait(control_name).inner_traits[0]
            text = open(fname).read()
            if fname.endswith('.csv'):
                format = 'CSV'
            else:
                format = 'JSON'
            value = ListControlWidget.parse_list(text, format, ',', elem_trait)
            if value is not None:
                setattr(parent_controller, control_name, value)
            else:
                QtGui.QMessageBox.warning(controller_widget, 'Parsing error',
                                          'Could not parse the input file',
                                          QtGui.QMessageBox.Cancel,
                                          QtGui.QMessageBox.Cancel)
コード例 #3
0
 def on_btn_load_json(self):
     """Load attributes from a json file"""
     # ask for a file name
     filename = qt_backend.getOpenFileName(
         self, 'Select a .json FOM attributes file', '',
         'JSON files (*.json)')
     if filename is None:
         return
     print 'load', filename
     attributes = json.load(open(filename))
     print "loaded:", attributes
     for att, value in attributes.iteritems():
         if att in self.process_with_fom.attributes:
             setattr(self.process_with_fom, att, value)
コード例 #4
0
 def on_btn_load_json(self):
     """Load attributes from a json file"""
     completion_engine = getattr(self.attributed_process,
                                 'completion_engine', None)
     if completion_engine is None:
         print('No completion engine with attributes in this process.')
         return
     # ask for a file name
     filename = qt_backend.getOpenFileName(
         self, 'Select a .json attributes file', '', 'JSON files (*.json)')
     if filename is None:
         return
     print('load', filename)
     attributes = json.load(open(filename))
     print("loaded:", attributes)
     completion_engine.get_attribute_values().import_from_dict(attributes)
コード例 #5
0
    def onBrowseClicked(control_instance):
        """ Browse the file system and update the control instance accordingly.

        If a valid file path has already been entered the file dialogue will
        automatically point to the file folder, otherwise the current working
        directory is used.

        Parameters
        ----------
        control_instance: QWidget (mandatory)
            the file widget item
        """
        # Get the current file path
        current_control_value = os.getcwd()
        if FileControlWidget.is_valid(control_instance):
            current_control_value \
                = six.text_type(control_instance.path.text())

        # get widget via a __self__ in a method, because control_instance may
        # be a weakproxy.
        widget = control_instance.__repr__.__self__
        ext = []
        trait = control_instance.trait
        if trait.allowed_extensions:
            ext = trait.allowed_extensions
        if trait.extensions:
            ext = trait.extensions
        ext = ['*%s' % e for e in ext]
        ext = ' '.join(ext)
        if ext:
            ext += ';; All files (*)'
        # Create a dialog to select a file
        if control_instance.output \
                or control_instance.trait.handler.exists is False:
            fname = qt_backend.getSaveFileName(
                widget, "Output file", current_control_value, ext,
                None, QtGui.QFileDialog.DontUseNativeDialog)
        else:
            fname = qt_backend.getOpenFileName(
                widget, "Open file", current_control_value, ext, None,
                QtGui.QFileDialog.DontUseNativeDialog)

        # Set the selected file path to the path sub control
        control_instance.path.set_value(six.text_type(fname))