Ejemplo n.º 1
0
 def displayText(self, val, locale):
     d = val.toDateTime()
     if d <= UNDEFINED_QDATETIME:
         return ''
     self.format = tweaks['gui_pubdate_display_format']
     if self.format is None:
         self.format = 'MMM yyyy'
     return format_date(qt_to_dt(d, as_utc=False), self.format)
Ejemplo n.º 2
0
 def __init__(self, date_read, is_read_only=False, default_to_today=False):
     if date_read == UNDEFINED_DATE and default_to_today:
         date_read = now()
     if is_read_only:
         QTableWidgetItem.__init__(self, format_date(date_read, None), QtGui.QTableWidgetItem.UserType)
         self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
     else:
         QTableWidgetItem.__init__(self, '', QtGui.QTableWidgetItem.UserType)
         self.setData(Qt.DisplayRole, QDateTime(date_read))
Ejemplo n.º 3
0
 def evaluate(self, formatter, kwargs, mi, locals, val, format_string):
     if not val or val == "None":
         return ""
     try:
         dt = parse_date(val)
         s = format_date(dt, format_string)
     except:
         s = "BAD DATE"
     return s
Ejemplo n.º 4
0
    def setup_ui(self):
        self.l = l = QVBoxLayout(self)
        self.splitter = s = QSplitter(self)
        s.setChildrenCollapsible(False)
        l.addWidget(s), l.addWidget(self.bb)
        self.bb.setStandardButtons(self.bb.Yes | self.bb.No)

        self.left = w = QWidget(self)
        s.addWidget(w)
        w.l = l = QVBoxLayout(w)
        l.setContentsMargins(0, 0, 0, 0)
        self.la = la = QLabel(self.msg)
        la.setWordWrap(True)
        l.addWidget(la)
        self.confirm = c = QCheckBox(_('Show this confirmation again'), self)
        c.setChecked(True)
        c.stateChanged.connect(self.toggle)
        l.addWidget(c)

        self.right = r = QTextBrowser(self)
        series = ''
        mi, fm = self.mi, field_metadata
        if mi.series:
            series = _('{num} of {series}').format(num=mi.format_series_index(), series='<i>%s</i>' % mi.series)
        r.setHtml('''
<h3 style="text-align:center">{mb}</h3>
<p><b>{title}</b> - <i>{authors}</i><br></p>
<table>
<tr><td>{fm[timestamp][name]}:</td><td>{date}</td></tr>
<tr><td>{fm[pubdate][name]}:</td><td>{published}</td></tr>
<tr><td>{fm[formats][name]}:</td><td>{formats}</td></tr>
<tr><td>{fm[series][name]}:</td><td>{series}</td></tr>
</table>
        '''.format(
            mb=_('Target book'),
            title=mi.title,
            authors=authors_to_string(mi.authors),
            date=format_date(mi.timestamp, tweaks['gui_timestamp_display_format']), fm=fm,
            published=(format_date(mi.pubdate, tweaks['gui_pubdate_display_format']) if mi.pubdate else ''),
            formats=', '.join(mi.formats or ()),
            series=series
        ))
        s.addWidget(r)
Ejemplo n.º 5
0
 def data_as_text(self, book, col):
     if col == 0:
         return unicode(book.gui_rank+1)
     if col == 1:
         t = book.title if book.title else _('Unknown')
         a = authors_to_string(book.authors) if book.authors else ''
         return '<b>%s</b><br><i>%s</i>' % (t, a)
     if col == 2:
         d = format_date(book.pubdate, 'yyyy') if book.pubdate else _('Unknown')
         p = book.publisher if book.publisher else ''
         return '<b>%s</b><br><i>%s</i>' % (d, p)
Ejemplo n.º 6
0
 def data_as_text(self, book, col):
     if col == 0:
         return unicode(book.gui_rank + 1)
     if col == 1:
         t = book.title if book.title else _("Unknown")
         a = authors_to_string(book.authors) if book.authors else ""
         return "<b>%s</b><br><i>%s</i>" % (t, a)
     if col == 2:
         d = format_date(book.pubdate, "yyyy") if book.pubdate else _("Unknown")
         p = book.publisher if book.publisher else ""
         return "<b>%s</b><br><i>%s</i>" % (d, p)
Ejemplo n.º 7
0
    def __init__(self, date_read, is_read_only=False, default_to_today=False, fmt=None):
#        debug_print("DateTableWidgetItem:__init__ - date_read=", date_read)
        if date_read is None or date_read == UNDEFINED_DATE and default_to_today:
            date_read = now()
        if is_read_only:
            QTableWidgetItem.__init__(self, format_date(date_read, fmt), QTableWidgetItem.UserType)
            self.setFlags(Qt.ItemIsSelectable|Qt.ItemIsEnabled)
            self.setData(Qt.DisplayRole, QDateTime(date_read))
        else:
            QTableWidgetItem.__init__(self, '', QTableWidgetItem.UserType)
            self.setData(Qt.DisplayRole, QDateTime(date_read))
Ejemplo n.º 8
0
    def __init__(self, mi, parent=None):
        QTextBrowser.__init__(self, parent)
        series = ''
        fm = field_metadata
        if mi.series:
            series = _('{num} of {series}').format(num=mi.format_series_index(), series='<i>%s</i>' % mi.series)
        self.setHtml('''
<h3 style="text-align:center">{mb}</h3>
<p><b>{title}</b> - <i>{authors}</i><br></p>
<table>
<tr><td>{fm[timestamp][name]}:</td><td>{date}</td></tr>
<tr><td>{fm[pubdate][name]}:</td><td>{published}</td></tr>
<tr><td>{fm[formats][name]}:</td><td>{formats}</td></tr>
<tr><td>{fm[series][name]}:</td><td>{series}</td></tr>
</table>
        '''.format(
            mb=_('Target book'),
            title=mi.title,
            authors=authors_to_string(mi.authors),
            date=format_date(mi.timestamp, tweaks['gui_timestamp_display_format']), fm=fm,
            published=(format_date(mi.pubdate, tweaks['gui_pubdate_display_format']) if mi.pubdate else ''),
            formats=', '.join(mi.formats or ()),
            series=series
        ))
Ejemplo n.º 9
0
 def sort_key(self, sort_by_pubdate=False, sort_by_name=False):
     if sort_by_pubdate:
         pub_date = self.pubdate()
         if pub_date is not None and pub_date.year > 101:
             return format_date(pub_date, 'yyyyMMdd')
     else:
         series = self.orig_series_name()
         series_number = self.orig_series_index() if self.orig_series_index() is not None else -1
         debug_print("sort_key - series_number=", series_number)
         debug_print("sort_key - series_number.__class__=", series_number.__class__)
         if series:
             if sort_by_name:
                 return '%s%06.2f'% (series, series_number)
             else:
                 return '%06.2f%s'% (series_number, series)
     return ''
Ejemplo n.º 10
0
 def _get_display_release_date(self, date_value, format='dd MMM yyyy'):
     if date_value and date_value != UNDEFINED_DATE:
         return format_date(date_value, format)
     return None
Ejemplo n.º 11
0
 def displayText(self, val, locale):
     d = val.toDateTime()
     if d <= UNDEFINED_QDATETIME:
         return ''
     return format_date(qt_to_dt(d, as_utc=False), self.format)
Ejemplo n.º 12
0
 def displayText(self, val, locale):
     d = qt_to_dt(val)
     if is_date_undefined(d):
         return ''
     return format_date(d, self.format)
Ejemplo n.º 13
0
    def format_field_extended(self, key, series_with_index=True):
        from calibre.ebooks.metadata import authors_to_string
        '''
        returns the tuple (display_name, formatted_value, original_value,
        field_metadata)
        '''
        from calibre.utils.date import format_date

        # Handle custom series index
        if key.startswith('#') and key.endswith('_index'):
            tkey = key[:-6]  # strip the _index
            cmeta = self.get_user_metadata(tkey, make_copy=False)
            if cmeta and cmeta['datatype'] == 'series':
                if self.get(tkey):
                    res = self.get_extra(tkey)
                    return (unicode(cmeta['name']+'_index'),
                            self.format_series_index(res), res, cmeta)
                else:
                    return (unicode(cmeta['name']+'_index'), '', '', cmeta)

        if key in self.custom_field_keys():
            res = self.get(key, None)       # get evaluates all necessary composites
            cmeta = self.get_user_metadata(key, make_copy=False)
            name = unicode(cmeta['name'])
            if res is None or res == '':    # can't check "not res" because of numeric fields
                return (name, res, None, None)
            orig_res = res
            datatype = cmeta['datatype']
            if datatype == 'text' and cmeta['is_multiple']:
                res = cmeta['is_multiple']['list_to_ui'].join(res)
            elif datatype == 'series' and series_with_index:
                if self.get_extra(key) is not None:
                    res = res + \
                        ' [%s]'%self.format_series_index(val=self.get_extra(key))
            elif datatype == 'datetime':
                res = format_date(res, cmeta['display'].get('date_format','dd MMM yyyy'))
            elif datatype == 'bool':
                res = _('Yes') if res else _('No')
            elif datatype == 'rating':
                res = u'%.2g'%(res/2.0)
            elif datatype in ['int', 'float']:
                try:
                    fmt = cmeta['display'].get('number_format', None)
                    res = fmt.format(res)
                except:
                    pass
            return (name, unicode(res), orig_res, cmeta)

        # convert top-level ids into their value
        if key in TOP_LEVEL_IDENTIFIERS:
            fmeta = field_metadata['identifiers']
            name = key
            res = self.get(key, None)
            return (name, res, res, fmeta)

        # Translate aliases into the standard field name
        fmkey = field_metadata.search_term_to_field_key(key)
        if fmkey in field_metadata and field_metadata[fmkey]['kind'] == 'field':
            res = self.get(key, None)
            fmeta = field_metadata[fmkey]
            name = unicode(fmeta['name'])
            if res is None or res == '':
                return (name, res, None, None)
            orig_res = res
            name = unicode(fmeta['name'])
            datatype = fmeta['datatype']
            if key == 'authors':
                res = authors_to_string(res)
            elif key == 'series_index':
                res = self.format_series_index(res)
            elif datatype == 'text' and fmeta['is_multiple']:
                if isinstance(res, dict):
                    res = [k + ':' + v for k,v in res.items()]
                res = fmeta['is_multiple']['list_to_ui'].join(sorted(filter(None, res), key=sort_key))
            elif datatype == 'series' and series_with_index:
                res = res + ' [%s]'%self.format_series_index()
            elif datatype == 'datetime':
                res = format_date(res, fmeta['display'].get('date_format','dd MMM yyyy'))
            elif datatype == 'rating':
                res = u'%.2g'%(res/2.0)
            elif key == 'size':
                res = human_readable(res)
            return (name, unicode(res), orig_res, fmeta)

        return (None, None, None, None)
Ejemplo n.º 14
0
 def _get_display_release_date(self, date_value, format="dd MMM yyyy"):
     if date_value and date_value != UNDEFINED_DATE:
         return QVariant(format_date(date_value, format))
     return NONE
Ejemplo n.º 15
0
 def evaluate(self, formatter, kwargs, mi, locals, fmt):
     fmt_data = mi.get("format_metadata", {})
     data = sorted(fmt_data.items(), key=lambda x: x[1]["mtime"], reverse=True)
     return ",".join(k.upper() + ":" + format_date(v["mtime"], fmt) for k, v in data)
Ejemplo n.º 16
0
 def evaluate(self, formatter, kwargs, mi, locals):
     return format_date(now(), "iso")