예제 #1
0
    def __init__(self, parent):
        super(createTable, self).__init__()

        self.ui = Ui_createTable()
        self.ui.setupUi(self)
        self.parent = parent

        self.ui.cancelButton.clicked.connect(self.cancel)
        self.ui.addButton.clicked.connect(self.addEntry)
        self.ui.acceptButton.clicked.connect(self.accept)

        self.ui.tableWidget.setColumnCount(2)
        self.ui.tableWidget.setHorizontalHeaderItem(
            0, QTableWidgetItem("Encounter Name"))
        self.ui.tableWidget.setHorizontalHeaderItem(
            1, QTableWidgetItem("Percent Chance"))
        self.ui.tableWidget.horizontalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)
예제 #2
0
    def __init__(self, parent):
        super(createTable, self).__init__()

        self.ui = Ui_createTable()
        self.ui.setupUi(self)
        self.parent = parent

        self.ui.cancelButton.clicked.connect(self.cancel)
        self.ui.addButton.clicked.connect(self.addEntry)
        self.ui.acceptButton.clicked.connect(self.accept)

        self.ui.tableWidget.setColumnCount(2)
        self.ui.tableWidget.setHorizontalHeaderItem(0, QTableWidgetItem("Encounter Name"))
        self.ui.tableWidget.setHorizontalHeaderItem(1, QTableWidgetItem("Percent Chance"))
        self.ui.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
예제 #3
0
class createTable(QWidget):
    def __init__(self, parent):
        super(createTable, self).__init__()

        self.ui = Ui_createTable()
        self.ui.setupUi(self)
        self.parent = parent

        self.ui.cancelButton.clicked.connect(self.cancel)
        self.ui.addButton.clicked.connect(self.addEntry)
        self.ui.acceptButton.clicked.connect(self.accept)

        self.ui.tableWidget.setColumnCount(2)
        self.ui.tableWidget.setHorizontalHeaderItem(0, QTableWidgetItem("Encounter Name"))
        self.ui.tableWidget.setHorizontalHeaderItem(1, QTableWidgetItem("Percent Chance"))
        self.ui.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)


    def cancel(self):
        self.close()

    def addEntry(self):
        self.w = addEncounter(self.parent, True, True, tableRef=self)
        self.w.show()

    def accept(self):
        table_name = self.ui.tableName.text()
        # If the table name is blank.
        if table_name == "":
            return

        # If the table by that name already exists.
        if table_name in self.parent.table_list:
            errorMessage("Table with that name already exists!")
            return

        # Put all the percents in a list.
        percents = []
        for i in range(self.ui.tableWidget.rowCount()):
            percents.append(self.ui.tableWidget.item(i, 1).text())
        # Check to make sure they are all ints and that they add up to 100.
        total = 0
        for item in percents:
            if not checkInt(item):
                errorMessage("Invalid percent in row " + str(percents.index(item) + 1))
                return
            total += int(item)
        if not total == 100:
            errorMessage("Percents do not add to 100!")
            return
        # Percents are all fine, now we can write the encounter information to the group file.
        with open(self.parent.filename, 'a')as file:
            # Write the header for the table.
            file.write("table:" + table_name + '\n\n')
            # Write the names of the encounters.
#            for i in range(self.ui.tableWidget.rowCount()):
#                file.write('~' + self.ui.tableWidget.item(i, 0).text() + ','
#                           + self.ui.tableWidget.item(i, 1).text() + '\n')

            # Read from the temp file and write to group file.
            temp = open('groups/~temp.csv', 'r')
            count = 0
            for line in temp:
                if line.startswith("table_encounter"):
                    file.write(line.rstrip('\n') + ',' + percents[count] + '\n')
                    count += 1
                else:
                    file.write(line)


            temp.close()
            os.remove("groups/~temp.csv")


        # Update the table list.
        self.parent.ui.tableList.addItem(QListWidgetItem(table_name))
        self.parent.table_list.append(table_name)

        self.close()
예제 #4
0
class createTable(QWidget):
    def __init__(self, parent):
        super(createTable, self).__init__()

        self.ui = Ui_createTable()
        self.ui.setupUi(self)
        self.parent = parent

        self.ui.cancelButton.clicked.connect(self.cancel)
        self.ui.addButton.clicked.connect(self.addEntry)
        self.ui.acceptButton.clicked.connect(self.accept)

        self.ui.tableWidget.setColumnCount(2)
        self.ui.tableWidget.setHorizontalHeaderItem(
            0, QTableWidgetItem("Encounter Name"))
        self.ui.tableWidget.setHorizontalHeaderItem(
            1, QTableWidgetItem("Percent Chance"))
        self.ui.tableWidget.horizontalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)

    def cancel(self):
        self.close()

    def addEntry(self):
        self.w = addEncounter(self.parent, True, True, tableRef=self)
        self.w.show()

    def accept(self):
        table_name = self.ui.tableName.text()
        # If the table name is blank.
        if table_name == "":
            return

        # If the table by that name already exists.
        if table_name in self.parent.table_list:
            errorMessage("Table with that name already exists!")
            return

        # Put all the percents in a list.
        percents = []
        for i in range(self.ui.tableWidget.rowCount()):
            percents.append(self.ui.tableWidget.item(i, 1).text())
        # Check to make sure they are all ints and that they add up to 100.
        total = 0
        for item in percents:
            if not checkInt(item):
                errorMessage("Invalid percent in row " +
                             str(percents.index(item) + 1))
                return
            total += int(item)
        if not total == 100:
            errorMessage("Percents do not add to 100!")
            return
        # Percents are all fine, now we can write the encounter information to the group file.
        with open(self.parent.filename, 'a') as file:
            # Write the header for the table.
            file.write("table:" + table_name + '\n\n')
            # Write the names of the encounters.
            #            for i in range(self.ui.tableWidget.rowCount()):
            #                file.write('~' + self.ui.tableWidget.item(i, 0).text() + ','
            #                           + self.ui.tableWidget.item(i, 1).text() + '\n')

            # Read from the temp file and write to group file.
            temp = open('groups/~temp.csv', 'r')
            count = 0
            for line in temp:
                if line.startswith("table_encounter"):
                    file.write(
                        line.rstrip('\n') + ',' + percents[count] + '\n')
                    count += 1
                else:
                    file.write(line)

            temp.close()
            os.remove("groups/~temp.csv")

        # Update the table list.
        self.parent.ui.tableList.addItem(QListWidgetItem(table_name))
        self.parent.table_list.append(table_name)

        self.close()