Ejemplo n.º 1
0
    def toolTip(self, column):
        """Return tooltip for column."""
        try:
            ds = self.doc.data[self.data[0]]
        except KeyError:
            return qt4.QVariant()

        c = self.cols[column]
        if c == "name":
            text = ds.description()
            if text is None:
                text = ''

            if ds.tags:
                text += '\n\n' + _('Tags: %s') % (' '.join(
                    list(sorted(ds.tags))))

            return qt4.QVariant(textwrap.fill(text, 40))
        elif c == "size" or (c == 'type' and 'size' not in self.cols):
            text = ds.userPreview()
            # add preview of dataset if possible
            pix = self.getPreviewPixmap(ds)
            if pix:
                text = text.replace("\n", "<br>")
                text = "<html>%s<br>%s</html>" % (text,
                                                  utils.pixmapAsHtml(pix))
            return qt4.QVariant(text)
        elif c == "linkfile" or c == "type":
            return qt4.QVariant(textwrap.fill(ds.linkedInformation(), 40))
        return qt4.QVariant()
Ejemplo n.º 2
0
    def headerData(self, section, orientation, role):
        """Return the header of the tree."""

        if orientation == qt4.Qt.Horizontal and role == qt4.Qt.DisplayRole:
            val = ('Name', 'Type')[section]
            return qt4.QVariant(val)

        return qt4.QVariant()
Ejemplo n.º 3
0
 def nodeData(self, column):
     """basename of filename for data."""
     if column == 0:
         if self.data[0] == "/":
             return qt4.QVariant("/")
         else:
             return qt4.QVariant(os.path.basename(self.data[0]))
     return qt4.QVariant()
Ejemplo n.º 4
0
    def data(self, index, role):
        if role == qt4.Qt.DisplayRole:
            # get data (note y is reversed, sigh)
            ds = self.document.data[self.dsname].data
            if ds is not None:
                num = ds[ds.shape[0] - index.row() - 1, index.column()]
                return qt4.QVariant(float(num))

        return qt4.QVariant()
Ejemplo n.º 5
0
 def headerData(self, section, orientation, role):
     """Return the headers at the top of the view."""
     if role == qt4.Qt.DisplayRole:
         if orientation == qt4.Qt.Horizontal:
             return qt4.QVariant(
                 (_('Type'), _('Name'), _('Definition'))[section])
         else:
             return qt4.QVariant(str(section + 1))
     return qt4.QVariant()
Ejemplo n.º 6
0
 def pluginAddClicked(self):
     """Add a new plugin."""
     filename = self.parent()._fileOpenDialog('py', _('Python scripts'),
                                              _('Choose plugin'))
     if filename:
         self.pluginmodel.insertRows(0, 1)
         self.pluginmodel.setData(self.pluginmodel.index(0),
                                  qt4.QVariant(filename))
Ejemplo n.º 7
0
    def data(self, index, role):
        """Return data associated with column given."""
        # get dataset
        ds = self.document.data[self.dsname]
        if ds is not None:
            # select correct part of dataset
            data = getattr(ds, ds.columns[index.column()])
        if ds is not None and data is not None and role == qt4.Qt.DisplayRole:
            # blank row at end of data
            if index.row() == len(data):
                return qt4.QVariant()

            # convert data to QVariant
            d = data[index.row()]
            return ds.uiDataItemToQVariant(d)

        # empty entry
        return qt4.QVariant()
Ejemplo n.º 8
0
    def headerData(self, section, orientation, role):
        """Return headers at top."""

        if role == qt4.Qt.DisplayRole:
            ds = self.document.data[self.dsname]

            if ds is not None:
                # return a number for the top left of the cell
                if orientation == qt4.Qt.Horizontal:
                    r = ds.xrange
                    num = ds.data.shape[1]
                else:
                    r = ds.yrange
                    r = (r[1], r[0])  # swap (as y reversed)
                    num = ds.data.shape[0]
                val = (r[1] - r[0]) / num * (section + 0.5) + r[0]
                return qt4.QVariant('%g' % val)

        return qt4.QVariant()
Ejemplo n.º 9
0
    def data(self, index, role):
        """Get text or tooltip."""
        if index.isValid():
            item = self.objFromIndex(index)
            if role == qt4.Qt.DisplayRole:
                return item.nodeData(index.column())
            elif role == qt4.Qt.ToolTipRole:
                return item.toolTip(index.column())

        return qt4.QVariant()
Ejemplo n.º 10
0
    def headerData(self, section, orientation, role):
        """Return headers at top."""

        try:
            ds = self.document.data[self.dsname]
        except KeyError:
            return qt4.QVariant()

        if role == qt4.Qt.DisplayRole:
            if orientation == qt4.Qt.Horizontal:
                # column names
                return qt4.QVariant(ds.column_descriptions[section])
            else:
                if section == len(ds.data):
                    return "+"
                # return row numbers
                return qt4.QVariant(section + 1)

        return qt4.QVariant()
Ejemplo n.º 11
0
    def data(self, index, role):
        """Lookup data in document customs list."""
        if role in (qt4.Qt.DisplayRole, qt4.Qt.EditRole):
            cust = self.document.customs[index.row()]
            if cust[0] == 'colormap' and index.column() == 2:
                # values are not a string
                return qt4.QVariant(repr(cust[2]))
            else:
                return qt4.QVariant(cust[index.column()])
        elif role == qt4.Qt.ToolTipRole:
            return (
                _('Constant, function, import or colormap'),
                _('Constant or colormap: enter name\n'
                  'Function: enter functionname(arg1, arg2...)\n'
                  'Import: enter module name'),
                _('Constant or function: expression giving value\n'
                  'Import: comma or space separated list of symbols to import\n'
                  'Colormap: (R,G,B[,alpha]) list surrounded by brackets, e.g. ((10,10,10), (20,20,20,128))'
                  ),
            )[index.column()]

        return qt4.QVariant()
Ejemplo n.º 12
0
    def selectDataset(self, dsname):
        """Find, and if possible select dataset name."""

        matches = self.model.match(
            self.model.index(0, 0, qt4.QModelIndex()), qt4.Qt.DisplayRole,
            qt4.QVariant(dsname), -1, qt4.Qt.MatchFixedString
            | qt4.Qt.MatchCaseSensitive | qt4.Qt.MatchRecursive)
        for idx in matches:
            if isinstance(self.model.objFromIndex(idx), DatasetNode):
                self.selectionModel().setCurrentIndex(
                    idx, qt4.QItemSelectionModel.SelectCurrent
                    | qt4.QItemSelectionModel.Clear
                    | qt4.QItemSelectionModel.Rows)
Ejemplo n.º 13
0
    def data(self, index, role):
        """Return data for the index given."""

        # why do we get passed invalid indicies? :-)
        if not index.isValid():
            return qt4.QVariant()

        column = index.column()
        obj = index.internalPointer()

        if role == qt4.Qt.DisplayRole:
            # return text for columns
            if column == 0:
                return qt4.QVariant(obj.name)
            elif column == 1:
                return qt4.QVariant(obj.typename)

        elif role == qt4.Qt.DecorationRole:
            # return icon for first column
            if column == 0:
                filename = 'button_%s' % obj.typename
                return qt4.QVariant(utils.getIcon(filename))

        elif role == qt4.Qt.ToolTipRole:
            # provide tool tip showing description
            if obj.userdescription:
                return qt4.QVariant(obj.userdescription)

        elif role == qt4.Qt.TextColorRole:
            # show disabled looking text if object or any parent is hidden
            hidden = False
            p = obj
            while p is not None:
                if 'hide' in p.settings and p.settings.hide:
                    hidden = True
                    break
                p = p.parent

            # return brush for hidden widget text, based on disabled text
            if hidden:
                return qt4.QVariant(qt4.QPalette().brush(
                    qt4.QPalette.Disabled, qt4.QPalette.Text))

        # return nothing
        return qt4.QVariant()
Ejemplo n.º 14
0
    def writeSettings(self):
        """Write the settings using QSettings.

        This is called by the mainwindow on close
        """

        s = qt4.QSettings(self.domain, self.product)

        # write each entry, keeping track of which ones haven't been written
        cleankeys = []
        for key, value in self.database.iteritems():
            cleankey = key.replace('/', self.sepchars)
            cleankeys.append(cleankey)

            # repr doesn't work on QStrings
            if isinstance(value, qt4.QString):
                value = unicode(value)

            s.setValue(cleankey, qt4.QVariant(repr(value)))

        # now remove all the values which have been removed
        for key in list(s.childKeys()):
            if unicode(key) not in cleankeys:
                s.remove(key)
Ejemplo n.º 15
0
 def nodeData(self, idx):
     """Get data with index given."""
     try:
         return qt4.QVariant(self.data[idx])
     except:
         return qt4.QVariant()
Ejemplo n.º 16
0
 def toolTip(self, column):
     """Full filename for tooltip."""
     if column == 0:
         return qt4.QVariant(self.data[0])
     return qt4.QVariant()
Ejemplo n.º 17
0
 def headerData(self, section, orientation, role):
     """Use root node to get headers."""
     if orientation == qt4.Qt.Horizontal and role == qt4.Qt.DisplayRole:
         return self.root.nodeData(section)
     return qt4.QVariant()
Ejemplo n.º 18
0
 def toolTip(self, column):
     """Return tooltip for column, if any."""
     return qt4.QVariant()
Ejemplo n.º 19
0
 def data(self, index, role):
     if role == qt4.Qt.DisplayRole and index.isValid():
         return qt4.QVariant(float(self.data[index.row()]))
     return qt4.QVariant()
Ejemplo n.º 20
0
 def setModelData(self, editor, model, index):
     """Update data in model."""
     model.setData(index, qt4.QVariant(editor.currentText()),
                   qt4.Qt.EditRole)