~ubuntu-branches/ubuntu/utopic/retext/utopic

« back to all changes in this revision

Viewing changes to retext.py

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2014-07-26 12:38:59 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140726123859-49z5c24mluzkpui1
Tags: 5.0.0-1
* New upstream release.
* Update debian/copyright.
* Run upstream tests during build.
* Wrap-and-sort debian/control.
* Update debian/watch to point to PyPI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python3
2
2
 
3
3
# ReText
4
 
# Copyright 2011-2013 Dmitry Shachnev
 
4
# Copyright 2011-2014 Dmitry Shachnev
5
5
 
6
6
# This program is free software; you can redistribute it and/or modify
7
7
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
import sys
22
22
import signal
23
 
from ReText import QtCore, QtWidgets, QtWebKit, datadirs, globalSettings
 
23
from os.path import join
 
24
from ReText import datadirs, globalSettings
24
25
from ReText.window import ReTextWindow
25
26
 
26
 
(QFile, QFileInfo, QIODevice, QLibraryInfo, QLocale, QTextStream,
27
 
 QTranslator) = (QtCore.QFile, QtCore.QFileInfo, QtCore.QIODevice,
28
 
 QtCore.QLibraryInfo, QtCore.QLocale, QtCore.QTextStream, QtCore.QTranslator)
29
 
QApplication = QtWidgets.QApplication
30
 
QWebSettings = QtWebKit.QWebSettings
 
27
from PyQt5.QtCore import QFile, QFileInfo, QIODevice, QLibraryInfo, \
 
28
 QTextStream, QTranslator
 
29
from PyQt5.QtWidgets import QApplication
 
30
 
 
31
def canonicalize(option):
 
32
        if option == '--preview':
 
33
                return option
 
34
        return QFileInfo(option).canonicalFilePath()
31
35
 
32
36
def main():
33
37
        app = QApplication(sys.argv)
34
38
        app.setOrganizationName("ReText project")
35
39
        app.setApplicationName("ReText")
36
 
        if hasattr(app, 'setApplicationDisplayName'):
37
 
                app.setApplicationDisplayName("ReText")
 
40
        app.setApplicationDisplayName("ReText")
38
41
        RtTranslator = QTranslator()
39
42
        for path in datadirs:
40
 
                if RtTranslator.load('retext_'+QLocale.system().name(), path+'/locale'):
 
43
                if RtTranslator.load('retext_' + globalSettings.uiLanguage,
 
44
                                     join(path, 'locale')):
41
45
                        break
42
46
        QtTranslator = QTranslator()
43
 
        QtTranslator.load("qt_"+QLocale.system().name(), QLibraryInfo.location(QLibraryInfo.TranslationsPath))
 
47
        QtTranslator.load("qt_" + globalSettings.uiLanguage,
 
48
                QLibraryInfo.location(QLibraryInfo.TranslationsPath))
44
49
        app.installTranslator(RtTranslator)
45
50
        app.installTranslator(QtTranslator)
46
51
        if globalSettings.appStyleSheet:
48
53
                sheetfile.open(QIODevice.ReadOnly)
49
54
                app.setStyleSheet(QTextStream(sheetfile).readAll())
50
55
                sheetfile.close()
51
 
        # A work-around for https://bugs.webkit.org/show_bug.cgi?id=114618
52
 
        webSettings = QWebSettings.globalSettings()
53
 
        webSettings.setFontFamily(QWebSettings.FixedFont, 'monospace')
54
56
        window = ReTextWindow()
55
57
        window.show()
56
 
        fileNames = [QFileInfo(arg).canonicalFilePath() for arg in sys.argv[1:]]
 
58
        # ReText can change directory when loading files, so we
 
59
        # need to have a list of canonical names before loading
 
60
        fileNames = list(map(canonicalize, sys.argv[1:]))
 
61
        previewMode = False
57
62
        for fileName in fileNames:
58
63
                if QFile.exists(fileName):
59
64
                        window.openFileWrapper(fileName)
 
65
                        if previewMode:
 
66
                                window.actionPreview.trigger()
 
67
                elif fileName == '--preview':
 
68
                        previewMode = True
 
69
        inputData = '' if sys.stdin.isatty() else sys.stdin.read()
 
70
        if inputData or not window.tabWidget.count():
 
71
                window.createNew(inputData)
60
72
        signal.signal(signal.SIGINT, lambda sig, frame: window.close())
61
 
        sys.exit(app.exec_())
 
73
        sys.exit(app.exec())
62
74
 
63
75
if __name__ == '__main__':
64
76
        main()