Exemple #1
0
def change_address_main(self):
    self.new_address_entry = gui_ut.Entry(self.top_bar, width=40)
    self.new_address_entry.insert(0, string=self.model.GOST_address)
    self.view_elements.append({
        "item": self.new_address_entry,
        "row": 0,
        "column": 1,
        "name": "new_address_entry"
    })

    self.confirm_address_button = gui_ut.Button(
        self.top_bar,
        text="Confirm changes",
        command=lambda: try_address(self))
    self.view_elements.append({
        "item": self.confirm_address_button,
        "row": 0,
        "column": 2,
        "name": "new_address_button"
    })

    self.keep_old_address_button = gui_ut.Button(
        self.top_bar,
        text="Keep old address",
        command=lambda: keep_address(self))
    self.view_elements.append({
        "item": self.keep_old_address_button,
        "row": 0,
        "column": 3,
        "name": "keep_old_address_button"
    })
    self.new_address_entry.grid(row=0, column=1)
    self.confirm_address_button.grid(row=0, column=2)
    self.keep_old_address_button.grid(row=0, column=4)
    gui_ut.populate(self.view_elements, self.main_area)
Exemple #2
0
    def show_options(
        self, a, b, c
    ):  # additional parameters a b c needed because it is called by Trace function
        gui_ut.clear_results(self)
        if self.related_type.get() != "No related OGC type":
            field_names = gui_ut.get_fields_names(self.related_type.get())
        elif self.related_type.get() == "No related OGC type":
            field_names = gui_ut.get_fields_names(self.selected_type.get())

        self.show_fields = gui_ut.Listbox(self.main_view.main_area,
                                          selectmode=gui_ut.MULTIPLE)

        self.show_fields.insert(gui_ut.END, "@iot.id")

        for item in field_names:
            self.show_fields.insert(gui_ut.END, item)

        self.show_fields.grid(column=1, row=8)
        self.view_elements.append({
            "item": self.show_fields,
            "row": 5,
            "column": 0,
            "name": "show_fields"
        })

        search_btn = gui_ut.Button(self.main_view.main_area,
                                   text="Search!",
                                   command=lambda: search(self),
                                   bg=gui_ut.action_color)
        self.view_elements.append({"item": search_btn, "row": 6, "column": 1})

        gui_ut.populate(self.view_elements, self.main_view.main_area)
Exemple #3
0
def keep_address(self):
    self.model.GOST_address = conn_conf.set_GOST_address()
    if bool(self.model.GOST_address):
        self.address_preview.configure(
            text=f"Current GOST address: {self.model.GOST_address} "
            f"\nclick here to change address")
    else:
        self.address_preview.configure(
            text=f"Current GOST address not working"
            f"\nclick here to change address\n"
            f"or retry to connect with the last saved address")
    indexes_to_delete = []
    for index, val in enumerate(self.view_elements):
        if "name" in val:
            if val["name"] in [
                    "new_address_entry", "new_address_button",
                    "keep_old_address_button", "new_port_entry",
                    "confirm_address_button", "confirm_port_button",
                    "Confirm changes", "old_port_button",
                    "keep_old_port_button", "new_port_button"
            ]:
                indexes_to_delete.append(index)
    for i in sorted(indexes_to_delete, reverse=True):
        self.view_elements[i]["item"].grid_forget()
        del self.view_elements[i]
    self.port_button = gui_ut.Button(self.top_bar,
                                     text="Change port number",
                                     command=lambda: change_port_number(self),
                                     bg=gui_ut.change_address_color)
    self.port_button.grid(row=0, column=4)
Exemple #4
0
def change_port_number(self):
    self.port_button.grid_forget()
    indexes_to_delete = []
    for index, val in enumerate(self.view_elements):
        if "name" in val:
            if val["name"] in [
                    "new_address_entry", "new_address_button",
                    "keep_old_address_button"
            ]:
                indexes_to_delete.append(index)
    for i in sorted(indexes_to_delete, reverse=True):
        self.view_elements[i]["item"].grid_forget()
        del self.view_elements[i]
    self.new_port_entry = gui_ut.Entry(self.top_bar, width=40)
    self.new_port_entry.insert(0, string=try_port(take=1))
    self.view_elements.append({
        "item": self.new_port_entry,
        "row": 0,
        "column": 1,
        "name": "new_port_entry"
    })

    self.confirm_port_button = gui_ut.Button(
        self.top_bar,
        text="Confirm changes",
        command=lambda: try_port(self, self.new_port_entry.get()))
    self.view_elements.append({
        "item": self.confirm_port_button,
        "row": 0,
        "column": 2,
        "name": "new_port_button"
    })
    self.keep_old_port_button = gui_ut.Button(
        self.top_bar, text="Keep old port", command=lambda: keep_address(self))
    self.view_elements.append({
        "item": self.keep_old_port_button,
        "row": 0,
        "column": 3,
        "name": "old_port_button"
    })
    self.new_port_entry.grid(row=0, column=1)
    self.confirm_port_button.grid(row=0, column=2)
    self.keep_old_port_button.grid(row=0, column=3)
    self.address_preview.configure(
        text=f"Current GOST address: {self.model.GOST_address} "
        f"\nclick here to change address")
Exemple #5
0
def try_port(self=None, port=None, address=None, b=None, take=None):
    if not address:
        address = conn_conf.get_address_from_file()
    x = address.split(":")
    y = x[2].split("/")
    if take:
        return y[0]
    y[0] = port
    first = "/".join(y)
    x[2] = first
    complete = ":".join(x)
    if conn_conf.test_connection(complete):
        conn_conf.set_GOST_address(complete)
        if b:
            self.main_view.model.GOST_address = complete
            self.change_address_description.configure(
                text="Insert a new address\n"
                f"format: http://x.x.x.x:port_number/v1.0\n{complete}")
            self.new_address.delete(0, "end")
            self.new_address.insert(0, self.main_view.model.GOST_address)
            self.main_view.address_preview.configure(
                text=f"Current GOST address: " +
                self.main_view.model.GOST_address +
                "\nclick here to change address")
        elif not b:
            self.model.GOST_address = complete
            indexes_to_delete = []
            for index, val in enumerate(self.view_elements):
                if "name" in val:
                    if val["name"] in [
                            "address_preview", "new_port_entry",
                            "Confirm changes", "new_port_button",
                            "Insert a new port number", "address_preview",
                            "confirm_port_button", "confirm_address_button",
                            "old_port_button"
                    ]:
                        indexes_to_delete.append(index)
            for i in sorted(indexes_to_delete, reverse=True):
                self.view_elements[i]["item"].grid_forget()
                del self.view_elements[i]
            self.port_button = gui_ut.Button(
                self.top_bar,
                text="Change port number",
                command=lambda: change_port_number(self),
                bg=gui_ut.change_address_color)
            self.port_button.grid(row=0, column=4)
            self.address_preview.configure(
                text=f"Current GOST address: {self.model.GOST_address} "
                f"\nclick here to change address")
        else:
            self.confirm_port_button.configure(
                text="To change port, insert a new port\nand click here")
    else:
        gui_ut.messagebox.showinfo("Error", "invalid Port number")
        self.address_preview.configure(text="Invalid port, insert a new port")
Exemple #6
0
    def show_options(
        self, a, b, c
    ):  # additional parameters a b c needed because it is called by Trace function
        gui_ut.clear_results(self)

        self.patch_btn = gui_ut.Button(
            self.main_view.main_area,
            text="Patch the selected items\nwith the following values:\n"
            "(empty fields will not be modified)",
            command=lambda: patch(self),
            bg=gui_ut.action_color)
        self.view_elements.append({
            "item": self.patch_btn,
            "row": 5,
            "column": 1,
            "name": "patching_button"
        })

        clear_old_patch_values(self)

        set_patches_fields(self)

        gui_ut.populate(self.view_elements, self.main_view.main_area)
Exemple #7
0
def try_address(self):
    new_address = self.new_address_entry.get(
    )  # checking if the new address works
    working_conn = conn_conf.test_connection(new_address)
    if working_conn:
        self.model.GOST_address = new_address

        conn_conf.set_GOST_address(new_address)  # saving the new address works

        self.address_preview.configure(
            text=f"Current GOST address: {self.model.GOST_address} "
            f"\nclick here to change address")
        indexes_to_delete = []
        for index, val in enumerate(self.view_elements):
            if "name" in val:
                if val["name"] in [
                        "new_address_entry", "new_address_button",
                        "keep_old_address_button", "confirm_address_button",
                        "confirm_port_button", "new_port_entry",
                        "new_port_button", "old_port_button"
                ]:
                    indexes_to_delete.append(index)
        for i in sorted(indexes_to_delete, reverse=True):
            self.view_elements[i]["item"].grid_forget()
            del self.view_elements[i]
        self.port_button = gui_ut.Button(
            self.top_bar,
            text="Change port number",
            command=lambda: change_port_number(self),
            bg=gui_ut.change_address_color)
        self.port_button.grid(row=0, column=4)
        gui_ut.populate(self.view_elements, self.main_area)

    else:
        gui_ut.messagebox.showinfo("Error", "invalid GOST address")
        self.address_preview.configure(
            text="Invalid address, insert a new address")
Exemple #8
0
    def __init__(self, main_view):
        self.view_elements = []
        self.main_view = main_view
        self.confirm_address_button = None

        main_view.current_command_view = self  # needed for hide() function to work on the current elements

        if bool(main_view.model.GOST_address):
            current_address = f"[Current GOST address: {self.main_view.model.GOST_address}]"
        else:
            current_address = "[Current GOST address is not working]"

        self.change_address_description = Label(
            self.main_view.main_area,
            text=f"Insert a new address\n"
            f"format: http://x.x.x.x:port_number/v1.0\n{current_address}")
        self.view_elements.append({
            "item": self.change_address_description,
            "row": 1,
            "column": 0
        })
        self.change_port_description = Label(self.main_view.main_area,
                                             text=f"Insert a new port")
        self.view_elements.append({
            "item": self.change_port_description,
            "row": 3,
            "column": 0
        })
        self.new_port = Entry(self.main_view.main_area, width=40)
        self.new_port.insert(0, conn_conf.try_port(take=1))
        self.new_address = Entry(self.main_view.main_area, width=40)
        self.new_address.insert(0, self.main_view.model.GOST_address)
        self.view_elements.append({
            "item": self.new_address,
            "row": 1,
            "column": 2
        })
        self.view_elements.append({
            "item": self.new_port,
            "row": 3,
            "column": 2
        })
        self.confirm_address_button = gui_ut.Button(
            self.main_view.main_area,
            text="Confirm change",
            command=lambda: change_address(self),
            bg=gui_ut.action_color)
        self.view_elements.append({
            "item": self.confirm_address_button,
            "row": 1,
            "column": 3
        })
        self.confirm_port_button = gui_ut.Button(
            self.main_view.main_area,
            text="Confirm change",
            command=lambda: conn_conf.try_port(self, self.new_port.get(), b=1),
            bg=gui_ut.action_color)
        self.view_elements.append({
            "item": self.confirm_port_button,
            "row": 3,
            "column": 3
        })
        self.ping_button = gui_ut.Button(
            self.main_view.main_area,
            text="Ping Connection",
            command=lambda: ping_connection(self, self.main_view.model.
                                            GOST_address),
            bg=gui_ut.action_color)
        self.view_elements.append({
            "item": self.ping_button,
            "row": 4,
            "column": 0
        })
        gui_ut.populate(self.view_elements)
Exemple #9
0
def patch(self):
    if patch_values_not_available(self):
        pass
    else:
        gui_ut.clear_results(self)
        self.selected_items = gui_ut.get_items(self)

        if len(self.selected_items) > 1 and gui_ut.name_in_patch(
                self.patch_values):  # control to avoid to patch two
            # items with the same name
            gui_ut.messagebox.showinfo(
                "ERROR",
                "Trying to patch multiple items with the same name\nItems not patched"
            )
        else:
            if self.selected_items != "error":
                self.result = gui_ut.scrollable_results(
                    self.selected_items, self.main_view.main_area)

                self.view_elements.append({
                    "item": self.result,
                    "row": 1,
                    "column": 1,
                    "name": "result"
                })
                self.patch_btn.config(
                    text=
                    "Click here to confirm \nthe Patching of the selected elements",
                    command=lambda: confirm_patching(self))
                self.abort_patch_btn = gui_ut.Button(
                    self.main_view.main_area,
                    text="Click here to abort the patching",
                    command=lambda: abort_patching(self),
                    bg='#ff502f')
                self.view_elements.append({
                    "item": self.abort_patch_btn,
                    "row": 6,
                    "column": 1,
                    "name": "abort_patching_button"
                })
                gui_ut.populate(self.view_elements, self.main_view.main_area)

                indexes_to_delete = [
                ]  # Deleting select item fields from the view
                for index, val in enumerate(self.view_elements):
                    if "name" in val:
                        if val["name"] in [
                                "select_introduction",
                                "selected_identifiers_description",
                                "selected_identifiers",
                                "selected_boolean_expression_description",
                                "selected_boolean_expression"
                        ]:
                            indexes_to_delete.append(index)
                for i in sorted(indexes_to_delete, reverse=True):
                    self.view_elements[i]["item"].grid_forget()

            for i in self.patch_values:
                if bool(i["field_entry"].get()):
                    i["field_entry"].config(state=gui_ut.DISABLED)
                else:
                    i["field_entry"].grid_forget()
Exemple #10
0
    def show_options(
        self, a, b, c
    ):  # additional parameters a b c needed because it is called by Trace function
        if not (self.selected_type.get() == "Select an OGC type"
                ):  # needed to avoid the restoring of action
            # buttons before action execution
            indexes_to_delete = []  # clearing the previously set patch options
            for index, val in enumerate(self.view_elements):
                if "name" in val:
                    if val["name"] in [
                            "create_field_name", "create_field_value",
                            "mandatory_field"
                    ]:
                        indexes_to_delete.append(index)
            for i in sorted(indexes_to_delete, reverse=True):
                self.view_elements[i]["item"].grid_forget()
                del self.view_elements[i]

            field_names = gui_ut.get_fields_names(self.selected_type.get(),
                                                  needed_for_editing=True)

            row = 11

            for item in field_names:
                temp_label = gui_ut.Label(self.main_view.main_area, text=item)
                self.view_elements.append({
                    "item": temp_label,
                    "row": row,
                    "column": 0,
                    "name": "create_field_name"
                })
                temp_entry = gui_ut.Entry(self.main_view.main_area, width=50)
                self.view_elements.append({
                    "item": temp_entry,
                    "row": row,
                    "column": 1,
                    "name": "create_field_value"
                })
                row += 1
                self.create_entries.append({
                    "field_name": item,
                    "field_entry": temp_entry
                })

            self.save_btn = gui_ut.Button(self.main_view.main_area,
                                          text="Save to a file",
                                          command=lambda: save(self))
            self.view_elements.append({
                "item": self.save_btn,
                "row": 10,
                "column": 0,
                "name": "save_button"
            })

            self.post_btn = gui_ut.Button(self.main_view.main_area,
                                          text="Post to GOST",
                                          command=lambda: direct_post(self))
            self.view_elements.append({
                "item": self.post_btn,
                "row": 10,
                "column": 1,
                "name": "post_button"
            })

            self.save_and_post_btn = gui_ut.Button(
                self.main_view.main_area,
                text="Save to a file\nand Post to GOST",
                command=lambda: save_and_post(self))
            self.view_elements.append({
                "item": self.save_and_post_btn,
                "row": 10,
                "column": 2,
                "name": "save_and_post_button"
            })
            self.post_from_file_btn = gui_ut.Button(
                self.main_view.main_area,
                text="POST records \ndefined in a file",
                command=lambda: post_from_file(self))
            self.view_elements.append({
                "item": self.post_from_file_btn,
                "row": 11,
                "column": 2,
                "name": "post_from_file_button"
            })
            if self.selected_type.get() == "Datastreams":
                red_label = gui_ut.Label(
                    self.main_view.main_area,
                    text="* Fields Things_id, ObservedProperty_id, "
                    "Sensor_id are mandatory",
                    fg="#FF0000",
                    font=(None, 15),
                    width=60)
                self.view_elements.append({
                    "item": red_label,
                    "row": row,
                    "column": 0,
                    "name": "mandatory_field"
                })
            elif self.selected_type.get() == "Observations":
                red_label = gui_ut.Label(
                    self.main_view.main_area,
                    text="* Fields Datastream_id and FeatureOfInterest(id) "
                    "are mandatory",
                    fg="#FF0000",
                    font=(None, 15),
                    width=60)
                self.view_elements.append({
                    "item": red_label,
                    "row": row,
                    "column": 0,
                    "name": "mandatory_field"
                })
            gui_ut.populate(self.view_elements, self.main_view.main_area)
Exemple #11
0
    def __init__(self):
        self.view_elements = []
        self.window = gui_ut.Tk()
        self.width = 1000
        self.height = 600
        self.current_command_view = None
        self.model = Model()
        self.window.title("GOST-CONTROLLER")

        self.window.geometry(f'{str(self.width)}x{str(self.height)}')

        # setting the general layout

        self.top_bar = gui_ut.Frame(self.window,
                                    width=self.width,
                                    bg="#ababab")
        main_area_frame = gui_ut.Frame(self.window,
                                       width=self.width,
                                       bg="#ababab")
        self.main_area = scroll.Scrollable(main_area_frame, width=16)
        self.top_bar.pack(side="top", fill="both")
        main_area_frame.pack(side="top", fill="both", expand=True)

        self.address_preview = None
        self.confirm_address_button = None
        self.new_address_entry = None
        self.keep_old_address_button = None
        self.back_button = None

        if bool(self.model.GOST_address):
            info_text = f"Current GOST address: {self.model.GOST_address}"
        else:
            info_text = "Invalid GOST address"

        self.address_preview = gui_ut.Button(
            self.top_bar,
            text=f"{info_text} \nclick here to change address",
            command=lambda: change_address_main(self),
            bg=gui_ut.change_address_color)
        self.port_button = gui_ut.Button(
            self.top_bar,
            text="Change port number",
            command=lambda: change_port_number(self),
            bg=gui_ut.change_address_color)
        self.ping_button = gui_ut.Button(
            self.top_bar,
            text="Ping Connection",
            command=lambda: ping_connection(self, self.model.GOST_address, True
                                            ),
            bg=gui_ut.change_address_color)
        self.ping_button.grid(row=0, column=5)
        self.address_preview.grid(row=0, column=0)
        self.port_button.grid(row=0, column=4)

        button_height = int(int(self.height) / 99)
        button_width = int(int(self.width) / 40)

        myFont = Font(family='Helvetica', size=20, weight='bold')

        GET_btn = gui_ut.Button(self.main_area,
                                text="GET",
                                height=button_height,
                                width=button_width,
                                command=lambda: get_command(self),
                                bg='#86f986')
        GET_btn["font"] = myFont

        DELETE_btn = gui_ut.Button(self.main_area,
                                   height=button_height,
                                   width=button_width,
                                   text="DELETE",
                                   command=lambda: delete_command(self),
                                   bg='#f17e7e')
        DELETE_btn["font"] = myFont

        PATCH_btn = gui_ut.Button(self.main_area,
                                  text="PATCH",
                                  command=lambda: patch_command(self),
                                  bg='#efca8c')
        PATCH_btn["font"] = myFont

        CREATE_btn = gui_ut.Button(self.main_area,
                                   text="CREATE/POST",
                                   height=button_height,
                                   width=button_width,
                                   command=lambda: create_command(self),
                                   bg='#9ea9f0')
        CREATE_btn["font"] = myFont

        SETTINGS_btn = gui_ut.Button(self.main_area,
                                     text="SETTINGS",
                                     command=lambda: change_settings(self),
                                     bg='#fff1c1')
        SETTINGS_btn["font"] = myFont

        self.main_view_elements = []

        self.main_view_elements.append({
            "item": GET_btn,
            "row": 0,
            "column": 0
        })
        self.main_view_elements.append({
            "item": DELETE_btn,
            "row": 1,
            "column": 0
        })
        self.main_view_elements.append({
            "item": PATCH_btn,
            "row": 0,
            "column": 1
        })
        self.main_view_elements.append({
            "item": CREATE_btn,
            "row": 1,
            "column": 1
        })
        self.main_view_elements.append({
            "item": SETTINGS_btn,
            "row": 2,
            "column": 0
        })

        self.main_area.columnconfigure(0, weight=1)
        self.main_area.columnconfigure(1, weight=1)
        self.main_area.rowconfigure(0, weight=1)
        self.main_area.rowconfigure(1, weight=1)
        self.main_area.rowconfigure(2, weight=1)
        self.main_area.rowconfigure(3, weight=1)

        gui_ut.populate(self.main_view_elements, self.main_area)

        self.back_button = gui_ut.Button(self.top_bar,
                                         text="Back to Main Menu",
                                         command=lambda: restore_main(self),
                                         bg='#ff502f')
        self.back_button.grid(row=0, column=6, sticky=gui_ut.N + gui_ut.S)
        self.back_button.grid_remove()

        self.window.mainloop()