320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
1 |
#!/usr/bin/env python3
|
2 |
||
3 |
# ReText
|
|
520
by Dmitry Shachnev
Bump copyright years in all files |
4 |
# Copyright 2011-2014 Dmitry Shachnev
|
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
5 |
|
6 |
# This program is free software; you can redistribute it and/or modify
|
|
7 |
# it under the terms of the GNU General Public License as published by
|
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
|
9 |
# (at your option) any later version.
|
|
10 |
||
11 |
# This program is distributed in the hope that it will be useful,
|
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
# GNU General Public License for more details.
|
|
15 |
||
16 |
# You should have received a copy of the GNU General Public License
|
|
17 |
# along with this program; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
19 |
# MA 02110-1301, USA.
|
|
20 |
||
21 |
import sys |
|
383
by Dmitry Shachnev
Correctly handle SIGINTs. Ticket 64. |
22 |
import signal |
523
by Dmitry Shachnev
[#83] Add uiLanguage configuration option |
23 |
from os.path import join |
599
by Dmitry Shachnev
Let Qt know the application version |
24 |
from ReText import datadirs, globalSettings, app_version |
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
25 |
from ReText.window import ReTextWindow |
26 |
||
508
by Dmitry Shachnev
Drop Qt 4.x support |
27 |
from PyQt5.QtCore import QFile, QFileInfo, QIODevice, QLibraryInfo, \ |
523
by Dmitry Shachnev
[#83] Add uiLanguage configuration option |
28 |
QTextStream, QTranslator |
508
by Dmitry Shachnev
Drop Qt 4.x support |
29 |
from PyQt5.QtWidgets import QApplication |
578
by Dmitry Shachnev
Tell Qt to use system proxy server when needed |
30 |
from PyQt5.QtNetwork import QNetworkProxyFactory |
437
by Dmitry Shachnev
Support switchable backends, and more |
31 |
|
484
by Dmitry Shachnev
[#102] Add support for '--preview' option. |
32 |
def canonicalize(option): |
33 |
if option == '--preview': |
|
34 |
return option |
|
35 |
return QFileInfo(option).canonicalFilePath() |
|
36 |
||
367
by Dmitry Shachnev
main: canonicalize file names before passing to openFileMain |
37 |
def main(): |
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
38 |
app = QApplication(sys.argv) |
39 |
app.setOrganizationName("ReText project") |
|
40 |
app.setApplicationName("ReText") |
|
511
by Dmitry Shachnev
Drop one more Qt 4 hack |
41 |
app.setApplicationDisplayName("ReText") |
599
by Dmitry Shachnev
Let Qt know the application version |
42 |
app.setApplicationVersion(app_version) |
578
by Dmitry Shachnev
Tell Qt to use system proxy server when needed |
43 |
QNetworkProxyFactory.setUseSystemConfiguration(True) |
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
44 |
RtTranslator = QTranslator() |
403
by Dmitry Shachnev
Support /usr/local installations |
45 |
for path in datadirs: |
523
by Dmitry Shachnev
[#83] Add uiLanguage configuration option |
46 |
if RtTranslator.load('retext_' + globalSettings.uiLanguage, |
47 |
join(path, 'locale')): |
|
403
by Dmitry Shachnev
Support /usr/local installations |
48 |
break
|
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
49 |
QtTranslator = QTranslator() |
523
by Dmitry Shachnev
[#83] Add uiLanguage configuration option |
50 |
QtTranslator.load("qt_" + globalSettings.uiLanguage, |
51 |
QLibraryInfo.location(QLibraryInfo.TranslationsPath)) |
|
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
52 |
app.installTranslator(RtTranslator) |
53 |
app.installTranslator(QtTranslator) |
|
428
by Dmitry Shachnev
Implement global settings class |
54 |
if globalSettings.appStyleSheet: |
55 |
sheetfile = QFile(globalSettings.appStyleSheet) |
|
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
56 |
sheetfile.open(QIODevice.ReadOnly) |
57 |
app.setStyleSheet(QTextStream(sheetfile).readAll()) |
|
58 |
sheetfile.close() |
|
59 |
window = ReTextWindow() |
|
60 |
window.show() |
|
484
by Dmitry Shachnev
[#102] Add support for '--preview' option. |
61 |
# ReText can change directory when loading files, so we
|
62 |
# need to have a list of canonical names before loading
|
|
63 |
fileNames = list(map(canonicalize, sys.argv[1:])) |
|
64 |
previewMode = False |
|
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
65 |
for fileName in fileNames: |
66 |
if QFile.exists(fileName): |
|
67 |
window.openFileWrapper(fileName) |
|
484
by Dmitry Shachnev
[#102] Add support for '--preview' option. |
68 |
if previewMode: |
69 |
window.actionPreview.trigger() |
|
70 |
elif fileName == '--preview': |
|
71 |
previewMode = True |
|
503
by Dmitry Shachnev
[#112] Allow pipe into ReText |
72 |
inputData = '' if sys.stdin.isatty() else sys.stdin.read() |
73 |
if inputData or not window.tabWidget.count(): |
|
74 |
window.createNew(inputData) |
|
383
by Dmitry Shachnev
Correctly handle SIGINTs. Ticket 64. |
75 |
signal.signal(signal.SIGINT, lambda sig, frame: window.close()) |
547
by Dmitry Shachnev
Print and exec are no longer keywords in Python 3 |
76 |
sys.exit(app.exec()) |
320
by Dmitry Shachnev
Revert renaming of scripts, as some filesystems are case-insensitive |
77 |
|
78 |
if __name__ == '__main__': |
|
367
by Dmitry Shachnev
main: canonicalize file names before passing to openFileMain |
79 |
main() |