class MainWindow(widgets.MainWindow): def __init__(self): widgets.MainWindow.__init__( self, "FGM Editor", ) self.resize(800, 600) self.fgm_data = FgmFile() self.widgets = [] self.tooltips = config.read_config("ovl_util/tooltips/fgm.txt") self.shaders = {} for game in games: self.shaders[game] = config.read_list( f"ovl_util/tooltips/fgm-shaders-{game.lower().replace(' ', '-')}.txt" ) self.cleaner = QtCore.QObjectCleanupHandler() self.scrollarea = QtWidgets.QScrollArea(self) self.scrollarea.setWidgetResizable(True) self.setCentralWidget(self.scrollarea) # the actual scrollable stuff self.widget = QtWidgets.QWidget() self.scrollarea.setWidget(self.widget) self.game_container = widgets.LabelCombo("Game:", games) self.game_container.entry.currentIndexChanged.connect( self.game_changed) self.game_container.entry.setEditable(False) self.file_widget = widgets.FileWidget(self, self.cfg, dtype="FGM") self.shader_container = widgets.LabelCombo("Shader:", ()) self.shader_container.entry.activated.connect(self.shader_changed) self.tex_container = QtWidgets.QGroupBox("Textures") self.attrib_container = QtWidgets.QGroupBox("Attributes") vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.file_widget) vbox.addWidget(self.game_container) vbox.addWidget(self.shader_container) vbox.addWidget(self.tex_container) vbox.addWidget(self.attrib_container) vbox.addStretch(1) self.widget.setLayout(vbox) self.tex_grid = self.create_grid() self.attrib_grid = self.create_grid() self.tex_container.setLayout(self.tex_grid) self.attrib_container.setLayout(self.attrib_grid) mainMenu = self.menuBar() fileMenu = mainMenu.addMenu('File') helpMenu = mainMenu.addMenu('Help') button_data = ( (fileMenu, "Open", self.file_widget.ask_open, "CTRL+O", ""), \ (fileMenu, "Save", self.save_fgm, "CTRL+S", ""), \ (fileMenu, "Exit", self.close, "", ""), \ (helpMenu, "Report Bug", self.report_bug, "", ""), \ (helpMenu, "Documentation", self.online_support, "", ""), \ ) self.add_to_menu(button_data) def game_changed(self, ): if self.file_widget.filepath: self.shader_container.entry.clear() game = self.game_container.entry.currentText() self.shader_container.entry.addItems(self.shaders[game]) def shader_changed(self, ): """Change the fgm data shader name if gui changes""" if self.file_widget.filepath: self.fgm_data.shader_name = self.shader_container.entry.currentText( ) @property def fgm_name(self, ): return self.file_widget.entry.text() def create_grid(self, ): g = QtWidgets.QGridLayout() g.setHorizontalSpacing(3) g.setVerticalSpacing(0) return g def clear_layout(self, layout): w = QtWidgets.QWidget() w.setLayout(layout) # while layout.count(): # item = layout.takeAt(0) # widget = item.widget() # # if widget has some id attributes you need to # # save in a list to maintain order, you can do that here # # i.e.: aList.append(widget.someId) # widget.deleteLater() def load(self): if self.file_widget.filepath: for w in self.widgets: w.deleteLater() try: self.fgm_data.load(self.file_widget.filepath) print(self.fgm_data) game = get_game(self.fgm_data) print("from game", game) self.game_container.entry.setText(game) # also for self.game_changed() self.shader_container.entry.setText(self.fgm_data.shader_name) # delete existing widgets self.clear_layout(self.tex_grid) self.clear_layout(self.attrib_grid) self.tex_grid = self.create_grid() self.tex_grid.setColumnStretch(1, 3) self.tex_grid.setColumnStretch(2, 1) self.attrib_grid = self.create_grid() self.tex_container.setLayout(self.tex_grid) self.attrib_container.setLayout(self.attrib_grid) for line_i, tex in enumerate(self.fgm_data.textures): w = widgets.VectorEntry(tex, self.tooltips) self.tex_grid.addWidget(w.delete, line_i, 0) self.tex_grid.addWidget(w.entry, line_i, 1) self.tex_grid.addWidget(w.data, line_i, 2) for line_i, attrib in enumerate(self.fgm_data.attributes): w = widgets.VectorEntry(attrib, self.tooltips) self.attrib_grid.addWidget(w.delete, line_i, 0) self.attrib_grid.addWidget(w.entry, line_i, 1) self.attrib_grid.addWidget(w.data, line_i, 2) except Exception as ex: traceback.print_exc() ovl_util.interaction.showdialog(str(ex)) print(ex) print("Done!") def save_fgm(self): if self.file_widget.filepath: file_out = QtWidgets.QFileDialog.getSaveFileName( self, 'Save FGM', os.path.join(self.cfg.get("dir_fgms_out", "C://"), self.fgm_name), "FGM files (*.fgm)", )[0] if file_out: self.cfg["dir_fgms_out"], fgm_name = os.path.split(file_out) self.fgm_data.save(file_out) print("Done!")
class MainWindow(widgets.MainWindow): def __init__(self): widgets.MainWindow.__init__(self, "FGM Editor", ) self.resize(800, 600) self.fgm_data = FgmFile() self.tooltips = config.read_config("ovl_util/tooltips/fgm.txt") self.games = [g.value for g in games] self.fgm_dict = None self.cleaner = QtCore.QObjectCleanupHandler() self.scrollarea = QtWidgets.QScrollArea(self) self.scrollarea.setWidgetResizable(True) self.setCentralWidget(self.scrollarea) # the actual scrollable stuff self.widget = QtWidgets.QWidget() self.scrollarea.setWidget(self.widget) self.game_container = widgets.LabelCombo("Game:", self.games) self.game_container.entry.currentIndexChanged.connect(self.game_changed) self.game_container.entry.setEditable(False) self.file_widget = widgets.FileWidget(self, self.cfg, dtype="FGM") self.shader_choice = widgets.LabelCombo("Shader:", ()) self.shader_choice.entry.activated.connect(self.shader_changed) self.attribute_choice = widgets.LabelCombo("Attribute:", ()) self.texture_choice = widgets.LabelCombo("Texture:", ()) self.attribute_add = QtWidgets.QPushButton("Add Attribute") self.attribute_add.clicked.connect(self.add_attribute) self.texture_add = QtWidgets.QPushButton("Add Texture") self.texture_add.clicked.connect(self.add_texture) self.tex_container = ProptertyContainer(self, "Textures") self.attrib_container = ProptertyContainer(self, "Attributes") self.game_changed() # self.populate_choices() self.shader_changed() vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.file_widget) vbox.addWidget(self.game_container) vbox.addWidget(self.shader_choice) vbox.addWidget(self.attribute_choice) vbox.addWidget(self.attribute_add) vbox.addWidget(self.texture_choice) vbox.addWidget(self.texture_add) vbox.addWidget(self.tex_container) vbox.addWidget(self.attrib_container) vbox.addStretch(1) self.widget.setLayout(vbox) main_menu = self.menuBar() file_menu = main_menu.addMenu('File') help_menu = main_menu.addMenu('Help') button_data = ( (file_menu, "Open", self.file_widget.ask_open, "CTRL+O", "dir"), (file_menu, "Save", self.save_fgm, "CTRL+S", "save"), (file_menu, "Save As", self.save_as_fgm, "CTRL+SHIFT+S", "save"), (file_menu, "Exit", self.close, "", "exit"), (help_menu, "Report Bug", self.report_bug, "", "report"), (help_menu, "Documentation", self.online_support, "", "manual") ) self.add_to_menu(button_data) def game_changed(self,): game = self.game_container.entry.currentText() logging.info(f"Changed game to {game}") try: set_game(self.fgm_data.context, game) set_game(self.fgm_data, game) except BaseException as err: print(err) if is_jwe2(self.fgm_data): self.fgm_dict = fgm_jwe2 elif is_pz16(self.fgm_data) or is_pz(self.fgm_data): self.fgm_dict = fgm_pz else: self.fgm_dict = None self.populate_choices() def populate_choices(self): if self.fgm_dict: self.shader_choice.entry.clear() self.shader_choice.entry.addItems(sorted(self.fgm_dict.shaders)) self.attribute_choice.entry.clear() self.attribute_choice.entry.addItems(sorted(self.fgm_dict.attributes)) self.texture_choice.entry.clear() self.texture_choice.entry.addItems(sorted(self.fgm_dict.textures)) def shader_changed(self,): self.fgm_data.shader_name = self.shader_choice.entry.currentText() def add_attribute(self,): if self.fgm_dict: attrib_name = self.attribute_choice.entry.currentText() self.fgm_data.add_attrib(attrib_name, self.fgm_dict.attributes[attrib_name]) self.attrib_container.update_gui(self.fgm_data.attributes) def add_texture(self,): tex_name = self.texture_choice.entry.currentText() self.fgm_data.add_texture(tex_name) self.tex_container.update_gui(self.fgm_data.textures) @property def fgm_name(self,): return self.file_widget.entry.text() def create_grid(self,): g = QtWidgets.QGridLayout() g.setHorizontalSpacing(3) g.setVerticalSpacing(0) return g def clear_layout(self, layout): w = QtWidgets.QWidget() w.setLayout(layout) # while layout.count(): # item = layout.takeAt(0) # widget = item.widget() # # if widget has some id attributes you need to # # save in a list to maintain order, you can do that here # # i.e.: aList.append(widget.someId) # widget.deleteLater() def load(self): if self.file_widget.filepath: try: self.fgm_data.load(self.file_widget.filepath) game = get_game(self.fgm_data)[0] logging.debug(f"from game {game}") self.game_container.entry.setText(game.value) self.game_changed() self.shader_choice.entry.setText(self.fgm_data.shader_name) self.tex_container.update_gui(self.fgm_data.textures) self.attrib_container.update_gui(self.fgm_data.attributes) except Exception as ex: traceback.print_exc() ovl_util.interaction.showdialog(str(ex)) logging.warning(ex) logging.info("Done!") def save_fgm(self): if self.file_widget.filepath: self.fgm_data.save(self.file_widget.filepath) def save_as_fgm(self): file_out = QtWidgets.QFileDialog.getSaveFileName(self, 'Save FGM', os.path.join(self.cfg.get("dir_fgms_out", "C://"), self.fgm_name), "FGM files (*.fgm)",)[0] if file_out: self.cfg["dir_fgms_out"], fgm_name = os.path.split(file_out) try: self.fgm_data.save(file_out) print(self.fgm_data) except BaseException as err: traceback.print_exc() interaction.showdialog(str(err)) logging.error(err) logging.info("Done!")