Exemplo n.º 1
0
def writeDocumentStart(file, bom, item, font, markup, config):
    title = markedUpFromHtml(item.title, markup, config, keepFonts=True)
    if markup.kind is FileKind.DOCX:
        text = markup.DocumentStart.format(title=title)
    else:
        text = markup.DocumentStart.format(
            version=QApplication.applicationVersion(),
            creator=markup.escape(config.Creator),
            date=datetime.date.today(),
            bom=bom,
            plaintitle=Lib.htmlToPlainText(item.title),
            title=title,
            encoding=markup.Encoding,
            nl="\n",
            stdfont=config.StdFont,
            stdfontsize=config.StdFontSize,
            altfont=config.AltFont,
            monofont=config.MonoFont,
            sectfont=font.family,
            sectfontsize=font.size)
    file.write(text)
    if item.note:
        note = markedUpFromHtml(item.note, markup, config, keepFonts=True)
        file.write(
            markup.Note.format(note=note,
                               nl="\n",
                               family=config.StdFont,
                               size=config.StdFontSize * 2))
Exemplo n.º 2
0
    def about(self):
        widget = QApplication.focusWidget()
        year = datetime.date.today().year
        year = "2015-{}".format(str(year)[-2:]) if year != 2015 else "2015"
        w = self.window.frameGeometry().width()
        h = self.window.frameGeometry().height()
        with Lib.Qt.DisableUI(*self.window.widgets(), forModalDialog=True):
            app = QApplication.applicationName()
            version = QApplication.applicationVersion()
            bits = 64 if IS64BIT else 32
            QMessageBox.about(
                self.window,
                "About — {}".format(QApplication.applicationName()), f"""
<p><b><font color=navy>{app} {version}</font></b></p>
<p><font color=navy>{app} is an easy to learn and use application
for creating, editing, and outputting indexes (e.g., for
books).</font>
</p>
<p>Copyright © Qtrac Ltd {year}. All Rights Reserved.</p>
<p>License:&nbsp;GPLv3.</p>
<hr>
<p>Window size: {w:,}x{h:,}</p>
<p>
Python
{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}/{
bits}-bit<br>
PySide {PySide.__version__}<br>
Qt {qVersion()}<br>
APSW {apsw.apswversion()}<br>
SQLite {apsw.sqlitelibversion()}<br>
{platform.platform()}</p>""")
        Lib.restoreFocus(widget)
Exemplo n.º 3
0
def outputEntries(model, config, prefix, reportProgress):
    markup = _markup(config)
    total = len(model)
    percents = set()
    utc = datetime.datetime.now().isoformat()[:19]
    with Lib.uopen(config.Filename, "wt") as file:
        file.write(
            DOCUMENT_START.format(version=QApplication.applicationVersion(),
                                  utc=utc,
                                  fname0=config.AltFont,
                                  fname1=config.MonoFont))
        fields = []
        indent = 0
        for i, entry in enumerate(
                list(model.entries(
                    entryData=EntryDataKind.ALL_DATA_AND_DATES))):
            percent = int(min(100, i * 100 // total))
            if percent not in percents:  # report every 1% done
                reportProgress("{} {}%".format(prefix, percent))
                percents.add(percent)
            term = _term(entry, markup, config)
            if entry.indent == 0:
                fields = [term]
                indent = 0
            elif entry.indent > indent:
                fields.append(term)
                indent += 1
            else:
                while len(fields) > entry.indent:
                    fields.pop()
                indent = entry.indent
                fields.append(term)
            _writeEntry(file, fields, entry, model, markup, config)
        file.write(DOCUMENT_END)
Exemplo n.º 4
0
Arquivo: Pdf.py Projeto: ra2003/xindex
def output(config, document):
    p = (
        """<p style="font-family: '{family}'; font-size: {size}pt;">""".format(
            family=config.StdFont, size=config.StdFontSize))
    pad = lambda match: p + (int(match.group("level")) * 4 * "&nbsp;")
    doc = QTextDocument()
    doc.setHtml(INDENT_RX.sub(pad, document))
    printer = getattr(config, "Printer", None)
    if printer is None:
        printer = QPrinter(QPrinter.HighResolution)
        printer.setCreator("{} {}".format(QApplication.applicationName(),
                                          QApplication.applicationVersion()))
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOrientation(QPrinter.Portrait)
        settings = QSettings()
        size = PaperSizeKind(
            int(settings.value(Gopt.Key.PaperSize, Gopt.Default.PaperSize)))
        printer.setPaperSize(
            QPrinter.A4 if size is PaperSizeKind.A4 else QPrinter.Letter)
        printer.setOutputFileName(config.Filename)
    doc.print_(printer)
Exemplo n.º 5
0
def main(argv):
    """
    TOWRITE

    :param `argc`: TOWRITE
    :type `argc`: int
    :param `argv`: TOWRITE
    :type `argv`: char
    :rtype: int
    """

    filesToOpen = []  # QStringList filesToOpen;
    filesToCheck = []

    bindings = defaultBindings
    bindings_flag = False
    for arg in argv[1:]:
        if bindings_flag:
            bindings_flag = False
            if not arg in ("pyside", "pyqt4"):
                usage()
            else:
                bindings = arg
        elif arg == "-d" or arg == "--debug":
            pass
        elif arg == "-h" or arg == "--help":
            usage()
        elif arg == "-v" or arg == "--version":
            version()
        elif arg == "-b" or arg == "--bindings":
            bindings_flag = True
        else:
            filesToCheck.append(arg)

    if exitApp:
        return 1

    # make global to all modules
    if bindings == "pyside":
        builtins.PYSIDE = True
        builtins.PYQT4 = False
    elif bindings == "pyqt4":
        builtins.PYSIDE = False
        builtins.PYQT4 = True

    if PYSIDE:
        from PySide.QtScript import QScriptEngine
        if not hasattr(QScriptEngine, "newFunction"):
            raise ImportError(
                'You need a patched version of PySide.\n'
                'see: https://codereview.qt-project.org/112333')

    #--PySide Imports.
    if PYSIDE:
        from PySide.QtCore import QObject, SIGNAL, SLOT, QFile
        from PySide.QtGui import QApplication
    elif PYQT4:
        import sip
        sip.setapi('QString', 2)
        sip.setapi('QVariant', 2)
        from PyQt4.QtCore import QObject, SIGNAL, SLOT, QFile
        from PyQt4.QtGui import QApplication

    from mainwindow import MainWindow

    for file_ in filesToCheck:
        if QFile.exists(file_) and MainWindow.validFileFormat(file_):
            filesToOpen.append(file_)
        else:
            usage()
            break

    if exitApp:
        return 1

    app = QApplication(argv)
    app.setApplicationName(_appName_)
    app.setApplicationVersion(_appVer_)

    mainWin = MainWindow()  # MainWindow* 

    QObject.connect(app, SIGNAL("lastWindowClosed()"), mainWin, SLOT("quit()"))

    mainWin.setWindowTitle(app.applicationName() + " " + app.applicationVersion())
    mainWin.show()

    # NOTE: If openFilesSelected() is called from within the mainWin constructor, slot commands wont work and the window menu will be screwed
    if filesToOpen:  # if(!filesToOpen.isEmpty())
        mainWin.openFilesSelected(filesToOpen)

    # return app.exec_()
    return app.exec_()
Exemplo n.º 6
0
def main(argv):
    """
    TOWRITE

    :param `argc`: TOWRITE
    :type `argc`: int
    :param `argv`: TOWRITE
    :type `argv`: char
    :rtype: int
    """

    filesToOpen = []  # QStringList filesToOpen;
    filesToCheck = []

    bindings = defaultBindings
    bindings_flag = False
    for arg in argv[1:]:
        if bindings_flag:
            bindings_flag = False
            if not arg in ("pyside", "pyqt4"):
                usage()
            else:
                bindings = arg
        elif arg == "-d" or arg == "--debug":
            pass
        elif arg == "-h" or arg == "--help":
            usage()
        elif arg == "-v" or arg == "--version":
            version()
        elif arg == "-b" or arg == "--bindings":
            bindings_flag = True
        else:
            filesToCheck.append(arg)

    if exitApp:
        return 1

    # make global to all modules
    if bindings == "pyside":
        builtins.PYSIDE = True
        builtins.PYQT4 = False
    elif bindings == "pyqt4":
        builtins.PYSIDE = False
        builtins.PYQT4 = True

    if PYSIDE:
        from PySide.QtScript import QScriptEngine

        if not hasattr(QScriptEngine, "newFunction"):
            raise ImportError("You need a patched version of PySide.\n" "see: https://codereview.qt-project.org/112333")

    # --PySide Imports.
    if PYSIDE:
        from PySide.QtCore import QObject, SIGNAL, SLOT, QFile
        from PySide.QtGui import QApplication
    elif PYQT4:
        import sip

        sip.setapi("QString", 2)
        sip.setapi("QVariant", 2)
        from PyQt4.QtCore import QObject, SIGNAL, SLOT, QFile
        from PyQt4.QtGui import QApplication

    from mainwindow import MainWindow

    for file_ in filesToCheck:
        if QFile.exists(file_) and MainWindow.validFileFormat(file_):
            filesToOpen.append(file_)
        else:
            usage()
            break

    if exitApp:
        return 1

    app = QApplication(argv)
    app.setApplicationName(_appName_)
    app.setApplicationVersion(_appVer_)

    mainWin = MainWindow()  # MainWindow*

    QObject.connect(app, SIGNAL("lastWindowClosed()"), mainWin, SLOT("quit()"))

    mainWin.setWindowTitle(app.applicationName() + " " + app.applicationVersion())
    mainWin.show()

    # NOTE: If openFilesSelected() is called from within the mainWin constructor, slot commands wont work and the window menu will be screwed
    if filesToOpen:  # if(!filesToOpen.isEmpty())
        mainWin.openFilesSelected(filesToOpen)

    # return app.exec_()
    return app.exec_()