manuskript/src/settings.py

162 lines
4.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import pickle
import pprint
2015-06-18 04:40:55 +12:00
from enums import *
viewSettings = {
"Tree": {
"Icon": "Nothing",
"Text": "Compile",
"Background": "Nothing",
2015-06-21 20:44:11 +12:00
"InfoFolder": "Nothing",
"InfoText": "Nothing",
},
"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
lastIndex = ""
2015-06-18 04:40:55 +12:00
autoSave = False
autoSaveDelay = 5
2015-06-18 04:40:55 +12:00
autoSaveNoChanges = True
autoSaveNoChangesDelay = 5
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-20 04:47:45 +12:00
fullScreenTheme = "spacedreams"
2015-06-17 23:25:46 +12:00
def save(filename=None):
global spellcheck, dict, corkSliderFactor, viewSettings, corkSizeFactor, folderView, lastTab, lastIndex, \
2015-06-18 06:45:24 +12:00
autoSave, autoSaveDelay, saveOnQuit, autoSaveNoChanges, autoSaveNoChangesDelay, outlineViewColumns, \
2015-06-20 04:47:45 +12:00
corkBackground, fullScreenTheme
allSettings = {
"viewSettings": viewSettings,
"dict": dict,
"spellcheck": spellcheck,
"corkSizeFactor": corkSizeFactor,
2015-06-16 06:30:18 +12:00
"folderView": folderView,
"lastTab": lastTab,
"lastIndex": lastIndex,
"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,
}
#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-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)
#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"]
if "lastIndex" in allSettings:
global lastIndex
lastIndex = allSettings["lastIndex"]
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
fullScreenTheme = allSettings["fullScreenTheme"]