def __init__(self, parent, encounter_name, for_table=None): super(activeEncounter, self).__init__() self.ui = Ui_activeEncounter() self.ui.setupUi(self) self.parent = parent self.encounter_name = encounter_name self.for_table = for_table self.ui.exitButton.clicked.connect(self.cancel) self.ui.encounterLabel.setText(self.encounter_name) self.ui.encounterTable.setColumnCount( len(self.parent.library_info.field_list)) i = 0 for item in self.parent.library_info.field_list: self.ui.encounterTable.setHorizontalHeaderItem( i, QTableWidgetItem(item)) i += 1 self.ui.encounterTable.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeToContents) self.fillEncounter()
def __init__(self, parent, encounter_name, for_table=None): super(activeEncounter, self).__init__() self.ui = Ui_activeEncounter() self.ui.setupUi(self) self.parent = parent self.encounter_name = encounter_name self.for_table = for_table self.ui.exitButton.clicked.connect(self.cancel) self.ui.encounterLabel.setText(self.encounter_name) self.ui.encounterTable.setColumnCount(len(self.parent.library_info.field_list)) i = 0 for item in self.parent.library_info.field_list: self.ui.encounterTable.setHorizontalHeaderItem(i, QTableWidgetItem(item)) i += 1 self.ui.encounterTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) self.fillEncounter()
class activeEncounter(QWidget): def __init__(self, parent, encounter_name, for_table=None): super(activeEncounter, self).__init__() self.ui = Ui_activeEncounter() self.ui.setupUi(self) self.parent = parent self.encounter_name = encounter_name self.for_table = for_table self.ui.exitButton.clicked.connect(self.cancel) self.ui.encounterLabel.setText(self.encounter_name) self.ui.encounterTable.setColumnCount(len(self.parent.library_info.field_list)) i = 0 for item in self.parent.library_info.field_list: self.ui.encounterTable.setHorizontalHeaderItem(i, QTableWidgetItem(item)) i += 1 self.ui.encounterTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) self.fillEncounter() def fillEncounter(self): conn = sqlite3.connect('libraries/' + self.parent.libraryName + '.db') table_name = cleanse(self.parent.libraryName) c = conn.cursor() encounter_list = [] with open(self.parent.filename, 'r') as file: found_encounter = False found_table = False for line in file: # If this is for a table then find that table entry first. if self.for_table is not None and line.rstrip('\n') == "table:" + self.for_table and not found_table: found_table = True continue # This is for a table and we have found it. elif self.for_table is not None and found_table and line.startswith( "table_encounter:" + self.encounter_name): found_encounter = True continue # Skip lines until we find the given encounter. elif line.startswith('encounter:' + self.encounter_name) and self.for_table is None: found_encounter = True continue if found_encounter: if line == '\n': break line = (line[1:]).split(',') quantity = int(line[0]) line.pop(0) name = ("".join(line)).rstrip('\n') command = '''SELECT * FROM ''' + table_name + ''' WHERE ''' +\ cleanse(self.parent.library_info.field_list[0]) + '''=?''' print(command) print(name) c.execute(command, (name,)) result = c.fetchone() if result is not None: for j in range(quantity): i = 0 self.ui.encounterTable.insertRow(self.ui.encounterTable.rowCount()) for item in result: self.ui.encounterTable.setItem(self.ui.encounterTable.rowCount()-1, self.parent.library_info.field_list.index( self.parent.library_info.true_columns[self.parent.library_info.table_columns[i]]), QTableWidgetItem(str(item))) i += 1 def cancel(self): self.close()
class activeEncounter(QWidget): def __init__(self, parent, encounter_name, for_table=None): super(activeEncounter, self).__init__() self.ui = Ui_activeEncounter() self.ui.setupUi(self) self.parent = parent self.encounter_name = encounter_name self.for_table = for_table self.ui.exitButton.clicked.connect(self.cancel) self.ui.encounterLabel.setText(self.encounter_name) self.ui.encounterTable.setColumnCount( len(self.parent.library_info.field_list)) i = 0 for item in self.parent.library_info.field_list: self.ui.encounterTable.setHorizontalHeaderItem( i, QTableWidgetItem(item)) i += 1 self.ui.encounterTable.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeToContents) self.fillEncounter() def fillEncounter(self): conn = sqlite3.connect('libraries/' + self.parent.libraryName + '.db') table_name = cleanse(self.parent.libraryName) c = conn.cursor() encounter_list = [] with open(self.parent.filename, 'r') as file: found_encounter = False found_table = False for line in file: # If this is for a table then find that table entry first. if self.for_table is not None and line.rstrip( '\n') == "table:" + self.for_table and not found_table: found_table = True continue # This is for a table and we have found it. elif self.for_table is not None and found_table and line.startswith( "table_encounter:" + self.encounter_name): found_encounter = True continue # Skip lines until we find the given encounter. elif line.startswith('encounter:' + self.encounter_name ) and self.for_table is None: found_encounter = True continue if found_encounter: if line == '\n': break line = (line[1:]).split(',') quantity = int(line[0]) line.pop(0) name = ("".join(line)).rstrip('\n') command = '''SELECT * FROM ''' + table_name + ''' WHERE ''' +\ cleanse(self.parent.library_info.field_list[0]) + '''=?''' print(command) print(name) c.execute(command, (name, )) result = c.fetchone() if result is not None: for j in range(quantity): i = 0 self.ui.encounterTable.insertRow( self.ui.encounterTable.rowCount()) for item in result: self.ui.encounterTable.setItem( self.ui.encounterTable.rowCount() - 1, self.parent.library_info.field_list.index( self.parent.library_info.true_columns[ self.parent.library_info. table_columns[i]]), QTableWidgetItem(str(item))) i += 1 def cancel(self): self.close()