Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[7b94e5]: ReText / __init__.py Maximize Restore History

Download this file

__init__.py    150 lines (128 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# This file is part of ReText
# Copyright: Dmitry Shachnev 2012
# License: GNU GPL v2 or higher
import markups
import markups.common
import sys
if '--pyqt4' in sys.argv:
from PyQt4 import QtCore, QtGui, QtWebKit
elif '--pyside' in sys.argv:
from PySide import QtCore, QtGui, QtWebKit
else:
try:
from PyQt5 import QtCore, QtPrintSupport, QtGui, QtWidgets, QtWebKit, QtWebKitWidgets
except ImportError:
try:
from PyQt4 import QtCore, QtGui, QtWebKit
except ImportError:
from PySide import QtCore, QtGui, QtWebKit
if not 'QtWidgets' in locals():
# PyQt4 or PySide
QtPrintSupport, QtWidgets, QtWebKitWidgets = QtGui, QtGui, QtWebKit
(QByteArray, QDir, QSettings) = (QtCore.QByteArray, QtCore.QDir, QtCore.QSettings)
QFont = QtGui.QFont
app_name = "ReText"
app_version = "4.1.0"
settings = QSettings('ReText project', 'ReText')
if not str(settings.fileName()).endswith('.conf'):
# We are on Windows probably
settings = QSettings(QSettings.IniFormat, QSettings.UserScope,
'ReText project', 'ReText')
try:
import enchant
import enchant.errors
except ImportError:
enchant_available = False
enchant = None
else:
enchant_available = True
try:
enchant.Dict()
except enchant.errors.Error:
enchant_available = False
icon_path = "icons/"
DOCTYPE_NONE = ''
DOCTYPE_MARKDOWN = markups.MarkdownMarkup.name
DOCTYPE_REST = markups.ReStructuredTextMarkup.name
DOCTYPE_HTML = 'html'
configOptions = {
'appStyleSheet': '',
'autoPlainText': True,
'autoSave': False,
'defaultMarkup': '',
'editorFont': 'monospace',
'editorFontSize': 0,
'font': '',
'fontSize': 0,
'iconTheme': '',
'handleWebLinks': False,
'hideToolBar': False,
'highlightCurrentLine': False,
'lineNumbersEnabled': False,
'previewState': False,
'pygmentsStyle': 'default',
'restorePreviewState': False,
'rightMargin': 0,
'saveWindowGeometry': False,
'spellCheck': False,
'spellCheckLocale': '',
'styleSheet': '',
'tabInsertsSpaces': True,
'tabWidth': 4,
'useWebKit': False,
'windowGeometry': QByteArray(),
}
def readFromSettings(key, keytype, settings=settings, default=None):
if not settings.contains(key):
return default
try:
value = settings.value(key, type=keytype)
return value if isinstance(value, keytype) else keytype(value)
except TypeError as error:
# Type mismatch
print('Warning: '+str(error))
# Return an instance of keytype
return default if (default is not None) else keytype()
def readListFromSettings(key, settings=settings):
if not settings.contains(key):
return []
value = settings.value(key)
if isinstance(value, str):
return [value]
else:
return value
def writeToSettings(key, value, default, settings=settings):
if value == default:
settings.remove(key)
else:
settings.setValue(key, value)
def writeListToSettings(key, value, settings=settings):
if len(value) > 1:
settings.setValue(key, value)
elif len(value) == 1:
settings.setValue(key, value[0])
else:
settings.remove(key)
class ReTextSettings(object):
def __init__(self):
for option in configOptions:
value = configOptions[option]
setattr(self, option, readFromSettings(option,
type(value), default=value))
def __setattr__(self, option, value):
if not option in configOptions:
raise AttributeError('Unknown attribute')
object.__setattr__(self, option, value)
writeToSettings(option, value, configOptions[option])
globalSettings = ReTextSettings()
markups.common.PYGMENTS_STYLE = globalSettings.pygmentsStyle
monofont = QFont()
monofont.setFamily(globalSettings.editorFont)
if globalSettings.editorFontSize:
monofont.setPointSize(globalSettings.editorFontSize)
datadirs = (
'.',
'/usr/share/retext',
'/usr/local/share/retext',
QDir.homePath()+'/.local/share/retext'
)