Beispiel #1
0
 def get_from_shell(self, oname=None):
     """Open an input dialog, receive an object and emit the
     :attr:`object_loaded` signal"""
     if oname is None:
         oname, ok = QInputDialog.getItem(
             self, 'Select variable',
             'Select a variable to import from the console',
             self.potential_object_names)
         if not ok:
             return
     if self.check(oname) and (self._instances2check or
                               not isinstance(oname, six.string_types)):
         obj = oname
         oname = 'object'
     else:
         found, obj = self.get_obj(oname.strip())
         if found:
             if not self.check(obj):
                 self.error_msg.showMessage(
                     'Object must be an instance of %r, not %r' % (
                         self.instances2check_str,
                         '%s.%s' % (type(obj).__module__,
                                    type(obj).__name__)))
                 return
         else:
             if not oname.strip():
                 msg = 'The variable name must not be empty!'
             else:
                 msg = 'Could not find object ' + oname
             self.error_msg.showMessage(msg)
             return
     self.object_loaded.emit(oname, obj)
Beispiel #2
0
    def start_tutorial(self, state, tutorial_cls=None):
        """Start or stop the tutorial

        Parameters
        ----------
        state: bool
            If False, the tutorial is stopped. Otherwise it is started
        tutorial_cls: straditize.widgets.tutorial.beginner.Tutorial
            The tutorial class to use. If None, it will be asked in a
            QInputDialog"""
        if self.tutorial is not None or not state:
            self.tutorial.close()
            self.tutorial_button.setText('Tutorial')
        elif state:
            if tutorial_cls is None:
                tutorial_cls, ok = QInputDialog.getItem(
                    self,
                    'Start tutorial',
                    "Select the tutorial type",
                    ["Beginner", "Advanced (Hoya del Castillo)"],
                    editable=False)
                if not ok:
                    self.tutorial_button.blockSignals(True)
                    self.tutorial_button.setChecked(False)
                    self.tutorial_button.blockSignals(False)
                    return
                if tutorial_cls == 'Beginner':
                    from straditize.widgets.tutorial import Tutorial
                else:
                    from straditize.widgets.tutorial import (
                        HoyaDelCastilloTutorial as Tutorial)
            else:
                Tutorial = tutorial_cls
            self.tutorial = Tutorial(self)
            self.tutorial_button.setText('Stop tutorial')
Beispiel #3
0
 def get_from_shell(self, oname=None):
     """Open an input dialog, receive an object and emit the
     :attr:`object_loaded` signal"""
     if oname is None:
         oname, ok = QInputDialog.getItem(
             self, 'Select variable',
             'Select a variable to import from the console',
             self.potential_object_names)
         if not ok:
             return
     if self.check(oname) and (self._instances2check
                               or not isinstance(oname, six.string_types)):
         obj = oname
         oname = 'object'
     else:
         found, obj = self.get_obj(oname.strip())
         if found:
             if not self.check(obj):
                 self.error_msg.showMessage(
                     'Object must be an instance of %r, not %r' %
                     (self.instances2check_str, '%s.%s' %
                      (type(obj).__module__, type(obj).__name__)))
                 return
         else:
             if not oname.strip():
                 msg = 'The variable name must not be empty!'
             else:
                 msg = 'Could not find object ' + oname
             self.error_msg.showMessage(msg)
             return
     self.object_loaded.emit(oname, obj)
Beispiel #4
0
 def ask_for_value(self, val=None, label=None):
     from psyplot_gui.compat.qtcompat import QInputDialog, QLineEdit
     from psyplot_gui.main import mainwindow
     initial = str(val) if val is not None else ''
     value, ok = QInputDialog().getText(mainwindow, self.message, label
                                        or self.label, QLineEdit.Normal,
                                        initial)
     if ok:
         self.value = self.dtype(value)
Beispiel #5
0
 def open_files(self, fnames):
     """Open a file and ask the user how"""
     fnames_s = ', '.join(map(os.path.basename, fnames))
     if len(fnames_s) > 30:
         fnames_s = fnames_s[:27] + '...'
     item, ok = QInputDialog.getItem(
         self, 'Open file...', 'Open %s as...' % fnames_s,
         list(self.open_file_options), current=0, editable=False)
     if ok:
         return self.open_file_options[item](fnames)
Beispiel #6
0
    def ask_for_value(self, val=None, label=None):
        """Ask for a value for the cross mark

        This method opens a QInputDialog to ask for a new :attr:`value`

        Parameters
        ----------
        val: float
            The initial value
        label: str
            the name of what to ask for"""
        from psyplot_gui.compat.qtcompat import QInputDialog, QLineEdit
        from psyplot_gui.main import mainwindow
        initial = str(val) if val is not None else ''
        value, ok = QInputDialog().getText(mainwindow, self.message, label
                                           or self.label, QLineEdit.Normal,
                                           initial)
        if ok:
            self.value = self.dtype(value)