Example #1
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if orientation == Qt.Horizontal and role == Qt.DisplayRole:
         if section == 0:
             return QVariant('Config Key')
         if section == 1:
             return QVariant('Config Value')
     return QVariant()
 def data(self, index, role):
     profile = self.profiles[index.row()]
     if role == Qt.DisplayRole:
         return QVariant(profile.name)
     if role in (Qt.ToolTipRole, Qt.StatusTipRole, Qt.WhatsThisRole):
         return QVariant(profile.description)
     return NONE
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     if orientation == Qt.Horizontal:
         return QVariant(self.headers[section])
     else:
         return QVariant(section+1)
Example #4
0
    def init_languages(self):
        self.language.blockSignals(True)
        self.language.clear()
        from calibre.utils.localization import (available_translations,
                                                get_language, get_lang,
                                                get_lc_messages_path)
        lang = get_lang()
        lang = get_lc_messages_path(lang) if lang else lang
        if lang is None or lang not in available_translations():
            lang = 'en'

        def get_esc_lang(l):
            if l == 'en':
                return 'English'
            return get_language(l)

        self.language.addItem(get_esc_lang(lang), QVariant(lang))
        items = [(l, get_esc_lang(l)) for l in available_translations()
                 if l != lang]
        if lang != 'en':
            items.append(('en', get_esc_lang('en')))
        items.sort(cmp=lambda x, y: cmp(x[1], y[1]))
        for item in items:
            self.language.addItem(item[1], QVariant(item[0]))
        self.language.blockSignals(False)
        prefs['language'] = str(
            self.language.itemData(self.language.currentIndex()).toString())
Example #5
0
 def create_widgets(self, opt):
     val = self.plugin.prefs[opt.name]
     if opt.type == 'number':
         c = QSpinBox if isinstance(opt.default, int) else QDoubleSpinBox
         widget = c(self)
         widget.setValue(val)
     elif opt.type == 'string':
         widget = QLineEdit(self)
         widget.setText(val if val else '')
     elif opt.type == 'bool':
         widget = QCheckBox(opt.label, self)
         widget.setChecked(bool(val))
     elif opt.type == 'choices':
         widget = QComboBox(self)
         for key, label in opt.choices.iteritems():
             widget.addItem(label, QVariant(key))
         idx = widget.findData(QVariant(val))
         widget.setCurrentIndex(idx)
     widget.opt = opt
     widget.setToolTip(textwrap.fill(opt.desc))
     self.widgets.append(widget)
     r = self.l.rowCount()
     if opt.type == 'bool':
         self.l.addWidget(widget, r, 0, 1, self.l.columnCount())
     else:
         l = QLabel(opt.label)
         l.setToolTip(widget.toolTip())
         self.memory.append(l)
         l.setBuddy(widget)
         self.l.addWidget(l, r, 0, 1, 1)
         self.l.addWidget(widget, r, 1, 1, 1)
Example #6
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if orientation == Qt.Horizontal and role == Qt.DisplayRole:
         if section == 0:
             return QVariant("Pref Name")
         if section == 1:
             return QVariant("Pref Value")
     return QVariant()
Example #7
0
    def createSubitem(self, parentItem, parentGroup, groupname):
        if groupname != 'data':
            attributes = parentGroup[groupname].attrs
            subItem = QtGui.QTreeWidgetItem()
            subItem.setText(0, groupname)
            filenameData = QVariant(
                str(parentItem.data(0, QtCore.Qt.UserRole).toString()))
            parentPath = str(
                parentItem.data(1, QtCore.Qt.UserRole).toString()).replace(
                    '/data', '')  # The possible data has to be stripped!
            if 'data' in parentGroup[groupname]:
                subgroupData = QVariant(parentPath + '/' + groupname + '/data')
            else:
                subgroupData = QVariant(parentPath + '/' + groupname)
            subItem.setData(0, QtCore.Qt.UserRole, filenameData)
            subItem.setData(1, QtCore.Qt.UserRole, subgroupData)
            subItem.setExpanded(True)

            try:
                subItem.setData(2, QtCore.Qt.UserRole, attributes)
                if 'Description' in attributes:
                    subItem.setToolTip(0, attributes['Description'])
            except:
                pass

            return subItem
Example #8
0
    def data(self, index, role):
        row, col = index.row(), index.column()
        try:
            book = self.results[row]
        except:
            return NONE
        if role == Qt.DisplayRole and col not in self.ICON_COLS:
            res = self.data_as_text(book, col)
            if res:
                return QVariant(res)
            return NONE
        elif role == Qt.DecorationRole and col in self.ICON_COLS:
            if col == 3 and getattr(book, 'has_cached_cover_url', False):
                return self.yes_icon
            if col == 4 and book.comments:
                return self.yes_icon
        elif role == Qt.UserRole:
            return book
        elif role == Qt.ToolTipRole and col == 3:
            return QVariant(
                _('The has cover indication is not fully\n'
                  'reliable. Sometimes results marked as not\n'
                  'having a cover will find a cover in the download\n'
                  'cover stage, and vice versa.'))

        return NONE
Example #9
0
 def data(self, index, role):
     if not index.isValid():
         return NONE
     if index.internalId() == 0:
         if role == Qt.DisplayRole:
             category = self.categories[index.row()]
             return QVariant(_("%(plugin_type)s %(plugins)s")%
                     dict(plugin_type=category, plugins=_('plugins')))
     else:
         plugin = self.index_to_plugin(index)
         disabled = is_disabled(plugin)
         if role == Qt.DisplayRole:
             ver = '.'.join(map(str, plugin.version))
             desc = '\n'.join(textwrap.wrap(plugin.description, 100))
             ans='%s (%s) %s %s\n%s'%(plugin.name, ver, _('by'), plugin.author, desc)
             c = plugin_customization(plugin)
             if c and not disabled:
                 ans += _('\nCustomization: ')+c
             if disabled:
                 ans += _('\n\nThis plugin has been disabled')
             return QVariant(ans)
         if role == Qt.DecorationRole:
             return self.disabled_icon if disabled else self.icon
         if role == Qt.ForegroundRole and disabled:
             return QVariant(QBrush(Qt.gray))
         if role == Qt.UserRole:
             return plugin
     return NONE
Example #10
0
 def data(self, index, role):
     if not index.isValid():
         return QVariant()
     if role != Qt.DisplayRole:
         return QVariant()
     item = index.internalPointer()
     return QVariant(item.node.name)
Example #11
0
    def __init__(self):
        QWidget.__init__(self)
        self.ui = Ui_KeyboardWidget()
        self.ui.setupUi(self)

        index = 0  # comboBox.addItem doesn't increase the currentIndex
        self.default_layout_index = None
        locales = sorted([(country, data)
                          for country, data in yali.localedata.locales.items()
                          ])
        for country, data in locales:
            if data["xkbvariant"]:
                i = 0
                for variant in data["xkbvariant"]:
                    _d = dict(data)
                    _d["xkbvariant"] = variant[0]
                    _d["name"] = variant[1]
                    _d["consolekeymap"] = data["consolekeymap"][i]
                    self.ui.keyboard_list.addItem(_d["name"], QVariant(_d))
                    i += 1
            else:
                self.ui.keyboard_list.addItem(data["name"], QVariant(data))
            if ctx.consts.lang == country:
                if ctx.consts.lang == "tr":
                    self.default_layout_index = index + 1
                else:
                    self.default_layout_index = index
            index += 1

        self.ui.keyboard_list.setCurrentIndex(self.default_layout_index)

        self.connect(self.ui.keyboard_list, SIGNAL("currentIndexChanged(int)"),
                     self.slotLayoutChanged)
Example #12
0
 def data(self, index, role):
     row, col = index.row(), index.column()
     if row < 0 or row >= self.rowCount():
         return NONE
     account = self.account_order[row]
     if account not in self.accounts:
         return NONE
     if role == Qt.UserRole:
         return (account, self.accounts[account])
     if role == Qt.ToolTipRole:
         return self.tooltips[col]
     if role in [Qt.DisplayRole, Qt.EditRole]:
         if col == 0:
             return QVariant(account)
         if col == 1:
             return QVariant(self.accounts[account][0])
         if col == 2:
             return QVariant(self.subjects.get(account, ''))
         if col == 4:
             return QVariant(self.aliases.get(account, ''))
     if role == Qt.FontRole and self.accounts[account][2]:
         return self.default_font
     if role == Qt.CheckStateRole and col == 3:
         return QVariant(
             Qt.Checked if self.accounts[account][1] else Qt.Unchecked)
     return NONE
Example #13
0
 def data(self, role):
     if role == Qt.DisplayRole:
         return QVariant(self.cdata + ' [%d]' % len(self.children))
     elif role == Qt.FontRole:
         return self.bold_font
     elif role == Qt.ForegroundRole and self.category == _('Scheduled'):
         return QVariant(QColor(0, 255, 0))
     return NONE
Example #14
0
 def closeEvent(self, QCloseEvent):
     settings = QSettings()
     settings.setValue('width', QVariant(self.settings['width']))
     settings.setValue('color', QVariant(self.settings['color']))
     settings.setValue('x_grid', QVariant(self.settings['x_grid']))
     settings.setValue('y_grid', QVariant(self.settings['y_grid']))
     settings.setValue('grid_opacity',
                       QVariant(self.settings['grid_opacity']))
Example #15
0
 def __init__(self, show_only_user_plugins=False):
     QAbstractItemModel.__init__(self)
     SearchQueryParser.__init__(self, ['all'])
     self.show_only_user_plugins = show_only_user_plugins
     self.icon = QVariant(QIcon(I('plugins.png')))
     p = QIcon(self.icon).pixmap(64, 64, QIcon.Disabled, QIcon.On)
     self.disabled_icon = QVariant(QIcon(p))
     self._p = p
     self.populate()
Example #16
0
 def data(self, index, role=Qt.DisplayRole):
     '''Returns the data stored under the given role 
     for the item referred to by the index.'''
     if not index.isValid():
         return QVariant()
     if role != Qt.DisplayRole and role != Qt.EditRole:
         return QVariant()
     nodePref = self.index2Pref(index)
     return QVariant(nodePref.qt_get_data(index.column()))
Example #17
0
 def _populate_combo_box(self):
     # diagnostic datasets can have only diagnostic outcomes
     if self.is_diag:
         self.datatype_cbo_box.addItem(QString("Diagnostic"),
                                       QVariant(DIAGNOSTIC))
     else:
         for name, type_id in zip(
             [QString(s) for s in ["Binary", "Continuous"]],
             [QVariant(i) for i in range(2)]):
             self.datatype_cbo_box.addItem(name, type_id)
Example #18
0
 def data(self, index, role=Qt.DisplayRole):
     if role == Qt.DisplayRole:
         return QVariant(self.label_for_row(index.row()))
     if role == Qt.FontRole and index.row() == self.pos:
         f = QApplication.instance().font()
         f.setBold(True)
         return QVariant(f)
     if role == Qt.UserRole:
         return QVariant(self.states[index.row()])
     return NONE
Example #19
0
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     text = ''
     if orientation == Qt.Horizontal:
         if section < len(self.HEADERS):
             text = self.HEADERS[section]
         return QVariant(text)
     else:
         return QVariant(section + 1)
Example #20
0
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     if orientation == Qt.Horizontal:
         if section == 0: text = _('Job')
         elif section == 1: text = _('Status')
         elif section == 2: text = _('Progress')
         elif section == 3: text = _('Running time')
         return QVariant(text)
     else:
         return QVariant(section + 1)
Example #21
0
 def data(self, index, role):
     row, col = index.row(), index.column()
     result = self.books[row]
     if role == Qt.DisplayRole:
         if col == 0:
             return QVariant(result.title)
         elif col == 1:
             return QVariant(result.author)
         elif col == 2:
             return QVariant(result.formats)
     return NONE
Example #22
0
 def data(self, index, role):
     if not index.isValid():
         return NONE
     row, col = index.row(), index.column()
     if row < 0 or row >= self.rowCount():
         return NONE
     display_plugin = self.display_plugins[row]
     if role in [Qt.DisplayRole, Qt.UserRole]:
         if col == 0:
             return QVariant(display_plugin.name)
         if col == 1:
             if display_plugin.donation_link:
                 return QVariant(_('PayPal'))
         if col == 2:
             return self._get_status(display_plugin)
         if col == 3:
             return QVariant(
                 self._get_display_version(
                     display_plugin.installed_version))
         if col == 4:
             return QVariant(
                 self._get_display_version(
                     display_plugin.available_version))
         if col == 5:
             if role == Qt.UserRole:
                 return self._get_display_release_date(
                     display_plugin.release_date, 'yyyyMMdd')
             else:
                 return self._get_display_release_date(
                     display_plugin.release_date)
         if col == 6:
             return QVariant(
                 self._get_display_version(
                     display_plugin.calibre_required_version))
         if col == 7:
             return QVariant(display_plugin.author)
     elif role == Qt.DecorationRole:
         if col == 0:
             return self._get_status_icon(display_plugin)
         if col == 1:
             if display_plugin.donation_link:
                 return QIcon(I('donate.png'))
     elif role == Qt.ToolTipRole:
         if col == 1 and display_plugin.donation_link:
             return QVariant(
                 _('This plugin is FREE but you can reward the developer for their effort\n'
                   'by donating to them via PayPal.\n\n'
                   'Right-click and choose Donate to reward: ') +
                 display_plugin.author)
         else:
             return self._get_status_tooltip(display_plugin)
     elif role == Qt.ForegroundRole:
         if col != 1:  # Never change colour of the donation column
             if display_plugin.is_deprecated:
                 return QVariant(QBrush(Qt.blue))
             if display_plugin.is_disabled():
                 return QVariant(QBrush(Qt.gray))
     return NONE
Example #23
0
File: jobs.py Project: sss/calibre
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     if orientation == Qt.Horizontal:
         return QVariant({
             0: _('Job'),
             1: _('Status'),
             2: _('Progress'),
             3: _('Running time'),
             4: _('Start time'),
         }.get(section, ''))
     else:
         return QVariant(section + 1)
Example #24
0
 def data(self, index, role):
     profile = self.profiles[index.row()]
     if role == Qt.DisplayRole:
         return QVariant(profile.name)
     if role in (Qt.ToolTipRole, Qt.StatusTipRole, Qt.WhatsThisRole):
         w, h = profile.screen_size
         if w >= 10000:
             ss = _('unlimited')
         else:
             ss = _('%(width)d x %(height)d pixels') % dict(width=w, height=h)
         ss = _('Screen size: %s') % ss
         return QVariant('%s [%s]' % (profile.description, ss))
     return NONE
Example #25
0
 def data(self, index, role):
     try:
         widget = self.widgets[index.row()]
     except:
         return NONE
     if role == Qt.DisplayRole:
         return QVariant(widget.config_title())
     if role == Qt.DecorationRole:
         return QVariant(widget.config_icon())
     if role == Qt.FontRole:
         f = QFont()
         f.setBold(True)
         return QVariant(f)
     return NONE
Example #26
0
 def data(self, index, role):
     try:
         family = self.families[index.row()]
     except:
         traceback.print_exc()
         return NONE
     if role == Qt.DisplayRole:
         return QVariant(family)
     if role == Qt.FontRole:
         # If a user chooses some non standard font as the interface font,
         # rendering some font names causes Qt to crash, so return what is
         # hopefully a "safe" font
         return QVariant(self.font)
     return NONE
Example #27
0
    def data(self, index, role=Qt.DisplayRole):
        row, col = index.row(), index.column()
        txout = self.dustTxOutlist[row]
        addrStr = script_to_addrStr(txout.getScript())
        pyAddr = self.wlt.addrMap[addrStr_to_hash160(addrStr)[1]]
        chainIndex = pyAddr.chainIndex + 1
        if role == Qt.DisplayRole:
            if col == DUSTCOLS.chainIndex: return QVariant(chainIndex)
            if col == DUSTCOLS.AddrStr: return QVariant(addrStr)
            if col == DUSTCOLS.Btc:
                return QVariant(coin2str(txout.getValue(), maxZeros=8))
        elif role == Qt.TextAlignmentRole:
            if col == DUSTCOLS.chainIndex:
                return QVariant(int(Qt.AlignLeft | Qt.AlignVCenter))
            if col == DUSTCOLS.AddrStr:
                return QVariant(int(Qt.AlignLeft | Qt.AlignVCenter))
            if col == DUSTCOLS.Btc:
                return QVariant(int(Qt.AlignRight | Qt.AlignVCenter))
        elif role == Qt.ForegroundRole:
            return QVariant(Colors.Foreground)
        elif role == Qt.FontRole:
            if col == DUSTCOLS.Btc:
                return GETFONT('Fixed')

        return QVariant()
 def data(self, index, role):
     row = index.row()
     if role == Qt.DisplayRole:
         fmt = self.fmts[row]
         count = self.counts[fmt]
         return QVariant('%s [%d]'%(fmt.upper(), count))
     if role == Qt.DecorationRole:
         return QVariant(self.fi.icon_from_ext(self.fmts[row].lower()))
     if role == Qt.ToolTipRole:
         fmt = self.fmts[row]
         count = self.counts[fmt]
         return QVariant(
             _('There are %(count)d book(s) with the %(fmt)s format')%dict(
                 count=count, fmt=fmt.upper()))
     return NONE
Example #29
0
 def data(self, index, role):
     try:
         if role == Qt.DisplayRole:
             search = self.searches[self.filtered_searches[index.row()]]
             return QVariant(search['name'])
         if role == Qt.ToolTipRole:
             search = self.searches[self.filtered_searches[index.row()]]
             tt = '\n'.join((search['find'], search['replace']))
             return QVariant(tt)
         if role == Qt.UserRole:
             search = self.searches[self.filtered_searches[index.row()]]
             return QVariant((self.filtered_searches[index.row()], search))
     except IndexError:
         pass
     return NONE
Example #30
0
 def headerData(self, section, orientation, role):
     if orientation == Qt.Horizontal and role == Qt.DisplayRole:
         try:
             return QVariant(self.COLUMNS[section])
         except:
             return NONE
     return NONE