예제 #1
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     """Set header data"""
     if role != Qt.DisplayRole:
         return to_qvariant()
     labels = self.xlabels if orientation == Qt.Horizontal else self.ylabels
     if labels is None:
         return to_qvariant(int(section))
     else:
         return to_qvariant(labels[section])
예제 #2
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     """Set header data"""
     if role != Qt.DisplayRole:
         return to_qvariant()
     labels = self.xlabels if orientation == Qt.Horizontal else self.ylabels
     if labels is None:
         return to_qvariant(int(section))
     else:
         return to_qvariant(labels[section])
예제 #3
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     """Overriding method headerData"""
     if role != Qt.DisplayRole:
         return to_qvariant()
     i_column = int(section)
     if orientation == Qt.Horizontal:
         headers = (_("Module"), _(" Required "), _(" Installed "), _("Provided features"))
         return to_qvariant(headers[i_column])
     else:
         return to_qvariant()
예제 #4
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     """Overriding method headerData"""
     if role != Qt.DisplayRole:
         return to_qvariant()
     i_column = int(section)
     if orientation == Qt.Horizontal:
         headers = (_("File"), _("Line"), _("Condition"), "")
         return to_qvariant( headers[i_column] )
     else:
         return to_qvariant()
예제 #5
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     """Overriding method headerData"""
     if role != Qt.DisplayRole:
         return to_qvariant()
     i_column = int(section)
     if orientation == Qt.Horizontal:
         headers = (_("File"), _("Line"), _("Condition"), "")
         return to_qvariant(headers[i_column])
     else:
         return to_qvariant()
예제 #6
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     """Overriding method headerData"""
     if role != Qt.DisplayRole:
         return to_qvariant()
     i_column = int(section)
     if orientation == Qt.Horizontal:
         headers = (_("Module"), _(" Required "), _(" Installed "),
                    _("Provided features"))
         return to_qvariant(headers[i_column])
     else:
         return to_qvariant()
예제 #7
0
 def data(self, index, role=Qt.DisplayRole):
     """Return a model data element"""
     if not index.isValid():
         return to_qvariant()
     if role == Qt.DisplayRole:
         return self._display_data(index)
     elif role == Qt.BackgroundColorRole:
         return to_qvariant(get_color(self._data[index.row()][index.column()], .2))
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignRight|Qt.AlignVCenter))
     return to_qvariant()
예제 #8
0
 def data(self, index, role=Qt.DisplayRole):
     """Return a model data element"""
     if not index.isValid():
         return to_qvariant()
     if role == Qt.DisplayRole:
         return self._display_data(index)
     elif role == Qt.BackgroundColorRole:
         return to_qvariant(get_color(self._data[index.row()][index.column()], 0.2))
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
     return to_qvariant()
예제 #9
0
    def headerData(self, section, orientation, role=Qt.DisplayRole):
        """Set header data"""
        if role != Qt.DisplayRole:
            return to_qvariant()

        if orientation == Qt.Horizontal:
            if section == 0:
                return 'Index'
            else:
                return to_qvariant(to_text_string(self.df_header[section - 1]))
        else:
            return to_qvariant()
예제 #10
0
    def headerData(self, section, orientation, role=Qt.DisplayRole):
        """Set header data"""
        if role != Qt.DisplayRole:
            return to_qvariant()

        if orientation == Qt.Horizontal:
            if section == 0:
                return 'Index'
            else:
                return to_qvariant(to_text_string(self.df_header[section-1]))
        else:
            return to_qvariant()
예제 #11
0
def create_action(parent, text, shortcut=None, icon=None, tip=None,
                  toggled=None, triggered=None, data=None, menurole=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        parent.connect(action, SIGNAL("triggered()"), triggered)
    if toggled is not None:
        parent.connect(action, SIGNAL("toggled(bool)"), toggled)
        action.setCheckable(True)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        action.setIcon(icon)
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(to_qvariant(data))
    if menurole is not None:
        action.setMenuRole(menurole)
    #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
    # (this will avoid calling shortcuts from another dockwidget
    #  since the context thing doesn't work quite well with these widgets)
    action.setShortcutContext(context)
    return action
예제 #12
0
 def create_combobox(self,
                     text,
                     choices,
                     option,
                     default=NoDefault,
                     tip=None,
                     restart=False):
     """choices: couples (name, key)"""
     label = QLabel(text)
     combobox = QComboBox()
     if tip is not None:
         combobox.setToolTip(tip)
     for name, key in choices:
         combobox.addItem(name, to_qvariant(key))
     self.comboboxes[combobox] = (option, default)
     layout = QHBoxLayout()
     layout.addWidget(label)
     layout.addWidget(combobox)
     layout.addStretch(1)
     layout.setContentsMargins(0, 0, 0, 0)
     widget = QWidget(self)
     widget.label = label
     widget.combobox = combobox
     widget.setLayout(layout)
     combobox.restart_required = restart
     combobox.label_text = text
     return widget
예제 #13
0
def create_action(parent,
                  text,
                  shortcut=None,
                  icon=None,
                  tip=None,
                  toggled=None,
                  triggered=None,
                  data=None,
                  menurole=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        action.triggered.connect(triggered)
    if toggled is not None:
        action.toggled.connect(toggled)
        action.setCheckable(True)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        action.setIcon(icon)
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(to_qvariant(data))
    if menurole is not None:
        action.setMenuRole(menurole)
    #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
    # (this will avoid calling shortcuts from another dockwidget
    #  since the context thing doesn't work quite well with these widgets)
    action.setShortcutContext(context)
    return action
예제 #14
0
    def data(self, index, role=Qt.DisplayRole):
        """Qt Override."""
        row = index.row()
        if not index.isValid() or not (0 <= row < len(self.shortcuts)):
            return to_qvariant()

        shortcut = self.shortcuts[row]
        key = shortcut.key
        column = index.column()

        if role == Qt.DisplayRole:
            if column == CONTEXT:
                return to_qvariant(shortcut.context)
            elif column == NAME:
                color = self.text_color
                if self._parent == QApplication.focusWidget():
                    if self.current_index().row() == row:
                        color = self.text_color_highlight
                    else:
                        color = self.text_color
                text = self.rich_text[row]
                text = '<p style="color:{0}">{1}</p>'.format(color, text)
                return to_qvariant(text)
            elif column == SEQUENCE:
                text = QKeySequence(key).toString(QKeySequence.NativeText)
                return to_qvariant(text)
            elif column == SEARCH_SCORE:
                # Treating search scores as a table column simplifies the
                # sorting once a score for a specific string in the finder
                # has been defined. This column however should always remain
                # hidden.
                return to_qvariant(self.scores[row])
        elif role == Qt.TextAlignmentRole:
            return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
        return to_qvariant()
예제 #15
0
 def highlight_current_line(self):
     """Highlight current line"""
     selection = QTextEdit.ExtraSelection()
     selection.format.setProperty(QTextFormat.FullWidthSelection, to_qvariant(True))
     selection.format.setBackground(self.currentline_color)
     selection.cursor = self.textCursor()
     selection.cursor.clearSelection()
     self.set_extra_selections("current_line", [selection])
     self.update_extra_selections()
예제 #16
0
파일: base.py 프로젝트: YP-Ye/spyderlib
 def highlight_current_line(self):
     """Highlight current line"""
     selection = QTextEdit.ExtraSelection()
     selection.format.setProperty(QTextFormat.FullWidthSelection,
                                  to_qvariant(True))
     selection.format.setBackground(self.currentline_color)
     selection.cursor = self.textCursor()
     selection.cursor.clearSelection()
     self.set_extra_selections('current_line', [selection])
     self.update_extra_selections()
예제 #17
0
    def data(self, index, role=Qt.DisplayRole):
        """Override Qt method"""
        if not index.isValid() or not 0 <= index.row() < len(self._rows):
            return to_qvariant()
        row = index.row()
        column = index.column()

        name, state = self.row(row)

        if role == Qt.DisplayRole or role == Qt.EditRole:
            if column == 0:
                return to_qvariant(name)
        elif role == Qt.CheckStateRole:
            if column == 0:
                if state:
                    return Qt.Checked
                else:
                    return Qt.Unchecked
            if column == 1:
                return to_qvariant(state)
        return to_qvariant()
예제 #18
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if role == Qt.TextAlignmentRole:
         if orientation == Qt.Horizontal:
             return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
         return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
     if role != Qt.DisplayRole:
         return to_qvariant()
     if orientation == Qt.Horizontal:
         if section == CONTEXT:
             return to_qvariant(_("Context"))
         elif section == NAME:
             return to_qvariant(_("Name"))
         elif section == MOD1:
             return to_qvariant(_("Mod1"))
         elif section == MOD2:
             return to_qvariant(_("Mod2"))
         elif section == MOD3:
             return to_qvariant(_("Mod3"))
         elif section == KEY:
             return to_qvariant(_("Key"))
     return to_qvariant()
예제 #19
0
 def data(self, index, role=Qt.DisplayRole):
     """Return data at table index"""
     if not index.isValid():
         return to_qvariant()
     dep = self.dependencies[index.row()]
     if role == Qt.DisplayRole:
         if index.column() == 0:
             value = self.get_value(index)
             return to_qvariant(value)
         else:
             value = self.get_value(index)
             return to_qvariant(value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignLeft|Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole:
         from spyderlib.dependencies import Dependency
         status = dep.get_status()
         if status == Dependency.NOK:
             color = QColor(Qt.red)
             color.setAlphaF(.25)
             return to_qvariant(color)
예제 #20
0
    def data(self, index, role=Qt.DisplayRole):
        """Override Qt method"""
        if not index.isValid() or not 0 <= index.row() < len(self._rows):
            return to_qvariant()
        row = index.row()
        column = index.column()

        name, state = self.row(row)

        if role == Qt.DisplayRole or role == Qt.EditRole:
            if column == 0:
                return to_qvariant(name)
        elif role == Qt.CheckStateRole:
            if column == 0:
                if state:
                    return Qt.Checked
                else:
                    return Qt.Unchecked
            if column == 1:
                return to_qvariant(state)
        return to_qvariant()
예제 #21
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if role == Qt.TextAlignmentRole:
         if orientation == Qt.Horizontal:
             return to_qvariant(int(Qt.AlignHCenter|Qt.AlignVCenter))
         return to_qvariant(int(Qt.AlignRight|Qt.AlignVCenter))
     if role != Qt.DisplayRole:
         return to_qvariant()
     if orientation == Qt.Horizontal:
         if section == CONTEXT:
             return to_qvariant(_("Context"))
         elif section == NAME:
             return to_qvariant(_("Name"))
         elif section == MOD1:
             return to_qvariant(_("Mod1"))
         elif section == MOD2:
             return to_qvariant(_("Mod2"))
         elif section == MOD3:
             return to_qvariant(_("Mod3"))
         elif section == KEY:
             return to_qvariant(_("Key"))
     return to_qvariant()
예제 #22
0
 def data(self, index, role=Qt.DisplayRole):
     """Return data at table index"""
     if not index.isValid():
         return to_qvariant()
     dep = self.dependencies[index.row()]
     if role == Qt.DisplayRole:
         if index.column() == 0:
             value = self.get_value(index)
             return to_qvariant(value)
         else:
             value = self.get_value(index)
             return to_qvariant(value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole:
         from spyderlib.dependencies import Dependency
         status = dep.get_status()
         if status == Dependency.NOK:
             color = QColor(Qt.red)
             color.setAlphaF(.25)
             return to_qvariant(color)
예제 #23
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return to_qvariant()
     value = self.get_value(index)
     if is_binary_string(value):
         try:
             value = to_text_string(value, 'utf8')
         except:
             pass
     if role == Qt.DisplayRole:
         if value is np.ma.masked:
             return ''
         else:
             return to_qvariant(self._format % value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignCenter|Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole and self.bgcolor_enabled \
       and value is not np.ma.masked:
         hue = self.hue0+\
               self.dhue*(self.vmax-self.color_func(value)) \
               /(self.vmax-self.vmin)
         hue = float(np.abs(hue))
         color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
         return to_qvariant(color)
     elif role == Qt.FontRole:
         return to_qvariant(get_font('arrayeditor'))
     return to_qvariant()
예제 #24
0
파일: shortcuts.py 프로젝트: ptocca/spyder
    def data(self, index, role=Qt.DisplayRole):
        """Qt Override"""
        if not index.isValid() or \
           not (0 <= index.row() < len(self.shortcuts)):
            return to_qvariant()

        shortcut = self.shortcuts[index.row()]
        key = shortcut.key
        column = index.column()

        if role == Qt.DisplayRole:
            if column == CONTEXT:
                return to_qvariant(shortcut.context)
            elif column == NAME:
                color = self.text_color
                if self._parent == QApplication.focusWidget():
                    if self.current_index().row() == index.row():
                        color = self.text_color_highlight
                    else:
                        color = self.text_color
                return to_qvariant(self._enrich_text(shortcut.name, color))
            elif column == SEQUENCE:
                text = QKeySequence(key).toString(QKeySequence.NativeText)
                return to_qvariant(text)
        elif role == Qt.TextAlignmentRole:
            return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
        return to_qvariant()
예제 #25
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return to_qvariant()
     value = self.get_value(index)
     if is_binary_string(value):
         try:
             value = to_text_string(value, 'utf8')
         except:
             pass
     if role == Qt.DisplayRole:
         if value is np.ma.masked:
             return ''
         else:
             return to_qvariant(self._format % value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignCenter|Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole and self.bgcolor_enabled \
       and value is not np.ma.masked:
         hue = self.hue0+\
               self.dhue*(self.vmax-self.color_func(value)) \
               /(self.vmax-self.vmin)
         hue = float(np.abs(hue))
         color = QColor.fromHsvF(hue, self.sat, self.val, self.alp)
         return to_qvariant(color)
     elif role == Qt.FontRole:
         return to_qvariant(get_font('arrayeditor'))
     return to_qvariant()
예제 #26
0
    def headerData(self, section, orientation, role=Qt.DisplayRole):
        """Set header data"""
        if role != Qt.DisplayRole:
            return to_qvariant()

        if orientation == Qt.Horizontal:
            if section == 0:
                return "Index"
            elif section == 1 and PY2:
                # Get rid of possible BOM utf-8 data present at the
                # beginning of a file, which gets attached to the first
                # column header when headers are present in the first
                # row.
                # Fixes Issue 2514
                try:
                    header = to_text_string(self.df_header[0], encoding="utf-8-sig")
                except:
                    header = to_text_string(self.df_header[0])
                return to_qvariant(header)
            else:
                return to_qvariant(to_text_string(self.df_header[section - 1]))
        else:
            return to_qvariant()
예제 #27
0
    def headerData(self, section, orientation, role=Qt.DisplayRole):
        """Set header data"""
        if role != Qt.DisplayRole:
            return to_qvariant()

        if orientation == Qt.Horizontal:
            if section == 0:
                return 'Index'
            elif section == 1 and PY2:
                # Get rid of possible BOM utf-8 data present at the
                # beginning of a file, which gets attached to the first
                # column header when headers are present in the first
                # row.
                # Fixes Issue 2514
                try:
                    header = to_text_string(self.df_header[0],
                                            encoding='utf-8-sig')
                except UnicodeDecodeError:
                    header = to_text_string(self.df_header[0])
                return to_qvariant(header)
            else:
                return to_qvariant(to_text_string(self.df_header[section - 1]))
        else:
            return to_qvariant()
예제 #28
0
 def createEditor(self, parent, option, index):
     """Create editor widget"""
     model = index.model()
     value = model.get_value(index)
     if model._data.dtype.name == "bool":
         value = not value
         model.setData(index, to_qvariant(value))
         return
     elif value is not np.ma.masked:
         editor = QLineEdit(parent)
         editor.setFont(get_font('arrayeditor'))
         editor.setAlignment(Qt.AlignCenter)
         if is_number(self.dtype):
             editor.setValidator(QDoubleValidator(editor))
         editor.returnPressed.connect(self.commitAndCloseEditor)
         return editor
예제 #29
0
 def createEditor(self, parent, option, index):
     """Create editor widget"""
     model = index.model()
     value = model.get_value(index)
     if model._data.dtype.name == "bool":
         value = not value
         model.setData(index, to_qvariant(value))
         return
     elif value is not np.ma.masked:
         editor = QLineEdit(parent)
         editor.setFont(get_font('arrayeditor'))
         editor.setAlignment(Qt.AlignCenter)
         if is_number(self.dtype):
             editor.setValidator(QDoubleValidator(editor))
         editor.returnPressed.connect(self.commitAndCloseEditor)
         return editor
예제 #30
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     """Qt Override."""
     if role == Qt.TextAlignmentRole:
         if orientation == Qt.Horizontal:
             return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
         return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
     if role != Qt.DisplayRole:
         return to_qvariant()
     if orientation == Qt.Horizontal:
         if section == CONTEXT:
             return to_qvariant(_("Context"))
         elif section == NAME:
             return to_qvariant(_("Name"))
         elif section == SEQUENCE:
             return to_qvariant(_("Shortcut"))
         elif section == SEARCH_SCORE:
             return to_qvariant(_("Score"))
     return to_qvariant()
예제 #31
0
 def data(self, index, role=Qt.DisplayRole):
     if not index.isValid() or not (0 <= index.row() < len(self.shortcuts)):
         return to_qvariant()
     shortcut = self.shortcuts[index.row()]
     key = shortcut.key
     column = index.column()
     if role == Qt.DisplayRole:
         if column == CONTEXT:
             return to_qvariant(shortcut.context)
         elif column == NAME:
             return to_qvariant(shortcut.name)
         elif column == MOD1:
             return to_qvariant(Key.MODIFIERNAMES[key.modifiers[0]])
         elif column == MOD2:
             return to_qvariant(Key.MODIFIERNAMES[key.modifiers[1]])
         elif column == MOD3:
             return to_qvariant(Key.MODIFIERNAMES[key.modifiers[2]])
         elif column == KEY:
             return to_qvariant(Key.KEYS[key.key])
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
     return to_qvariant()
예제 #32
0
 def data(self, index, role=Qt.DisplayRole):
     if not index.isValid() or \
        not (0 <= index.row() < len(self.shortcuts)):
         return to_qvariant()
     shortcut = self.shortcuts[index.row()]
     key = shortcut.key
     column = index.column()
     if role == Qt.DisplayRole:
         if column == CONTEXT:
             return to_qvariant(shortcut.context)
         elif column == NAME:
             return to_qvariant(shortcut.name)
         elif column == MOD1:
             return to_qvariant(Key.MODIFIERNAMES[key.modifiers[0]])
         elif column == MOD2:
             return to_qvariant(Key.MODIFIERNAMES[key.modifiers[1]])
         elif column == MOD3:
             return to_qvariant(Key.MODIFIERNAMES[key.modifiers[2]])
         elif column == KEY:
             return to_qvariant(Key.KEYS[key.key])
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
     return to_qvariant()
예제 #33
0
 def create_combobox(self, text, choices, option, default=NoDefault,
                     tip=None):
     """choices: couples (name, key)"""
     label = QLabel(text)
     combobox = QComboBox()
     if tip is not None:
         combobox.setToolTip(tip)
     for name, key in choices:
         combobox.addItem(name, to_qvariant(key))
     self.comboboxes[combobox] = (option, default)
     layout = QHBoxLayout()
     for subwidget in (label, combobox):
         layout.addWidget(subwidget)
     layout.addStretch(1)
     layout.setContentsMargins(0, 0, 0, 0)
     widget = QWidget(self)
     widget.setLayout(layout)
     return widget
예제 #34
0
 def create_combobox(self, text, choices, option, default=NoDefault,
                     tip=None):
     """choices: couples (name, key)"""
     label = QLabel(text)
     combobox = QComboBox()
     if tip is not None:
         combobox.setToolTip(tip)
     for name, key in choices:
         combobox.addItem(name, to_qvariant(key))
     self.comboboxes[combobox] = (option, default)
     layout = QHBoxLayout()
     for subwidget in (label, combobox):
         layout.addWidget(subwidget)
     layout.addStretch(1)
     layout.setContentsMargins(0, 0, 0, 0)
     widget = QWidget(self)
     widget.setLayout(layout)
     return widget
예제 #35
0
파일: base.py 프로젝트: jromang/spyderlib
 def highlight_current_cell(self):
     """Highlight current cell"""
     selection = QTextEdit.ExtraSelection()
     selection.format.setProperty(QTextFormat.FullWidthSelection,
                                  to_qvariant(True))
     selection.format.setBackground(self.currentcell_color)
     selection.cursor, whole_file_selected, whole_screen_selected =\
         self.select_current_cell_in_visible_portion()
     if whole_file_selected: 
         self.clear_extra_selections('current_cell')
     elif whole_screen_selected:
         if self.has_cell_separators:
             self.set_extra_selections('current_cell', [selection])
             self.update_extra_selections()
         else:
             self.clear_extra_selections('current_cell')
     else:
         self.set_extra_selections('current_cell', [selection])
         self.update_extra_selections()
예제 #36
0
파일: base.py 프로젝트: YP-Ye/spyderlib
 def highlight_current_cell(self):
     """Highlight current cell"""
     if self.cell_separators is None:
         return
     selection = QTextEdit.ExtraSelection()
     selection.format.setProperty(QTextFormat.FullWidthSelection,
                                  to_qvariant(True))
     selection.format.setBackground(self.currentcell_color)
     selection.cursor, whole_file_selected, whole_screen_selected =\
         self.select_current_cell_in_visible_portion()
     if whole_file_selected:
         self.clear_extra_selections('current_cell')
     elif whole_screen_selected:
         if self.has_cell_separators:
             self.set_extra_selections('current_cell', [selection])
             self.update_extra_selections()
         else:
             self.clear_extra_selections('current_cell')
     else:
         self.set_extra_selections('current_cell', [selection])
         self.update_extra_selections()
예제 #37
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return to_qvariant()
     if role == Qt.DisplayRole or role == Qt.EditRole:
         column = index.column()
         row = index.row()
         if column == 0:
             return to_qvariant(to_text_string(self.df_index[row]))
         else:
             value = self.get_value(row, column - 1)
             if isinstance(value, float):
                 return to_qvariant(self._format % value)
             else:
                 try:
                     return to_qvariant(to_text_string(value))
                 except UnicodeDecodeError:
                     return to_qvariant(encoding.to_unicode(value))
     elif role == Qt.BackgroundColorRole:
         return to_qvariant(self.get_bgcolor(index))
     elif role == Qt.FontRole:
         return to_qvariant(get_font('arrayeditor'))
     return to_qvariant()
예제 #38
0
 def data(self, index, role=Qt.DisplayRole):
     """Cell content"""
     if not index.isValid():
         return to_qvariant()
     if role == Qt.DisplayRole or role == Qt.EditRole:
         column = index.column()
         row = index.row()
         if column == 0:
             return to_qvariant(to_text_string(self.df_index[row]))
         else:
             value = self.get_value(row, column-1)
             if isinstance(value, float):
                 return to_qvariant(self._format % value)
             else:
                 try:
                     return to_qvariant(to_text_string(value))
                 except UnicodeDecodeError:
                     return to_qvariant(encoding.to_unicode(value))
     elif role == Qt.BackgroundColorRole:
         return to_qvariant(self.get_bgcolor(index))
     elif role == Qt.FontRole:
         return to_qvariant(get_font('arrayeditor'))
     return to_qvariant()
예제 #39
0
 def create_combobox(self, text, choices, option, default=NoDefault,
                     tip=None, restart=False):
     """choices: couples (name, key)"""
     label = QLabel(text)
     combobox = QComboBox()
     if tip is not None:
         combobox.setToolTip(tip)
     for name, key in choices:
         combobox.addItem(name, to_qvariant(key))
     self.comboboxes[combobox] = (option, default)
     layout = QHBoxLayout()
     layout.addWidget(label)
     layout.addWidget(combobox)
     layout.addStretch(1)
     layout.setContentsMargins(0, 0, 0, 0)
     widget = QWidget(self)
     widget.label = label
     widget.combobox = combobox
     widget.setLayout(layout)
     combobox.restart_required = restart
     combobox.label_text = text
     return widget
예제 #40
0
 def data(self, index, role=Qt.DisplayRole):
     """Return data at table index"""
     if not index.isValid():
         return to_qvariant()
     if role == Qt.DisplayRole:
         if index.column() == 0:
             value = osp.basename(self.get_value(index))
             return to_qvariant(value)
         else:
             value = self.get_value(index)
             return to_qvariant(value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter))
     elif role == Qt.ToolTipRole:
         if index.column() == 0:
             value = self.get_value(index)
             return to_qvariant(value)
         else:
             return to_qvariant()
예제 #41
0
 def data(self, index, role=Qt.DisplayRole):
     """Return data at table index"""
     if not index.isValid():
         return to_qvariant()
     if role == Qt.DisplayRole:
         if index.column() == 0:
             value = osp.basename(self.get_value(index))
             return to_qvariant(value)
         else:
             value = self.get_value(index)
             return to_qvariant(value)
     elif role == Qt.TextAlignmentRole:
         return to_qvariant(int(Qt.AlignLeft|Qt.AlignVCenter))
     elif role == Qt.ToolTipRole:
         if index.column() == 0:
             value = self.get_value(index)
             return to_qvariant(value)
         else:
             return to_qvariant()
예제 #42
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))
예제 #43
0
 def setModelData(self, editor, model, index):
     if index.column() in (MOD1, MOD2, MOD3, KEY):
         model.setData(index, to_qvariant(editor.currentText()))
     else:
         QItemDelegate.setModelData(self, editor, model, index)
예제 #44
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))
예제 #45
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))
예제 #46
0
def set_item_user_text(item, text):
    """Set QTreeWidgetItem user role string"""
    item.setData(0, Qt.UserRole, to_qvariant(text))
예제 #47
0
 def _display_data(self, index):
     """Return a data element"""
     return to_qvariant(self._data[index.row()][index.column()])
예제 #48
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))
예제 #49
0
 def _display_data(self, index):
     """Return a data element"""
     return to_qvariant(self._data[index.row()][index.column()])
예제 #50
0
 def setModelData(self, editor, model, index):
     if index.column() in (MOD1, MOD2, MOD3, KEY):
         model.setData(index, to_qvariant(editor.currentText()))
     else:
         QItemDelegate.setModelData(self, editor, model, index)
예제 #51
0
def set_item_user_text(item, text):
    """Set QTreeWidgetItem user role string"""
    item.setData(0, Qt.UserRole, to_qvariant(text))