def __init__(self, target_property_name, template): QGroupBox.__init__(self) PropertyWidget.__init__(self, target_property_name) main_layout = QVBoxLayout(self) button_layout = QHBoxLayout() self.make_unique_button = QPushButton("Make Unique") self.make_unique_button.setSizePolicy( QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) self.clear_button = QPushButton("Clear") self.clear_button.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) self.toggle_button = QPushButton("Toggle Editor") self.toggle_button.setSizePolicy( QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) button_layout.addWidget(self.make_unique_button) button_layout.addWidget(self.clear_button) button_layout.addWidget(self.toggle_button) main_layout.addLayout(button_layout) self.property_form = PropertyForm(template) self.form_widget = QWidget() self.property_form.setContentsMargins(0, 0, 0, 0) self.form_widget.setLayout(self.property_form) main_layout.addWidget(self.form_widget) self.setLayout(main_layout) self.form_widget.setVisible(False) self.make_unique_button.clicked.connect(self._on_make_unique_clicked) self.clear_button.clicked.connect(self._on_clear_clicked) self.toggle_button.clicked.connect(lambda: self.form_widget.setVisible( not self.form_widget.isVisible()))
class ObjectEditor(QWidget): def __init__(self, module): super().__init__() self.module = module self.element = self.module.element self.setWindowTitle(module.name) self.setWindowIcon(QIcon("paragon.ico")) central_layout = QVBoxLayout() scroll_area = QScrollArea() form_widget = QWidget() self.editors = [] self.property_form = PropertyForm(self.element) self.property_form.update_target(self.element) form_widget.setLayout(self.property_form) scroll_area.setWidget(form_widget) scroll_area.setWidgetResizable(True) central_layout.addWidget(scroll_area) self.setLayout(central_layout) logging.info("Generated ObjectEditor for " + self.module.name) def show(self): if self.element: self.property_form.update_target(self.element) super().show()
def __init__(self, parent=None): super().__init__(parent) self.contents = QWidget() self.form = PropertyForm(get_spawn_template()) self.contents.setLayout(self.form) self.setWidgetResizable(True) self.setWidget(self.contents)
def __init__(self): super().__init__() self.chapter_data = None module_service = locator.get_scoped("ModuleService") config_module = module_service.get_common_module_template("Map Config") self.module = module_service.get_module("Chapters") self.text_data_widget = FE14ChapterTextDataWidget() self.header_scroll, self.header_property_form = PropertyForm.create_with_scroll( self.module.element_template) self.config_scroll, self.config_property_form = PropertyForm.create_with_scroll( config_module.element_template) self.header_property_form.editors["CID"].setEnabled(False) self.header_property_form.editors["Key (CID)"].setEnabled(False) self.vertical_layout = QVBoxLayout(parent=self) self.splitter = QSplitter(parent=self) self.splitter.setOrientation(QtCore.Qt.Vertical) self.splitter2 = QSplitter(parent=self) self.splitter2.setOrientation(QtCore.Qt.Horizontal) self.splitter.addWidget(self.text_data_widget) self.splitter.addWidget(self.splitter2) self.splitter2.addWidget(self.header_scroll) self.splitter2.addWidget(self.config_scroll) self.vertical_layout.addWidget(self.splitter) self.scroll_content = QWidget() self.scroll_content.setLayout(self.vertical_layout) self.setWidget(self.scroll_content) self.setWidgetResizable(True)
def __init__(self, module: TableModule): super().__init__() self.setupUi(self) self.module = module self.selection = None self.model = self.module.entries_model self.proxy_model = QtCore.QSortFilterProxyModel() self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.proxy_model.setSourceModel(self.model) self.list_view.setModel(self.proxy_model) self.clear_selection_shortcut = QShortcut(QKeySequence.Cancel, self) self.list_view.selectionModel().currentRowChanged.connect( self._update_selection) self.clear_selection_shortcut.activated.connect( lambda: self._update_selection(QModelIndex())) self.search_field.textChanged.connect(self._update_filter) self.add_button.clicked.connect(self._on_add_pressed) self.remove_button.clicked.connect(self._on_remove_pressed) self.copy_to_button.clicked.connect(self._on_copy_to_pressed) self.property_form = PropertyForm(module.element_template) self.form_layout.setLayout(self.property_form) self.setWindowTitle(self.module.name) self.setWindowIcon(QIcon("paragon.ico")) self.copy_to_button.setEnabled(False) self.remove_button.setEnabled(False) self.splitter.setSizes([300, 680]) self.splitter.setStretchFactor(0, 0) self.splitter.setStretchFactor(1, 1) self.list_context_menu = QMenu(self) self.add_action = QAction("Add Element") self.add_action.triggered.connect(self._on_add_pressed) self.remove_action = QAction("Remove Element") self.remove_action.triggered.connect(self._on_remove_pressed) self.copy_to_action = QAction("Copy To") self.copy_to_action.triggered.connect(self._on_copy_to_pressed) self.list_context_menu.addActions( [self.add_action, self.remove_action, self.copy_to_action]) self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.list_view.customContextMenuRequested.connect( self._on_list_context_menu_requested) if self.module.disable_add_remove: self.add_action.setEnabled(False) self.remove_action.setEnabled(False) self.add_button.setVisible(False) self.remove_button.setVisible(False) self._update_selection(QModelIndex()) logging.info("Generated SimpleEditor for " + self.module.name)
class FE14SpawnEditorPane(QScrollArea): def __init__(self, parent=None): super().__init__(parent) self.contents = QWidget() self.form = PropertyForm(get_spawn_template()) self.contents.setLayout(self.form) self.setWidgetResizable(True) self.setWidget(self.contents) def update_target(self, new_target: Optional[PropertyContainer]): self.form.update_target(new_target) def update_coordinate_of_target(self, coordinate_key: str, updated_spawn): self.form.editors[coordinate_key].update_target(updated_spawn)
def __init__(self): super().__init__() self.chapter_data = None self.dispos_model = None self.dispos = None self.terrain = None self.tiles_model = None self.terrain_mode = False self.initialized_selection_signal = False self.selected_faction = None left_panel_container = QWidget() left_panel_layout = QVBoxLayout() self.toggle_editor_type_checkbox = QCheckBox() self.toggle_editor_type_checkbox.setText("Spawns/Terrain") self.toggle_editor_type_checkbox.setChecked(True) self.toggle_editor_type_checkbox.stateChanged.connect( self._on_mode_change_requested) self.toggle_coordinate_type_checkbox = QCheckBox() self.toggle_coordinate_type_checkbox.setText( "Coordinate (1)/Coordinate (2)") self.toggle_coordinate_type_checkbox.setChecked(True) self.toggle_coordinate_type_checkbox.stateChanged.connect( self._on_coordinate_change_requested) self.tree_view = QTreeView() left_panel_layout.addWidget(self.toggle_editor_type_checkbox) left_panel_layout.addWidget(self.toggle_coordinate_type_checkbox) left_panel_layout.addWidget(self.tree_view) left_panel_container.setLayout(left_panel_layout) self.grid = FE14MapGrid() self.dispos_scroll, self.dispos_form = PropertyForm.create_with_scroll( dispo.SPAWN_TEMPLATE) self.terrain_form, self.terrain_persistent_editors, self.tile_form = _create_terrain_form( ) self.organizer = QSplitter() self.organizer.addWidget(left_panel_container) self.organizer.addWidget(self.grid) self.organizer.addWidget(self.dispos_scroll) main_layout = QVBoxLayout(self) main_layout.addWidget(self.organizer) self.setLayout(main_layout) self.add_faction_shortcut = QShortcut(QKeySequence("Ctrl+F"), self) self.add_item_shortcut = QShortcut(QKeySequence("Ctrl+N"), self) self.grid.focused_spawn_changed.connect(self._on_focused_spawn_changed) self.add_faction_shortcut.activated.connect( self._on_add_faction_requested) self.add_item_shortcut.activated.connect(self._on_add_item_requested) self.dispos_form.editors["PID"].editingFinished.connect( self._on_pid_field_changed) self.dispos_form.editors["Team"].currentIndexChanged.connect( self._on_team_field_changed) self.dispos_form.editors["Coordinate (1)"].textChanged.connect( self._on_coordinate_1_field_changed) self.dispos_form.editors["Coordinate (2)"].textChanged.connect( self._on_coordinate_2_field_changed)
def _create_terrain_form(): terrain = Terrain() persistent_form = QFormLayout() persistent_editors = [] _create_editor_for_property(terrain.map_model, persistent_form, persistent_editors) _create_editor_for_property(terrain.map_size_x, persistent_form, persistent_editors) _create_editor_for_property(terrain.map_size_y, persistent_form, persistent_editors) _create_editor_for_property(terrain.border_size_x, persistent_form, persistent_editors) _create_editor_for_property(terrain.border_size_y, persistent_form, persistent_editors) _create_editor_for_property(terrain.trimmed_size_x, persistent_form, persistent_editors) _create_editor_for_property(terrain.trimmed_size_y, persistent_form, persistent_editors) tile_scroll, tile_form = PropertyForm.create_with_scroll( fe14.terrain.TILE_TEMPLATE) tile_form.editors["ID"].setEnabled(False) persistent_form_container = QWidget() persistent_form_container.setLayout(persistent_form) container = QWidget() layout = QVBoxLayout() layout.addWidget(persistent_form_container) layout.addWidget(tile_scroll) container.setLayout(layout) return container, persistent_editors, tile_form
def __init__(self, parent=None): super().__init__(parent) terrain = Terrain() persistent_properties_template = terrain.adapter() self.persistent_scroll, self.persistent_form = PropertyForm.create_with_scroll(persistent_properties_template) self.tile_scroll, self.tile_form = PropertyForm.create_with_scroll(get_tile_template()) self.toggle_persistent_button = QPushButton(text="Toggle Map/Grid Properties") self.persistent_scroll.setFixedHeight(300) self.layout = QVBoxLayout() self.container = QWidget() self.layout.addWidget(self.toggle_persistent_button) self.layout.addWidget(self.persistent_scroll) self.layout.addWidget(self.tile_scroll) self.container.setLayout(self.layout) self.setWidgetResizable(True) self.setWidget(self.container) self.toggle_persistent_button.clicked.connect(self._on_toggle_persistent_button_pressed)
class PointerPropertyEditor(QGroupBox, PropertyWidget): def __init__(self, target_property_name, template): QGroupBox.__init__(self) PropertyWidget.__init__(self, target_property_name) main_layout = QVBoxLayout(self) button_layout = QHBoxLayout() self.make_unique_button = QPushButton("Make Unique") self.make_unique_button.setSizePolicy( QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) self.clear_button = QPushButton("Clear") self.clear_button.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) self.toggle_button = QPushButton("Toggle Editor") self.toggle_button.setSizePolicy( QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) button_layout.addWidget(self.make_unique_button) button_layout.addWidget(self.clear_button) button_layout.addWidget(self.toggle_button) main_layout.addLayout(button_layout) self.property_form = PropertyForm(template) self.form_widget = QWidget() self.property_form.setContentsMargins(0, 0, 0, 0) self.form_widget.setLayout(self.property_form) main_layout.addWidget(self.form_widget) self.setLayout(main_layout) self.form_widget.setVisible(False) self.make_unique_button.clicked.connect(self._on_make_unique_clicked) self.clear_button.clicked.connect(self._on_clear_clicked) self.toggle_button.clicked.connect(lambda: self.form_widget.setVisible( not self.form_widget.isVisible())) def _on_make_unique_clicked(self): if self.target: self.target[self.target_property_name].make_unique() self._on_target_changed() # Pointer value changes here. def _on_clear_clicked(self): if self.target: self.target[self.target_property_name].clear_value() self._on_target_changed() # Pointer value changes here. def _on_target_changed(self): if self.target: target_for_children = self._get_target_value() self.property_form.update_target(target_for_children) self.form_widget.setEnabled(target_for_children is not None) else: self.property_form.update_target(None)
def __init__(self, is_person=False, parent=None): super().__init__(parent) self.is_person = is_person self.module: TableModule = locator.get_scoped( "ModuleService").get_module("Characters") self.proxy_model = QSortFilterProxyModel() self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.proxy_model.setSourceModel(self.module.entries_model) self.characters_list_view.setModel(self.proxy_model) self.selection: Optional[PropertyContainer] = None self.character_details_form_1 = PropertyForm( self.module.element_template, category="character_description_1") self.character_details_form_contents_1.setLayout( self.character_details_form_1) self.character_details_form_2 = PropertyForm( self.module.element_template, category="character_description_2") self.character_details_form_contents_2.setLayout( self.character_details_form_2) self.character_details_form_2.fix_editor_width(100) self.stats_editor = MergedStatsEditor( ["Bases", "Growths", "Modifiers", "Penalties", "Bonuses"]) self.stats_form = PropertyForm(self.module.element_template, category="stats") self.stats_layout.addWidget(self.stats_editor) self.stats_layout.addLayout(self.stats_form) self.skills_form = PropertyForm(self.module.element_template, category="skills", sort_editors=True) self.skills_contents.setLayout(self.skills_form) self.flags_editor = MergedFlagsEditor( ["Bitflags (1)", "Bitflags (2)", "Bitflags (3)", "Bitflags (4)"], self.module.element_template) self.flags_editor_2 = MergedFlagsEditor( ["Bitflags (5)", "Bitflags (6)", "Bitflags (7)", "Bitflags (8)"], self.module.element_template) self.misc_form = PropertyForm(self.module.element_template, category="misc") self.misc_layout.addWidget(self.flags_editor) self.misc_layout.addWidget(self.flags_editor_2) self.misc_layout.addLayout(self.misc_form) self.ids_form = PropertyForm(self.module.element_template, category="ids") self.ids_tab.setLayout(self.ids_form) self.classes_form = PropertyForm(self.module.element_template, category="classes", sort_editors=True) self.classes_tab.setLayout(self.classes_form) if not self.is_person: self.dialogue_tab = DialogueEditor() self.supports_tab = QWidget() self.supports_layout = QHBoxLayout() self.supports_widget = FE14SupportWidget() self.supports_scroll = QScrollArea() self.supports_scroll_contents = QWidget() self.supports_scroll.setWidget(self.supports_scroll_contents) self.supports_scroll.setWidgetResizable(True) self.supports_layout.addWidget(self.supports_widget) self.supports_layout.addWidget(self.supports_scroll) self.supports_tab.setLayout(self.supports_layout) self.supports_form = PropertyForm(self.module.element_template, category="supports") self.supports_scroll_contents.setLayout(self.supports_form) self.tab_widget.addTab(self.supports_tab, "Supports") self.tab_widget.addTab(self.dialogue_tab, "Dialogue") self.context_menu = QMenu(self) self.context_menu.addActions( [self.action_add, self.action_remove, self.action_copy_to]) self.clear_selection_shortcut = QShortcut(QKeySequence.Cancel, self) self._install_signals() self._clear()
class FE14CharacterEditor(Ui_FE14CharacterEditor): def __init__(self, is_person=False, parent=None): super().__init__(parent) self.is_person = is_person self.module: TableModule = locator.get_scoped( "ModuleService").get_module("Characters") self.proxy_model = QSortFilterProxyModel() self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.proxy_model.setSourceModel(self.module.entries_model) self.characters_list_view.setModel(self.proxy_model) self.selection: Optional[PropertyContainer] = None self.character_details_form_1 = PropertyForm( self.module.element_template, category="character_description_1") self.character_details_form_contents_1.setLayout( self.character_details_form_1) self.character_details_form_2 = PropertyForm( self.module.element_template, category="character_description_2") self.character_details_form_contents_2.setLayout( self.character_details_form_2) self.character_details_form_2.fix_editor_width(100) self.stats_editor = MergedStatsEditor( ["Bases", "Growths", "Modifiers", "Penalties", "Bonuses"]) self.stats_form = PropertyForm(self.module.element_template, category="stats") self.stats_layout.addWidget(self.stats_editor) self.stats_layout.addLayout(self.stats_form) self.skills_form = PropertyForm(self.module.element_template, category="skills", sort_editors=True) self.skills_contents.setLayout(self.skills_form) self.flags_editor = MergedFlagsEditor( ["Bitflags (1)", "Bitflags (2)", "Bitflags (3)", "Bitflags (4)"], self.module.element_template) self.flags_editor_2 = MergedFlagsEditor( ["Bitflags (5)", "Bitflags (6)", "Bitflags (7)", "Bitflags (8)"], self.module.element_template) self.misc_form = PropertyForm(self.module.element_template, category="misc") self.misc_layout.addWidget(self.flags_editor) self.misc_layout.addWidget(self.flags_editor_2) self.misc_layout.addLayout(self.misc_form) self.ids_form = PropertyForm(self.module.element_template, category="ids") self.ids_tab.setLayout(self.ids_form) self.classes_form = PropertyForm(self.module.element_template, category="classes", sort_editors=True) self.classes_tab.setLayout(self.classes_form) if not self.is_person: self.dialogue_tab = DialogueEditor() self.supports_tab = QWidget() self.supports_layout = QHBoxLayout() self.supports_widget = FE14SupportWidget() self.supports_scroll = QScrollArea() self.supports_scroll_contents = QWidget() self.supports_scroll.setWidget(self.supports_scroll_contents) self.supports_scroll.setWidgetResizable(True) self.supports_layout.addWidget(self.supports_widget) self.supports_layout.addWidget(self.supports_scroll) self.supports_tab.setLayout(self.supports_layout) self.supports_form = PropertyForm(self.module.element_template, category="supports") self.supports_scroll_contents.setLayout(self.supports_form) self.tab_widget.addTab(self.supports_tab, "Supports") self.tab_widget.addTab(self.dialogue_tab, "Dialogue") self.context_menu = QMenu(self) self.context_menu.addActions( [self.action_add, self.action_remove, self.action_copy_to]) self.clear_selection_shortcut = QShortcut(QKeySequence.Cancel, self) self._install_signals() self._clear() def set_module(self, module: TableModule): self.module = module if self.module: self.proxy_model.setSourceModel(self.module.entries_model) else: self.proxy_model.setSourceModel(None) self.setEnabled(self.module is not None) self._clear() def _on_context_menu_requested(self, point: QPoint): self.context_menu.exec_(self.characters_list_view.mapToGlobal(point)) def _install_signals(self): self.characters_list_view.selectionModel().currentRowChanged.connect( self._update_selection) self.characters_list_view.customContextMenuRequested.connect( self._on_context_menu_requested) self.search_bar.textChanged.connect(self._update_filter) self.action_add.triggered.connect(self._on_add_character_triggered) self.action_remove.triggered.connect( self._on_remove_character_triggered) self.action_copy_to.triggered.connect(self._on_copy_to_triggered) self.clear_selection_shortcut.activated.connect(self._clear) if self.character_details_form_1.editors['Name'] != None: self.character_details_form_1.editors[ 'Name'].value_editor.editingFinished.connect( self._update_conversation_widget) def _clear(self): self.characters_list_view.clearSelection() self.characters_list_view.selectionModel().clearCurrentIndex() def _update_selection(self, index: QModelIndex): self.selection = self.proxy_model.data(index, QtCore.Qt.UserRole) self.portraits_tab.update_target(self.selection) self.character_details_form_1.update_target(self.selection) self.character_details_form_2.update_target(self.selection) self.stats_editor.update_target(self.selection) self.ids_form.update_target(self.selection) self.classes_form.update_target(self.selection) self.stats_form.update_target(self.selection) self.skills_form.update_target(self.selection) self.flags_editor.update_target(self.selection) self.flags_editor_2.update_target(self.selection) self.misc_form.update_target(self.selection) if not self.is_person: self.dialogue_tab.update_target(self.selection) self.supports_widget.update_target(self.selection) self.supports_form.update_target(self.selection) if self.selection: locator.get_scoped("SpriteService").get_sprite_for_character( self.selection, 0) self.action_remove.setEnabled(self.selection is not None) self.action_copy_to.setEnabled(self.selection is not None) self._update_portrait_box() def _update_portrait_box(self): portrait_service = locator.get_scoped("PortraitService") mini_portraits = portrait_service.get_sorted_portraits_for_character( self.selection, "bu") if mini_portraits: _, texture = mini_portraits[0] scene = QGraphicsScene() scene.addPixmap(QPixmap.fromImage(texture.image())) self.portrait_display.setScene(scene) else: self.portrait_display.setScene(None) def _update_filter(self): self.proxy_model.setFilterRegExp(self.search_bar.text()) def _on_add_character_triggered(self): model = self.module.entries_model model.insertRow(model.rowCount()) source = self.module.entries[0] destination = self.module.entries[-1] source.copy_to(destination) # Update any present conversation widget with the new obj list self._update_conversation_widget() def _on_remove_character_triggered(self): if self.characters_list_view.currentIndex().isValid(): model = self.module.entries_model model.removeRow(self.characters_list_view.currentIndex().row()) model.beginResetModel() model.endResetModel() # Update any present conversation widget with the new obj list self._update_conversation_widget() def _update_conversation_widget(self): for editor in self.supports_widget.service._conversation_editors: editor: FE14ConversationEditor character_list = list() [ character_list.append(child[1]) for child in self.module.children() ] editor.text_area._character_list = character_list def _on_copy_to_triggered(self): if not self.selection: return logging.info("Beginning copy to for " + self.module.name) choices = [] for i in range(0, len(self.module.entries)): choices.append( str(i + 1) + ". " + self.module.entries[i].get_display_name()) choice = QInputDialog.getItem(self, "Select Destination", "Destination", choices) if choice[1]: for i in range(0, len(choices)): if choice[0] == choices[i]: self.selection.copy_to(self.module.entries[i]) # Update any present conversation widget with the new obj list self._update_conversation_widget() else: logging.info("No choice selected for " + self.module.name + " copy to. Aborting.")
def __init__(self): super().__init__() self.setupUi(self) self.setWindowTitle("Voice Set Editor") self.setWindowIcon(QIcon("paragon.ico")) self.service = locator.get_scoped("SoundService") self.voice_set_model = self.service.get_voice_set_model() self.error_dialog = None self.form = PropertyForm(self.service.template) self.form_widget = QWidget() self.form_widget.setLayout(self.form) self.horizontalLayout_3.addWidget(self.form_widget) self.proxy_model = QtCore.QSortFilterProxyModel() self.proxy_model.setSourceModel(self.voice_set_model) self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.sets_menu = QMenu(self) self.add_set_action = QAction("Add Voice Set") self.remove_set_action = QAction("Remove Voice Set") self.remove_set_action.setDisabled(True) self.sets_menu.addActions( [self.add_set_action, self.remove_set_action]) self.sets_list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.sets_list_view.customContextMenuRequested.connect( self._on_sets_menu_requested) self.entries_menu = QMenu(self) self.entries_menu.setDisabled(True) self.add_entry_action = QAction("Add Entry") self.remove_entry_action = QAction("Remove Entry") self.copy_tag_action = QAction("Copy Tag to All Entries") self.entries_menu.addActions([ self.add_entry_action, self.remove_entry_action, self.copy_tag_action ]) self.sounds_list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.sounds_list_view.customContextMenuRequested.connect( self._on_entries_menu_requested) self.sets_list_view.setModel(self.proxy_model) self.sets_list_view.selectionModel().currentRowChanged.connect( self._update_set_selection) self.search_bar.textChanged.connect(self._update_filter) self.add_set_action.triggered.connect(self._on_add_set_triggered) self.remove_set_action.triggered.connect(self._on_remove_set_triggered) self.add_entry_action.triggered.connect(self._on_add_entry_triggered) self.remove_entry_action.triggered.connect( self._on_remove_entry_triggered) self.copy_tag_action.triggered.connect(self._on_copy_tags_triggered) self.form.editors["Name"].editingFinished.connect( self._write_back_entry) self.form.editors["Tag"].editingFinished.connect( self._write_back_entry) self.selected_voice_set: Optional[VoiceSetEntriesModel] = None self.selected_voice_set_entry: Optional[PropertyContainer] = None self.service.set_in_use() self._update_set_selection(QModelIndex())
class FE14SoundEditor(QWidget, Ui_sound_editor): def __init__(self): super().__init__() self.setupUi(self) self.setWindowTitle("Voice Set Editor") self.setWindowIcon(QIcon("paragon.ico")) self.service = locator.get_scoped("SoundService") self.voice_set_model = self.service.get_voice_set_model() self.error_dialog = None self.form = PropertyForm(self.service.template) self.form_widget = QWidget() self.form_widget.setLayout(self.form) self.horizontalLayout_3.addWidget(self.form_widget) self.proxy_model = QtCore.QSortFilterProxyModel() self.proxy_model.setSourceModel(self.voice_set_model) self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.sets_menu = QMenu(self) self.add_set_action = QAction("Add Voice Set") self.remove_set_action = QAction("Remove Voice Set") self.remove_set_action.setDisabled(True) self.sets_menu.addActions( [self.add_set_action, self.remove_set_action]) self.sets_list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.sets_list_view.customContextMenuRequested.connect( self._on_sets_menu_requested) self.entries_menu = QMenu(self) self.entries_menu.setDisabled(True) self.add_entry_action = QAction("Add Entry") self.remove_entry_action = QAction("Remove Entry") self.copy_tag_action = QAction("Copy Tag to All Entries") self.entries_menu.addActions([ self.add_entry_action, self.remove_entry_action, self.copy_tag_action ]) self.sounds_list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.sounds_list_view.customContextMenuRequested.connect( self._on_entries_menu_requested) self.sets_list_view.setModel(self.proxy_model) self.sets_list_view.selectionModel().currentRowChanged.connect( self._update_set_selection) self.search_bar.textChanged.connect(self._update_filter) self.add_set_action.triggered.connect(self._on_add_set_triggered) self.remove_set_action.triggered.connect(self._on_remove_set_triggered) self.add_entry_action.triggered.connect(self._on_add_entry_triggered) self.remove_entry_action.triggered.connect( self._on_remove_entry_triggered) self.copy_tag_action.triggered.connect(self._on_copy_tags_triggered) self.form.editors["Name"].editingFinished.connect( self._write_back_entry) self.form.editors["Tag"].editingFinished.connect( self._write_back_entry) self.selected_voice_set: Optional[VoiceSetEntriesModel] = None self.selected_voice_set_entry: Optional[PropertyContainer] = None self.service.set_in_use() self._update_set_selection(QModelIndex()) def show(self): super().show() self.setDisabled(not self.service.load_succeeded) if not self.service.load_succeeded: self.error_dialog = ErrorDialog( "Unable to load required data. See the log for details.") self.error_dialog.show() def _update_filter(self): self.proxy_model.setFilterRegExp(self.search_bar.text()) def _on_entries_menu_requested(self, point: QPoint): self.entries_menu.exec_(self.sounds_list_view.mapToGlobal(point)) def _on_sets_menu_requested(self, point: QPoint): self.sets_menu.exec_(self.sets_list_view.mapToGlobal(point)) def _update_set_selection(self, index: QtCore.QModelIndex): if self.selected_voice_set: self.sounds_list_view.selectionModel( ).currentRowChanged.disconnect() self.selected_voice_set = self.proxy_model.data( index, QtCore.Qt.UserRole) self.sounds_list_view.setModel(self.selected_voice_set) if self.selected_voice_set: self.sounds_list_view.selectionModel().currentRowChanged.connect( self._update_sound_selection) self.entries_menu.setDisabled(False) self.remove_set_action.setDisabled(False) else: self.entries_menu.setDisabled(True) self.remove_set_action.setDisabled(True) self.form_widget.setDisabled(True) self.remove_entry_action.setDisabled(True) self.copy_tag_action.setDisabled(True) self.selected_voice_set_entry = None self.form.update_target(self.selected_voice_set_entry) def _update_sound_selection(self, index: QtCore.QModelIndex): self.selected_voice_set_entry = self.selected_voice_set.data( index, QtCore.Qt.UserRole) self.form_widget.setDisabled(self.selected_voice_set_entry is None) self.remove_entry_action.setDisabled( self.selected_voice_set_entry is None) self.copy_tag_action.setDisabled(self.selected_voice_set_entry is None) self.form.update_target(self.selected_voice_set_entry) def _write_back_entry(self): if self.selected_voice_set and self.selected_voice_set_entry: self.selected_voice_set.save_entry(self.selected_voice_set_entry) def _on_add_entry_triggered(self): if self.selected_voice_set: self.selected_voice_set.insertRow( self.selected_voice_set.rowCount()) def _on_remove_entry_triggered(self): if self.selected_voice_set and self.selected_voice_set_entry: self.selected_voice_set.remove_entry(self.selected_voice_set_entry) self.sounds_list_view.selectionModel().clearCurrentIndex() def _on_copy_tags_triggered(self): if self.selected_voice_set and self.selected_voice_set_entry: self.selected_voice_set.synchronize_tags( self.selected_voice_set_entry) def _on_add_set_triggered(self): (desired_name, ok) = QInputDialog.getText(self, "Enter a unique name for the voice set.", "Name") if not ok: return try: self.voice_set_model.create_voice_set(desired_name) except NameError: self.error_dialog = ErrorDialog( "Voice set name %s is already in use." % desired_name) self.error_dialog.show() except: logging.exception( "Unknown error when adding voice set to IndirectSound.") self.error_dialog = ErrorDialog( "An unknown error occurred. See the log for details.") self.error_dialog.show() def _on_remove_set_triggered(self): if self.selected_voice_set: self.voice_set_model.remove_voice_set( self.selected_voice_set.voice_set_label) self.sets_list_view.clearSelection()
class SimpleEditor(QWidget, Ui_simple_editor): def __init__(self, module: TableModule): super().__init__() self.setupUi(self) self.module = module self.selection = None self.model = self.module.entries_model self.proxy_model = QtCore.QSortFilterProxyModel() self.proxy_model.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive) self.proxy_model.setSourceModel(self.model) self.list_view.setModel(self.proxy_model) self.clear_selection_shortcut = QShortcut(QKeySequence.Cancel, self) self.list_view.selectionModel().currentRowChanged.connect( self._update_selection) self.clear_selection_shortcut.activated.connect( lambda: self._update_selection(QModelIndex())) self.search_field.textChanged.connect(self._update_filter) self.add_button.clicked.connect(self._on_add_pressed) self.remove_button.clicked.connect(self._on_remove_pressed) self.copy_to_button.clicked.connect(self._on_copy_to_pressed) self.property_form = PropertyForm(module.element_template) self.form_layout.setLayout(self.property_form) self.setWindowTitle(self.module.name) self.setWindowIcon(QIcon("paragon.ico")) self.copy_to_button.setEnabled(False) self.remove_button.setEnabled(False) self.splitter.setSizes([300, 680]) self.splitter.setStretchFactor(0, 0) self.splitter.setStretchFactor(1, 1) self.list_context_menu = QMenu(self) self.add_action = QAction("Add Element") self.add_action.triggered.connect(self._on_add_pressed) self.remove_action = QAction("Remove Element") self.remove_action.triggered.connect(self._on_remove_pressed) self.copy_to_action = QAction("Copy To") self.copy_to_action.triggered.connect(self._on_copy_to_pressed) self.list_context_menu.addActions( [self.add_action, self.remove_action, self.copy_to_action]) self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.list_view.customContextMenuRequested.connect( self._on_list_context_menu_requested) if self.module.disable_add_remove: self.add_action.setEnabled(False) self.remove_action.setEnabled(False) self.add_button.setVisible(False) self.remove_button.setVisible(False) self._update_selection(QModelIndex()) logging.info("Generated SimpleEditor for " + self.module.name) def _on_list_context_menu_requested(self, point: QPoint): self.list_context_menu.exec_(self.list_view.mapToGlobal(point)) def _update_selection(self, index: QtCore.QModelIndex): logging.info("Updating " + self.module.name + " to selected index " + str(index.row())) self.selection = self.proxy_model.data(index, QtCore.Qt.UserRole) self.property_form.update_target(self.selection) self.scrollArea.setEnabled(self.selection is not None) self.remove_action.setEnabled(self.selection is not None) self.copy_to_action.setEnabled(self.selection is not None) self.remove_button.setEnabled(self.selection is not None) self.copy_to_button.setEnabled(self.selection is not None) if not self.selection: self.list_view.clearSelection() def _update_filter(self): self.proxy_model.setFilterRegExp(self.search_field.text()) def _on_add_pressed(self): # Add the new entry. self.model.insertRow(self.model.rowCount()) # Copy the first entry's properties into the new entry. source = self.module.entries[0] dest = self.module.entries[len(self.module.entries) - 1] source.copy_to(dest) def _on_remove_pressed(self): for i in range(0, len(self.module.entries)): if self.module.entries[i] == self.selection: self.model.removeRow(i) self.model.beginResetModel() self.model.endResetModel() return def _on_copy_to_pressed(self): logging.info("Beginning copy to for " + self.module.name) choices = [] for i in range(0, len(self.module.entries)): choices.append( str(i + 1) + ". " + self.model.data(self.model.index(i, 0), QtCore.Qt.DisplayRole)) choice = QInputDialog.getItem(self, "Select Destination", "Destination", choices) if choice[1]: for i in range(0, len(choices)): if choice[0] == choices[i]: self.selection.copy_to(self.module.entries[i]) else: logging.info("No choice selected for " + self.module.name + " copy to. Aborting.")