-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttonFunctions.py
205 lines (161 loc) · 8.59 KB
/
buttonFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# ██████╗░██╗░░░██╗████████╗████████╗░█████╗░███╗░░██╗ ███████╗██╗░░░██╗███╗░░██╗░█████╗░████████╗██╗░█████╗░███╗░░██╗░██████╗
# ██╔══██╗██║░░░██║╚══██╔══╝╚══██╔══╝██╔══██╗████╗░██║ ██╔════╝██║░░░██║████╗░██║██╔══██╗╚══██╔══╝██║██╔══██╗████╗░██║██╔════╝
# ██████╦╝██║░░░██║░░░██║░░░░░░██║░░░██║░░██║██╔██╗██║ █████╗░░██║░░░██║██╔██╗██║██║░░╚═╝░░░██║░░░██║██║░░██║██╔██╗██║╚█████╗░
# ██╔══██╗██║░░░██║░░░██║░░░░░░██║░░░██║░░██║██║╚████║ ██╔══╝░░██║░░░██║██║╚████║██║░░██╗░░░██║░░░██║██║░░██║██║╚████║░╚═══██╗
# ██████╦╝╚██████╔╝░░░██║░░░░░░██║░░░╚█████╔╝██║░╚███║ ██║░░░░░╚██████╔╝██║░╚███║╚█████╔╝░░░██║░░░██║╚█████╔╝██║░╚███║██████╔╝
# ╚═════╝░░╚═════╝░░░░╚═╝░░░░░░╚═╝░░░░╚════╝░╚═╝░░╚══╝ ╚═╝░░░░░░╚═════╝░╚═╝░░╚══╝░╚════╝░░░░╚═╝░░░╚═╝░╚════╝░╚═╝░░╚══╝╚═════╝░
from __future__ import annotations # Type hinting
from PyQt5.QtWidgets import *
from typehinting import startProgram
from miscFunctions import miscFunctions
class buttonFunctions():
def __init__(this, self: startProgram) -> None:
this.self = self;
this.functions = miscFunctions(self);
# Character stuff
def acceptCharacterBtn(this, newChar: bool):
"""
Function to run when the accept button is pressed on the editCharacterUI
Args:
newChar (bool): Whether a character is new or not
"""
self = this.self;
ui = self.characterUI;
charID = ui.characterID.value();
if(newChar and len(self.data["characters"]) >=1):
charID = self.data["characters"][-1][0] + 1;
name = ui.name.text();
title = ui.titleSelector.currentIndex();
age = ui.age.value();
species = ui.species.text();
info = ui.textEdit.toPlainText();
gender = ui.genderSelector.currentIndex();
isDead = 0;
if(ui.dead.isChecked()):
isDead = 1;
relationArray = []
for relation in self._characterRelations:
relationArray.append(f"{relation[0]}|{relation[1]}");
relationString = ", ".join(relationArray);
self.editCharacterWindow.close(); # We no longer need anything from this ui, the rest can be done with it closed
if(newChar): # New Character, apply to data
self.data["characters"].append((int(charID), name, int(title), int(age), int(gender), species, int(isDead), info, relationString));
else: # Not new character, find the character and overwrite it
for i in range(len(self.data["characters"])):
if(self.data["characters"][i][0] == charID):
self.data["characters"][i] = (int(charID), name, int(title), int(age), int(gender), species, int(isDead), info, relationString);
break;
# Update the current list
self.ui.characterList.clear();
this.functions.populateList(self.ui.characterList, "characters");
# End of function
def removeCharacterBtn(this) -> None:
"""
Function to run when pressing the remove button on the mainWindowUI
"""
self = this.self;
ui = self.ui;
indexOfItem = ui.characterList.currentRow();
ui.characterList.takeItem(ui.characterList.currentRow());
del self.data["characters"][indexOfItem];
this.functions.unlockEditRemoveCharacterBtns();
# End of function
# Relation stuff
def addRelationToListBtn(this, existing: bool) -> None:
"""
Function to run when pressing the accept button on the addRelationUI
"""
self = this.self;
# Person Information
selectedPerson = self.addRelationUI.characterList.currentRow();
personData = self.data["characters"][selectedPerson];
# Relationship
selectedRelation = self.addRelationUI.relationType.currentRow();
relationship = this.functions.relationConversion(selectedRelation);
spaces = (self.settings["longestRelation"] - len(relationship)) * " ";
relationship = relationship + spaces + " | ";
if(existing):
itemRow = self.characterUI.relationTable.currentRow();
self._characterRelations[itemRow] = (personData[0], selectedRelation);
else:
# Add to the internal relationship list
self._characterRelations.append((personData[0], selectedRelation));
# Adding to the table
self.characterUI.relationTable.clear();
this.functions.populateList(self.characterUI.relationTable, "relation");
self.addRelationWindow.close(); # Finally closing the UI
# End of function
def removeRelationBtn(this) -> None:
"""
Function to run when the remove button is pressed on the editCharacterUI
"""
self = this.self;
currRow = self.characterUI.relationTable.currentRow();
if(currRow > -1):
self.characterUI.relationTable.takeItem(currRow);
del self._characterRelations[currRow];
# End of function
# World Buidling Stuff
def addWorldBuildingToListBtn(this, newDetail: bool) -> None:
"""
Function to run when clicking the accept button on the worldBuildingUI
Args:
newDetail (bool): Whether or not it's a new detail
"""
self = this.self;
text = self.worldBuildingUI.textEditor.toPlainText();
if(newDetail):
self.data["world"].append((text, 0));
else:
itemRow = self.ui.worldBuildingList.currentRow();
self.data["world"][itemRow] = (text, 0);
self.ui.worldBuildingList.clear();
this.functions.populateList(self.ui.worldBuildingList, "world");
self.worldBuildingWindow.close();
# End of function
def removeWorldBuilding(this) -> None:
"""
Function to run when clicking the remove button on the mainWindowUI
"""
self = this.self;
currRow = self.ui.worldBuildingList.currentRow();
if(currRow > -1):
self.ui.worldBuildingList.takeItem(currRow);
del self.data["world"][currRow];
# End of function
def moveRow(this, upDown: int):
"""
Function to move a list item up or down
Args:
upDown (int): 1 for down, -1 for up
"""
self = this.self;
currentRow = self.ui.characterList.currentRow();
currentItemText = self.ui.characterList.item(currentRow).text();
currentItemIcon = self.ui.characterList.item(currentRow).icon();
newRowIndex = currentRow + upDown;
newItemText = self.ui.characterList.item(newRowIndex).text();
newItemIcon = self.ui.characterList.item(newRowIndex).icon();
# Swapping the data in the internal
self.data["characters"][currentRow], self.data["characters"][newRowIndex] = self.data["characters"][newRowIndex], self.data["characters"][currentRow];
# Setting newItem
self.ui.characterList.item(currentRow).setText(newItemText);
self.ui.characterList.item(currentRow).setIcon(newItemIcon);
# Setting currentItem
self.ui.characterList.item(newRowIndex).setText(currentItemText);
self.ui.characterList.item(newRowIndex).setIcon(currentItemIcon);
self.ui.characterList.setCurrentRow(currentRow + upDown);
# End of function
def setConfig(this, settings: list[tuple[str, str]]):
self = this.self;
theme = self.settings["theme"];
# lang = self.settings["lang"];
# Set the settings
for setting in settings:
self.settings[setting[0]] = setting[1];
# If the theme changed, change the theme
if(theme != self.settings["theme"]):
self.themeManager.setTheme(self, "main");
# Close the window
self.optionsWindow.close();
this.functions.populateList(self.ui.characterList, "characters");