コード例 #1
0
    def show_data(self, html):
        def color_to_string(col):
            ans = '#000000'
            if col.isValid():
                col = col.toRgb()
                if col.isValid():
                    ans = unicode(col.name())
            return ans

        fi = QFontInfo(QApplication.font(self.parent()))
        f = fi.pixelSize()+1+int(tweaks['change_book_details_font_size_by'])
        fam = unicode(fi.family()).strip().replace('"', '')
        if not fam:
            fam = 'sans-serif'

        c = color_to_string(QApplication.palette().color(QPalette.Normal,
                        QPalette.WindowText))
        templ = '''\
        <html>
            <head>
            <style type="text/css">
                body, td {background-color: transparent; font-family: "%s"; font-size: %dpx; color: %s }
                a { text-decoration: none; color: blue }
                div.description { margin-top: 0; padding-top: 0; text-indent: 0 }
                table { margin-bottom: 0; padding-bottom: 0; }
            </style>
            </head>
            <body>
            <div class="description">
            %%s
            </div>
            </body>
        <html>
        '''%(fam, f, c)
        self.setHtml(templ%html)
コード例 #2
0
ファイル: look_feel.py プロジェクト: shamray/calibre
    def update_font_display(self):
        font = self.build_font_obj()
        fi = QFontInfo(font)
        name = unicode(fi.family())

        self.font_display.setFont(font)
        self.font_display.setText(name + ' [%dpt]' % fi.pointSize())
コード例 #3
0
ファイル: look_feel.py プロジェクト: jackpinto/calibre
    def update_font_display(self):
        font = self.build_font_obj()
        fi = QFontInfo(font)
        name = unicode(fi.family())

        self.font_display.setFont(font)
        self.font_display.setText(name + " [%dpt]" % fi.pointSize())
コード例 #4
0
def render_html(mi,
                css,
                vertical,
                widget,
                all_fields=False,
                render_data_func=None):  # {{{
    table, comment_fields = (render_data_func or render_data)(
        mi,
        all_fields=all_fields,
        use_roman_numbers=config['use_roman_numerals_for_series_number'])

    def color_to_string(col):
        ans = '#000000'
        if col.isValid():
            col = col.toRgb()
            if col.isValid():
                ans = unicode(col.name())
        return ans

    fi = QFontInfo(QApplication.font(widget))
    f = fi.pixelSize() + 1 + int(tweaks['change_book_details_font_size_by'])
    fam = unicode(fi.family()).strip().replace('"', '')
    if not fam:
        fam = 'sans-serif'

    c = color_to_string(QApplication.palette().color(QPalette.Normal,
                                                     QPalette.WindowText))
    templ = u'''\
    <html>
        <head>
        <style type="text/css">
            body, td {
                background-color: transparent;
                font-size: %dpx;
                font-family: "%s",sans-serif;
                color: %s
            }
        </style>
        <style type="text/css">
            %s
        </style>
        </head>
        <body>
        %%s
        </body>
    <html>
    ''' % (f, fam, c, css)
    comments = u''
    if comment_fields:
        comments = '\n'.join(u'<div>%s</div>' % x for x in comment_fields)
    right_pane = u'<div id="comments" class="comments">%s</div>' % comments

    if vertical:
        ans = templ % (table + right_pane)
    else:
        ans = templ % (
            u'<table><tr><td valign="top" '
            'style="padding-right:2em; width:40%%">%s</td><td valign="top">%s</td></tr></table>'
            % (table, right_pane))
    return ans
コード例 #5
0
ファイル: single_download.py プロジェクト: yeyanchao/calibre
    def show_data(self, html):
        def color_to_string(col):
            ans = '#000000'
            if col.isValid():
                col = col.toRgb()
                if col.isValid():
                    ans = unicode(col.name())
            return ans

        fi = QFontInfo(QApplication.font(self.parent()))
        f = fi.pixelSize()+1+int(tweaks['change_book_details_font_size_by'])
        fam = unicode(fi.family()).strip().replace('"', '')
        if not fam:
            fam = 'sans-serif'

        c = color_to_string(QApplication.palette().color(QPalette.Normal,
                        QPalette.WindowText))
        templ = '''\
        <html>
            <head>
            <style type="text/css">
                body, td {background-color: transparent; font-family: "%s"; font-size: %dpx; color: %s }
                a { text-decoration: none; color: blue }
                div.description { margin-top: 0; padding-top: 0; text-indent: 0 }
                table { margin-bottom: 0; padding-bottom: 0; }
            </style>
            </head>
            <body>
            <div class="description">
            %%s
            </div>
            </body>
        <html>
        '''%(fam, f, c)
        self.setHtml(templ%html)
コード例 #6
0
ファイル: look_feel.py プロジェクト: jackpinto/calibre
 def change_font(self, *args):
     fd = QFontDialog(self.build_font_obj(), self)
     if fd.exec_() == fd.Accepted:
         font = fd.selectedFont()
         fi = QFontInfo(font)
         self.current_font = [unicode(fi.family()), fi.pointSize(), fi.weight(), fi.italic(), font.stretch()]
         self.update_font_display()
         self.changed_signal.emit()
コード例 #7
0
ファイル: book_details.py プロジェクト: hashken/calibre
def render_html(mi, css, vertical, widget, all_fields=False, render_data_func=None):  # {{{
    table, comment_fields = (render_data_func or render_data)(
        mi, all_fields=all_fields, use_roman_numbers=config["use_roman_numerals_for_series_number"]
    )

    def color_to_string(col):
        ans = "#000000"
        if col.isValid():
            col = col.toRgb()
            if col.isValid():
                ans = unicode(col.name())
        return ans

    fi = QFontInfo(QApplication.font(widget))
    f = fi.pixelSize() + 1 + int(tweaks["change_book_details_font_size_by"])
    fam = unicode(fi.family()).strip().replace('"', "")
    if not fam:
        fam = "sans-serif"

    c = color_to_string(QApplication.palette().color(QPalette.Normal, QPalette.WindowText))
    templ = u"""\
    <html>
        <head>
        <style type="text/css">
            body, td {
                background-color: transparent;
                font-size: %dpx;
                font-family: "%s",sans-serif;
                color: %s
            }
        </style>
        <style type="text/css">
            %s
        </style>
        </head>
        <body>
        %%s
        </body>
    <html>
    """ % (
        f,
        fam,
        c,
        css,
    )
    comments = u""
    if comment_fields:
        comments = "\n".join(u"<div>%s</div>" % x for x in comment_fields)
    right_pane = u'<div id="comments" class="comments">%s</div>' % comments

    if vertical:
        ans = templ % (table + right_pane)
    else:
        ans = templ % (
            u'<table><tr><td valign="top" '
            'style="padding-right:2em; width:40%%">%s</td><td valign="top">%s</td></tr></table>' % (table, right_pane)
        )
    return ans
コード例 #8
0
ファイル: book_details.py プロジェクト: BobPyron/calibre
def render_html(mi, css, vertical, widget, all_fields=False):  # {{{
    table = render_data(mi, all_fields=all_fields,
            use_roman_numbers=config['use_roman_numerals_for_series_number'])

    def color_to_string(col):
        ans = '#000000'
        if col.isValid():
            col = col.toRgb()
            if col.isValid():
                ans = unicode(col.name())
        return ans

    fi = QFontInfo(QApplication.font(widget))
    f = fi.pixelSize() + 1 + int(tweaks['change_book_details_font_size_by'])
    fam = unicode(fi.family()).strip().replace('"', '')
    if not fam:
        fam = 'sans-serif'

    c = color_to_string(QApplication.palette().color(QPalette.Normal,
                    QPalette.WindowText))
    templ = u'''\
    <html>
        <head>
        <style type="text/css">
            body, td {
                background-color: transparent;
                font-size: %dpx;
                font-family: "%s",sans-serif;
                color: %s
            }
        </style>
        <style type="text/css">
            %s
        </style>
        </head>
        <body>
        %%s
        </body>
    <html>
    '''%(f, fam, c, css)
    fm = getattr(mi, 'field_metadata', field_metadata)
    fl = dict(get_field_list(fm))
    show_comments = (all_fields or fl.get('comments', True))
    comments = u''
    if mi.comments and show_comments:
        comments = comments_to_html(force_unicode(mi.comments))
    right_pane = u'<div id="comments" class="comments">%s</div>'%comments

    if vertical:
        ans = templ%(table+right_pane)
    else:
        ans = templ%(u'<table><tr><td valign="top" '
            'style="padding-right:2em; width:40%%">%s</td><td valign="top">%s</td></tr></table>'
                % (table, right_pane))
    return ans
コード例 #9
0
ファイル: comments_editor.py プロジェクト: Gondulf/calibre
    def set_font_style(self):
        fi = QFontInfo(QApplication.font(self))
        f  = fi.pixelSize() + 1 + int(tweaks['change_book_details_font_size_by'])
        fam = unicode(fi.family()).strip().replace('"', '')
        if not fam:
            fam = 'sans-serif'
        style = 'font-size: %fpx; font-family:"%s",sans-serif;' % (f, fam)

        # toList() is needed because PyQt on Debian is old/broken
        for body in self.page().mainFrame().documentElement().findAll('body').toList():
            body.setAttribute('style', style)
        self.page().setContentEditable(not self.readonly)
コード例 #10
0
    def set_font_style(self):
        fi = QFontInfo(QApplication.font(self))
        f  = fi.pixelSize() + 1 + int(tweaks['change_book_details_font_size_by'])
        fam = unicode(fi.family()).strip().replace('"', '')
        if not fam:
            fam = 'sans-serif'
        style = 'font-size: %fpx; font-family:"%s",sans-serif;' % (f, fam)

        # toList() is needed because PyQt on Debian is old/broken
        for body in self.page().mainFrame().documentElement().findAll('body').toList():
            body.setAttribute('style', style)
        self.page().setContentEditable(not self.readonly)
コード例 #11
0
    def popup(self, select_first=True):
        if self.disable_popup:
            return
        p = self
        m = p.model()
        widget = self.completer_widget()
        if widget is None:
            return
        screen = QApplication.desktop().availableGeometry(widget)
        h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) +
             3) + 3
        hsb = p.horizontalScrollBar()
        if hsb and hsb.isVisible():
            h += hsb.sizeHint().height()

        rh = widget.height()
        pos = widget.mapToGlobal(QPoint(0, widget.height() - 2))
        w = min(widget.width(), screen.width())

        if (pos.x() + w) > (screen.x() + screen.width()):
            pos.setX(screen.x() + screen.width() - w)
        if pos.x() < screen.x():
            pos.setX(screen.x())

        top = pos.y() - rh - screen.top() + 2
        bottom = screen.bottom() - pos.y()
        h = max(h, p.minimumHeight())
        if h > bottom:
            h = min(max(top, bottom), h)

            if top > bottom:
                pos.setY(pos.y() - h - rh + 2)

        p.setGeometry(pos.x(), pos.y(), w, h)

        if (tweaks['preselect_first_completion'] and select_first
                and not self.currentIndex().isValid()
                and self.model().rowCount() > 0):
            self.setCurrentIndex(self.model().index(0))

        if not p.isVisible():
            if isosx and get_osx_version() >= (10, 9, 0):
                # On mavericks the popup menu seems to use a font smaller than
                # the widgets font, see for example:
                # https://bugs.launchpad.net/bugs/1243761
                fp = QFontInfo(widget.font())
                f = QFont()
                f.setPixelSize(fp.pixelSize())
                self.setFont(f)
            p.show()
コード例 #12
0
ファイル: complete2.py プロジェクト: briangraeme/calibre
    def popup(self, select_first=True):
        if self.disable_popup:
            return
        p = self
        m = p.model()
        widget = self.completer_widget()
        if widget is None:
            return
        screen = QApplication.desktop().availableGeometry(widget)
        h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) +
                3) + 3
        hsb = p.horizontalScrollBar()
        if hsb and hsb.isVisible():
            h += hsb.sizeHint().height()

        rh = widget.height()
        pos = widget.mapToGlobal(QPoint(0, widget.height() - 2))
        w = min(widget.width(), screen.width())

        if (pos.x() + w) > (screen.x() + screen.width()):
            pos.setX(screen.x() + screen.width() - w)
        if pos.x() < screen.x():
            pos.setX(screen.x())

        top = pos.y() - rh - screen.top() + 2
        bottom = screen.bottom() - pos.y()
        h = max(h, p.minimumHeight())
        if h > bottom:
            h = min(max(top, bottom), h)

            if top > bottom:
                pos.setY(pos.y() - h - rh + 2)

        p.setGeometry(pos.x(), pos.y(), w, h)

        if (tweaks['preselect_first_completion'] and select_first and not
                self.currentIndex().isValid() and self.model().rowCount() > 0):
            self.setCurrentIndex(self.model().index(0))

        if not p.isVisible():
            if isosx and get_osx_version() >= (10, 9, 0):
                # On mavericks the popup menu seems to use a font smaller than
                # the widgets font, see for example:
                # https://bugs.launchpad.net/bugs/1243761
                fp = QFontInfo(widget.font())
                f = QFont()
                f.setPixelSize(fp.pixelSize())
                self.setFont(f)
            p.show()
コード例 #13
0
ファイル: delegates.py プロジェクト: oheil/calibre
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args, **kwargs)
     self.rf = QFont(rating_font())
     self.em = Qt.ElideMiddle
     delta = 0
     if iswindows and sys.getwindowsversion().major >= 6:
         delta = 2
     self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
コード例 #14
0
 def change_font(self, *args):
     fd = QFontDialog(self.build_font_obj(), self)
     if fd.exec_() == fd.Accepted:
         font = fd.selectedFont()
         fi = QFontInfo(font)
         self.current_font = [unicode(fi.family()), fi.pointSize(),
                 fi.weight(), fi.italic(), font.stretch()]
         self.update_font_display()
         self.changed_signal.emit()
コード例 #15
0
 def get_value(self, g):
     from calibre.gui2.convert.xpath_wizard import XPathEdit
     from calibre.gui2.convert.regex_builder import RegexEdit
     from calibre.gui2.widgets import EncodingComboBox
     ret = self.get_value_handler(g)
     if ret != 'this is a dummy return value, xcswx1avcx4x':
         return ret
     if isinstance(g, (QSpinBox, QDoubleSpinBox)):
         return g.value()
     elif isinstance(g, (QLineEdit, QTextEdit)):
         func = getattr(g, 'toPlainText', getattr(g, 'text', None))()
         ans = unicode(func)
         if self.STRIP_TEXT_FIELDS:
             ans = ans.strip()
         if not ans:
             ans = None
         return ans
     elif isinstance(g, QFontComboBox):
         return unicode(QFontInfo(g.currentFont()).family())
     elif isinstance(g, FontFamilyChooser):
         return g.font_family
     elif isinstance(g, EncodingComboBox):
         ans = unicode(g.currentText()).strip()
         try:
             codecs.lookup(ans)
         except:
             ans = ''
         if not ans:
             ans = None
         return ans
     elif isinstance(g, QComboBox):
         return unicode(g.currentText())
     elif isinstance(g, QCheckBox):
         return bool(g.isChecked())
     elif isinstance(g, XPathEdit):
         return g.xpath if g.xpath else None
     elif isinstance(g, RegexEdit):
         return g.regex if g.regex else None
     else:
         raise Exception('Can\'t get value from %s'%type(g))
コード例 #16
0
    def do_paint(self, painter, option, index):
        text = unicode(index.data(Qt.DisplayRole).toString())
        font = QFont(option.font)
        font.setPointSize(QFontInfo(font).pointSize() * 1.5)
        font2 = QFont(font)
        font2.setFamily(text)

        system, has_latin = writing_system_for_font(font2)
        if has_latin:
            font = font2

        r = option.rect

        if option.state & QStyle.State_Selected:
            painter.setPen(QPen(option.palette.highlightedText(), 0))

        if (option.direction == Qt.RightToLeft):
            r.setRight(r.right() - 4)
        else:
            r.setLeft(r.left() + 4)

        painter.setFont(font)
        painter.drawText(r,
                         Qt.AlignVCenter | Qt.AlignLeading | Qt.TextSingleLine,
                         text)

        if (system != QFontDatabase.Any):
            w = painter.fontMetrics().width(text + "  ")
            painter.setFont(font2)
            sample = QFontDatabase().writingSystemSample(system)
            if (option.direction == Qt.RightToLeft):
                r.setRight(r.right() - w)
            else:
                r.setLeft(r.left() + w)
            painter.drawText(
                r, Qt.AlignVCenter | Qt.AlignLeading | Qt.TextSingleLine,
                sample)
コード例 #17
0
ファイル: book_details.py プロジェクト: bindx/EE-Book
def render_html(current_book, css, vertical, widget, all_fields=False, render_data_func=None):
    u"""

    :param current_book:
    :param css:
    :param vertical:
    :param widget:
    :param all_fields:
    :param render_data_func:
    :return:
    """
    table, comment_fields = render_data(current_book, all_fields=all_fields, use_roman_numbers=True)

    def color_to_string(col):
        ans = '#000000'
        if col.isValid():
            col = col.toRgb()
            if col.isValid():
                ans = unicode(col.name())
        return ans

    font_info = QFontInfo(QApplication.font(widget))
    font_px = font_info.pixelSize() + 1
    font_family = unicode(font_info.family()).strip().replace('"', '')

    if not font_family:
        font_family = 'sans-serif'

    body_td_color = color_to_string(QApplication.palette().color(QPalette.Normal, QPalette.WindowText))

    template = u"""
    <html>
        <head>
        <style type="text/css">
            body, td {
                background-color: transparent;
                font-size: %dpx;
                font-family: "%s", sans-serif;
                color: %s
            }
        </style>
        <style type="text/css">
            %s
        </style>
        </head>
        <body>
        %%s
        </body>
    </html>
    """ % (font_px, font_family, body_td_color, css)
    comments = u''
    comment_fields = None
    if comment_fields:
        comments = '\n'.join(u'<div>%s</div>' % x for x in comment_fields)
    right_pane = u'<div id="comments" class="comments">%s</div>' % comments

    if vertical:
        ans = template % (table+right_pane)
    else:
        ans = template % (u'<table><tr><td valign="top" '
        'style="padding-right:2em; width:40%%">%s</td><td valign="top">%s</td></tr></table>'
                          % (table, right_pane))
    return ans
コード例 #18
0
 def do_size_hint(self, option, index):
     text = index.data(Qt.DisplayRole).toString()
     font = QFont(option.font)
     font.setPointSize(QFontInfo(font).pointSize() * 1.5)
     m = QFontMetrics(font)
     return QSize(m.width(text), m.height())
コード例 #19
0
def render_html(current_book,
                css,
                vertical,
                widget,
                all_fields=False,
                render_data_func=None):
    u"""

    :param current_book:
    :param css:
    :param vertical:
    :param widget:
    :param all_fields:
    :param render_data_func:
    :return:
    """
    table, comment_fields = render_data(current_book,
                                        all_fields=all_fields,
                                        use_roman_numbers=True)

    def color_to_string(col):
        ans = '#000000'
        if col.isValid():
            col = col.toRgb()
            if col.isValid():
                ans = unicode(col.name())
        return ans

    font_info = QFontInfo(QApplication.font(widget))
    font_px = font_info.pixelSize() + 1
    font_family = unicode(font_info.family()).strip().replace('"', '')

    if not font_family:
        font_family = 'sans-serif'

    body_td_color = color_to_string(QApplication.palette().color(
        QPalette.Normal, QPalette.WindowText))

    template = u"""
    <html>
        <head>
        <style type="text/css">
            body, td {
                background-color: transparent;
                font-size: %dpx;
                font-family: "%s", sans-serif;
                color: %s
            }
        </style>
        <style type="text/css">
            %s
        </style>
        </head>
        <body>
        %%s
        </body>
    </html>
    """ % (font_px, font_family, body_td_color, css)
    comments = u''
    comment_fields = None
    if comment_fields:
        comments = '\n'.join(u'<div>%s</div>' % x for x in comment_fields)
    right_pane = u'<div id="comments" class="comments">%s</div>' % comments

    if vertical:
        ans = template % (table + right_pane)
    else:
        ans = template % (
            u'<table><tr><td valign="top" '
            'style="padding-right:2em; width:40%%">%s</td><td valign="top">%s</td></tr></table>'
            % (table, right_pane))
    return ans