2015-06-16 06:09:16 +12:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import pickle
|
|
|
|
import pprint
|
2015-06-18 04:40:55 +12:00
|
|
|
from enums import *
|
2015-06-26 03:06:07 +12:00
|
|
|
from qt import *
|
2015-07-04 09:00:54 +12:00
|
|
|
import collections
|
2015-06-16 06:09:16 +12:00
|
|
|
|
|
|
|
viewSettings = {
|
|
|
|
"Tree": {
|
|
|
|
"Icon": "Nothing",
|
|
|
|
"Text": "Compile",
|
|
|
|
"Background": "Nothing",
|
2015-06-21 20:44:11 +12:00
|
|
|
"InfoFolder": "Nothing",
|
|
|
|
"InfoText": "Nothing",
|
2015-06-16 06:09:16 +12:00
|
|
|
},
|
|
|
|
"Cork": {
|
|
|
|
"Icon": "Nothing",
|
|
|
|
"Text": "Nothing",
|
|
|
|
"Background": "Nothing",
|
|
|
|
"Corner": "Label",
|
|
|
|
"Border": "Nothing",
|
|
|
|
},
|
|
|
|
"Outline": {
|
|
|
|
"Icon": "Nothing",
|
|
|
|
"Text": "Compile",
|
|
|
|
"Background": "Nothing",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
spellcheck = False
|
|
|
|
dict = None
|
|
|
|
corkSizeFactor = 100
|
|
|
|
folderView = "cork"
|
2015-06-16 06:30:18 +12:00
|
|
|
lastTab = 0
|
2015-06-30 00:21:57 +12:00
|
|
|
openIndexes = [""]
|
2015-06-18 04:40:55 +12:00
|
|
|
autoSave = False
|
2015-06-17 19:33:25 +12:00
|
|
|
autoSaveDelay = 5
|
2015-06-18 04:40:55 +12:00
|
|
|
autoSaveNoChanges = True
|
|
|
|
autoSaveNoChangesDelay = 5
|
2015-06-17 19:33:25 +12:00
|
|
|
saveOnQuit = True
|
2015-06-18 04:40:55 +12:00
|
|
|
outlineViewColumns = [Outline.title.value, Outline.POV.value, Outline.status.value,
|
|
|
|
Outline.compile.value, Outline.wordCount.value, Outline.goal.value,
|
|
|
|
Outline.goalPercentage.value, Outline.label.value]
|
2015-06-18 06:45:24 +12:00
|
|
|
corkBackground = {
|
|
|
|
"color": "#926239",
|
|
|
|
"image": ""
|
|
|
|
}
|
2015-06-25 20:01:28 +12:00
|
|
|
defaultTextType = "t2t"
|
2015-06-20 04:47:45 +12:00
|
|
|
fullScreenTheme = "spacedreams"
|
|
|
|
|
2015-06-26 03:06:07 +12:00
|
|
|
textEditor = {
|
2015-07-02 00:51:43 +12:00
|
|
|
"background": "fff",
|
2015-06-26 03:06:07 +12:00
|
|
|
"fontColor": "#000",
|
|
|
|
"font": qApp.font().toString(),
|
|
|
|
"misspelled": "#F00",
|
|
|
|
"lineSpacing": 100,
|
|
|
|
"tabWidth": 20,
|
|
|
|
"indent": True,
|
|
|
|
"spacingAbove": 5,
|
|
|
|
"spacingBelow": 5,
|
|
|
|
}
|
|
|
|
|
2015-07-04 09:00:54 +12:00
|
|
|
revisions = {
|
|
|
|
"keep": True,
|
|
|
|
"smartremove": True,
|
|
|
|
"rules": collections.OrderedDict({
|
|
|
|
10 * 60: 60, # One per minute for the last 10mn
|
|
|
|
60 * 60: 60 * 10, # One per 10mn for the last hour
|
|
|
|
60 * 60 * 24: 60 * 60, # One per hour for the last day
|
|
|
|
60 * 60 * 24 * 30: 60 * 60 * 24, # One per day for the last month
|
|
|
|
None: 60 * 60 * 24 * 7, # One per week for eternity
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-06-17 23:25:46 +12:00
|
|
|
def save(filename=None):
|
2015-06-16 06:09:16 +12:00
|
|
|
|
2015-06-30 00:21:57 +12:00
|
|
|
global spellcheck, dict, corkSliderFactor, viewSettings, corkSizeFactor, folderView, lastTab, openIndexes, \
|
2015-06-18 06:45:24 +12:00
|
|
|
autoSave, autoSaveDelay, saveOnQuit, autoSaveNoChanges, autoSaveNoChangesDelay, outlineViewColumns, \
|
2015-07-04 09:00:54 +12:00
|
|
|
corkBackground, fullScreenTheme, defaultTextType, textEditor, revisions
|
2015-06-16 06:09:16 +12:00
|
|
|
|
|
|
|
allSettings = {
|
|
|
|
"viewSettings": viewSettings,
|
|
|
|
"dict": dict,
|
|
|
|
"spellcheck": spellcheck,
|
|
|
|
"corkSizeFactor": corkSizeFactor,
|
2015-06-16 06:30:18 +12:00
|
|
|
"folderView": folderView,
|
|
|
|
"lastTab": lastTab,
|
2015-06-30 00:21:57 +12:00
|
|
|
"openIndexes": openIndexes,
|
2015-06-17 19:33:25 +12:00
|
|
|
"autoSave":autoSave,
|
|
|
|
"autoSaveDelay":autoSaveDelay,
|
|
|
|
"saveOnQuit":saveOnQuit,
|
2015-06-18 04:40:55 +12:00
|
|
|
"autoSaveNoChanges":autoSaveNoChanges,
|
|
|
|
"autoSaveNoChangesDelay":autoSaveNoChangesDelay,
|
|
|
|
"outlineViewColumns":outlineViewColumns,
|
2015-06-18 06:45:24 +12:00
|
|
|
"corkBackground":corkBackground,
|
2015-06-20 04:47:45 +12:00
|
|
|
"fullScreenTheme":fullScreenTheme,
|
2015-06-25 20:01:28 +12:00
|
|
|
"defaultTextType":defaultTextType,
|
2015-06-26 03:06:07 +12:00
|
|
|
"textEditor":textEditor,
|
2015-07-04 09:00:54 +12:00
|
|
|
"revisions":revisions,
|
2015-06-16 06:09:16 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
#pp=pprint.PrettyPrinter(indent=4, compact=False)
|
|
|
|
#print("Saving:")
|
|
|
|
#pp.pprint(allSettings)
|
|
|
|
|
2015-06-17 23:25:46 +12:00
|
|
|
if filename:
|
|
|
|
f = open(filename, "wb")
|
|
|
|
pickle.dump(allSettings, f)
|
|
|
|
else:
|
|
|
|
return pickle.dumps(allSettings)
|
2015-06-16 06:09:16 +12:00
|
|
|
|
2015-06-17 23:25:46 +12:00
|
|
|
def load(string, fromString=False):
|
|
|
|
"""Load settings from 'string'. 'string' is the filename of the pickle dump.
|
|
|
|
If fromString=True, string is the data of the pickle dumps."""
|
|
|
|
global allSettings
|
|
|
|
|
|
|
|
if not fromString:
|
|
|
|
try:
|
|
|
|
f = open(string, "rb")
|
|
|
|
allSettings = pickle.load(f)
|
|
|
|
|
|
|
|
except:
|
|
|
|
print("{} doesn't exist, cannot load settings.".format(string))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
allSettings = pickle.loads(string)
|
2015-06-16 06:09:16 +12:00
|
|
|
|
|
|
|
#pp=pprint.PrettyPrinter(indent=4, compact=False)
|
|
|
|
#print("Loading:")
|
|
|
|
#pp.pprint(allSettings)
|
|
|
|
|
|
|
|
if "viewSettings" in allSettings:
|
|
|
|
global viewSettings
|
|
|
|
viewSettings = allSettings["viewSettings"]
|
|
|
|
|
|
|
|
if "dict" in allSettings:
|
|
|
|
global dict
|
|
|
|
dict = allSettings["dict"]
|
|
|
|
|
|
|
|
if "spellcheck" in allSettings:
|
|
|
|
global spellcheck
|
|
|
|
spellcheck = allSettings["spellcheck"]
|
|
|
|
|
|
|
|
if "corkSizeFactor" in allSettings:
|
|
|
|
global corkSizeFactor
|
|
|
|
corkSizeFactor = allSettings["corkSizeFactor"]
|
|
|
|
|
|
|
|
if "folderView" in allSettings:
|
|
|
|
global folderView
|
|
|
|
folderView = allSettings["folderView"]
|
|
|
|
|
2015-06-16 06:30:18 +12:00
|
|
|
if "lastTab" in allSettings:
|
|
|
|
global lastTab
|
|
|
|
lastTab = allSettings["lastTab"]
|
|
|
|
|
2015-06-30 00:21:57 +12:00
|
|
|
if "openIndexes" in allSettings:
|
|
|
|
global openIndexes
|
|
|
|
openIndexes = allSettings["openIndexes"]
|
2015-06-16 06:30:18 +12:00
|
|
|
|
2015-06-17 19:33:25 +12:00
|
|
|
if "autoSave" in allSettings:
|
|
|
|
global autoSave
|
|
|
|
autoSave = allSettings["autoSave"]
|
|
|
|
|
|
|
|
if "autoSaveDelay" in allSettings:
|
|
|
|
global autoSaveDelay
|
|
|
|
autoSaveDelay = allSettings["autoSaveDelay"]
|
|
|
|
|
|
|
|
if "saveOnQuit" in allSettings:
|
|
|
|
global saveOnQuit
|
|
|
|
saveOnQuit = allSettings["saveOnQuit"]
|
|
|
|
|
2015-06-18 04:40:55 +12:00
|
|
|
if "autoSaveNoChanges" in allSettings:
|
|
|
|
global autoSaveNoChanges
|
|
|
|
autoSaveNoChanges = allSettings["autoSaveNoChanges"]
|
|
|
|
|
|
|
|
if "autoSaveNoChangesDelay" in allSettings:
|
|
|
|
global autoSaveNoChangesDelay
|
|
|
|
autoSaveNoChangesDelay = allSettings["autoSaveNoChangesDelay"]
|
|
|
|
|
|
|
|
if "outlineViewColumns" in allSettings:
|
|
|
|
global outlineViewColumns
|
|
|
|
outlineViewColumns = allSettings["outlineViewColumns"]
|
2015-06-18 06:45:24 +12:00
|
|
|
|
|
|
|
if "corkBackground" in allSettings:
|
|
|
|
global corkBackground
|
2015-06-20 04:47:45 +12:00
|
|
|
corkBackground = allSettings["corkBackground"]
|
|
|
|
|
|
|
|
if "fullScreenTheme" in allSettings:
|
|
|
|
global fullScreenTheme
|
2015-06-24 04:22:39 +12:00
|
|
|
fullScreenTheme = allSettings["fullScreenTheme"]
|
2015-06-25 20:01:28 +12:00
|
|
|
|
|
|
|
if "defaultTextType" in allSettings:
|
|
|
|
global defaultTextType
|
2015-06-26 03:06:07 +12:00
|
|
|
defaultTextType = allSettings["defaultTextType"]
|
|
|
|
|
|
|
|
if "textEditor" in allSettings:
|
|
|
|
global textEditor
|
2015-07-04 09:00:54 +12:00
|
|
|
textEditor = allSettings["textEditor"]
|
|
|
|
|
|
|
|
if "revisions" in allSettings:
|
|
|
|
global revisions
|
|
|
|
revisions = allSettings["revisions"]
|