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