示例#1
0
    def change_history_depth(self, value=None):
        """
        Set history maximum entries.

        Parameters
        ----------
        value: int or None, optional
            The valur to set  the maximum history depth. If no value is
            provided, an input dialog will be launched. Default is None.
        """
        if value is None:
            dialog = QInputDialog(self)

            # Set dialog properties
            dialog.setModal(False)
            dialog.setWindowTitle(_("History"))
            dialog.setLabelText(_("Maximum entries"))
            dialog.setInputMode(QInputDialog.IntInput)
            dialog.setIntRange(MIN_HISTORY_ENTRIES, MAX_HISTORY_ENTRIES)
            dialog.setIntStep(1)
            dialog.setIntValue(self.get_option("max_entries"))

            # Connect slot
            dialog.intValueSelected.connect(
                lambda value: self.set_option("max_entries", value))

            dialog.show()
        else:
            self.set_option("max_entries", value)
示例#2
0
    def set_max_results(self, value=None):
        """
        Set maximum amount of results to add to the result browser.

        Parameters
        ----------
        value: int, optional
            Number of results. If None an input dialog will be used.
            Default is None.
        """
        if value is None:
            # Create dialog
            dialog = QInputDialog(self)

            # Set dialog properties
            dialog.setModal(False)
            dialog.setWindowTitle(self.get_name())
            dialog.setLabelText(_('Set maximum number of results: '))
            dialog.setInputMode(QInputDialog.IntInput)
            dialog.setIntRange(1, 10000)
            dialog.setIntStep(1)
            dialog.setIntValue(self.get_option('max_results'))

            # Connect slot
            dialog.intValueSelected.connect(
                lambda value: self.set_option('max_results', value))

            dialog.show()
        else:
            self.set_option('max_results', value)
示例#3
0
    def GetInputOptions(
        self, message='', options='', default='', address='', addressType=''
    ):
        # Construct the list of options if options are given
        ok = False
        item = ''
        if options != '':
            input_dialog = QInputDialog()
            input_dialog.setComboBoxItems(options)
            input_dialog.setComboBoxEditable(False)
            if default:  # of there is no default, the first item will be the default
                input_dialog.setTextValue(default)
            input_dialog.setWindowTitle("Input")
            input_dialog.setLabelText(message)
            input_dialog.setModal(False)
            input_dialog.show()
            while input_dialog.isVisible():
                QCoreApplication.processEvents()
            ok = input_dialog.result()
            item = input_dialog.textValue()
        response = item if ok and item else 'stop'

        if response == 'stop':
            self.addlog(response)
            raise Exception('User requested stop')
        self.StoreMeasurement(address, addressType, response)
        self.addlog(response)
        return self.returnlog()
示例#4
0
    def rename_tab_dialog(self):
        logger, index = self.current_logger_and_index()
        if not logger:
            return

        d = QInputDialog(self)
        d.setLabelText('Enter the new name for the "{}" tab:'.format(
            logger.name))
        d.setWindowTitle('Rename the "{}" tab'.format(logger.name))
        d.textValueSelected.connect(self.rename_current_tab)
        d.open()
示例#5
0
    def trim_records_dialog(self):
        logger, index = self.current_logger_and_index()
        if not logger:
            return

        d = QInputDialog(self)
        d.setInputMode(QInputDialog.IntInput)
        d.setIntRange(
            0, 100000000)  # because it sets intMaximum to 99 by default. why??
        d.setLabelText('Keep this many records out of {}:'.format(
            logger.record_model.rowCount()))
        d.setWindowTitle('Trim tab records of "{}" logger'.format(logger.name))
        d.intValueSelected.connect(self.trim_current_tab_records)
        d.open()
示例#6
0
def input_qinputdialog(prompt: str = "") -> str:
    """
    Raises a QInputDialog with a given prompt and returns the user input as a string.
    If the user cancels the dialog, an EOFError is raised.
    Intended to be used to override python's `input` function to be more user friendly.
    """
    dlg = QInputDialog()
    dlg.setInputMode(QInputDialog.TextInput)
    dlg.setLabelText(str(prompt) if prompt is not None else "")
    accepted = dlg.exec_()
    if accepted:
        return dlg.textValue()
    else:
        raise EOFError("User input request cancelled")
示例#7
0
    def max_capacity_dialog(self):
        logger, index = self.current_logger_and_index()
        if not logger:
            return

        d = QInputDialog(self)
        d.setInputMode(QInputDialog.IntInput)
        d.setIntRange(
            0, 100000000)  # because it sets intMaximum to 99 by default. why??
        max_now = logger.record_model.max_capacity
        max_now = "not set" if max_now is None else max_now
        label_str = 'Set max capacity for "{}" logger\nCurrently {}. Set to 0 to disable:'
        d.setLabelText(label_str.format(logger.name, max_now))
        d.setWindowTitle('Set max capacity')
        d.intValueSelected.connect(self.set_max_capacity)
        d.open()
示例#8
0
    def GetInput(self, message='', default='', address='', addressType=''):
        input_dialog = QInputDialog()
        input_dialog.setTextEchoMode(QLineEdit.Normal)
        input_dialog.setTextValue(default)
        input_dialog.setWindowTitle("Input")
        input_dialog.setLabelText(message)
        input_dialog.setModal(False)
        input_dialog.show()
        while input_dialog.isVisible():
            QCoreApplication.processEvents()
        ok = input_dialog.result()
        item = input_dialog.textValue()
        response = item if ok else 'stop'

        if response == '':
            response = default
        elif response == 'stop':
            self.addlog(response)
            raise Exception('User requested stop')
        self.StoreMeasurement(address, addressType, response)
        self.addlog(response)
        return self.returnlog()
示例#9
0
 def new_preset_dialog(self):
     d = QInputDialog(self)
     d.setLabelText('Enter the new name for the new preset:')
     d.setWindowTitle('Create new preset')
     d.textValueSelected.connect(self.create_new_preset)
     d.open()