예제 #1
0
    def __init__(self, parentWidget, settings):
        QWidget.__init__(self, parentWidget)

        self.settings = settings
        self.theLayout = QHBoxLayout()
        self.splitter = QSplitter(self)
        self.theLayout.addWidget(self.splitter)

        self.browserWidget = BrowserWidget(self, self.settings)
        self.browserWidget.itemSelected.connect(self.itemSelected)

        self.tabWidget = QTabWidget(self)

        tab = QWidget()

        tabLayout = QVBoxLayout(tab)
        tab.setLayout(tabLayout)

        self.editorWidget = EditorWidget(tab)

        self.editorWidget.setObjectName("EditorWidget1")
        self.editorWidget.message.connect(self.showMessage)
        self.editorWidget.titleChanged.connect(self.updateWindowTitle)
        self.editorWidget.navigate.connect(self.navigate)

        tabLayout.addWidget(self.editorWidget)
        self.editTabIdx = self.tabWidget.addTab(tab, "Edit")
#############################

        self.browser = QWebView(self.tabWidget)
        self.browser.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.browser.linkClicked.connect(self.navigateWeb)
        self.webTabIdx = self.tabWidget.addTab(self.browser, "View web")

        self.pdfTabIdx = self.tabWidget.addTab(QWidget(self.tabWidget), "View pdf")

        self.textView = QTextEdit(self.tabWidget)
        self.textView.setReadOnly(True)
        self.textView.setFontFamily('Courier')
        self.textView.setFontPointSize(8)
        self.structureTabIdx = self.tabWidget.addTab(self.textView, "View document structure")

        self.customView = QTextEdit(self.tabWidget)
        self.customView.setReadOnly(True)
        self.customView.setFontFamily('Courier')
        self.customView.setFontPointSize(10)
        self.xmlTabIdx = self.tabWidget.addTab(self.customView, "View XML")

        self.htmlView = QTextEdit(self.tabWidget)
        self.htmlView.setReadOnly(True)
        self.htmlView.setFontFamily('Courier')
        self.htmlView.setFontPointSize(10)
        self.htmlTabIdx = self.tabWidget.addTab(self.htmlView, "View Html")

        self.tabWidget.currentChanged.connect(self.tabSelected)

# Search/Links widget in lower left corner ####################################
        self.searchWidget = SearchWidget(self)
        self.searchWidget.resultSelected.connect(self.navigateDirect)

        self.toLinksWidget = LinklistWidget(self)
        self.toLinksWidget.resultSelected.connect(self.navigateDirect)

        self.fromLinksWidget = LinklistWidget(self)
        self.fromLinksWidget.resultSelected.connect(self.navigateDirect)

        self.listsWidget = QTabWidget(self)
        self.listsWidget.addTab(self.searchWidget, 'Search')
        self.listsWidget.addTab(self.toLinksWidget, 'Links to')
        self.listsWidget.addTab(self.fromLinksWidget, 'Links from')
###############################################################################

        leftWidget = QSplitter(Qt.Vertical, self)
        leftWidget.addWidget(self.browserWidget)
        leftWidget.addWidget(self.listsWidget)

        self.splitter.addWidget(leftWidget)
        self.splitter.addWidget(self.tabWidget)
        leftWidget.setSizes([400, 100])             # TODO

        self.setLayout(self.theLayout)
        self.splitter.setSizes([100, 400])          # TODO
        # self.splitter.setChildrenCollapsible(False)
        self.editorWidget.setEnabled(False)
예제 #2
0
    def __init__(self, parentWidget, settings):
        QWidget.__init__(self, parentWidget)

        self.settings = settings
        self.theLayout = QHBoxLayout()
        self.splitter = QSplitter(self)
        self.theLayout.addWidget(self.splitter)

        self.browserWidget = BrowserWidget(self, self.settings)
        self.browserWidget.itemSelected.connect(self.itemSelected)

        self.tabWidget = QTabWidget(self)

        tab = QWidget()

        tabLayout = QVBoxLayout(tab)
        tab.setLayout(tabLayout)

        self.editorWidget = EditorWidget(tab)

        self.editorWidget.setObjectName("EditorWidget1")
        self.editorWidget.message.connect(self.showMessage)
        self.editorWidget.titleChanged.connect(self.updateWindowTitle)
        self.editorWidget.navigate.connect(self.navigate)

        tabLayout.addWidget(self.editorWidget)
        self.editTabIdx = self.tabWidget.addTab(tab, "Edit")
        #############################

        self.browser = QWebView(self.tabWidget)
        self.browser.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.browser.linkClicked.connect(self.navigateWeb)
        self.webTabIdx = self.tabWidget.addTab(self.browser, "View web")

        self.pdfTabIdx = self.tabWidget.addTab(QWidget(self.tabWidget),
                                               "View pdf")

        self.textView = QTextEdit(self.tabWidget)
        self.textView.setReadOnly(True)
        self.textView.setFontFamily('Courier')
        self.textView.setFontPointSize(8)
        self.structureTabIdx = self.tabWidget.addTab(
            self.textView, "View document structure")

        self.customView = QTextEdit(self.tabWidget)
        self.customView.setReadOnly(True)
        self.customView.setFontFamily('Courier')
        self.customView.setFontPointSize(10)
        self.xmlTabIdx = self.tabWidget.addTab(self.customView, "View XML")

        self.htmlView = QTextEdit(self.tabWidget)
        self.htmlView.setReadOnly(True)
        self.htmlView.setFontFamily('Courier')
        self.htmlView.setFontPointSize(10)
        self.htmlTabIdx = self.tabWidget.addTab(self.htmlView, "View Html")

        self.tabWidget.currentChanged.connect(self.tabSelected)

        # Search/Links widget in lower left corner ####################################
        self.searchWidget = SearchWidget(self)
        self.searchWidget.resultSelected.connect(self.navigateDirect)

        self.toLinksWidget = LinklistWidget(self)
        self.toLinksWidget.resultSelected.connect(self.navigateDirect)

        self.fromLinksWidget = LinklistWidget(self)
        self.fromLinksWidget.resultSelected.connect(self.navigateDirect)

        self.listsWidget = QTabWidget(self)
        self.listsWidget.addTab(self.searchWidget, 'Search')
        self.listsWidget.addTab(self.toLinksWidget, 'Links to')
        self.listsWidget.addTab(self.fromLinksWidget, 'Links from')
        ###############################################################################

        leftWidget = QSplitter(Qt.Vertical, self)
        leftWidget.addWidget(self.browserWidget)
        leftWidget.addWidget(self.listsWidget)

        self.splitter.addWidget(leftWidget)
        self.splitter.addWidget(self.tabWidget)
        leftWidget.setSizes([400, 100])  # TODO

        self.setLayout(self.theLayout)
        self.splitter.setSizes([100, 400])  # TODO
        # self.splitter.setChildrenCollapsible(False)
        self.editorWidget.setEnabled(False)
예제 #3
0
class CentralWidget(QWidget):

    l = logging.getLogger('CentralWidget')

    updateWindowTitle = pyqtSignal(str)

    def __init__(self, parentWidget, settings):
        QWidget.__init__(self, parentWidget)

        self.settings = settings
        self.theLayout = QHBoxLayout()
        self.splitter = QSplitter(self)
        self.theLayout.addWidget(self.splitter)

        self.browserWidget = BrowserWidget(self, self.settings)
        self.browserWidget.itemSelected.connect(self.itemSelected)

        self.tabWidget = QTabWidget(self)

        tab = QWidget()

        tabLayout = QVBoxLayout(tab)
        tab.setLayout(tabLayout)

        self.editorWidget = EditorWidget(tab)

        self.editorWidget.setObjectName("EditorWidget1")
        self.editorWidget.message.connect(self.showMessage)
        self.editorWidget.titleChanged.connect(self.updateWindowTitle)
        self.editorWidget.navigate.connect(self.navigate)

        tabLayout.addWidget(self.editorWidget)
        self.editTabIdx = self.tabWidget.addTab(tab, "Edit")
#############################

        self.browser = QWebView(self.tabWidget)
        self.browser.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.browser.linkClicked.connect(self.navigateWeb)
        self.webTabIdx = self.tabWidget.addTab(self.browser, "View web")

        self.pdfTabIdx = self.tabWidget.addTab(QWidget(self.tabWidget), "View pdf")

        self.textView = QTextEdit(self.tabWidget)
        self.textView.setReadOnly(True)
        self.textView.setFontFamily('Courier')
        self.textView.setFontPointSize(8)
        self.structureTabIdx = self.tabWidget.addTab(self.textView, "View document structure")

        self.customView = QTextEdit(self.tabWidget)
        self.customView.setReadOnly(True)
        self.customView.setFontFamily('Courier')
        self.customView.setFontPointSize(10)
        self.xmlTabIdx = self.tabWidget.addTab(self.customView, "View XML")

        self.htmlView = QTextEdit(self.tabWidget)
        self.htmlView.setReadOnly(True)
        self.htmlView.setFontFamily('Courier')
        self.htmlView.setFontPointSize(10)
        self.htmlTabIdx = self.tabWidget.addTab(self.htmlView, "View Html")

        self.tabWidget.currentChanged.connect(self.tabSelected)

# Search/Links widget in lower left corner ####################################
        self.searchWidget = SearchWidget(self)
        self.searchWidget.resultSelected.connect(self.navigateDirect)

        self.toLinksWidget = LinklistWidget(self)
        self.toLinksWidget.resultSelected.connect(self.navigateDirect)

        self.fromLinksWidget = LinklistWidget(self)
        self.fromLinksWidget.resultSelected.connect(self.navigateDirect)

        self.listsWidget = QTabWidget(self)
        self.listsWidget.addTab(self.searchWidget, 'Search')
        self.listsWidget.addTab(self.toLinksWidget, 'Links to')
        self.listsWidget.addTab(self.fromLinksWidget, 'Links from')
###############################################################################

        leftWidget = QSplitter(Qt.Vertical, self)
        leftWidget.addWidget(self.browserWidget)
        leftWidget.addWidget(self.listsWidget)

        self.splitter.addWidget(leftWidget)
        self.splitter.addWidget(self.tabWidget)
        leftWidget.setSizes([400, 100])             # TODO

        self.setLayout(self.theLayout)
        self.splitter.setSizes([100, 400])          # TODO
        # self.splitter.setChildrenCollapsible(False)
        self.editorWidget.setEnabled(False)


    def navigateWeb(self, url):
        if url.scheme() == 'file':
            pageId = url.fileName()
            self.navigate(pageId)
            self.tabSelected(1)
        elif url.scheme() == 'http' or url.scheme() == 'https':
            self.browser.setUrl(url)


    def showMessage(self, message):
        self.parent().statusBar.showMessage(message, 3000)


    def navigate(self, pageId):
        """Assumption: pageId is sub page of current page"""
        self.l.debug('Navigating to sub page "{}"'.format(pageId))

        self.editorWidget.save()
        self.browserWidget.navigate(pageId)        # Will implicitly load the page


    def navigateDirect(self, pageId):
        """Assumption: pageId is NOT sub page of current page. 
        Hence we need to let the browser point to the first occurrence of the page."""
        self.l.debug('Navigating directly to "{}"'.format(pageId))

        self.editorWidget.save()
        self.browserWidget.navigateDirect(pageId)   # Will implicitly load the page


    def itemSelected(self):
        treeNode = self.browserWidget.currentItem
        self.l.debug('Selected tree node: {}'.format(treeNode))

        pageId = treeNode.getPageId()
        notepad = treeNode.getNotepad()

        self.editorWidget.setEnabled(True)
        self.editorWidget.save()
        self.editorWidget.load(notepad, pageId)

        self.updateLinkLists(notepad, pageId)


    def updateLinkLists(self, notepad, pageId):
        
        linksTo = notepad.getChildPages(pageId)
        linksFrom = notepad.getParentPages(pageId)

        self.toLinksWidget.setContents(linksTo)
        self.fromLinksWidget.setContents(linksFrom)


    def tabSelected(self, index):
        if index == self.editTabIdx:
            pass
        elif index == self.webTabIdx:
            self.activateWebView()
        elif index == self.pdfTabIdx:
            pass
        elif index == self.structureTabIdx:
            self.activateStructureView()
        elif index == self.xmlTabIdx:
            self.activateXMLView()
        elif index == self.htmlTabIdx:
            self.activateHTMLView()


    def activateWebView(self):
        exporter = HTMLExporter(self.editorWidget.page.getPageDir())
        self.htmlView.setPlainText(exporter.getHtmlString(self.editorWidget.editView.document()))

        ########### get URL for the stylesheet and for the base URL

        webpageCSS = pkg_resources.resource_string(data.__name__, 'webpage.css')
        print("webpage.css file: {} - {}".format(webpageCSS, type(webpageCSS)))

        mypath = os.getcwd()
        mypath = mypath.replace('\\', '/')
        baseURL = QUrl('file:///{}/'.format(mypath))

        # The location must be either a path on the local filesystem, or a 
        # data URL with UTF-8 and Base64 encoded data, such as:
        # "data:text/css;charset=utf-8;base64,cCB7IGJhY2tncm91bmQtY29sb3I6IHJlZCB9Ow=="
        # BASE64 works on bytes!!
        import base64
        cssData = base64.b64encode(webpageCSS)
        cssData = cssData.decode('utf-8')
        cssDataUrl = 'data:text/css;charset=utf-8;base64,{}'.format(cssData)
        print("webpage.css base64: {}".format(cssDataUrl ))
        # cssDataUrl = QUrl('data:text/css;charset=utf-8;base64,{}'.format(cssData)) # 'file:///{}/webpage.css'.format(mypath))

        ###########

        self.browser.settings().setUserStyleSheetUrl(QUrl(cssDataUrl))

        self.browser.setHtml(self.htmlView.toPlainText(), baseURL)


    def activateStructureView(self):
        self.textView.clear()

        doc = self.editorWidget.editView.document()
        traversal = TextDocumentTraversal()
        tree = traversal.traverse(doc)
        
        sp = StructurePrinter(tree, self.textView.insertPlainText)
        sp.traverse()


    def activateXMLView(self):
        exporter = XMLExporter(self.editorWidget.page.getPageDir(), None)
        self.customView.setPlainText(exporter.getXmlString(self.editorWidget.editView.document()))


    def activateHTMLView(self):
        exporter = HTMLExporter(self.editorWidget.page.getPageDir())
        self.htmlView.setPlainText(exporter.getHtmlString(self.editorWidget.editView.document()))
예제 #4
0
class CentralWidget(QWidget):

    l = logging.getLogger('CentralWidget')

    updateWindowTitle = pyqtSignal(str)

    def __init__(self, parentWidget, settings):
        QWidget.__init__(self, parentWidget)

        self.settings = settings
        self.theLayout = QHBoxLayout()
        self.splitter = QSplitter(self)
        self.theLayout.addWidget(self.splitter)

        self.browserWidget = BrowserWidget(self, self.settings)
        self.browserWidget.itemSelected.connect(self.itemSelected)

        self.tabWidget = QTabWidget(self)

        tab = QWidget()

        tabLayout = QVBoxLayout(tab)
        tab.setLayout(tabLayout)

        self.editorWidget = EditorWidget(tab)

        self.editorWidget.setObjectName("EditorWidget1")
        self.editorWidget.message.connect(self.showMessage)
        self.editorWidget.titleChanged.connect(self.updateWindowTitle)
        self.editorWidget.navigate.connect(self.navigate)

        tabLayout.addWidget(self.editorWidget)
        self.editTabIdx = self.tabWidget.addTab(tab, "Edit")
        #############################

        self.browser = QWebView(self.tabWidget)
        self.browser.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.browser.linkClicked.connect(self.navigateWeb)
        self.webTabIdx = self.tabWidget.addTab(self.browser, "View web")

        self.pdfTabIdx = self.tabWidget.addTab(QWidget(self.tabWidget),
                                               "View pdf")

        self.textView = QTextEdit(self.tabWidget)
        self.textView.setReadOnly(True)
        self.textView.setFontFamily('Courier')
        self.textView.setFontPointSize(8)
        self.structureTabIdx = self.tabWidget.addTab(
            self.textView, "View document structure")

        self.customView = QTextEdit(self.tabWidget)
        self.customView.setReadOnly(True)
        self.customView.setFontFamily('Courier')
        self.customView.setFontPointSize(10)
        self.xmlTabIdx = self.tabWidget.addTab(self.customView, "View XML")

        self.htmlView = QTextEdit(self.tabWidget)
        self.htmlView.setReadOnly(True)
        self.htmlView.setFontFamily('Courier')
        self.htmlView.setFontPointSize(10)
        self.htmlTabIdx = self.tabWidget.addTab(self.htmlView, "View Html")

        self.tabWidget.currentChanged.connect(self.tabSelected)

        # Search/Links widget in lower left corner ####################################
        self.searchWidget = SearchWidget(self)
        self.searchWidget.resultSelected.connect(self.navigateDirect)

        self.toLinksWidget = LinklistWidget(self)
        self.toLinksWidget.resultSelected.connect(self.navigateDirect)

        self.fromLinksWidget = LinklistWidget(self)
        self.fromLinksWidget.resultSelected.connect(self.navigateDirect)

        self.listsWidget = QTabWidget(self)
        self.listsWidget.addTab(self.searchWidget, 'Search')
        self.listsWidget.addTab(self.toLinksWidget, 'Links to')
        self.listsWidget.addTab(self.fromLinksWidget, 'Links from')
        ###############################################################################

        leftWidget = QSplitter(Qt.Vertical, self)
        leftWidget.addWidget(self.browserWidget)
        leftWidget.addWidget(self.listsWidget)

        self.splitter.addWidget(leftWidget)
        self.splitter.addWidget(self.tabWidget)
        leftWidget.setSizes([400, 100])  # TODO

        self.setLayout(self.theLayout)
        self.splitter.setSizes([100, 400])  # TODO
        # self.splitter.setChildrenCollapsible(False)
        self.editorWidget.setEnabled(False)

    def navigateWeb(self, url):
        if url.scheme() == 'file':
            pageId = url.fileName()
            self.navigate(pageId)
            self.tabSelected(1)
        elif url.scheme() == 'http' or url.scheme() == 'https':
            self.browser.setUrl(url)

    def showMessage(self, message):
        self.parent().statusBar.showMessage(message, 3000)

    def navigate(self, pageId):
        """Assumption: pageId is sub page of current page"""
        self.l.debug('Navigating to sub page "{}"'.format(pageId))

        self.editorWidget.save()
        self.browserWidget.navigate(pageId)  # Will implicitly load the page

    def navigateDirect(self, pageId):
        """Assumption: pageId is NOT sub page of current page. 
        Hence we need to let the browser point to the first occurrence of the page."""
        self.l.debug('Navigating directly to "{}"'.format(pageId))

        self.editorWidget.save()
        self.browserWidget.navigateDirect(
            pageId)  # Will implicitly load the page

    def itemSelected(self):
        treeNode = self.browserWidget.currentItem
        self.l.debug('Selected tree node: {}'.format(treeNode))

        pageId = treeNode.getPageId()
        notepad = treeNode.getNotepad()

        self.editorWidget.setEnabled(True)
        self.editorWidget.save()
        self.editorWidget.load(notepad, pageId)

        self.updateLinkLists(notepad, pageId)

    def updateLinkLists(self, notepad, pageId):

        linksTo = notepad.getChildPages(pageId)
        linksFrom = notepad.getParentPages(pageId)

        self.toLinksWidget.setContents(linksTo)
        self.fromLinksWidget.setContents(linksFrom)

    def tabSelected(self, index):
        if index == self.editTabIdx:
            pass
        elif index == self.webTabIdx:
            self.activateWebView()
        elif index == self.pdfTabIdx:
            pass
        elif index == self.structureTabIdx:
            self.activateStructureView()
        elif index == self.xmlTabIdx:
            self.activateXMLView()
        elif index == self.htmlTabIdx:
            self.activateHTMLView()

    def activateWebView(self):
        exporter = HTMLExporter(self.editorWidget.page.getPageDir())
        self.htmlView.setPlainText(
            exporter.getHtmlString(self.editorWidget.editView.document()))

        ########### get URL for the stylesheet and for the base URL

        webpageCSS = pkg_resources.resource_string(data.__name__,
                                                   'webpage.css')
        print("webpage.css file: {} - {}".format(webpageCSS, type(webpageCSS)))

        mypath = os.getcwd()
        mypath = mypath.replace('\\', '/')
        baseURL = QUrl('file:///{}/'.format(mypath))

        # The location must be either a path on the local filesystem, or a
        # data URL with UTF-8 and Base64 encoded data, such as:
        # "data:text/css;charset=utf-8;base64,cCB7IGJhY2tncm91bmQtY29sb3I6IHJlZCB9Ow=="
        # BASE64 works on bytes!!
        import base64
        cssData = base64.b64encode(webpageCSS)
        cssData = cssData.decode('utf-8')
        cssDataUrl = 'data:text/css;charset=utf-8;base64,{}'.format(cssData)
        print("webpage.css base64: {}".format(cssDataUrl))
        # cssDataUrl = QUrl('data:text/css;charset=utf-8;base64,{}'.format(cssData)) # 'file:///{}/webpage.css'.format(mypath))

        ###########

        self.browser.settings().setUserStyleSheetUrl(QUrl(cssDataUrl))

        self.browser.setHtml(self.htmlView.toPlainText(), baseURL)

    def activateStructureView(self):
        self.textView.clear()

        doc = self.editorWidget.editView.document()
        traversal = TextDocumentTraversal()
        tree = traversal.traverse(doc)

        sp = StructurePrinter(tree, self.textView.insertPlainText)
        sp.traverse()

    def activateXMLView(self):
        exporter = XMLExporter(self.editorWidget.page.getPageDir(), None)
        self.customView.setPlainText(
            exporter.getXmlString(self.editorWidget.editView.document()))

    def activateHTMLView(self):
        exporter = HTMLExporter(self.editorWidget.page.getPageDir())
        self.htmlView.setPlainText(
            exporter.getHtmlString(self.editorWidget.editView.document()))