Skip to content

Commit

Permalink
Clones importance setting.
Browse files Browse the repository at this point in the history
When creating a new character, sets an appropriate importance level.
* If a character is selected, the new character has the same importance level.
* If a top-level importance level is selected, the new character has that level
* Otherwise, the importance level is zero
  • Loading branch information
BentleyJOakes committed Feb 21, 2021
1 parent 917f1a2 commit bcb6956
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manuskript/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def makeConnections(self):
self.lstCharacters.setCharactersModel(self.mdlCharacter)
self.tblPersoInfos.setModel(self.mdlCharacter)

self.btnAddPerso.clicked.connect(self.mdlCharacter.addCharacter, F.AUC)
self.btnAddPerso.clicked.connect(self.lstCharacters.addCharacter, F.AUC)
try:
self.btnRmPerso.clicked.connect(self.lstCharacters.removeCharacter, F.AUC)
self.btnPersoColor.clicked.connect(self.lstCharacters.choseCharacterColor, F.AUC)
Expand Down
9 changes: 5 additions & 4 deletions manuskript/models/characterModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ def getCharacterByID(self, ID):
# ADDING / REMOVING
###############################################################################

def addCharacter(self):
def addCharacter(self, importance = 0):
"""
Creates a new character
@param importance: the importance level of the character
@return: the character
"""
c = Character(model=self, name=self.tr("New character"))
c = Character(model=self, name=self.tr("New character"), importance = importance)
self.beginInsertRows(QModelIndex(), len(self.characters), len(self.characters))
self.characters.append(c)
self.endInsertRows()
Expand Down Expand Up @@ -222,15 +223,15 @@ def removeCharacterInfo(self, ID):
###############################################################################

class Character():
def __init__(self, model, name="No name"):
def __init__(self, model, name="No name", importance = 0):
self._model = model
self.lastPath = ""

self._data = {}
self._data[C.name.value] = name
self.assignUniqueID()
self.assignRandomColor()
self._data[C.importance.value] = "0"
self._data[C.importance.value] = str(importance)

self.infos = []

Expand Down
26 changes: 22 additions & 4 deletions manuskript/ui/views/characterTreeView.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(self, parent=None):
self._rootItem = QTreeWidgetItem()
self.insertTopLevelItem(0, self._rootItem)

self.importanceMap = {self.tr("Main"):2, self.tr("Secondary"):1, self.tr("Minor"):0}

def setCharactersModel(self, model):
self._model = model
self._model.dataChanged.connect(self.updateMaybe)
Expand Down Expand Up @@ -86,11 +88,9 @@ def updateItems(self):
self.clear()
characters = self._model.getCharactersByImportance()

h = [self.tr("Main"), self.tr("Secondary"), self.tr("Minor")]

for i in range(3):
for i, importanceLevel in enumerate(self.importanceMap):
# Create category item
cat = QTreeWidgetItem(self, [h[i]])
cat = QTreeWidgetItem(self, [importanceLevel])
cat.setBackground(0, QBrush(QColor(S.highlightLight)))
cat.setForeground(0, QBrush(QColor(S.highlightedTextDark)))
cat.setTextAlignment(0, Qt.AlignCenter)
Expand Down Expand Up @@ -119,6 +119,24 @@ def updateItems(self):
self.expandAll()
self._updating = False

def addCharacter(self):
curr_item = self.currentItem()
curr_importance = 0

# check if an item is selected
if curr_item is not None:
if curr_item.parent() is None:
# this is a top-level category, so find its importance
# get the current text, then look up the importance level
text = curr_item.text(0)
curr_importance = self.importanceMap[text]
else:
# get the importance from the currently-highlighted character
curr_character = self.currentCharacter()
curr_importance = curr_character.importance()

self._model.addCharacter(importance=curr_importance)

def removeCharacter(self):
"""
Removes selected character.
Expand Down

0 comments on commit bcb6956

Please sign in to comment.