コード例 #1
0
    def apply(self):
        """
        Applies the settings, stores them and keeps the window open
        """
        # update id size when changed
        if self.id_size_def != self.id_size_def_new:
            Settings.alter_default_id_size(self.id_size_def_new)

        # auto update roles when changed
        if self.auto_update_roles != self.auto_update_roles_new:
            Settings.alter_auto_update_roles(self.auto_update_roles_new)

        # update the logfile location and update the logging
        if self.logfile_path != self.logfile_path_new:
            Settings.alter_default_logfile_name(self.logfile_path_new)

        # update the node types folder and reset the node types
        if self.node_types_path != self.node_types_path_new:
            Settings.alter_default_node_types_folder(self.node_types_path_new)
            self.gui.main_listener.open_node_types_signal.emit()

        # update the jsons folder and open it as a collection
        if self.jsons_path != self.jsons_path_new:
            Settings.alter_default_json_folder(self.jsons_path_new)
            self.gui.menubar.open_collection()

        # disable the apply button
        self.enable_apply(False)
 def test_invalid_alteration(self, tmpdir):
     # use tmpdir, so we're not overriding the official settings file
     json_settings = read_json(Settings.SETTINGS_PATH)
     tmp_path = tmpdir / 'settings.json'
     write_json(tmp_path, json_settings)
     with pytest.raises(SettingNotFoundException):
         Settings.alter_setting("test", "blahs", "test", tmp_path)
 def test_from_path_default(self):
     def_json = Settings.default_json_folder()
     Settings.alter_default_json_folder(self.path)
     collection = Collection.from_path()
     Settings.alter_default_json_folder(def_json)
     # collection should not contain the invalid roles/InvalidRole.json
     assert 'InvalidRole' not in collection.collection.get('roles').keys()
     assert Collection(self.collection) == collection
 def test_write_default_path(self, tmpdir):
     # case where path is not set and not called
     node_types = NodeTypes.from_csv()
     def_path = Settings.default_node_types_folder()
     Settings.alter_default_node_types_folder(tmpdir)
     # test if writing does not return in an error
     node_types.write()
     read = NodeTypes.from_csv(tmpdir)
     Settings.alter_default_node_types_folder(def_path)
     assert node_types == read
 def test_write_collection_default_path1(self, tmpdir):
     def_path = Settings.default_json_folder()
     Settings.alter_default_json_folder(tmpdir)
     collection = Collection.from_path()
     collection.write_collection()
     read = Collection.from_path(tmpdir)
     Settings.alter_default_json_folder(def_path)
     # sets path equal, so objects are equal
     collection.path = None
     read.path = None
     assert collection == read
 def test_verify_trees(self):
     collection = Collection.from_path(Settings.default_json_folder(), only_verify_mathematical_properties=False)
     for category in collection.collection:
         for file in collection.collection[category]:
             # skip these two files as there is a decorator with two children
             if not (file == "GetBallTestTactic.json" or file == "GetBallTestStrategy.json"):
                 assert 0 is len(collection.verify_tree(collection.collection[category][file], category))
 def test_from_csv(self):
     node_types = NodeTypes.from_csv(Settings.default_node_types_folder())
     assert '.hiddenfile.csv' not in node_types.node_types.keys()
     assert 'filewithotherextension.abc' not in node_types.node_types.keys()
     assert 'composites' in node_types.node_types.keys()
     assert 'conditions' in node_types.node_types.keys()
     assert 'decorators' in node_types.node_types.keys()
     assert 'other' in node_types.node_types.keys()
     assert 'skills' in node_types.node_types.keys()
コード例 #8
0
 def save_collection_as(self):
     """
     Emits a signal to write the collection to a custom path
     Custom path selected from folder selector
     """
     json_path = Settings.default_json_folder()
     path = Dialogs.open_folder_dialog('Save collection folder', json_path)
     # do a call to the controller to write the collection
     if path:
         self.main_window.main_listener.write_collection_custom_path_signal.emit(
             self.main_window.collection, path)
 def test_valid_alteration(self, tmpdir):
     # use tmpdir, so we're not overriding the official settings file
     json_settings = read_json(Settings.SETTINGS_PATH)
     tmp_path = tmpdir / 'settings.json'
     write_json(tmp_path, json_settings)
     default_json_folder_path = Path(Settings.default_json_folder())
     Settings.alter_default_json_folder(Path("blahs"))
     assert Settings.default_json_folder() == Path("blahs")
     Settings.alter_default_json_folder(Path(default_json_folder_path))
     assert Settings.default_json_folder() == default_json_folder_path
コード例 #10
0
 def open_collection_custom_path(self):
     """
     Displays a folder selector
     Calls the emit signal for opening a collection
         if a folder is selected, otherwise nothing happens (cancel)
     """
     json_path = Settings.default_json_folder()
     path = Dialogs.open_folder_dialog('Open collection folder', json_path)
     # do a call to the controller to open the collection
     if path:
         self.main_window.check_unsaved_changes(write=True)
         self.main_window.main_listener.open_collection_custom_path_signal.emit(
             path)
コード例 #11
0
 def save_tree_as(self):
     """
     Saves the tree currently displayed to a custom directory
     selected by a file save selector
     nothing happens when cancel is pressed
     """
     json_path = Settings.default_json_folder() / self.main_window.category
     path = Dialogs.save_file_dialog(
         'Save tree as',
         json_path / self.main_window.filename,
     )
     # do a call to the controller to write the collection
     if path:
         self.main_window.main_listener.write_tree_custom_path_signal.emit(
             path, self.main_window.tree)
コード例 #12
0
 def update_tree(self, node: Node = None):
     """
     Method that needs to be called when updating self.tree. Will automatically run the verification
     """
     self.toolbar_widget.verify_tree()
     # if node is given check if a subtree changed
     changed_nodes = []
     if node and Settings.auto_update_roles():
         view_node = self.tree_view_widget.graphics_scene.nodes[node.id]
         node = self.tree.find_role_subtree_node_above_node(node)
         if node:
             changed_nodes = self.collection.update_subtrees_in_collection(
                 self.tree, node)
         elif 'roles' == self.category:
             changed_nodes = self.collection.update_subtrees_in_collection(
                 self.tree)
         self.tree_view_widget.graphics_scene.update_children(changed_nodes)
         view_node.initiate_view(True)
     # rebuild menu bar
     self.update_window_title_and_menu_bar()
コード例 #13
0
 def test_json_path(self):
     collection = Collection.from_path(self.path)
     assert collection.jsons_path() == self.path
     collection = Collection.from_path()
     assert collection.jsons_path() == Settings.default_json_folder()
 def test_alter_auto_update_roles(self):
     val = Settings.auto_update_roles()
     Settings.alter_auto_update_roles(not val)
     assert val is not Settings.auto_update_roles()
     # revert to original value
     Settings.alter_auto_update_roles(val)
 def test_auto_update_roles(self):
     assert True is Settings.auto_update_roles()
 def test_set_up_logging(self):
     # check that it runs without exceptions
     Settings.set_up_logging()
 def test_alter_default_logfile_name(self, tmpdir):
     def_path = Settings.default_logfile_name()
     Settings.alter_default_logfile_name(tmpdir / "log")
     assert tmpdir / "log" == Settings.default_logfile_name()
     Settings.alter_default_logfile_name(def_path)
     assert def_path == Settings.default_logfile_name()
 def test_alter_default_id_size(self):
     def_int = Settings.default_id_size()
     Settings.alter_default_id_size(15)
     assert 15 == Settings.default_id_size()
     Settings.alter_default_id_size(def_int)
     assert def_int == Settings.default_id_size()
 def test_default_id_size(self):
     assert 16 == Settings.default_id_size()
def test_read_csv():
    file = read_csv(Settings.default_node_types_folder() / 'conditions.csv')
    assert csv_file == file
 def test_default_jsons_folder(self):
     assert Path('json/jsons') == Settings.default_json_folder()
 def test_invalid_query(self):
     with pytest.raises(SettingNotFoundException):
         Settings.query_setting("nonexistent", "test")
 def test_valid_alteration_default(self, tmpdir):
     default_json_folder_path = Path(Settings.default_json_folder())
     Settings.alter_default_json_folder(Path("blahs"))
     assert Settings.default_json_folder() == Path("blahs")
     Settings.alter_default_json_folder(default_json_folder_path)
     assert Settings.default_json_folder() == default_json_folder_path
 def test_default_logfile_name(self):
     assert "log" == Settings.default_logfile_name()
 def test_default_node_types_folder(self):
     assert Path('json/node_types') == Settings.default_node_types_folder()
 def test_valid_query(self):
     assert "json/jsons" == Settings.query_setting("default_json_folder",
                                                   "test")
     assert "json/jsons" == Settings.query_setting("default_json_folder",
                                                   "test",
                                                   Settings.SETTINGS_PATH)
コード例 #27
0
    def __init__(self, gui: MainWindow):
        super(SettingsDialog, self).__init__()
        self.gui = gui
        self.main_layout = QVBoxLayout()
        self.setLayout(self.main_layout)
        self.setMinimumWidth(500)
        self.setWindowTitle("Settings")

        # grid layout for showing the settings
        self.settings_widget = QWidget()
        self.settings_layout = QGridLayout()
        self.settings_widget.setLayout(self.settings_layout)
        self.settings_layout.setContentsMargins(0, 0, 0, 0)
        self.main_layout.addWidget(self.settings_widget)

        # layout and widget for the ok, apply and cancel button
        self.buttons_widget = QWidget()
        self.buttons_layout = QHBoxLayout()
        self.buttons_widget.setLayout(self.buttons_layout)
        self.buttons_layout.setContentsMargins(0, 0, 0, 0)
        self.main_layout.addWidget(self.buttons_widget)
        self.buttons_layout.addStretch(1)

        # ok, apply and cancel button
        self.ok_button = QPushButton("Ok")
        self.buttons_layout.addWidget(self.ok_button)
        self.ok_button.clicked.connect(self.ok)
        self.apply_button = QPushButton("Apply")
        self.buttons_layout.addWidget(self.apply_button)
        self.apply_button.clicked.connect(self.apply)
        self.cancel_button = QPushButton("Cancel")
        self.cancel_button.clicked.connect(self.reject)
        self.buttons_layout.addWidget(self.cancel_button)
        self.enable_apply(False)

        # settings for the jsons folder
        self.jsons_label = QLabel("JSONS:")
        self.jsons_path = Settings.default_json_folder()
        self.jsons_path_new = self.jsons_path
        self.jsons_edit = QLineEdit(str(self.jsons_path))
        self.jsons_edit.setEnabled(False)
        self.jsons_select = QPushButton("Select")
        self.jsons_select.clicked.connect(self.select_jsons_folder)
        self.settings_layout.addWidget(self.jsons_label, 0, 0)
        self.settings_layout.addWidget(self.jsons_edit, 0, 1)
        self.settings_layout.addWidget(self.jsons_select, 0, 2)

        # settings for the node types folder
        self.node_types_label = QLabel("Node Types:")
        self.node_types_path = Settings.default_node_types_folder()
        self.node_types_path_new = self.node_types_path
        self.node_types_edit = QLineEdit(str(self.node_types_path))
        self.node_types_edit.setEnabled(False)
        self.node_types_select = QPushButton("Select")
        self.node_types_select.clicked.connect(self.select_node_types_folder)
        self.settings_layout.addWidget(self.node_types_label, 1, 0)
        self.settings_layout.addWidget(self.node_types_edit, 1, 1)
        self.settings_layout.addWidget(self.node_types_select, 1, 2)

        # settings for selecting logfile
        self.logfile_label = QLabel("Logfile:")
        self.logfile_path = Settings.default_logfile_name()
        self.logfile_path_new = self.logfile_path
        self.logfile_edit = QLineEdit(str(self.logfile_path))
        self.logfile_edit.setEnabled(False)
        self.logfile_select = QPushButton("Select")
        self.logfile_select.clicked.connect(self.select_logfile)
        self.settings_layout.addWidget(self.logfile_label, 2, 0)
        self.settings_layout.addWidget(self.logfile_edit, 2, 1)
        self.settings_layout.addWidget(self.logfile_select, 2, 2)

        # settings for selecting the id size
        self.id_size_label = QLabel("Node id size:")
        self.id_size_def = Settings.default_id_size()
        self.id_size_def_new = self.id_size_def
        self.id_size_select = QSpinBox()
        self.id_size_select.setMinimum(1)
        self.id_size_select.setValue(self.id_size_def)
        self.id_size_select.valueChanged.connect(self.select_id_size_changed)
        self.settings_layout.addWidget(self.id_size_label, 3, 0)
        self.settings_layout.addWidget(self.id_size_select, 3, 1, 1, 2)

        # checkbox for enabling auto updating of roles
        self.auto_update_roles = Settings.auto_update_roles()
        self.auto_update_roles_new = self.auto_update_roles
        self.auto_update_roles_check = QCheckBox()
        self.auto_update_roles_check.setChecked(self.auto_update_roles)
        self.auto_update_roles_check.setText(
            'Automatically update roles subtrees (Experimental)')
        self.auto_update_roles_check.stateChanged.connect(
            self.auto_update_roles_changed)
        self.settings_layout.addWidget(self.auto_update_roles_check, 4, 0, 1,
                                       0)
 def test_alter_default_node_types_folder(self, tmpdir):
     def_path = Settings.default_node_types_folder()
     Settings.alter_default_node_types_folder(tmpdir)
     assert tmpdir == Settings.default_node_types_folder()
     Settings.alter_default_node_types_folder(def_path)
     assert def_path == Settings.default_node_types_folder()