Make some remaining project class bariables private
This commit is contained in:
+31
-25
@@ -23,8 +23,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import novelwriter
|
||||
@@ -49,7 +47,6 @@ from novelwriter.common import (
|
||||
checkStringNone, formatTimeStamp, hexToInt, isHandle, makeFileNameSafe, minmax
|
||||
)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -78,10 +75,8 @@ class NWProject(QObject):
|
||||
self._projOpened = 0 # The time stamp of when the project file was opened
|
||||
self._projChanged = False # The project has unsaved changes
|
||||
self._projAltered = False # The project has been altered this session
|
||||
self.lockedBy = None # Data on which computer has the project open
|
||||
|
||||
# Class Settings
|
||||
self.projFiles = [] # A list of all files in the content folder on load
|
||||
self._lockedBy = None # Data on which computer has the project open
|
||||
self._projFiles = [] # A list of all files in the content folder on load
|
||||
|
||||
# Internal Mapping
|
||||
self.tr = partial(QCoreApplication.translate, "NWProject")
|
||||
@@ -127,6 +122,10 @@ class NWProject(QObject):
|
||||
def projAltered(self):
|
||||
return self._projAltered
|
||||
|
||||
@property
|
||||
def projFiles(self):
|
||||
return self._projFiles
|
||||
|
||||
##
|
||||
# Item Methods
|
||||
##
|
||||
@@ -246,7 +245,7 @@ class NWProject(QObject):
|
||||
self._data = NWProjectData(self)
|
||||
|
||||
# Project Settings
|
||||
self.projFiles = []
|
||||
self._projFiles = []
|
||||
|
||||
return
|
||||
|
||||
@@ -274,7 +273,7 @@ class NWProject(QObject):
|
||||
logger.warning("Failed to check lock file")
|
||||
else:
|
||||
logger.error("Project is locked, so not opening")
|
||||
self.lockedBy = lockStatus
|
||||
self._lockedBy = lockStatus
|
||||
self.clearProject()
|
||||
return False
|
||||
else:
|
||||
@@ -446,22 +445,9 @@ class NWProject(QObject):
|
||||
self._storage.clearLockFile()
|
||||
self._storage.closeSession()
|
||||
self.clearProject()
|
||||
self.lockedBy = None
|
||||
self._lockedBy = None
|
||||
return True
|
||||
|
||||
def setDefaultStatusImport(self):
|
||||
"""Set the default status and importance values.
|
||||
"""
|
||||
self._data.itemStatus.write(None, self.tr("New"), (100, 100, 100))
|
||||
self._data.itemStatus.write(None, self.tr("Note"), (200, 50, 0))
|
||||
self._data.itemStatus.write(None, self.tr("Draft"), (200, 150, 0))
|
||||
self._data.itemStatus.write(None, self.tr("Finished"), (50, 200, 0))
|
||||
self._data.itemImport.write(None, self.tr("New"), (100, 100, 100))
|
||||
self._data.itemImport.write(None, self.tr("Minor"), (200, 50, 0))
|
||||
self._data.itemImport.write(None, self.tr("Major"), (200, 150, 0))
|
||||
self._data.itemImport.write(None, self.tr("Main"), (50, 200, 0))
|
||||
return
|
||||
|
||||
def backupProject(self, doNotify):
|
||||
"""Create a zip file of the entire project.
|
||||
"""
|
||||
@@ -520,6 +506,19 @@ class NWProject(QObject):
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setDefaultStatusImport(self):
|
||||
"""Set the default status and importance values.
|
||||
"""
|
||||
self._data.itemStatus.write(None, self.tr("New"), (100, 100, 100))
|
||||
self._data.itemStatus.write(None, self.tr("Note"), (200, 50, 0))
|
||||
self._data.itemStatus.write(None, self.tr("Draft"), (200, 150, 0))
|
||||
self._data.itemStatus.write(None, self.tr("Finished"), (50, 200, 0))
|
||||
self._data.itemImport.write(None, self.tr("New"), (100, 100, 100))
|
||||
self._data.itemImport.write(None, self.tr("Minor"), (200, 50, 0))
|
||||
self._data.itemImport.write(None, self.tr("Major"), (200, 150, 0))
|
||||
self._data.itemImport.write(None, self.tr("Main"), (50, 200, 0))
|
||||
return
|
||||
|
||||
def setProjectLang(self, theLang):
|
||||
"""Set the project-specific language.
|
||||
"""
|
||||
@@ -567,6 +566,13 @@ class NWProject(QObject):
|
||||
# Getters
|
||||
##
|
||||
|
||||
def getLockStatus(self):
|
||||
"""Return the project lock information for the project.
|
||||
"""
|
||||
if isinstance(self._lockedBy, list) and len(self._lockedBy) == 4:
|
||||
return self._lockedBy
|
||||
return None
|
||||
|
||||
def getFormattedAuthors(self):
|
||||
"""Return a formatted string of authors.
|
||||
"""
|
||||
@@ -725,7 +731,7 @@ class NWProject(QObject):
|
||||
# Then check the files in the data folder
|
||||
logger.debug("Checking files in project content folder")
|
||||
orphanFiles = []
|
||||
self.projFiles = []
|
||||
self._projFiles = []
|
||||
|
||||
for item in contentPath.iterdir():
|
||||
itemName = item.name
|
||||
@@ -742,7 +748,7 @@ class NWProject(QObject):
|
||||
continue
|
||||
|
||||
if fHandle in self._tree:
|
||||
self.projFiles.append(fHandle)
|
||||
self._projFiles.append(fHandle)
|
||||
logger.debug("Checking file %s, handle '%s': OK", itemName, fHandle)
|
||||
else:
|
||||
logger.warning("Checking file %s, handle '%s': Orphaned", itemName, fHandle)
|
||||
|
||||
@@ -447,7 +447,8 @@ class GuiMain(QMainWindow):
|
||||
if not self.theProject.openProject(projFile):
|
||||
# The project open failed.
|
||||
|
||||
if self.theProject.lockedBy is None:
|
||||
lockStatus = self.theProject.getLockStatus()
|
||||
if lockStatus is None:
|
||||
# The project is not locked, so failed for some other
|
||||
# reason handled by the project class.
|
||||
return False
|
||||
@@ -459,10 +460,8 @@ class GuiMain(QMainWindow):
|
||||
"'{0}' ({1} {2}), last active on {3}."
|
||||
)
|
||||
).format(
|
||||
self.theProject.lockedBy[0],
|
||||
self.theProject.lockedBy[1],
|
||||
self.theProject.lockedBy[2],
|
||||
datetime.fromtimestamp(int(self.theProject.lockedBy[3])).strftime("%x %X")
|
||||
lockStatus[0], lockStatus[1], lockStatus[2],
|
||||
datetime.fromtimestamp(int(lockStatus[3])).strftime("%x %X")
|
||||
)
|
||||
except Exception:
|
||||
lockDetails = ""
|
||||
|
||||
Reference in New Issue
Block a user