Replace key generator in the NWStatus class
This commit is contained in:
@@ -218,12 +218,12 @@ class NWProject():
|
|||||||
}
|
}
|
||||||
self.spellCheck = False
|
self.spellCheck = False
|
||||||
self.autoOutline = True
|
self.autoOutline = True
|
||||||
self.statusItems = NWStatus("s")
|
self.statusItems = NWStatus(NWStatus.STATUS)
|
||||||
self.statusItems.write(None, self.tr("New"), (100, 100, 100))
|
self.statusItems.write(None, self.tr("New"), (100, 100, 100))
|
||||||
self.statusItems.write(None, self.tr("Note"), (200, 50, 0))
|
self.statusItems.write(None, self.tr("Note"), (200, 50, 0))
|
||||||
self.statusItems.write(None, self.tr("Draft"), (200, 150, 0))
|
self.statusItems.write(None, self.tr("Draft"), (200, 150, 0))
|
||||||
self.statusItems.write(None, self.tr("Finished"), (50, 200, 0))
|
self.statusItems.write(None, self.tr("Finished"), (50, 200, 0))
|
||||||
self.importItems = NWStatus("i")
|
self.importItems = NWStatus(NWStatus.IMPORT)
|
||||||
self.importItems.write(None, self.tr("New"), (100, 100, 100))
|
self.importItems.write(None, self.tr("New"), (100, 100, 100))
|
||||||
self.importItems.write(None, self.tr("Minor"), (200, 50, 0))
|
self.importItems.write(None, self.tr("Minor"), (200, 50, 0))
|
||||||
self.importItems.write(None, self.tr("Major"), (200, 150, 0))
|
self.importItems.write(None, self.tr("Major"), (200, 150, 0))
|
||||||
@@ -267,6 +267,7 @@ class NWProject():
|
|||||||
logger.error("No project path set for the new project")
|
logger.error("No project path set for the new project")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self.clearProject()
|
||||||
if not self.setProjectPath(projPath, newProject=True):
|
if not self.setProjectPath(projPath, newProject=True):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -39,9 +39,12 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class NWStatus():
|
class NWStatus():
|
||||||
|
|
||||||
|
STATUS = 1
|
||||||
|
IMPORT = 2
|
||||||
|
|
||||||
def __init__(self, type):
|
def __init__(self, type):
|
||||||
|
|
||||||
self._type = str(type)
|
self._type = type
|
||||||
self._store = {}
|
self._store = {}
|
||||||
self._reverse = {}
|
self._reverse = {}
|
||||||
self._default = None
|
self._default = None
|
||||||
@@ -51,6 +54,13 @@ class NWStatus():
|
|||||||
pixmap.fill(QColor(100, 100, 100))
|
pixmap.fill(QColor(100, 100, 100))
|
||||||
self._defaultIcon = QIcon(pixmap)
|
self._defaultIcon = QIcon(pixmap)
|
||||||
|
|
||||||
|
if self._type == self.STATUS:
|
||||||
|
self._prefix = "s"
|
||||||
|
elif self._type == self.IMPORT:
|
||||||
|
self._prefix = "i"
|
||||||
|
else:
|
||||||
|
raise Exception("This is a bug!")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def write(self, key, name, cols, count=None):
|
def write(self, key, name, cols, count=None):
|
||||||
@@ -209,21 +219,21 @@ class NWStatus():
|
|||||||
flags. The Python recursion limit is given the job to handle
|
flags. The Python recursion limit is given the job to handle
|
||||||
the extreme case and will cause an app crash.
|
the extreme case and will cause an app crash.
|
||||||
"""
|
"""
|
||||||
key = f"{self._type}{random.randint(0, 0xffffff):06x}"
|
key = f"{self._prefix}{random.getrandbits(24):06x}"
|
||||||
if key in self._store:
|
if key in self._store:
|
||||||
key = self._newKey()
|
key = self._newKey()
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def _isKey(self, key):
|
def _isKey(self, value):
|
||||||
"""Check if a string is a key or not.
|
"""Check if a value is a key or not.
|
||||||
"""
|
"""
|
||||||
if not isinstance(key, str):
|
if not isinstance(value, str):
|
||||||
return False
|
return False
|
||||||
if len(key) != 7:
|
if len(value) != 7:
|
||||||
return False
|
return False
|
||||||
if key[0] != self._type:
|
if value[0] != self._prefix:
|
||||||
return False
|
return False
|
||||||
for c in key[1:]:
|
for c in value[1:]:
|
||||||
if c not in "0123456789abcdef":
|
if c not in "0123456789abcdef":
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user