Beispiel #1
0
def testBaseCommon_ReadTextFile(monkeypatch, fncDir, ipsumText):
    """Test the readTextFile function.
    """
    testText = "\n\n".join(ipsumText) + "\n"
    testFile = os.path.join(fncDir, "ipsum.txt")
    writeFile(testFile, testText)

    assert readTextFile(os.path.join(fncDir, "not_a_file.txt")) == ""
    assert readTextFile(testFile) == testText

    with monkeypatch.context() as mp:
        mp.setattr("builtins.open", causeOSError)
        assert readTextFile(testFile) == ""
Beispiel #2
0
 def _fillLicensePage(self):
     """Load the content for the Licence page.
     """
     docPath = os.path.join(self.mainConf.assetPath, "text", "gplv3_en.htm")
     docText = readTextFile(docPath)
     if docText:
         self.pageLicense.setHtml(docText)
     else:
         self.pageLicense.setHtml("Error loading licence text ...")
     return
Beispiel #3
0
 def _fillNotesPage(self):
     """Load the content for the Release Notes page.
     """
     docPath = os.path.join(self.mainConf.assetPath, "text",
                            "release_notes.htm")
     docText = readTextFile(docPath)
     if docText:
         self.pageNotes.setHtml(docText)
     else:
         self.pageNotes.setHtml("Error loading release notes text ...")
     return
Beispiel #4
0
    def _doInsert(self):
        """Load the text and insert it in the open document.
        """
        lipsumFile = os.path.join(self.mainConf.assetPath, "text",
                                  "lipsum.txt")
        lipsumText = readTextFile(lipsumFile).splitlines()

        if self.randSwitch.isChecked():
            random.shuffle(lipsumText)

        pCount = self.paraCount.value()
        inText = "\n\n".join(lipsumText[0:pCount]) + "\n\n"

        self.mainGui.docEditor.insertText(inText)

        return
Beispiel #5
0
    def loadTheme(self):
        """Load the currently specified GUI theme.
        """
        logger.info("Loading GUI theme '%s'", self.guiTheme)

        # Config File
        confParser = NWConfigParser()
        try:
            with open(self.themeFile, mode="r", encoding="utf-8") as inFile:
                confParser.read_file(inFile)
        except Exception:
            logger.error("Could not load theme settings from: %s",
                         self.themeFile)
            logException()
            return False

        # Main
        cnfSec = "Main"
        if confParser.has_section(cnfSec):
            self.themeName = confParser.rdStr(cnfSec, "name", "")
            self.themeDescription = confParser.rdStr(cnfSec, "description",
                                                     "N/A")
            self.themeAuthor = confParser.rdStr(cnfSec, "author", "N/A")
            self.themeCredit = confParser.rdStr(cnfSec, "credit", "N/A")
            self.themeUrl = confParser.rdStr(cnfSec, "url", "")
            self.themeLicense = confParser.rdStr(cnfSec, "license", "N/A")
            self.themeLicenseUrl = confParser.rdStr(cnfSec, "licenseurl", "")

        # Palette
        cnfSec = "Palette"
        if confParser.has_section(cnfSec):
            self._setPalette(confParser, cnfSec, "window", QPalette.Window)
            self._setPalette(confParser, cnfSec, "windowtext",
                             QPalette.WindowText)
            self._setPalette(confParser, cnfSec, "base", QPalette.Base)
            self._setPalette(confParser, cnfSec, "alternatebase",
                             QPalette.AlternateBase)
            self._setPalette(confParser, cnfSec, "text", QPalette.Text)
            self._setPalette(confParser, cnfSec, "tooltipbase",
                             QPalette.ToolTipBase)
            self._setPalette(confParser, cnfSec, "tooltiptext",
                             QPalette.ToolTipText)
            self._setPalette(confParser, cnfSec, "button", QPalette.Button)
            self._setPalette(confParser, cnfSec, "buttontext",
                             QPalette.ButtonText)
            self._setPalette(confParser, cnfSec, "brighttext",
                             QPalette.BrightText)
            self._setPalette(confParser, cnfSec, "highlight",
                             QPalette.Highlight)
            self._setPalette(confParser, cnfSec, "highlightedtext",
                             QPalette.HighlightedText)
            self._setPalette(confParser, cnfSec, "link", QPalette.Link)
            self._setPalette(confParser, cnfSec, "linkvisited",
                             QPalette.LinkVisited)

        # GUI
        cnfSec = "GUI"
        if confParser.has_section(cnfSec):
            self.statNone = self._loadColour(confParser, cnfSec, "statusnone")
            self.statUnsaved = self._loadColour(confParser, cnfSec,
                                                "statusunsaved")
            self.statSaved = self._loadColour(confParser, cnfSec,
                                              "statussaved")

        # CSS File
        cssData = readTextFile(self.cssFile)
        if cssData:
            qApp.setStyleSheet(cssData)

        # Apply Styles
        qApp.setPalette(self._guiPalette)

        return True