def __init__(self, ref, filename): super(activeGroup, self).__init__() self.ui = Ui_activeGroup() self.ui.setupUi(self) self.ref = ref self.filename = filename self.w = None self.encounter_list = [] self.table_list = [] self.ui.exitButton.clicked.connect(self.cancel) self.ui.addEncounterButton.clicked.connect(self.addEncounterWindow) self.ui.deleteEncounterButton.clicked.connect(self.deleteEncounter) self.ui.openEncounterButton.clicked.connect(self.activeEncounterWindow) self.ui.editLibraryButton.clicked.connect(self.editLibraryWindow) self.ui.addTableButton.clicked.connect(self.createTableWindow) self.ui.openTableButton.clicked.connect(self.activeTableWindow) self.ui.deleteTableButton.clicked.connect(self.deleteTable) self.groupName = filename.split('/')[-1] # Trim off file extension self.groupName = self.groupName[:-6] # Set the group label self.ui.groupLabel.setText(self.groupName) self.setWindowTitle(self.groupName) self.libraryName = "" # Parse Library name, encounters, and tables from file. with open(filename, 'r') as file: for line in file: if line.startswith("library:"): self.libraryName = line.split(":")[1] self.libraryName = self.libraryName.rstrip('\n') self.ui.libraryLabel.setText(self.libraryName) elif line.startswith("encounter:"): line = line.split(':') line.pop(0) line = "".join(line) line = line.rstrip('\n') self.ui.encounterList.addItem(QListWidgetItem(line)) self.encounter_list.append(line) elif line.startswith("table:"): line = line.split(':') line.pop(0) line = "".join(line) line = line.rstrip('\n') self.ui.tableList.addItem(QListWidgetItem(line)) self.table_list.append(line) self.library_info = getLibraryInfo(self.libraryName)
class activeGroup(QWidget): def __init__(self, ref, filename): super(activeGroup, self).__init__() self.ui = Ui_activeGroup() self.ui.setupUi(self) self.ref = ref self.filename = filename self.w = None self.encounter_list = [] self.table_list = [] self.ui.exitButton.clicked.connect(self.cancel) self.ui.addEncounterButton.clicked.connect(self.addEncounterWindow) self.ui.deleteEncounterButton.clicked.connect(self.deleteEncounter) self.ui.openEncounterButton.clicked.connect(self.activeEncounterWindow) self.ui.editLibraryButton.clicked.connect(self.editLibraryWindow) self.ui.addTableButton.clicked.connect(self.createTableWindow) self.ui.openTableButton.clicked.connect(self.activeTableWindow) self.ui.deleteTableButton.clicked.connect(self.deleteTable) self.groupName = filename.split('/')[-1] # Trim off file extension self.groupName = self.groupName[:-6] # Set the group label self.ui.groupLabel.setText(self.groupName) self.setWindowTitle(self.groupName) self.libraryName = "" # Parse Library name, encounters, and tables from file. with open(filename, 'r') as file: for line in file: if line.startswith("library:"): self.libraryName = line.split(":")[1] self.libraryName = self.libraryName.rstrip('\n') self.ui.libraryLabel.setText(self.libraryName) elif line.startswith("encounter:"): line = line.split(':') line.pop(0) line = "".join(line) line = line.rstrip('\n') self.ui.encounterList.addItem(QListWidgetItem(line)) self.encounter_list.append(line) elif line.startswith("table:"): line = line.split(':') line.pop(0) line = "".join(line) line = line.rstrip('\n') self.ui.tableList.addItem(QListWidgetItem(line)) self.table_list.append(line) self.library_info = getLibraryInfo(self.libraryName) def activeEncounterWindow(self): if not self.ui.encounterList.currentItem() is None: self.w = activeEncounter(self, self.ui.encounterList.currentItem().text()) self.w.show() def activeTableWindow(self): if not self.ui.tableList.currentItem() is None: self.w = activeTable(self, self.ui.tableList.currentItem().text()) self.w.show() def createTableWindow(self): self.w = createTable(self) self.w.show() def addEncounterWindow(self): self.w = addEncounter(self, True, False) self.w.show() def deleteEncounter(self): deleted_encounter = self.ui.encounterList.currentItem().text() self.ui.encounterList.takeItem(self.ui.encounterList.currentRow()) file = open(self.filename, 'r') lines = file.readlines() file.close() found_encounter = False with open(self.filename, 'w') as file: for line in lines: # If we have reached our encounter. if line.startswith("encounter:" + deleted_encounter) and not found_encounter: found_encounter = True continue elif found_encounter: # If we have reached the next entry. if line.startswith("table:") or line.startswith("encounter:"): found_encounter = False file.write(line) continue else: file.write(line) def deleteTable(self): deleted_table = self.ui.tableList.currentItem().text() self.ui.tableList.takeItem(self.ui.tableList.currentRow()) file = open(self.filename, 'r') lines = file.readlines() file.close() found_table = False with open(self.filename, 'w') as file: for line in lines: # If we have reached our encounter. if line.startswith("table:" + deleted_table) and not found_table: found_table = True continue elif found_table: # If we have reached the next entry. if line.startswith("table:") or line.startswith("encounter:"): found_table = False file.write(line) continue else: file.write(line) def editLibraryWindow(self): self.w = editLibrary(self) self.w.show() def cancel(self): self.close() self.ref.show()
class activeGroup(QWidget): def __init__(self, ref, filename): super(activeGroup, self).__init__() self.ui = Ui_activeGroup() self.ui.setupUi(self) self.ref = ref self.filename = filename self.w = None self.encounter_list = [] self.table_list = [] self.ui.exitButton.clicked.connect(self.cancel) self.ui.addEncounterButton.clicked.connect(self.addEncounterWindow) self.ui.deleteEncounterButton.clicked.connect(self.deleteEncounter) self.ui.openEncounterButton.clicked.connect(self.activeEncounterWindow) self.ui.editLibraryButton.clicked.connect(self.editLibraryWindow) self.ui.addTableButton.clicked.connect(self.createTableWindow) self.ui.openTableButton.clicked.connect(self.activeTableWindow) self.ui.deleteTableButton.clicked.connect(self.deleteTable) self.groupName = filename.split('/')[-1] # Trim off file extension self.groupName = self.groupName[:-6] # Set the group label self.ui.groupLabel.setText(self.groupName) self.setWindowTitle(self.groupName) self.libraryName = "" # Parse Library name, encounters, and tables from file. with open(filename, 'r') as file: for line in file: if line.startswith("library:"): self.libraryName = line.split(":")[1] self.libraryName = self.libraryName.rstrip('\n') self.ui.libraryLabel.setText(self.libraryName) elif line.startswith("encounter:"): line = line.split(':') line.pop(0) line = "".join(line) line = line.rstrip('\n') self.ui.encounterList.addItem(QListWidgetItem(line)) self.encounter_list.append(line) elif line.startswith("table:"): line = line.split(':') line.pop(0) line = "".join(line) line = line.rstrip('\n') self.ui.tableList.addItem(QListWidgetItem(line)) self.table_list.append(line) self.library_info = getLibraryInfo(self.libraryName) def activeEncounterWindow(self): if not self.ui.encounterList.currentItem() is None: self.w = activeEncounter( self, self.ui.encounterList.currentItem().text()) self.w.show() def activeTableWindow(self): if not self.ui.tableList.currentItem() is None: self.w = activeTable(self, self.ui.tableList.currentItem().text()) self.w.show() def createTableWindow(self): self.w = createTable(self) self.w.show() def addEncounterWindow(self): self.w = addEncounter(self, True, False) self.w.show() def deleteEncounter(self): deleted_encounter = self.ui.encounterList.currentItem().text() self.ui.encounterList.takeItem(self.ui.encounterList.currentRow()) file = open(self.filename, 'r') lines = file.readlines() file.close() found_encounter = False with open(self.filename, 'w') as file: for line in lines: # If we have reached our encounter. if line.startswith("encounter:" + deleted_encounter) and not found_encounter: found_encounter = True continue elif found_encounter: # If we have reached the next entry. if line.startswith("table:") or line.startswith( "encounter:"): found_encounter = False file.write(line) continue else: file.write(line) def deleteTable(self): deleted_table = self.ui.tableList.currentItem().text() self.ui.tableList.takeItem(self.ui.tableList.currentRow()) file = open(self.filename, 'r') lines = file.readlines() file.close() found_table = False with open(self.filename, 'w') as file: for line in lines: # If we have reached our encounter. if line.startswith("table:" + deleted_table) and not found_table: found_table = True continue elif found_table: # If we have reached the next entry. if line.startswith("table:") or line.startswith( "encounter:"): found_table = False file.write(line) continue else: file.write(line) def editLibraryWindow(self): self.w = editLibrary(self) self.w.show() def cancel(self): self.close() self.ref.show()