Ejemplo n.º 1
0
    def setData(self, index, value, role=Qt.EditRole, change_type=None):
        """Cell content change"""
        column = index.column()
        row = index.row()

        if change_type is not None:
            try:
                value = self.data(index, role=Qt.DisplayRole)
                val = from_qvariant(value, str)
                if change_type is bool:
                    val = bool_false_check(val)
                self.df.iloc[row, column - 1] = change_type(val)
            except ValueError:
                self.df.iloc[row, column - 1] = change_type('0')
        else:
            val = from_qvariant(value, str)
            current_value = self.get_value(row, column-1)
            if isinstance(current_value, bool):
                val = bool_false_check(val)
            if isinstance(current_value, ((bool,) + _sup_nr + _sup_com)) or \
               is_text_string(current_value):
                try:
                    self.df.iloc[row, column-1] = current_value.__class__(val)
                except ValueError as e:
                    QMessageBox.critical(self.dialog, "Error",
                                         "Value error: %s" % str(e))
                    return False
            else:
                QMessageBox.critical(self.dialog, "Error",
                                     "The type of the cell is not a supported "
                                     "type")
                return False
        self.max_min_col_update()
        return True
Ejemplo n.º 2
0
    def setData(self, index, value, role=Qt.EditRole, change_type=None):
        """Cell content change"""
        column = index.column()
        row = index.row()

        if change_type is not None:
            try:
                value = self.data(index, role=Qt.DisplayRole)
                val = from_qvariant(value, str)
                if change_type is bool:
                    val = bool_false_check(val)
                self.df.iloc[row, column - 1] = change_type(val)
            except ValueError:
                self.df.iloc[row, column - 1] = change_type('0')
        else:
            val = from_qvariant(value, str)
            current_value = self.get_value(row, column-1)
            if isinstance(current_value, bool):
                val = bool_false_check(val)
            if isinstance(current_value, ((bool,) + _sup_nr + _sup_com)) or \
               is_text_string(current_value):
                try:
                    self.df.iloc[row, column-1] = current_value.__class__(val)
                except ValueError as e:
                    QMessageBox.critical(self.dialog, "Error",
                                         "Value error: %s" % str(e))
                    return False
            else:
                QMessageBox.critical(self.dialog, "Error",
                                     "The type of the cell is not a supported "
                                     "type")
                return False
        self.max_min_col_update()
        return True
Ejemplo n.º 3
0
 def save_to_conf(self):
     """Save settings to configuration file"""
     for checkbox, (option, _default) in list(self.checkboxes.items()):
         self.set_option(option, checkbox.isChecked())
     for radiobutton, (option, _default) in list(self.radiobuttons.items()):
         self.set_option(option, radiobutton.isChecked())
     for lineedit, (option, _default) in list(self.lineedits.items()):
         self.set_option(option, to_text_string(lineedit.text()))
     for spinbox, (option, _default) in list(self.spinboxes.items()):
         self.set_option(option, spinbox.value())
     for combobox, (option, _default) in list(self.comboboxes.items()):
         data = combobox.itemData(combobox.currentIndex())
         self.set_option(option, from_qvariant(data, to_text_string))
     for (fontbox, sizebox), option in list(self.fontboxes.items()):
         font = fontbox.currentFont()
         font.setPointSize(sizebox.value())
         self.set_font(font, option)
     for clayout, (option, _default) in list(self.coloredits.items()):
         self.set_option(option, to_text_string(clayout.lineedit.text()))
     for (clayout, cb_bold,
          cb_italic), (option, _default) in list(self.scedits.items()):
         color = to_text_string(clayout.lineedit.text())
         bold = cb_bold.isChecked()
         italic = cb_italic.isChecked()
         self.set_option(option, (color, bold, italic))
Ejemplo n.º 4
0
 def setData(self, index, value, role=Qt.EditRole):
     """Cell content change"""
     if not index.isValid() or self.readonly:
         return False
     i = index.row()
     j = index.column()
     value = from_qvariant(value, str)
     if self._data.dtype.name == "bool":
         try:
             val = bool(float(value))
         except ValueError:
             val = value.lower() == "true"
     elif self._data.dtype.name.startswith("string"):
         val = str(value)
     elif self._data.dtype.name.startswith("unicode"):
         val = unicode(value)
     else:
         if value.lower().startswith('e') or value.lower().endswith('e'):
             return False
         try:
             val = complex(value)
             if not val.imag:
                 val = val.real
         except ValueError, e:
             QMessageBox.critical(self.dialog, "Error",
                                  "Value error: %s" % str(e))
             return False
Ejemplo n.º 5
0
 def setEditorData(self, editor, index):
     text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
     if index.column() in (MOD1, MOD2, MOD3, KEY):
         i = editor.findText(text)
         if i == -1:
             i = 0
         editor.setCurrentIndex(i)
     else:
         QItemDelegate.setEditorData(self, editor, index)
Ejemplo n.º 6
0
 def setEditorData(self, editor, index):
     text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
     if index.column() in (MOD1, MOD2, MOD3, KEY):
         i = editor.findText(text)
         if i == -1:
             i = 0
         editor.setCurrentIndex(i)
     else:
         QItemDelegate.setEditorData(self, editor, index)
Ejemplo n.º 7
0
 def _save_lang(self):
     """
     Get selected language setting and save to language configuration file.
     """
     for combobox, (option, _default) in list(self.comboboxes.items()):
         if option == 'interface_language':
             data = combobox.itemData(combobox.currentIndex())
             value = from_qvariant(data, to_text_string)
             break
     save_lang_conf(value)
     self.set_option('interface_language', value)
Ejemplo n.º 8
0
 def _save_lang(self):
     """
     Get selected language setting and save to language configuration file.
     """
     for combobox, (option, _default) in list(self.comboboxes.items()):
         if option == 'interface_language':
             data = combobox.itemData(combobox.currentIndex())
             value = from_qvariant(data, to_text_string)
             break
     save_lang_conf(value)
     self.set_option('interface_language', value)
Ejemplo n.º 9
0
 def setData(self, index, value, role=Qt.EditRole):
     """Qt Override."""
     if index.isValid() and 0 <= index.row() < len(self.shortcuts):
         shortcut = self.shortcuts[index.row()]
         column = index.column()
         text = from_qvariant(value, str)
         if column == SEQUENCE:
             shortcut.key = text
         self.dataChanged.emit(index, index)
         return True
     return False
Ejemplo n.º 10
0
    def setData(self, index, value, role):
        """Override Qt method"""
        row = index.row()
        name, state = self.row(row)

        if role == Qt.CheckStateRole:
            self.set_row(row, [name, not state])
            self._parent.setCurrentIndex(index)
            self._parent.setFocus()
            self.dataChanged.emit(index, index)
            return True
        elif role == Qt.EditRole:
            self.set_row(row, [from_qvariant(value, to_text_string), state])
            self.dataChanged.emit(index, index)
            return True
        return True
Ejemplo n.º 11
0
    def setData(self, index, value, role):
        """Override Qt method"""
        row = index.row()
        name, state = self.row(row)

        if role == Qt.CheckStateRole:
            self.set_row(row, [name, not state])
            self._parent.setCurrentIndex(index)
            self._parent.setFocus()
            self.dataChanged.emit(index, index)
            return True
        elif role == Qt.EditRole:
            self.set_row(row, [from_qvariant(value, to_text_string), state])
            self.dataChanged.emit(index, index)
            return True
        return True
Ejemplo n.º 12
0
 def setData(self, index, value, role=Qt.EditRole):
     if index.isValid() and 0 <= index.row() < len(self.shortcuts):
         shortcut = self.shortcuts[index.row()]
         key = shortcut.key
         column = index.column()
         text = from_qvariant(value, str)
         if column == MOD1:
             key.modifiers[0] = Key.modifier_from_name(text)
         elif column == MOD2:
             key.modifiers[1] = Key.modifier_from_name(text)
         elif column == MOD3:
             key.modifiers[2] = Key.modifier_from_name(text)
         elif column == KEY:
             key.key = Key.key_from_str(text)
         self.dataChanged.emit(index, index)
         return True
     return False
Ejemplo n.º 13
0
 def setData(self, index, value, role=Qt.EditRole):
     if index.isValid() and 0 <= index.row() < len(self.shortcuts):
         shortcut = self.shortcuts[index.row()]
         key = shortcut.key
         column = index.column()
         text = from_qvariant(value, str)
         if column == MOD1:
             key.modifiers[0] = Key.modifier_from_name(text)
         elif column == MOD2:
             key.modifiers[1] = Key.modifier_from_name(text)
         elif column == MOD3:
             key.modifiers[2] = Key.modifier_from_name(text)
         elif column == KEY:
             key.key = Key.key_from_str(text)
         self.dataChanged.emit(index, index)
         return True
     return False
Ejemplo n.º 14
0
def display_to_value(value, default_value, ignore_errors=True):
    """Convert back to value"""
    from spyderlib.qt.compat import from_qvariant
    value = from_qvariant(value, to_text_string)
    try:
        np_dtype = get_numpy_dtype(default_value)
        if isinstance(default_value, bool):
            # We must test for boolean before NumPy data types
            # because `bool` class derives from `int` class
            try:
                value = bool(float(value))
            except ValueError:
                value = value.lower() == "true"
        elif np_dtype is not None:
            if 'complex' in str(type(default_value)):
                value = np_dtype(complex(value))
            else:
                value = np_dtype(value)
        elif is_binary_string(default_value):
            value = to_binary_string(value, 'utf8')
        elif is_text_string(default_value):
            value = to_text_string(value)
        elif isinstance(default_value, complex):
            value = complex(value)
        elif isinstance(default_value, float):
            value = float(value)
        elif isinstance(default_value, int):
            try:
                value = int(value)
            except ValueError:
                value = float(value)
        elif isinstance(default_value, datetime.datetime):
            value = datestr_to_datetime(value)
        elif isinstance(default_value, datetime.date):
            value = datestr_to_datetime(value).date()
        elif ignore_errors:
            value = try_to_eval(value)
        else:
            value = eval(value)
    except (ValueError, SyntaxError):
        if ignore_errors:
            value = try_to_eval(value)
        else:
            return default_value
    return value
Ejemplo n.º 15
0
def display_to_value(value, default_value, ignore_errors=True):
    """Convert back to value"""
    from spyderlib.qt.compat import from_qvariant
    value = from_qvariant(value, to_text_string)
    try:
        np_dtype = get_numpy_dtype(default_value)
        if isinstance(default_value, bool):
            # We must test for boolean before NumPy data types
            # because `bool` class derives from `int` class
            try:
                value = bool(float(value))
            except ValueError:
                value = value.lower() == "true"
        elif np_dtype is not None:
            if 'complex' in str(type(default_value)):
                value = np_dtype(complex(value))
            else:
                value = np_dtype(value)
        elif is_binary_string(default_value):
            value = to_binary_string(value, 'utf8')
        elif is_text_string(default_value):
            value = to_text_string(value)
        elif isinstance(default_value, complex):
            value = complex(value)
        elif isinstance(default_value, float):
            value = float(value)
        elif isinstance(default_value, int):
            try:
                value = int(value)
            except ValueError:
                value = float(value)
        elif isinstance(default_value, datetime.datetime):
            value = datestr_to_datetime(value)
        elif isinstance(default_value, datetime.date):
            value = datestr_to_datetime(value).date()
        elif ignore_errors:
            value = try_to_eval(value)
        else:
            value = eval(value)
    except (ValueError, SyntaxError):
        if ignore_errors:
            value = try_to_eval(value)
        else:
            return default_value
    return value
Ejemplo n.º 16
0
 def setData(self, index, value, role=Qt.EditRole):
     """Cell content change"""
     if not index.isValid() or self.readonly:
         return False
     i = index.row()
     j = index.column()
     value = from_qvariant(value, str)
     dtype = self._data.dtype.name
     if dtype == "bool":
         try:
             val = bool(float(value))
         except ValueError:
             val = value.lower() == "true"
     elif dtype.startswith("string") or dtype.startswith("bytes"):
         val = to_binary_string(value, 'utf8')
     elif dtype.startswith("unicode") or dtype.startswith("str"):
         val = to_text_string(value)
     else:
         if value.lower().startswith('e') or value.lower().endswith('e'):
             return False
         try:
             val = complex(value)
             if not val.imag:
                 val = val.real
         except ValueError as e:
             QMessageBox.critical(self.dialog, "Error",
                                  "Value error: %s" % str(e))
             return False
     try:
         self.test_array[0] = val # will raise an Exception eventually
     except OverflowError as e:
         print(type(e.message))
         QMessageBox.critical(self.dialog, "Error",
                              "Overflow error: %s" % e.message)
         return False
     
     # Add change to self.changes
     self.changes[(i, j)] = val
     self.dataChanged.emit(index, index)
     if not is_string(val):
         if val > self.vmax:
             self.vmax = val
         if val < self.vmin:
             self.vmin = val
     return True
Ejemplo n.º 17
0
 def setData(self, index, value, role=Qt.EditRole):
     """Cell content change"""
     if not index.isValid() or self.readonly:
         return False
     i = index.row()
     j = index.column()
     value = from_qvariant(value, str)
     dtype = self._data.dtype.name
     if dtype == "bool":
         try:
             val = bool(float(value))
         except ValueError:
             val = value.lower() == "true"
     elif dtype.startswith("string") or dtype.startswith("bytes"):
         val = to_binary_string(value, 'utf8')
     elif dtype.startswith("unicode") or dtype.startswith("str"):
         val = to_text_string(value)
     else:
         if value.lower().startswith('e') or value.lower().endswith('e'):
             return False
         try:
             val = complex(value)
             if not val.imag:
                 val = val.real
         except ValueError as e:
             QMessageBox.critical(self.dialog, "Error",
                                  "Value error: %s" % str(e))
             return False
     try:
         self.test_array[0] = val # will raise an Exception eventually
     except OverflowError as e:
         print(type(e.message))
         QMessageBox.critical(self.dialog, "Error",
                              "Overflow error: %s" % e.message)
         return False
     
     # Add change to self.changes
     self.changes[(i, j)] = val
     self.dataChanged.emit(index, index)
     if not is_string(val):
         if val > self.vmax:
             self.vmax = val
         if val < self.vmin:
             self.vmin = val
     return True
Ejemplo n.º 18
0
 def __init__(self, name, line, parent, preceding):
     if preceding is None:
         QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
     else:
         if preceding is not parent:
             # Preceding must be either the same as item's parent
             # or have the same parent as item
             while preceding.parent() is not parent:
                 preceding = preceding.parent()
                 if preceding is None:
                     break
         if preceding is None:
             QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
         else:
             QTreeWidgetItem.__init__(self, parent, preceding, QTreeWidgetItem.Type)
     self.setText(0, name)
     parent_text = from_qvariant(parent.data(0, Qt.UserRole), to_text_string)
     set_item_user_text(self, parent_text + "/" + name)
     self.line = line
Ejemplo n.º 19
0
 def __init__(self, name, line, parent, preceding):
     if preceding is None:
         QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
     else:
         if preceding is not parent:
             # Preceding must be either the same as item's parent
             # or have the same parent as item
             while preceding.parent() is not parent:
                 preceding = preceding.parent()
                 if preceding is None:
                     break
         if preceding is None:
             QTreeWidgetItem.__init__(self, parent, QTreeWidgetItem.Type)
         else:
             QTreeWidgetItem.__init__(self, parent, preceding,
                                      QTreeWidgetItem.Type)
     self.setText(0, name)
     parent_text = from_qvariant(parent.data(0, Qt.UserRole),
                                 to_text_string)
     set_item_user_text(self, parent_text + '/' + name)
     self.line = line
Ejemplo n.º 20
0
    def delete_layout(self):
        """ """
        names, order, active = self.names, self.order, self.order
        name = from_qvariant(self.table.selectionModel().currentIndex().data(),
                             to_text_string)

        if name in names:
            index = names.index(name)
            # In case nothing has focus in the table
        if index != -1:
            order.remove(name)
            names[index] = None
            if name in active:
                active.remove(name)
            self.names, self.order, self.active = names, order, active
            self.table.model().set_data(order, active)
            index = self.table.model().index(0, 0)
            self.table.setCurrentIndex(index)
            self.table.setFocus()
            self.selection_changed(None, None)
            if len(order) == 0:
                self.button_move_up.setDisabled(True)
                self.button_move_down.setDisabled(True)
                self.button_delete.setDisabled(True)
Ejemplo n.º 21
0
    def delete_layout(self):
        """ """
        names, order, active = self.names, self.order, self.order
        name = from_qvariant(self.table.selectionModel().currentIndex().data(),
                             to_text_string)

        if name in names:
            index = names.index(name)
            # In case nothing has focus in the table
        if index != -1:
            order.remove(name)
            names[index] = None
            if name in active:
                active.remove(name)
            self.names, self.order, self.active = names, order, active
            self.table.model().set_data(order, active)
            index = self.table.model().index(0, 0)
            self.table.setCurrentIndex(index)
            self.table.setFocus()
            self.selection_changed(None, None)
            if len(order) == 0:
                self.button_move_up.setDisabled(True)
                self.button_move_down.setDisabled(True)
                self.button_delete.setDisabled(True)
Ejemplo n.º 22
0
 def save_to_conf(self):
     """Save settings to configuration file"""
     for checkbox, (option, _default) in list(self.checkboxes.items()):
         self.set_option(option, checkbox.isChecked())
     for radiobutton, (option, _default) in list(self.radiobuttons.items()):
         self.set_option(option, radiobutton.isChecked())
     for lineedit, (option, _default) in list(self.lineedits.items()):
         self.set_option(option, to_text_string(lineedit.text()))
     for spinbox, (option, _default) in list(self.spinboxes.items()):
         self.set_option(option, spinbox.value())
     for combobox, (option, _default) in list(self.comboboxes.items()):
         data = combobox.itemData(combobox.currentIndex())
         self.set_option(option, from_qvariant(data, to_text_string))
     for (fontbox, sizebox), option in list(self.fontboxes.items()):
         font = fontbox.currentFont()
         font.setPointSize(sizebox.value())
         self.set_font(font, option)
     for clayout, (option, _default) in list(self.coloredits.items()):
         self.set_option(option, to_text_string(clayout.lineedit.text()))
     for (clayout, cb_bold, cb_italic), (option, _default) in list(self.scedits.items()):
         color = to_text_string(clayout.lineedit.text())
         bold = cb_bold.isChecked()
         italic = cb_italic.isChecked()
         self.set_option(option, (color, bold, italic))
Ejemplo n.º 23
0
def keybinding(attr):
    """Return keybinding"""
    ks = getattr(QKeySequence, attr)
    return from_qvariant(QKeySequence.keyBindings(ks)[0], str)
Ejemplo n.º 24
0
 def setEditorData(self, editor, index):
     """Set editor widget's data"""
     text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
     editor.setText(text)
Ejemplo n.º 25
0
    def load_from_conf(self):
        """Load settings from configuration file"""
        for checkbox, (option, default) in list(self.checkboxes.items()):
            checkbox.setChecked(self.get_option(option, default))
            # Checkboxes work differently for PySide and PyQt
            if API == 'pyqt':
                checkbox.clicked.connect(
                    lambda _foo, opt=option: self.has_been_modified(opt))
            else:
                checkbox.clicked.connect(
                    lambda opt=option: self.has_been_modified(opt))
        for radiobutton, (option, default) in list(self.radiobuttons.items()):
            radiobutton.setChecked(self.get_option(option, default))
            radiobutton.toggled.connect(
                lambda _foo, opt=option: self.has_been_modified(opt))
        for lineedit, (option, default) in list(self.lineedits.items()):
            lineedit.setText(self.get_option(option, default))
            lineedit.textChanged.connect(
                lambda _foo, opt=option: self.has_been_modified(opt))
        for spinbox, (option, default) in list(self.spinboxes.items()):
            spinbox.setValue(self.get_option(option, default))
            spinbox.valueChanged.connect(
                lambda _foo, opt=option: self.has_been_modified(opt))
        for combobox, (option, default) in list(self.comboboxes.items()):
            value = self.get_option(option, default)
            for index in range(combobox.count()):
                data = from_qvariant(combobox.itemData(index), to_text_string)
                # For PyQt API v2, it is necessary to convert `data` to
                # unicode in case the original type was not a string, like an
                # integer for example (see spyderlib.qt.compat.from_qvariant):
                if to_text_string(data) == to_text_string(value):
                    break
            combobox.setCurrentIndex(index)
            combobox.currentIndexChanged.connect(
                lambda _foo, opt=option: self.has_been_modified(opt))
            if combobox.restart_required:
                self.restart_options[option] = combobox.label_text

        for (fontbox, sizebox), option in list(self.fontboxes.items()):
            font = self.get_font(option)
            fontbox.setCurrentFont(font)
            sizebox.setValue(font.pointSize())
            if option is None:
                property = 'plugin_font'
            else:
                property = option
            fontbox.currentIndexChanged.connect(
                lambda _foo, opt=property: self.has_been_modified(opt))
            sizebox.valueChanged.connect(
                lambda _foo, opt=property: self.has_been_modified(opt))
        for clayout, (option, default) in list(self.coloredits.items()):
            property = to_qvariant(option)
            edit = clayout.lineedit
            btn = clayout.colorbtn
            edit.setText(self.get_option(option, default))
            btn.clicked.connect(lambda opt=option: self.has_been_modified(opt))
            edit.textChanged.connect(
                lambda _foo, opt=option: self.has_been_modified(opt))
        for (clayout, cb_bold,
             cb_italic), (option, default) in list(self.scedits.items()):
            edit = clayout.lineedit
            btn = clayout.colorbtn
            color, bold, italic = self.get_option(option, default)
            edit.setText(color)
            cb_bold.setChecked(bold)
            cb_italic.setChecked(italic)
            btn.clicked.connect(lambda opt=option: self.has_been_modified(opt))
            edit.textChanged.connect(
                lambda _foo, opt=option: self.has_been_modified(opt))
            if API == 'pyqt':
                cb_bold.clicked.connect(
                    lambda _foo, opt=option: self.has_been_modified(opt))
            else:
                cb_bold.clicked.connect(
                    lambda opt=option: self.has_been_modified(opt))
            if API == 'pyqt':
                cb_italic.clicked.connect(
                    lambda _foo, opt=option: self.has_been_modified(opt))
            else:
                cb_italic.clicked.connect(
                    lambda opt=option: self.has_been_modified(opt))
Ejemplo n.º 26
0
def get_item_user_text(item):
    """Get QTreeWidgetItem user role string"""
    return from_qvariant(item.data(0, Qt.UserRole), to_text_string)
Ejemplo n.º 27
0
def keybinding(attr):
    """Return keybinding"""
    ks = getattr(QKeySequence, attr)
    return from_qvariant(QKeySequence.keyBindings(ks)[0], str)
Ejemplo n.º 28
0
 def load_from_conf(self):
     """Load settings from configuration file"""
     for checkbox, (option, default) in list(self.checkboxes.items()):
         checkbox.setChecked(self.get_option(option, default))
         self.connect(checkbox, SIGNAL("clicked(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for radiobutton, (option, default) in list(self.radiobuttons.items()):
         radiobutton.setChecked(self.get_option(option, default))
         self.connect(radiobutton, SIGNAL("toggled(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for lineedit, (option, default) in list(self.lineedits.items()):
         lineedit.setText(self.get_option(option, default))
         self.connect(lineedit, SIGNAL("textChanged(QString)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for spinbox, (option, default) in list(self.spinboxes.items()):
         spinbox.setValue(self.get_option(option, default))
         self.connect(spinbox, SIGNAL('valueChanged(int)'),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for combobox, (option, default) in list(self.comboboxes.items()):
         value = self.get_option(option, default)
         for index in range(combobox.count()):
             data = from_qvariant(combobox.itemData(index), to_text_string)
             # For PyQt API v2, it is necessary to convert `data` to 
             # unicode in case the original type was not a string, like an 
             # integer for example (see spyderlib.qt.compat.from_qvariant):
             if to_text_string(data) == to_text_string(value):
                 break
         combobox.setCurrentIndex(index)
         self.connect(combobox, SIGNAL('currentIndexChanged(int)'),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for (fontbox, sizebox), option in list(self.fontboxes.items()):
         font = self.get_font(option)
         fontbox.setCurrentFont(font)
         sizebox.setValue(font.pointSize())
         if option is None:
             property = 'plugin_font'
         else:
             property = option
         self.connect(fontbox, SIGNAL('currentIndexChanged(int)'),
                      lambda _foo, opt=property: self.has_been_modified(opt))
         self.connect(sizebox, SIGNAL('valueChanged(int)'),
                      lambda _foo, opt=property: self.has_been_modified(opt))
     for clayout, (option, default) in list(self.coloredits.items()):
         property = to_qvariant(option)
         edit = clayout.lineedit
         btn = clayout.colorbtn
         edit.setText(self.get_option(option, default))
         self.connect(btn, SIGNAL('clicked()'),
                      lambda opt=option: self.has_been_modified(opt))
         self.connect(edit, SIGNAL("textChanged(QString)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for (clayout, cb_bold, cb_italic
          ), (option, default) in list(self.scedits.items()):
         edit = clayout.lineedit
         btn = clayout.colorbtn
         color, bold, italic = self.get_option(option, default)
         edit.setText(color)
         cb_bold.setChecked(bold)
         cb_italic.setChecked(italic)
         self.connect(btn, SIGNAL('clicked()'),
                      lambda opt=option: self.has_been_modified(opt))
         self.connect(edit, SIGNAL("textChanged(QString)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
         self.connect(cb_bold, SIGNAL("clicked(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
         self.connect(cb_italic, SIGNAL("clicked(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
Ejemplo n.º 29
0
 def load_from_conf(self):
     """Load settings from configuration file"""
     for checkbox, (option, default) in list(self.checkboxes.items()):
         checkbox.setChecked(self.get_option(option, default))
         self.connect(checkbox,
                      SIGNAL("clicked(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for radiobutton, (option, default) in list(self.radiobuttons.items()):
         radiobutton.setChecked(self.get_option(option, default))
         self.connect(radiobutton,
                      SIGNAL("toggled(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for lineedit, (option, default) in list(self.lineedits.items()):
         lineedit.setText(self.get_option(option, default))
         self.connect(lineedit,
                      SIGNAL("textChanged(QString)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for spinbox, (option, default) in list(self.spinboxes.items()):
         spinbox.setValue(self.get_option(option, default))
         self.connect(spinbox,
                      SIGNAL('valueChanged(int)'),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for combobox, (option, default) in list(self.comboboxes.items()):
         value = self.get_option(option, default)
         for index in range(combobox.count()):
             data = from_qvariant(combobox.itemData(index), to_text_string)
             # For PyQt API v2, it is necessary to convert `data` to
             # unicode in case the original type was not a string, like an
             # integer for example (see spyderlib.qt.compat.from_qvariant):
             if to_text_string(data) == to_text_string(value):
                 break
         combobox.setCurrentIndex(index)
         self.connect(combobox,
                      SIGNAL('currentIndexChanged(int)'),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for (fontbox, sizebox), option in list(self.fontboxes.items()):
         font = self.get_font(option)
         fontbox.setCurrentFont(font)
         sizebox.setValue(font.pointSize())
         if option is None:
             property = 'plugin_font'
         else:
             property = option
         self.connect(
             fontbox,
             SIGNAL('currentIndexChanged(int)'),
             lambda _foo, opt=property: self.has_been_modified(opt))
         self.connect(
             sizebox,
             SIGNAL('valueChanged(int)'),
             lambda _foo, opt=property: self.has_been_modified(opt))
     for clayout, (option, default) in list(self.coloredits.items()):
         property = to_qvariant(option)
         edit = clayout.lineedit
         btn = clayout.colorbtn
         edit.setText(self.get_option(option, default))
         self.connect(btn,
                      SIGNAL('clicked()'),
                      lambda opt=option: self.has_been_modified(opt))
         self.connect(edit,
                      SIGNAL("textChanged(QString)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
     for (clayout, cb_bold,
          cb_italic), (option, default) in list(self.scedits.items()):
         edit = clayout.lineedit
         btn = clayout.colorbtn
         color, bold, italic = self.get_option(option, default)
         edit.setText(color)
         cb_bold.setChecked(bold)
         cb_italic.setChecked(italic)
         self.connect(btn,
                      SIGNAL('clicked()'),
                      lambda opt=option: self.has_been_modified(opt))
         self.connect(edit,
                      SIGNAL("textChanged(QString)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
         self.connect(cb_bold,
                      SIGNAL("clicked(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
         self.connect(cb_italic,
                      SIGNAL("clicked(bool)"),
                      lambda _foo, opt=option: self.has_been_modified(opt))
Ejemplo n.º 30
0
    def load_from_conf(self):
        """Load settings from configuration file"""
        for checkbox, (option, default) in list(self.checkboxes.items()):
            checkbox.setChecked(self.get_option(option, default))
            # Checkboxes work differently for PySide and PyQt
            if API == 'pyqt':
                checkbox.clicked.connect(lambda _foo, opt=option:
                                         self.has_been_modified(opt))
            else:
                checkbox.clicked.connect(lambda opt=option:
                                         self.has_been_modified(opt))
        for radiobutton, (option, default) in list(self.radiobuttons.items()):
            radiobutton.setChecked(self.get_option(option, default))
            radiobutton.toggled.connect(lambda _foo, opt=option:
                                        self.has_been_modified(opt))
        for lineedit, (option, default) in list(self.lineedits.items()):
            lineedit.setText(self.get_option(option, default))
            lineedit.textChanged.connect(lambda _foo, opt=option:
                                         self.has_been_modified(opt))
        for spinbox, (option, default) in list(self.spinboxes.items()):
            spinbox.setValue(self.get_option(option, default))
            spinbox.valueChanged.connect(lambda _foo, opt=option:
                                         self.has_been_modified(opt))
        for combobox, (option, default) in list(self.comboboxes.items()):
            value = self.get_option(option, default)
            for index in range(combobox.count()):
                data = from_qvariant(combobox.itemData(index), to_text_string)
                # For PyQt API v2, it is necessary to convert `data` to 
                # unicode in case the original type was not a string, like an 
                # integer for example (see spyderlib.qt.compat.from_qvariant):
                if to_text_string(data) == to_text_string(value):
                    break
            combobox.setCurrentIndex(index)
            combobox.currentIndexChanged.connect(lambda _foo, opt=option:
                                                 self.has_been_modified(opt))
            if combobox.restart_required:
                self.restart_options[option] = combobox.label_text

        for (fontbox, sizebox), option in list(self.fontboxes.items()):
            font = self.get_font(option)
            fontbox.setCurrentFont(font)
            sizebox.setValue(font.pointSize())
            if option is None:
                property = 'plugin_font'
            else:
                property = option
            fontbox.currentIndexChanged.connect(lambda _foo, opt=property:
                                                self.has_been_modified(opt))
            sizebox.valueChanged.connect(lambda _foo, opt=property:
                                         self.has_been_modified(opt))
        for clayout, (option, default) in list(self.coloredits.items()):
            property = to_qvariant(option)
            edit = clayout.lineedit
            btn = clayout.colorbtn
            edit.setText(self.get_option(option, default))
            btn.clicked.connect(lambda opt=option: self.has_been_modified(opt))
            edit.textChanged.connect(lambda _foo, opt=option:
                                     self.has_been_modified(opt))
        for (clayout, cb_bold, cb_italic
             ), (option, default) in list(self.scedits.items()):
            edit = clayout.lineedit
            btn = clayout.colorbtn
            color, bold, italic = self.get_option(option, default)
            edit.setText(color)
            cb_bold.setChecked(bold)
            cb_italic.setChecked(italic)
            btn.clicked.connect(lambda opt=option: self.has_been_modified(opt))
            edit.textChanged.connect(lambda _foo, opt=option:
                                     self.has_been_modified(opt))
            if API == 'pyqt':
                cb_bold.clicked.connect(lambda _foo, opt=option:
                                        self.has_been_modified(opt))
            else:
                cb_bold.clicked.connect(lambda opt=option:
                                        self.has_been_modified(opt))
            if API == 'pyqt':
                cb_italic.clicked.connect(lambda _foo, opt=option:
                                          self.has_been_modified(opt))
            else:
                cb_italic.clicked.connect(lambda opt=option:
                                          self.has_been_modified(opt))
Ejemplo n.º 31
0
 def setEditorData(self, editor, index):
     """Set editor widget's data"""
     text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
     editor.setText(text)
Ejemplo n.º 32
0
def get_item_user_text(item):
    """Get QTreeWidgetItem user role string"""
    return from_qvariant(item.data(0, Qt.UserRole), to_text_string)