コード例 #1
0
ファイル: main.py プロジェクト: marcellmars/letssharebooks
class CapturePhotoCover(QDialog):
    def __init__(self, gui, icon, do_user_config, qaction, us):
        QDialog.__init__(self, gui)
        self.main_gui = gui
        self.do_user_config = do_user_config
        self.qaction = qaction
        self.us = us

        #- main UI layout -----------------------------------------------------
        self.ll = QVBoxLayout()

        self.l = QHBoxLayout()
        self.l.setSpacing(0)
        #self.l.setMargin(0) # not in Qt5
        self.w = QWidget()
        self.w.setLayout(self.l)

        self.setLayout(self.ll)
        self.setWindowIcon(icon)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        #- webkit -------------------------------------------------------------

        self.webview = QWebView()
        self.webview.setMaximumWidth(680)
        self.webview.setMaximumHeight(320)
        self.webview.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        # self.webview.load(QUrl.fromLocalFile(
        #     os.path.join(self.us.portable_directory,
        #                  "portable/kaliweb.html")))
        self.loadUrl()
        self.webview.page().networkAccessManager().sslErrors.connect(
            self.sslErrorHandler)
        #self.connect(self.webview.page().networkAccessManager(),
        #             SIGNAL("sslErrors (QNetworkReply *, \
        #                                       const QList<QSslError> &)"),
        #             self.sslErrorHandler)

        logger.info("KALIWEB PATH: {}".format(
            os.path.join(self.us.portable_directory, "portable/kaliweb.html")))
        self.ll.addWidget(self.webview)

    def loadUrl(self):
        if self.us.initial:
            self.webview.page().mainFrame().load(QUrl("https://google.com"))
            self.us.initial = False

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            pass

    def sslErrorHandler(self, reply, errorList):
        reply.ignoreSslErrors()
        logger.debug("SSL ERRORS: {}".format(errorList))
        return

    def closeEvent(self, e):
        self.hide()
コード例 #2
0
ファイル: main.py プロジェクト: marcellmars/letssharebooks
class CapturePhotoCover(QDialog):
    def __init__(self, gui, icon, do_user_config, qaction, us):
        QDialog.__init__(self, gui)
        self.main_gui = gui
        self.do_user_config = do_user_config
        self.qaction = qaction
        self.us = us

        #- main UI layout -----------------------------------------------------
        self.ll = QVBoxLayout()

        self.l = QHBoxLayout()
        self.l.setSpacing(0)
        #self.l.setMargin(0) # not in Qt5
        self.w = QWidget()
        self.w.setLayout(self.l)

        self.setLayout(self.ll)
        self.setWindowIcon(icon)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        #- webkit -------------------------------------------------------------

        self.webview = QWebView()
        self.webview.setMaximumWidth(680)
        self.webview.setMaximumHeight(320)
        self.webview.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        # self.webview.load(QUrl.fromLocalFile(
        #     os.path.join(self.us.portable_directory,
        #                  "portable/kaliweb.html")))
        self.loadUrl()
        self.webview.page().networkAccessManager().sslErrors.connect(self.sslErrorHandler)
        #self.connect(self.webview.page().networkAccessManager(),
        #             SIGNAL("sslErrors (QNetworkReply *, \
        #                                       const QList<QSslError> &)"),
        #             self.sslErrorHandler)

        logger.info("KALIWEB PATH: {}".format(
                    os.path.join(self.us.portable_directory,
                                 "portable/kaliweb.html")))
        self.ll.addWidget(self.webview)

    def loadUrl(self):
        if self.us.initial:
            self.webview.page().mainFrame().load(QUrl("https://google.com"))
            self.us.initial = False

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            pass

    def sslErrorHandler(self, reply, errorList):
            reply.ignoreSslErrors()
            logger.debug("SSL ERRORS: {}".format(errorList))
            return

    def closeEvent(self, e):
        self.hide()
コード例 #3
0
 def __init__(self, vertical, parent=None):
     QWebView.__init__(self, parent)
     s = self.settings()
     s.setAttribute(s.JavascriptEnabled, False)
     self.vertical = vertical
     self.page().setLinkDelegationPolicy(self.page().DelegateAllLinks)
     self.linkClicked.connect(self.link_activated)
     self._link_clicked = False
     self.setAttribute(Qt.WA_OpaquePaintEvent, False)
     palette = self.palette()
     self.setAcceptDrops(False)
     palette.setBrush(QPalette.Base, Qt.transparent)
     self.page().setPalette(palette)
     # TODO
     self.css = ''
     self.setFocusPolicy(Qt.NoFocus)
コード例 #4
0
ファイル: book_details.py プロジェクト: bindx/EE-Book
 def __init__(self, vertical, parent=None):
     QWebView.__init__(self, parent)
     s = self.settings()
     s.setAttribute(s.JavascriptEnabled, False)
     self.vertical = vertical
     self.page().setLinkDelegationPolicy(self.page().DelegateAllLinks)
     self.linkClicked.connect(self.link_activated)
     self._link_clicked = False
     self.setAttribute(Qt.WA_OpaquePaintEvent, False)
     palette = self.palette()
     self.setAcceptDrops(False)
     palette.setBrush(QPalette.Base, Qt.transparent)
     self.page().setPalette(palette)
     # TODO
     self.css = ''
     self.setFocusPolicy(Qt.NoFocus)
コード例 #5
0
ファイル: main.py プロジェクト: marcellmars/letssharebooks
    def __init__(self, gui, icon, do_user_config, qaction, us):
        QDialog.__init__(self, gui)
        self.main_gui = gui
        self.do_user_config = do_user_config
        self.qaction = qaction
        self.us = us

        #- main UI layout -----------------------------------------------------
        self.ll = QVBoxLayout()

        self.l = QHBoxLayout()
        self.l.setSpacing(0)
        #self.l.setMargin(0) # not in Qt5
        self.w = QWidget()
        self.w.setLayout(self.l)

        self.setLayout(self.ll)
        self.setWindowIcon(icon)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        #- webkit -------------------------------------------------------------

        self.webview = QWebView()
        self.webview.setMaximumWidth(680)
        self.webview.setMaximumHeight(320)
        self.webview.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        # self.webview.load(QUrl.fromLocalFile(
        #     os.path.join(self.us.portable_directory,
        #                  "portable/kaliweb.html")))
        self.loadUrl()
        self.webview.page().networkAccessManager().sslErrors.connect(
            self.sslErrorHandler)
        #self.connect(self.webview.page().networkAccessManager(),
        #             SIGNAL("sslErrors (QNetworkReply *, \
        #                                       const QList<QSslError> &)"),
        #             self.sslErrorHandler)

        logger.info("KALIWEB PATH: {}".format(
            os.path.join(self.us.portable_directory, "portable/kaliweb.html")))
        self.ll.addWidget(self.webview)
コード例 #6
0
ファイル: main.py プロジェクト: marcellmars/letssharebooks
    def __init__(self, gui, icon, do_user_config, qaction, us):
        QDialog.__init__(self, gui)
        self.main_gui = gui
        self.do_user_config = do_user_config
        self.qaction = qaction
        self.us = us

        #- main UI layout -----------------------------------------------------
        self.ll = QVBoxLayout()

        self.l = QHBoxLayout()
        self.l.setSpacing(0)
        #self.l.setMargin(0) # not in Qt5
        self.w = QWidget()
        self.w.setLayout(self.l)

        self.setLayout(self.ll)
        self.setWindowIcon(icon)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        #- webkit -------------------------------------------------------------

        self.webview = QWebView()
        self.webview.setMaximumWidth(680)
        self.webview.setMaximumHeight(320)
        self.webview.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        # self.webview.load(QUrl.fromLocalFile(
        #     os.path.join(self.us.portable_directory,
        #                  "portable/kaliweb.html")))
        self.loadUrl()
        self.webview.page().networkAccessManager().sslErrors.connect(self.sslErrorHandler)
        #self.connect(self.webview.page().networkAccessManager(),
        #             SIGNAL("sslErrors (QNetworkReply *, \
        #                                       const QList<QSslError> &)"),
        #             self.sslErrorHandler)

        logger.info("KALIWEB PATH: {}".format(
                    os.path.join(self.us.portable_directory,
                                 "portable/kaliweb.html")))
        self.ll.addWidget(self.webview)
コード例 #7
0
ファイル: stats.py プロジェクト: john-peterson/calibre
    def __init__(self, container):
        self.container = container
        self.log = self.logger = container.log
        must_use_qt()

        self.loop = QEventLoop()
        self.view = QWebView()
        self.page = Page(self.log)
        self.view.setPage(self.page)
        self.page.setViewportSize(QSize(1200, 1600))

        self.view.loadFinished.connect(self.collect,
                type=Qt.QueuedConnection)

        self.render_queue = list(container.spine_items)
        self.font_stats = {}

        QTimer.singleShot(0, self.render_book)

        if self.loop.exec_() == 1:
            raise Exception('Failed to gather statistics from book, see log for details')
コード例 #8
0
ファイル: stats.py プロジェクト: john-peterson/calibre
class StatsCollector(object):

    def __init__(self, container):
        self.container = container
        self.log = self.logger = container.log
        must_use_qt()

        self.loop = QEventLoop()
        self.view = QWebView()
        self.page = Page(self.log)
        self.view.setPage(self.page)
        self.page.setViewportSize(QSize(1200, 1600))

        self.view.loadFinished.connect(self.collect,
                type=Qt.QueuedConnection)

        self.render_queue = list(container.spine_items)
        self.font_stats = {}

        QTimer.singleShot(0, self.render_book)

        if self.loop.exec_() == 1:
            raise Exception('Failed to gather statistics from book, see log for details')

    def render_book(self):
        try:
            if not self.render_queue:
                self.loop.exit()
            else:
                self.render_next()
        except:
            self.logger.exception('Rendering failed')
            self.loop.exit(1)

    def render_next(self):
        item = unicode(self.render_queue.pop(0))
        self.current_item = item
        load_html(item, self.view)

    def collect(self, ok):
        if not ok:
            self.log.error('Failed to render document: %s'%self.container.relpath(self.current_item))
            self.loop.exit(1)
            return
        try:
            self.page.load_js()
            self.collect_font_stats()
        except:
            self.log.exception('Failed to collect font stats from: %s'%self.container.relpath(self.current_item))
            self.loop.exit(1)
            return

        self.render_book()

    def collect_font_stats(self):
        self.page.evaljs('window.font_stats.get_font_face_rules()')
        font_face_rules = self.page.bridge_value
        if not isinstance(font_face_rules, list):
            raise Exception('Unknown error occurred while reading font-face rules')

        # Weed out invalid font-face rules
        rules = []
        for rule in font_face_rules:
            ff = rule.get('font-family', None)
            if not ff: continue
            style = parseStyle('font-family:%s'%ff, validate=False)
            ff = [x.value for x in
                  style.getProperty('font-family').propertyValue]
            if not ff or ff[0] == 'inherit':
                continue
            rule['font-family'] = frozenset(icu_lower(f) for f in ff)
            src = rule.get('src', None)
            if not src: continue
            style = parseStyle('background-image:%s'%src, validate=False)
            src = style.getProperty('background-image').propertyValue[0].uri
            if not src.startswith('file://'):
                self.log.warn('Unknown URI in @font-face: %r'%src)
                continue
            src = src[len('file://'):]
            if iswindows and src.startswith('/'):
                src = src[1:]
            src = src.replace('/', os.sep)
            src = unquote(src)
            name = self.container.abspath_to_name(src)
            if not self.container.has_name(name):
                self.log.warn('Font %r referenced in @font-face rule not found'
                              %name)
                continue
            rule['src'] = name
            normalize_font_properties(rule)
            rule['width'] = widths[rule['font-stretch']]
            rule['weight'] = int(rule['font-weight'])
            rules.append(rule)

        if not rules:
            return

        for rule in rules:
            if rule['src'] not in self.font_stats:
                self.font_stats[rule['src']] = set()

        self.page.evaljs('window.font_stats.get_font_usage()')
        font_usage = self.page.bridge_value
        if not isinstance(font_usage, list):
            raise Exception('Unknown error occurred while reading font usage')
        exclude = {'\n', '\r', '\t'}
        for font in font_usage:
            text = set()
            for t in font['text']:
                text |= frozenset(t)
            text.difference_update(exclude)
            if not text: continue
            for rule in get_matching_rules(rules, font):
                self.font_stats[rule['src']] |= text