Exemplo n.º 1
0
class Browser(QWidget):
    """LilyPond documentation browser widget."""
    def __init__(self, dockwidget):
        super(Browser, self).__init__(dockwidget)

        layout = QVBoxLayout(spacing=0)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        self.toolbar = tb = QToolBar()
        self.webview = QWebView(contextMenuPolicy=Qt.CustomContextMenu)
        self.chooser = QComboBox(sizeAdjustPolicy=QComboBox.AdjustToContents)
        self.search = SearchEntry(maximumWidth=200)

        layout.addWidget(self.toolbar)
        layout.addWidget(self.webview)

        ac = dockwidget.actionCollection
        ac.help_back.triggered.connect(self.webview.back)
        ac.help_forward.triggered.connect(self.webview.forward)
        ac.help_home.triggered.connect(self.showHomePage)
        ac.help_print.triggered.connect(self.slotPrint)

        self.webview.page().setNetworkAccessManager(
            lilydoc.network.accessmanager())
        self.webview.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.webview.page().linkClicked.connect(self.openUrl)
        self.webview.page().setForwardUnsupportedContent(True)
        self.webview.page().unsupportedContent.connect(self.slotUnsupported)
        self.webview.urlChanged.connect(self.slotUrlChanged)
        self.webview.customContextMenuRequested.connect(
            self.slotShowContextMenu)

        tb.addAction(ac.help_back)
        tb.addAction(ac.help_forward)
        tb.addSeparator()
        tb.addAction(ac.help_home)
        tb.addAction(ac.help_print)
        tb.addSeparator()
        tb.addWidget(self.chooser)
        tb.addWidget(self.search)

        self.chooser.activated[int].connect(self.showHomePage)
        self.search.textEdited.connect(self.slotSearchChanged)
        self.search.returnPressed.connect(self.slotSearchReturnPressed)
        dockwidget.mainwindow().iconSizeChanged.connect(
            self.updateToolBarSettings)
        dockwidget.mainwindow().toolButtonStyleChanged.connect(
            self.updateToolBarSettings)

        app.settingsChanged.connect(self.readSettings)
        self.readSettings()
        self.loadDocumentation()
        self.showInitialPage()
        app.settingsChanged.connect(self.loadDocumentation)
        app.translateUI(self)

    def readSettings(self):
        s = QSettings()
        s.beginGroup("documentation")
        ws = self.webview.page().settings()
        family = s.value("fontfamily", self.font().family(), type(""))
        size = s.value("fontsize", 16, int)
        ws.setFontFamily(QWebSettings.StandardFont, family)
        ws.setFontSize(QWebSettings.DefaultFontSize, size)
        fixed = textformats.formatData('editor').font
        ws.setFontFamily(QWebSettings.FixedFont, fixed.family())
        ws.setFontSize(QWebSettings.DefaultFixedFontSize,
                       fixed.pointSizeF() * 96 / 72)

    def keyPressEvent(self, ev):
        if ev.text() == "/":
            self.search.setFocus()
        else:
            super(Browser, self).keyPressEvent(ev)

    def translateUI(self):
        try:
            self.search.setPlaceholderText(_("Search..."))
        except AttributeError:
            pass  # not in Qt 4.6

    def showInitialPage(self):
        """Shows the preferred start page.
        
        If a local documentation instance already has a suitable version,
        just loads it. Otherwise connects to the allLoaded signal, that is
        emitted when all the documentation instances have loaded their version
        information and then shows the start page (if another page wasn't yet
        loaded).
        
        """
        if self.webview.url().isEmpty():
            docs = lilydoc.manager.docs()
            version = lilypondinfo.preferred().version()
            index = -1
            if version:
                for num, doc in enumerate(docs):
                    if doc.version() is not None and doc.version() >= version:
                        index = num  # a suitable documentation is found
                        break
            if index == -1:
                # nothing found (or LilyPond version not available),
                # wait for loading or show the most recent version
                if not lilydoc.manager.loaded():
                    lilydoc.manager.allLoaded.connect(self.showInitialPage)
                    return
                index = len(docs) - 1
            self.chooser.setCurrentIndex(index)
            self.showHomePage()

    def loadDocumentation(self):
        """Puts the available documentation instances in the combobox."""
        i = self.chooser.currentIndex()
        self.chooser.clear()
        for doc in lilydoc.manager.docs():
            v = doc.versionString()
            if doc.isLocal():
                t = _("(local)")
            else:
                t = _("({hostname})").format(hostname=doc.url().host())
            self.chooser.addItem("{0} {1}".format(v or _("<unknown>"), t))
        self.chooser.setCurrentIndex(i)
        if not lilydoc.manager.loaded():
            lilydoc.manager.allLoaded.connect(self.loadDocumentation, -1)
            return

    def updateToolBarSettings(self):
        mainwin = self.parentWidget().mainwindow()
        self.toolbar.setIconSize(mainwin.iconSize())
        self.toolbar.setToolButtonStyle(mainwin.toolButtonStyle())

    def showManual(self):
        """Invoked when the user presses F1."""
        self.slotHomeFrescobaldi()  # TEMP

    def slotUrlChanged(self):
        ac = self.parentWidget().actionCollection
        ac.help_back.setEnabled(self.webview.history().canGoBack())
        ac.help_forward.setEnabled(self.webview.history().canGoForward())

    def openUrl(self, url):
        if url.path().endswith(('.ily', '.lyi', '.ly')):
            self.sourceViewer().showReply(lilydoc.network.get(url))
        else:
            self.webview.load(url)

    def slotUnsupported(self, reply):
        helpers.openUrl(reply.url())

    def slotSearchChanged(self):
        text = self.search.text()
        if not text.startswith(':'):
            self.webview.page().findText(text,
                                         QWebPage.FindWrapsAroundDocument)

    def slotSearchReturnPressed(self):
        text = self.search.text()
        if not text.startswith(':'):
            self.slotSearchChanged()
        else:
            pass  # TODO: implement full doc search

    def sourceViewer(self):
        try:
            return self._sourceviewer
        except AttributeError:
            from . import sourceviewer
            self._sourceviewer = sourceviewer.SourceViewer(self)
            return self._sourceviewer

    def showHomePage(self):
        """Shows the homepage of the LilyPond documentation."""
        i = self.chooser.currentIndex()
        if i < 0:
            i = 0
        doc = lilydoc.manager.docs()[i]

        url = doc.home()
        if doc.isLocal():
            path = url.toLocalFile()
            langs = lilydoc.network.langs()
            if langs:
                for lang in langs:
                    if os.path.exists(path + '.' + lang + '.html'):
                        path += '.' + lang
                        break
            url = QUrl.fromLocalFile(path + '.html')
        self.webview.load(url)

    def slotPrint(self):
        printer = QPrinter()
        dlg = QPrintDialog(printer, self)
        dlg.setWindowTitle(app.caption(_("Print")))
        if dlg.exec_():
            self.webview.print_(printer)

    def slotShowContextMenu(self, pos):
        hit = self.webview.page().currentFrame().hitTestContent(pos)
        menu = QMenu()
        if hit.linkUrl().isValid():
            a = self.webview.pageAction(QWebPage.CopyLinkToClipboard)
            a.setIcon(icons.get("edit-copy"))
            a.setText(_("Copy &Link"))
            menu.addAction(a)
            menu.addSeparator()
            a = menu.addAction(icons.get("window-new"),
                               _("Open Link in &New Window"))
            a.triggered.connect(
                (lambda url: lambda: self.slotNewWindow(url))(hit.linkUrl()))
        else:
            if hit.isContentSelected():
                a = self.webview.pageAction(QWebPage.Copy)
                a.setIcon(icons.get("edit-copy"))
                a.setText(_("&Copy"))
                menu.addAction(a)
                menu.addSeparator()
            a = menu.addAction(icons.get("window-new"),
                               _("Open Document in &New Window"))
            a.triggered.connect((lambda url: lambda: self.slotNewWindow(url))(
                self.webview.url()))
        if menu.actions():
            menu.exec_(self.webview.mapToGlobal(pos))

    def slotNewWindow(self, url):
        helpers.openUrl(url)
Exemplo n.º 2
0
class Browser(QWidget):
    """LilyPond documentation browser widget."""
    def __init__(self, dockwidget):
        super(Browser, self).__init__(dockwidget)
        
        layout = QVBoxLayout(spacing=0)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)
        
        self.toolbar = tb = QToolBar()
        self.webview = QWebView(contextMenuPolicy=Qt.CustomContextMenu)
        self.chooser = QComboBox(sizeAdjustPolicy=QComboBox.AdjustToContents)
        self.search = SearchEntry(maximumWidth=200)
        
        layout.addWidget(self.toolbar)
        layout.addWidget(self.webview)
        
        ac = dockwidget.actionCollection
        ac.help_back.triggered.connect(self.webview.back)
        ac.help_forward.triggered.connect(self.webview.forward)
        ac.help_home.triggered.connect(self.showHomePage)
        ac.help_print.triggered.connect(self.slotPrint)
        
        self.webview.page().setNetworkAccessManager(lilydoc.network.accessmanager())
        self.webview.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.webview.page().linkClicked.connect(self.openUrl)
        self.webview.page().setForwardUnsupportedContent(True)
        self.webview.page().unsupportedContent.connect(self.slotUnsupported)
        self.webview.urlChanged.connect(self.slotUrlChanged)
        self.webview.customContextMenuRequested.connect(self.slotShowContextMenu)
        
        tb.addAction(ac.help_back)
        tb.addAction(ac.help_forward)
        tb.addSeparator()
        tb.addAction(ac.help_home)
        tb.addAction(ac.help_print)
        tb.addSeparator()
        tb.addWidget(self.chooser)
        tb.addWidget(self.search)
        
        self.chooser.activated[int].connect(self.showHomePage)
        self.search.textEdited.connect(self.slotSearchChanged)
        self.search.returnPressed.connect(self.slotSearchReturnPressed)
        dockwidget.mainwindow().iconSizeChanged.connect(self.updateToolBarSettings)
        dockwidget.mainwindow().toolButtonStyleChanged.connect(self.updateToolBarSettings)
        
        app.settingsChanged.connect(self.readSettings)
        self.readSettings()
        self.loadDocumentation()
        self.showInitialPage()
        app.settingsChanged.connect(self.loadDocumentation)
        app.translateUI(self)
    
    def readSettings(self):
        s = QSettings()
        s.beginGroup("documentation")
        ws = self.webview.page().settings()
        family = s.value("fontfamily", self.font().family(), type(""))
        size = s.value("fontsize", 16, int)
        ws.setFontFamily(QWebSettings.StandardFont, family)
        ws.setFontSize(QWebSettings.DefaultFontSize, size)
        fixed = textformats.formatData('editor').font
        ws.setFontFamily(QWebSettings.FixedFont, fixed.family())
        ws.setFontSize(QWebSettings.DefaultFixedFontSize, fixed.pointSizeF() * 96 / 72)
        
    def keyPressEvent(self, ev):
        if ev.text() == "/":
            self.search.setFocus()
        else:
            super(Browser, self).keyPressEvent(ev)
        
    def translateUI(self):
        try:
            self.search.setPlaceholderText(_("Search..."))
        except AttributeError:
            pass # not in Qt 4.6
    
    def showInitialPage(self):
        """Shows the preferred start page.
        
        If a local documentation instance already has a suitable version,
        just loads it. Otherwise connects to the allLoaded signal, that is
        emitted when all the documentation instances have loaded their version
        information and then shows the start page (if another page wasn't yet
        loaded).
        
        """
        if self.webview.url().isEmpty():
            docs = lilydoc.manager.docs()
            version = lilypondinfo.preferred().version()
            index = -1
            if version:
                for num, doc in enumerate(docs):
                    if doc.version() is not None and doc.version() >= version:
                        index = num # a suitable documentation is found
                        break
            if index == -1:
                # nothing found (or LilyPond version not available),
                # wait for loading or show the most recent version
                if not lilydoc.manager.loaded():
                    lilydoc.manager.allLoaded.connect(self.showInitialPage)
                    return
                index = len(docs) - 1
            self.chooser.setCurrentIndex(index)
            self.showHomePage()
    
    def loadDocumentation(self):
        """Puts the available documentation instances in the combobox."""
        i = self.chooser.currentIndex()
        self.chooser.clear()
        for doc in lilydoc.manager.docs():
            v = doc.versionString()
            if doc.isLocal():
                t = _("(local)")
            else:
                t = _("({hostname})").format(hostname=doc.url().host())
            self.chooser.addItem("{0} {1}".format(v or _("<unknown>"), t))
        self.chooser.setCurrentIndex(i)
        if not lilydoc.manager.loaded():
            lilydoc.manager.allLoaded.connect(self.loadDocumentation, -1)
            return
        
    def updateToolBarSettings(self):
        mainwin = self.parentWidget().mainwindow()
        self.toolbar.setIconSize(mainwin.iconSize())
        self.toolbar.setToolButtonStyle(mainwin.toolButtonStyle())
        
    def showManual(self):
        """Invoked when the user presses F1."""
        self.slotHomeFrescobaldi() # TEMP
        
    def slotUrlChanged(self):
        ac = self.parentWidget().actionCollection
        ac.help_back.setEnabled(self.webview.history().canGoBack())
        ac.help_forward.setEnabled(self.webview.history().canGoForward())
    
    def openUrl(self, url):
        if url.path().endswith(('.ily', '.lyi', '.ly')):
            self.sourceViewer().showReply(lilydoc.network.get(url))
        else:
            self.webview.load(url)
    
    def slotUnsupported(self, reply):
        helpers.openUrl(reply.url())
    
    def slotSearchChanged(self):
        text = self.search.text()
        if not text.startswith(':'):
            self.webview.page().findText(text, QWebPage.FindWrapsAroundDocument)
    
    def slotSearchReturnPressed(self):
        text = self.search.text()
        if not text.startswith(':'):
            self.slotSearchChanged()
        else:
            pass # TODO: implement full doc search
    
    def sourceViewer(self):
        try:
            return self._sourceviewer
        except AttributeError:
            from . import sourceviewer
            self._sourceviewer = sourceviewer.SourceViewer(self)
            return self._sourceviewer
    
    def showHomePage(self):
        """Shows the homepage of the LilyPond documentation."""
        i = self.chooser.currentIndex()
        if i < 0:
            i = 0
        doc = lilydoc.manager.docs()[i]
        
        url = doc.home()
        if doc.isLocal():
            path = url.toLocalFile()
            langs = lilydoc.network.langs()
            if langs:
                for lang in langs:
                    if os.path.exists(path + '.' + lang + '.html'):
                        path += '.' + lang
                        break
            url = QUrl.fromLocalFile(path + '.html')
        self.webview.load(url)
    
    def slotPrint(self):
        printer = QPrinter()
        dlg = QPrintDialog(printer, self)
        dlg.setWindowTitle(app.caption(_("Print")))
        if dlg.exec_():
            self.webview.print_(printer)
    
    def slotShowContextMenu(self, pos):
        hit = self.webview.page().currentFrame().hitTestContent(pos)
        menu = QMenu()
        if hit.linkUrl().isValid():
            a = self.webview.pageAction(QWebPage.CopyLinkToClipboard)
            a.setIcon(icons.get("edit-copy"))
            a.setText(_("Copy &Link"))
            menu.addAction(a)
            menu.addSeparator()
            a = menu.addAction(icons.get("window-new"), _("Open Link in &New Window"))
            a.triggered.connect((lambda url: lambda: self.slotNewWindow(url))(hit.linkUrl()))
        else:
            if hit.isContentSelected():
                a = self.webview.pageAction(QWebPage.Copy)
                a.setIcon(icons.get("edit-copy"))
                a.setText(_("&Copy"))
                menu.addAction(a)
                menu.addSeparator()
            a = menu.addAction(icons.get("window-new"), _("Open Document in &New Window"))
            a.triggered.connect((lambda url: lambda: self.slotNewWindow(url))(self.webview.url()))
        if menu.actions():
            menu.exec_(self.webview.mapToGlobal(pos))
    
    def slotNewWindow(self, url):
        helpers.openUrl(url)
Exemplo n.º 3
0
class Browser(QFrame):

    # =======================================================================
    def __init__(self, parent=None, _PARENT=None):

        # -------------------------------------------------------------------
        QFrame.__init__(self, parent)

        _SIZE = [3, 5, 975, 585]

        self.setGeometry(_SIZE[0], _SIZE[1], _SIZE[2], _SIZE[3])
        self.PARENT = _PARENT
        self.CONF = _PARENT.CONF

        self.setStyleSheet(
            "QFrame{ font: 12px 'monospace'; color: #000; background-color: transparent; background-image: url('./data/imgs/TAB_Browser.png'); }"
        )

        # -------------------------------------------------------------------
        self.BROWSER = QWebView(self)
        self.BROWSER.setGeometry(6, 83, 963, 500)
        self.BROWSER.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        #self.BROWSER.loadFinished.connect( self.on_loadFinished );

        self.connect(self.BROWSER.page(), SIGNAL('linkClicked (QUrl)'),
                     self.LINK_CLICKED)
        self.connect(self.BROWSER.page(), SIGNAL('loadProgress (int)'),
                     self.PAGE_LOADPROGRESS)
        # void linkHovered (const QString&,const QString&,const QString&)
        self.connect(self.BROWSER.page(),
                     SIGNAL('linkHovered (QString, QString, QString)'),
                     self.LINK_HOVERED)

        #self.BROWSER.load(QUrl.fromUserInput(sys.argv[1]))

        # -------------------------------------------------------------------
        self.HISTORY = []
        # -------------------------------------------------------------------
        # CONTROLS

        # BACK
        self.CONTROL_BACK_BTN = QPushButton("", self)
        self.CONTROL_BACK_BTN.setGeometry(11, 15, 43, 34)
        self.CONTROL_BACK_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_BACK_BTN, SIGNAL('clicked()'),
                     self.BROWSER.back)

        # STOP
        self.CONTROL_STOP_BTN = QPushButton("", self)
        self.CONTROL_STOP_BTN.setGeometry(55, 15, 49, 34)
        self.CONTROL_STOP_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_STOP_BTN, SIGNAL('clicked()'),
                     self.BROWSER.stop)

        # RELOAD
        self.CONTROL_RELOAD_BTN = QPushButton("", self)
        self.CONTROL_RELOAD_BTN.setGeometry(105, 15, 52, 34)
        self.CONTROL_RELOAD_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_RELOAD_BTN, SIGNAL('clicked()'),
                     self.BROWSER.reload)

        # FOREWARDE
        self.CONTROL_FOREWARDE_BTN = QPushButton("", self)
        self.CONTROL_FOREWARDE_BTN.setGeometry(158, 15, 43, 34)
        self.CONTROL_FOREWARDE_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_FOREWARDE_BTN, SIGNAL('clicked()'),
                     self.BROWSER.forward)

        # URL-BAR
        self.URL_BAR = QLineEdit(
            "tradingview.com/chart/BNC1/BLX/YFDnalUh-The-Road-to-Obsolescence-A-Seven-Year-Cycle-in-Bitcoin/, https://www.bitstamp.net/, https://blockchain.info/charts/market-cap/",
            self)
        self.URL_BAR.setGeometry(6, 55, 950, 27)
        self.URL_BAR.setPlaceholderText(
            "bitstamp.net, blockchain.info/charts/market-cap/")
        self.URL_BAR.setStyleSheet(
            "QLineEdit{ background-color: #222; color: #fff; padding-left: 10px; border-style: none; }"
        )
        self.connect(self.URL_BAR, SIGNAL('returnPressed ()'), self.GO_TO)

        # CALENDER
        self.CONTROL_CALENDER_BTN = QPushButton("", self)
        self.CONTROL_CALENDER_BTN.setGeometry(769, 15, 43, 34)
        self.CONTROL_CALENDER_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_CALENDER_BTN, SIGNAL('clicked()'),
                     self.GET_CALENDER)

        # BC-E HOME
        self.BTCE_HOME_LNK = "https://btc-e.com/exchange/ltc_usd"
        self.CONTROL_BTCE_HOME_BTN = QPushButton("", self)
        self.CONTROL_BTCE_HOME_BTN.setGeometry(812, 15, 49, 34)
        self.CONTROL_BTCE_HOME_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_BTCE_HOME_BTN, SIGNAL('clicked()'),
                     lambda: self.BROWSER.load(QUrl(self.BTCE_HOME_LNK)))

        # BLOCKCHAIN
        self.BLOCKCHAIN_LNK = "https://blockchain.info/charts/market-cap/?showDataPoints=true&timespan=30days&show_header=false&daysAverageString=7&scale=1&address="
        self.CONTROL_BLOCKCHAIN_BTN = QPushButton("", self)
        self.CONTROL_BLOCKCHAIN_BTN.setGeometry(862, 15, 53, 34)
        self.CONTROL_BLOCKCHAIN_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_BLOCKCHAIN_BTN, SIGNAL('clicked()'),
                     lambda: self.BROWSER.load(QUrl(self.BLOCKCHAIN_LNK)))

        # GOOGLE
        self.GOOGLE_LNK = "https://google.com/"
        self.CONTROL_GOOGLE_BTN = QPushButton("", self)
        self.CONTROL_GOOGLE_BTN.setGeometry(913, 15, 43, 34)
        self.CONTROL_GOOGLE_BTN.setStyleSheet(
            "QPushButton{ background-color: transparent; border-style: none; }"
        )
        self.connect(self.CONTROL_GOOGLE_BTN, SIGNAL('clicked()'),
                     lambda: self.BROWSER.load(QUrl(self.GOOGLE_LNK)))

        # STATUS-BAR
        self.STATUS_BAR = QLineEdit("status-bar", self)
        self.STATUS_BAR.setGeometry(6, 585 - 27, 950, 27)
        self.STATUS_BAR.setStyleSheet(
            "QLineEdit{ background-color: #333; color: #fff; padding-left: 10px; border-style: none; }"
        )

        # -------------------------------------------------------------------
        self.setMouseTracking(True)

        self.MOUSE_X = 0
        self.MOUSE_Y = 0

        #self.load(QUrl('https://www.bitstamp.net/market/tradeview/'))
        #self.load(QUrl('https://www.bitstamp.net/'))
        #self.load(QUrl('https://btc-e.com/'))
        #self.BROWSER.load(QUrl('https://google.com/'))

        # -------------------------------------------------------------------
        self.INTI()
        # -------------------------------------------------------------------

    # =======================================================================
    def INTI(self):

        # -------------------------------------------------------------------
        #self.GET_CALENDER();
        pass
        # -------------------------------------------------------------------

    # =======================================================================
    def PAGE_LOADPROGRESS(self, _int_pr):

        # -------------------------------------------------------------------
        #loadProgress (int)
        #print(_int_pr);
        pass
        # -------------------------------------------------------------------

    # =======================================================================
    def LINK_HOVERED(self, _link):

        # -------------------------------------------------------------------
        self.STATUS_BAR.setText(_link)
        print(_link)
        # -------------------------------------------------------------------

    # =======================================================================
    def LINK_CLICKED(self, _link):

        # -------------------------------------------------------------------
        _link = str(_link.toString())
        self.HISTORY.append(_link)
        self.URL_BAR.setText(_link)
        # -------------------------------------------------------------------

    # =======================================================================
    def GET_CALENDER(self):

        # -------------------------------------------------------------------
        style = "ecoDayBackground=%23000000&"
        style += "defaultFont=%23333333&"
        style += "innerBorderColor=%2300FF00&"
        style += "borderColor=%23000000&"
        style += "ecoDayFontColor=%23FFFFFF&"

        self.MACRO_CALENDER_DATA = """
            <!DOCTYPE html>
            <html lang="en-US">
            <!-- =============================================================================== -->
            <head>

                <!-- ............................................. -->
                <meta charset="utf-8"/>
                <title>Экономический онлайн-календарь</title>

                <!--
                <link rel="stylesheet" type="text/css" href="css/ids.css">
                <script type="text/javascript" src="js/temax-main.js"></script>
                -->
                <script type="text/javascript">

                    window.addEventListener("load", function(){  

                        //alert("Yes we can");

                    });


                </script>

            </head>
            <!-- =============================================================================== -->
            <body>

                <iframe src="http://ec.ru.forexprostools.com?""" + style + """columns=exc_flags,exc_currency,exc_importance,exc_actual,exc_forecast,exc_previous&features=datepicker,timezone&countries=25,4,17,39,72,26,10,6,37,97,96,43,56,36,5,61,22,12,89,110,35&calType=week&timeZone=58&lang=7" width="943" height="450" frameborder="0" allowtransparency="true" marginwidth="0" marginheight="0"> <a href="http://google.com">GOOGLE</a> </iframe>
                <div class="poweredBy" style="font-family: Arial, Helvetica, sans-serif;">
                    <span style="font-size: 11px;color: #333333;text-decoration: none;">
                        <a href="http://ru.investing.com/" rel="nofollow" target="_blank" style="font-size: 11px;color: #06529D; font-weight: bold;" class="underline_link">Investing.com</a>
                    </span>
                </div>

            </body>
            <!-- =============================================================================== -->
            </html>
        """

        self.BROWSER.setHtml(self.MACRO_CALENDER_DATA)
        # -------------------------------------------------------------------

    # =======================================================================
    def AA(self):

        # -------------------------------------------------------------------
        self.BROWSER.stop()
        self.BROWSER.reload()
        #self.BROWSER.print();

        self.BROWSER.back()
        self.BROWSER.forward()
        #QWebHistory self.BROWSER.history();

        # -------------------------------------------------------------------
        self.BROWSER.history()
        # -------------------------------------------------------------------

    # =======================================================================
    def GO_TO(self):

        # -------------------------------------------------------------------
        self.BROWSER.load(QUrl(str(self.URL_BAR.text()).strip()))
        self.update()
        # -------------------------------------------------------------------
        #print( self.BROWSER.history() );
        # -------------------------------------------------------------------

    # =======================================================================
    @pyqtSlot(str)
    def showMessage(self, message):

        # -------------------------------------------------------------------
        print "Message from website:", message
        # -------------------------------------------------------------------

    # =======================================================================
    @pyqtSlot()
    def on_loadFinished(self):

        # -------------------------------------------------------------------
        pass
Exemplo n.º 4
0
class Browser(QFrame):

    # =======================================================================
    def __init__(self, parent=None, _PARENT=None):

        # -------------------------------------------------------------------
        QFrame.__init__(self, parent);

        _SIZE                               = [3, 5, 975, 585];

        self.setGeometry( _SIZE[0], _SIZE[1], _SIZE[2], _SIZE[3] );
        self.PARENT                         = _PARENT;
        self.CONF                           = _PARENT.CONF;

        self.setStyleSheet( "QFrame{ font: 12px 'monospace'; color: #000; background-color: transparent; background-image: url('./data/imgs/TAB_Browser.png'); }" );

        # -------------------------------------------------------------------
        self.BROWSER                    = QWebView(self);
        self.BROWSER.setGeometry(6, 83, 963, 500);
        self.BROWSER.page().setLinkDelegationPolicy( QWebPage.DelegateAllLinks );
        #self.BROWSER.loadFinished.connect( self.on_loadFinished );

        self.connect( self.BROWSER.page(), SIGNAL('linkClicked (QUrl)'), self.LINK_CLICKED );
        self.connect( self.BROWSER.page(), SIGNAL('loadProgress (int)'), self.PAGE_LOADPROGRESS );
        # void linkHovered (const QString&,const QString&,const QString&)
        self.connect( self.BROWSER.page(), SIGNAL('linkHovered (QString, QString, QString)'), self.LINK_HOVERED );


        #self.BROWSER.load(QUrl.fromUserInput(sys.argv[1]))

        # -------------------------------------------------------------------
        self.HISTORY                        = [];
        # -------------------------------------------------------------------
        # CONTROLS

        # BACK
        self.CONTROL_BACK_BTN               = QPushButton("", self);
        self.CONTROL_BACK_BTN.setGeometry(11, 15, 43, 34);
        self.CONTROL_BACK_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_BACK_BTN, SIGNAL('clicked()') , self.BROWSER.back );

        # STOP
        self.CONTROL_STOP_BTN               = QPushButton("", self);
        self.CONTROL_STOP_BTN.setGeometry(55, 15, 49, 34);
        self.CONTROL_STOP_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_STOP_BTN, SIGNAL('clicked()') , self.BROWSER.stop );

        # RELOAD
        self.CONTROL_RELOAD_BTN             = QPushButton("", self);
        self.CONTROL_RELOAD_BTN.setGeometry(105, 15, 52, 34);
        self.CONTROL_RELOAD_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_RELOAD_BTN, SIGNAL('clicked()') , self.BROWSER.reload );

        # FOREWARDE
        self.CONTROL_FOREWARDE_BTN          = QPushButton("", self);
        self.CONTROL_FOREWARDE_BTN.setGeometry(158, 15, 43, 34);
        self.CONTROL_FOREWARDE_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_FOREWARDE_BTN, SIGNAL('clicked()') , self.BROWSER.forward );
        
        # URL-BAR
        self.URL_BAR                        = QLineEdit("tradingview.com/chart/BNC1/BLX/YFDnalUh-The-Road-to-Obsolescence-A-Seven-Year-Cycle-in-Bitcoin/, https://www.bitstamp.net/, https://blockchain.info/charts/market-cap/", self); 
        self.URL_BAR.setGeometry(6, 55, 950, 27);
        self.URL_BAR.setPlaceholderText("bitstamp.net, blockchain.info/charts/market-cap/");
        self.URL_BAR.setStyleSheet("QLineEdit{ background-color: #222; color: #fff; padding-left: 10px; border-style: none; }");
        self.connect( self.URL_BAR, SIGNAL('returnPressed ()') , self.GO_TO );

        # CALENDER
        self.CONTROL_CALENDER_BTN           = QPushButton("", self);
        self.CONTROL_CALENDER_BTN.setGeometry(769, 15, 43, 34);
        self.CONTROL_CALENDER_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_CALENDER_BTN, SIGNAL('clicked()') , self.GET_CALENDER );

        # BC-E HOME
        self.BTCE_HOME_LNK                  = "https://btc-e.com/exchange/ltc_usd";
        self.CONTROL_BTCE_HOME_BTN          = QPushButton("", self);
        self.CONTROL_BTCE_HOME_BTN.setGeometry(812, 15, 49, 34);
        self.CONTROL_BTCE_HOME_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_BTCE_HOME_BTN, SIGNAL('clicked()') , lambda: self.BROWSER.load( QUrl( self.BTCE_HOME_LNK )) );

        # BLOCKCHAIN
        self.BLOCKCHAIN_LNK                 = "https://blockchain.info/charts/market-cap/?showDataPoints=true&timespan=30days&show_header=false&daysAverageString=7&scale=1&address="; 
        self.CONTROL_BLOCKCHAIN_BTN         = QPushButton("", self);
        self.CONTROL_BLOCKCHAIN_BTN.setGeometry(862, 15, 53, 34);
        self.CONTROL_BLOCKCHAIN_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_BLOCKCHAIN_BTN, SIGNAL('clicked()') , lambda: self.BROWSER.load( QUrl( self.BLOCKCHAIN_LNK )) );

        # GOOGLE
        self.GOOGLE_LNK                     = "https://google.com/";
        self.CONTROL_GOOGLE_BTN             = QPushButton("", self);
        self.CONTROL_GOOGLE_BTN.setGeometry(913, 15, 43, 34);
        self.CONTROL_GOOGLE_BTN.setStyleSheet("QPushButton{ background-color: transparent; border-style: none; }")
        self.connect( self.CONTROL_GOOGLE_BTN, SIGNAL('clicked()') , lambda: self.BROWSER.load( QUrl( self.GOOGLE_LNK )) );


        # STATUS-BAR
        self.STATUS_BAR                      = QLineEdit("status-bar", self); 
        self.STATUS_BAR.setGeometry(6, 585-27, 950, 27);
        self.STATUS_BAR.setStyleSheet("QLineEdit{ background-color: #333; color: #fff; padding-left: 10px; border-style: none; }");
        
        # -------------------------------------------------------------------
        self.setMouseTracking(True);
        
        self.MOUSE_X                        = 0; 
        self.MOUSE_Y                        = 0; 


        #self.load(QUrl('https://www.bitstamp.net/market/tradeview/'))
        #self.load(QUrl('https://www.bitstamp.net/'))
        #self.load(QUrl('https://btc-e.com/'))
        #self.BROWSER.load(QUrl('https://google.com/'))

        # -------------------------------------------------------------------
        self.INTI();
        # -------------------------------------------------------------------
        

    # =======================================================================
    def INTI(self):

        # -------------------------------------------------------------------
        #self.GET_CALENDER();
        pass;
        # -------------------------------------------------------------------


    # =======================================================================
    def PAGE_LOADPROGRESS(self, _int_pr):

        # -------------------------------------------------------------------
        #loadProgress (int)
        #print(_int_pr);
        pass;
        # -------------------------------------------------------------------

    # =======================================================================
    def LINK_HOVERED(self, _link):

        # -------------------------------------------------------------------
        self.STATUS_BAR.setText( _link );
        print(_link);
        # -------------------------------------------------------------------

    # =======================================================================
    def LINK_CLICKED(self, _link):

        # -------------------------------------------------------------------
        _link = str(_link.toString());
        self.HISTORY.append( _link );
        self.URL_BAR.setText( _link );
        # -------------------------------------------------------------------

    # =======================================================================
    def GET_CALENDER(self):

        # -------------------------------------------------------------------
        style = "ecoDayBackground=%23000000&"
        style += "defaultFont=%23333333&";
        style += "innerBorderColor=%2300FF00&";
        style += "borderColor=%23000000&";
        style += "ecoDayFontColor=%23FFFFFF&";

        self.MACRO_CALENDER_DATA = """
            <!DOCTYPE html>
            <html lang="en-US">
            <!-- =============================================================================== -->
            <head>

                <!-- ............................................. -->
                <meta charset="utf-8"/>
                <title>Экономический онлайн-календарь</title>

                <!--
                <link rel="stylesheet" type="text/css" href="css/ids.css">
                <script type="text/javascript" src="js/temax-main.js"></script>
                -->
                <script type="text/javascript">

                    window.addEventListener("load", function(){  

                        //alert("Yes we can");

                    });


                </script>

            </head>
            <!-- =============================================================================== -->
            <body>

                <iframe src="http://ec.ru.forexprostools.com?"""+style+"""columns=exc_flags,exc_currency,exc_importance,exc_actual,exc_forecast,exc_previous&features=datepicker,timezone&countries=25,4,17,39,72,26,10,6,37,97,96,43,56,36,5,61,22,12,89,110,35&calType=week&timeZone=58&lang=7" width="943" height="450" frameborder="0" allowtransparency="true" marginwidth="0" marginheight="0"> <a href="http://google.com">GOOGLE</a> </iframe>
                <div class="poweredBy" style="font-family: Arial, Helvetica, sans-serif;">
                    <span style="font-size: 11px;color: #333333;text-decoration: none;">
                        <a href="http://ru.investing.com/" rel="nofollow" target="_blank" style="font-size: 11px;color: #06529D; font-weight: bold;" class="underline_link">Investing.com</a>
                    </span>
                </div>

            </body>
            <!-- =============================================================================== -->
            </html>
        """

        self.BROWSER.setHtml( self.MACRO_CALENDER_DATA );
        # -------------------------------------------------------------------

    # =======================================================================
    def AA(self):

        # -------------------------------------------------------------------
        self.BROWSER.stop();
        self.BROWSER.reload();
        #self.BROWSER.print();

        self.BROWSER.back();
        self.BROWSER.forward();
        #QWebHistory self.BROWSER.history();

        # -------------------------------------------------------------------
        self.BROWSER.history()
        # -------------------------------------------------------------------

    # =======================================================================
    def GO_TO(self):

        # -------------------------------------------------------------------
        self.BROWSER.load(QUrl( str(self.URL_BAR.text()).strip() ));
        self.update();
        # -------------------------------------------------------------------
        #print( self.BROWSER.history() );
        # -------------------------------------------------------------------
    # =======================================================================
    @pyqtSlot(str)  
    def showMessage(self, message):

        # -------------------------------------------------------------------
        print "Message from website:", message
        # -------------------------------------------------------------------

    # =======================================================================
    @pyqtSlot()
    def on_loadFinished(self):

        # -------------------------------------------------------------------
        pass;