Exemplo n.º 1
0
 def fetch_wp_mscolab(self):
     server_xml = self.request_wps_from_server()
     server_waypoints_model = ft.WaypointsTableModel(xml_content=server_xml)
     self.merge_dialog = MscolabMergeWaypointsDialog(self.waypoints_model, server_waypoints_model, True, self)
     if self.merge_dialog.exec_():
         xml_content = self.merge_dialog.get_values()
         if xml_content is not None:
             self.waypoints_model = ft.WaypointsTableModel(xml_content=xml_content)
             self.waypoints_model.save_to_ftml(self.local_ftml_file)
             self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
             self.reload_view_windows()
             show_popup(self, "Success", "New Waypoints Fetched To Local File!", icon=1)
     self.merge_dialog = None
Exemplo n.º 2
0
 def save_wp_mscolab(self, comment=None):
     server_xml = self.request_wps_from_server()
     server_waypoints_model = ft.WaypointsTableModel(xml_content=server_xml)
     self.merge_dialog = MscolabMergeWaypointsDialog(self.waypoints_model, server_waypoints_model, parent=self)
     if self.merge_dialog.exec_():
         xml_content = self.merge_dialog.get_values()
         if xml_content is not None:
             self.conn.save_file(self.token, self.active_pid, xml_content, comment=comment)
             self.waypoints_model = ft.WaypointsTableModel(xml_content=xml_content)
             self.waypoints_model.save_to_ftml(self.local_ftml_file)
             self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
             self.reload_view_windows()
             show_popup(self, "Success", "New Waypoints Saved To Server!", icon=1)
     self.merge_dialog = None
Exemplo n.º 3
0
    def setup(self):
        self.application = QtWidgets.QApplication(sys.argv)
        self.port = PORTS.pop()
        self.tempdir = tempfile.mkdtemp()
        if not os.path.exists(self.tempdir):
            os.mkdir(self.tempdir)
        self.thread = multiprocessing.Process(target=application.run,
                                              args=("127.0.0.1", self.port))
        self.thread.start()

        initial_waypoints = [
            ft.Waypoint(40., 25., 0),
            ft.Waypoint(60., -10., 0),
            ft.Waypoint(40., 10, 0)
        ]
        waypoints_model = ft.WaypointsTableModel("")
        waypoints_model.insertRows(0,
                                   rows=len(initial_waypoints),
                                   waypoints=initial_waypoints)
        self.window = tv.MSSLinearViewWindow(model=waypoints_model)
        self.window.show()
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(2000)
        QtTest.QTest.qWaitForWindowExposed(self.window)
        QtWidgets.QApplication.processEvents()
        self.window.cbTools.currentIndexChanged.emit(1)
        QtWidgets.QApplication.processEvents()
        self.wms_control = self.window.docks[0].widget()
        self.wms_control.multilayers.cbWMS_URL.setEditText("")
Exemplo n.º 4
0
 def _setup(self, widget_type):
     self.port = PORTS.pop()
     self.application = QtWidgets.QApplication(sys.argv)
     if widget_type == "hsec":
         self.view = HSecViewMockup()
     else:
         self.view = VSecViewMockup()
     self.tempdir = tempfile.mkdtemp()
     if not os.path.exists(self.tempdir):
         os.mkdir(self.tempdir)
     QtTest.QTest.qWait(3000)
     self.thread = multiprocessing.Process(
         target=application.run,
         args=("127.0.0.1", self.port))
     self.thread.start()
     if widget_type == "hsec":
         self.window = wc.HSecWMSControlWidget(view=self.view, wms_cache=self.tempdir)
     else:
         initial_waypoints = [ft.Waypoint(40., 25., 0), ft.Waypoint(60., -10., 0), ft.Waypoint(40., 10, 0)]
         waypoints_model = ft.WaypointsTableModel("")
         waypoints_model.insertRows(0, rows=len(initial_waypoints), waypoints=initial_waypoints)
         self.window = wc.VSecWMSControlWidget(
             view=self.view, wms_cache=self.tempdir, waypoints_model=waypoints_model)
     self.window.show()
     QtWidgets.QApplication.processEvents()
     QtTest.QTest.qWait(2000)
     QtTest.QTest.qWaitForWindowExposed(self.window)
     QtTest.QTest.mouseClick(self.window.cbCacheEnabled, QtCore.Qt.LeftButton)
     QtWidgets.QApplication.processEvents()
Exemplo n.º 5
0
    def setup(self):
        self.application = QtWidgets.QApplication(sys.argv)

        # Create an initital flight track.
        initial_waypoints = [
            ft.Waypoint(flightlevel=0, location="EDMO",
                        comments="take off OP"),
            ft.Waypoint(48.10, 10.27, 200),
            ft.Waypoint(52.32, 09.21, 200),
            ft.Waypoint(52.55, 09.99, 200),
            ft.Waypoint(flightlevel=0,
                        location="Hamburg",
                        comments="landing HH")
        ]

        waypoints_model = ft.WaypointsTableModel("")
        waypoints_model.insertRows(0,
                                   rows=len(initial_waypoints),
                                   waypoints=initial_waypoints)

        self.window = tv.MSSTableViewWindow(model=waypoints_model)
        self.window.show()

        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWaitForWindowExposed(self.window)
        QtWidgets.QApplication.processEvents()
Exemplo n.º 6
0
        def load_function_wrapper(self):
            filename = get_open_filename(self,
                                         "Import Flight Track",
                                         self.last_save_directory,
                                         "All Files (*." + extension + ")",
                                         pickertype=pickertype)
            if filename is not None:
                try:
                    ft_name, new_waypoints = function(filename)
                # wildcard exception to be resilient against error introduced by user code
                except Exception as ex:
                    logging.error("file io plugin error: %s %s", type(ex), ex)
                    QtWidgets.QMessageBox.critical(
                        self, self.tr("file io plugin error"),
                        self.tr(f"ERROR: {type(ex)} {ex}"))
                else:
                    if not ft_name:
                        ft_name = filename
                    waypoints_model = ft.WaypointsTableModel(
                        name=ft_name, waypoints=new_waypoints)

                    listitem = QFlightTrackListWidgetItem(
                        waypoints_model, self.listFlightTracks)
                    listitem.setFlags(QtCore.Qt.ItemIsSelectable
                                      | QtCore.Qt.ItemIsEnabled)

                    self.listFlightTracks.setCurrentItem(listitem)
                    self.activate_flight_track(listitem)
Exemplo n.º 7
0
    def create_new_flight_track(self, template=None, filename=None):
        """Creates a new flight track model from a template. Adds a new entry to
           the list of flight tracks. Called when the user selects the 'new/open
           flight track' menu entries.

        Arguments:
        template -- copy the specified template to the new flight track (so that
                    it is not empty).
        filename -- if not None, load the flight track in the specified file.
        """
        if template is None:
            template = []
            waypoints = config_loader(dataset="new_flighttrack_template")
            default_flightlevel = config_loader(
                dataset="new_flighttrack_flightlevel")
            for wp in waypoints:
                template.append(
                    ft.Waypoint(flightlevel=default_flightlevel, location=wp))
            if len(template) < 2:
                QtWidgets.QMessageBox.critical(
                    self, self.tr("flighttrack template"),
                    self.
                    tr("ERROR:Flighttrack template in configuration is too short. "
                       "Please add at least two valid locations."))

        if filename is not None:
            waypoints_model = ft.WaypointsTableModel(filename=filename)
        else:
            # Create a new flight track from the waypoints template.
            self.new_flight_track_counter += 1
            waypoints_model = ft.WaypointsTableModel(
                name=f"new flight track ({self.new_flight_track_counter:d})")
            # Make a copy of the template. Otherwise all new flight tracks would
            # use the same data structure in memory.
            template_copy = copy.deepcopy(template)
            waypoints_model.insertRows(0,
                                       rows=len(template_copy),
                                       waypoints=template_copy)
        # Create a new list entry for the flight track. Make the item name
        # editable.
        listitem = QFlightTrackListWidgetItem(waypoints_model,
                                              self.listFlightTracks)
        listitem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)

        self.activate_flight_track(listitem)
Exemplo n.º 8
0
 def setup(self):
     self.application = QtWidgets.QApplication(sys.argv)
     initial_waypoints = [ft.Waypoint(40., 25., 0), ft.Waypoint(60., -10., 0), ft.Waypoint(40., 10, 0)]
     waypoints_model = ft.WaypointsTableModel("")
     waypoints_model.insertRows(
         0, rows=len(initial_waypoints), waypoints=initial_waypoints)
     self.window = tv.MSSTopViewWindow(model=waypoints_model)
     self.window.show()
     QtWidgets.QApplication.processEvents()
     QtTest.QTest.qWaitForWindowExposed(self.window)
     QtWidgets.QApplication.processEvents()
Exemplo n.º 9
0
    def test_save_merge_points(self, mockbox):
        pytest.skip("probably a timing problem, fails sometimes")
        self.emailid = "*****@*****.**"
        self._create_user_data(emailid=self.emailid)
        self.window.workLocallyCheckBox.setChecked(True)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        self.window.waypoints_model.invert_direction()
        merge_waypoints_model = None

        def handle_merge_dialog():
            nonlocal merge_waypoints_model
            self._select_waypoints(
                self.window.merge_dialog.localWaypointsTable)
            self._select_waypoints(
                self.window.merge_dialog.serverWaypointsTable)
            merge_waypoints_model = self.window.merge_dialog.merge_waypoints_model
            assert merge_waypoints_model is not None
            QtTest.QTest.mouseClick(self.window.merge_dialog.saveBtn,
                                    QtCore.Qt.LeftButton)
            QtWidgets.QApplication.processEvents()
            QtTest.QTest.qWait(100)

        QtCore.QTimer.singleShot(3000, handle_merge_dialog)
        QtTest.QTest.mouseClick(self.window.save_ft,
                                QtCore.Qt.LeftButton,
                                delay=1)
        QtWidgets.QApplication.processEvents()
        # get the updated waypoints model from the server
        # ToDo understand why requesting in follow up test of self.window.waypoints_model not working
        server_xml = self.window.request_wps_from_server()
        server_waypoints_model = ft.WaypointsTableModel(xml_content=server_xml)
        new_local_wp = server_waypoints_model
        new_wp_count = len(merge_waypoints_model.waypoints)
        assert new_wp_count == 4
        assert len(new_local_wp.waypoints) == new_wp_count
        for wp_index in range(new_wp_count):
            assert new_local_wp.waypoint_data(
                wp_index).lat == merge_waypoints_model.waypoint_data(
                    wp_index).lat
        self.window.workLocallyCheckBox.setChecked(False)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        new_server_wp = self.window.waypoints_model
        assert len(new_server_wp.waypoints) == new_wp_count
        for wp_index in range(new_wp_count):
            assert new_server_wp.waypoint_data(
                wp_index).lat == merge_waypoints_model.waypoint_data(
                    wp_index).lat
Exemplo n.º 10
0
    def _setup(self, widget_type):
        wc.WMS_SERVICE_CACHE = {}
        self.port = PORTS.pop()
        self.application = QtWidgets.QApplication(sys.argv)
        if widget_type == "hsec":
            self.view = HSecViewMockup()
        else:
            self.view = VSecViewMockup()
        self.tempdir = tempfile.mkdtemp()
        if not os.path.exists(self.tempdir):
            os.mkdir(self.tempdir)
        QtTest.QTest.qWait(3000)
        self.thread = multiprocessing.Process(target=application.run,
                                              args=("127.0.0.1", self.port))
        self.thread.start()
        if widget_type == "hsec":
            self.window = wc.HSecWMSControlWidget(view=self.view,
                                                  wms_cache=self.tempdir)
        else:
            initial_waypoints = [
                ft.Waypoint(40., 25., 0),
                ft.Waypoint(60., -10., 0),
                ft.Waypoint(40., 10, 0)
            ]
            waypoints_model = ft.WaypointsTableModel("")
            waypoints_model.insertRows(0,
                                       rows=len(initial_waypoints),
                                       waypoints=initial_waypoints)
            self.window = wc.VSecWMSControlWidget(
                view=self.view,
                wms_cache=self.tempdir,
                waypoints_model=waypoints_model)
        self.window.show()

        # Remove all previous cached URLs
        for url in self.window.multilayers.layers.copy():
            server = self.window.multilayers.listLayers.findItems(
                url, QtCore.Qt.MatchFixedString)[0]
            self.window.multilayers.delete_server(server)

        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(2000)
        QtTest.QTest.qWaitForWindowExposed(self.window)
        QtTest.QTest.mouseClick(self.window.cbCacheEnabled,
                                QtCore.Qt.LeftButton)
        QtWidgets.QApplication.processEvents()
Exemplo n.º 11
0
    def handle_selection(self, selected, deselected, wp_model, wp_dict):
        len_selected = len(selected.indexes())
        len_deselected = len(deselected.indexes())
        columns = self.localWaypointsTable.model().columnCount()

        for index in range(0, len_selected, columns):
            row = selected.indexes()[index].row()
            waypoint = wp_model.waypoint_data(row)
            wp_dict[row] = waypoint
            self.merge_waypoints_list.append(waypoint)

        for index in range(0, len_deselected, columns):
            row = deselected.indexes()[index].row()
            delete_waypoint = wp_dict[row]
            self.merge_waypoints_list.remove(delete_waypoint)

        self.merge_waypoints_model = ft.WaypointsTableModel(waypoints=self.merge_waypoints_list)
        self.mergedWaypointsTable.setModel(self.merge_waypoints_model)
Exemplo n.º 12
0
 def handle_import(self):
     file_path = get_open_filename(self, "Select a file", "", "Flight track (*.ftml)")
     if file_path is None:
         return
     dir_path, file_name = fs.path.split(file_path)
     with open_fs(dir_path) as file_dir:
         xml_content = file_dir.readtext(file_name)
     try:
         model = ft.WaypointsTableModel(xml_content=xml_content)
     except SyntaxError:
         show_popup(self, "Import Failed", f"The file - {file_name}, does not contain valid XML")
         return
     self.waypoints_model = model
     if self.workLocallyCheckBox.isChecked():
         self.waypoints_model.save_to_ftml(self.local_ftml_file)
         self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
     else:
         self.conn.save_file(self.token, self.active_pid, xml_content, comment=None)
         self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
     self.reload_view_windows()
     show_popup(self, "Import Success", f"The file - {file_name}, was imported successfully!", 1)
Exemplo n.º 13
0
    def test_save_keep_server_points(self, mockbox):
        self.emailid = "*****@*****.**"
        self._create_user_data(emailid=self.emailid)
        wp_server_before = self.window.mscolab.waypoints_model.waypoint_data(0)
        self.window.workLocallyCheckbox.setChecked(True)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        wp_local = self.window.mscolab.waypoints_model.waypoint_data(0)
        assert wp_local.lat == wp_server_before.lat
        self.window.mscolab.waypoints_model.invert_direction()
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        wp_local_before = self.window.mscolab.waypoints_model.waypoint_data(0)
        assert wp_server_before.lat != wp_local_before.lat

        # ToDo mock this messagebox
        def handle_merge_dialog():
            QtTest.QTest.mouseClick(
                self.window.mscolab.merge_dialog.keepServerBtn,
                QtCore.Qt.LeftButton)
            QtWidgets.QApplication.processEvents()
            QtTest.QTest.qWait(100)

        QtCore.QTimer.singleShot(3000, handle_merge_dialog)
        # trigger save to server action from server options combobox
        self.window.serverOptionsCb.setCurrentIndex(2)
        QtWidgets.QApplication.processEvents()
        # get the updated waypoints model from the server
        # ToDo understand why requesting in follow up test self.window.waypoints_model not working
        server_xml = self.window.mscolab.request_wps_from_server()
        server_waypoints_model = ft.WaypointsTableModel(xml_content=server_xml)
        new_local_wp = server_waypoints_model.waypoint_data(0)

        assert wp_local_before.lat != new_local_wp.lat
        assert new_local_wp.lat == wp_server_before.lat
        self.window.workLocallyCheckbox.setChecked(False)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        new_server_wp = self.window.mscolab.waypoints_model.waypoint_data(0)
        assert wp_server_before.lat == new_server_wp.lat
Exemplo n.º 14
0
    def test_save_overwrite_to_server(self, mockbox):
        pytest.skip("probably a timing problem, fails sometimes")
        self.emailid = "*****@*****.**"
        self._create_user_data(emailid=self.emailid)
        wp_server_before = self.window.waypoints_model.waypoint_data(0)
        self.window.workLocallyCheckBox.setChecked(True)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        wp_local = self.window.waypoints_model.waypoint_data(0)
        assert wp_local.lat == wp_server_before.lat
        self.window.waypoints_model.invert_direction()
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        wp_local_before = self.window.waypoints_model.waypoint_data(0)
        assert wp_server_before.lat != wp_local_before.lat

        def handle_merge_dialog():
            QtTest.QTest.mouseClick(self.window.merge_dialog.overwriteBtn,
                                    QtCore.Qt.LeftButton)
            QtWidgets.QApplication.processEvents()
            QtTest.QTest.qWait(100)

        QtCore.QTimer.singleShot(3000, handle_merge_dialog)
        QtTest.QTest.mouseClick(self.window.save_ft,
                                QtCore.Qt.LeftButton,
                                delay=2)
        QtWidgets.QApplication.processEvents()
        # get the updated waypoints model from the server
        # ToDo understand why requesting in follow up test self.window.waypoints_model not working
        server_xml = self.window.request_wps_from_server()
        server_waypoints_model = ft.WaypointsTableModel(xml_content=server_xml)
        new_local_wp = server_waypoints_model.waypoint_data(0)
        assert wp_local_before.lat == new_local_wp.lat
        self.window.workLocallyCheckBox.setChecked(False)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        new_server_wp = self.window.waypoints_model.waypoint_data(0)
        assert wp_local_before.lat == new_server_wp.lat
Exemplo n.º 15
0
    def __init__(self, local_waypoints_model, server_waypoints_model, fetch=False, parent=None):
        super(MscolabMergeWaypointsDialog, self).__init__(parent)
        self.setupUi(self)

        self.local_waypoints_model = local_waypoints_model
        self.server_waypoints_model = server_waypoints_model
        self.merge_waypoints_model = ft.WaypointsTableModel()
        self.localWaypointsTable.setModel(self.local_waypoints_model)
        self.serverWaypointsTable.setModel(self.server_waypoints_model)
        self.mergedWaypointsTable.setModel(self.merge_waypoints_model)
        self.mergedWaypointsTable.dropEvent = types.MethodType(dropEvent, self.mergedWaypointsTable)
        self.mergedWaypointsTable.dragEnterEvent = types.MethodType(dragEnterEvent, self.mergedWaypointsTable)

        self.xml_content = None
        self.local_waypoints_dict = {}
        self.server_waypoints_dict = {}
        self.merge_waypoints_list = []

        # Event Listeners
        self.overwriteBtn.clicked.connect(lambda: self.save_waypoints(self.local_waypoints_model))
        self.keepServerBtn.clicked.connect(lambda: self.save_waypoints(self.server_waypoints_model))
        self.saveBtn.clicked.connect(lambda: self.save_waypoints(self.merge_waypoints_model))
        self.localWaypointsTable.selectionModel().selectionChanged.connect(
            lambda selected, deselected:
            self.handle_selection(selected, deselected, self.local_waypoints_model, self.local_waypoints_dict)
        )
        self.serverWaypointsTable.selectionModel().selectionChanged.connect(
            lambda selected, deselected:
            self.handle_selection(selected, deselected, self.server_waypoints_model, self.server_waypoints_dict)
        )

        if fetch is True:
            self.setWindowTitle(self.tr("Fetch Waypoints From Server"))
            btn_size_policy = self.overwriteBtn.sizePolicy()
            btn_size_policy.setRetainSizeWhenHidden(True)
            self.overwriteBtn.setSizePolicy(btn_size_policy)
            self.overwriteBtn.setVisible(False)
            self.saveBtn.setText(self.tr("Save Waypoints To Local File"))
Exemplo n.º 16
0
    def test_fetch_from_server(self, mockbox):
        self.emailid = "*****@*****.**"
        self._create_user_data(emailid=self.emailid)
        wp_server_before = self.window.waypoints_model.waypoint_data(0)
        self.window.workLocallyCheckBox.setChecked(True)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        wp_local = self.window.waypoints_model.waypoint_data(0)
        assert wp_local.lat == wp_server_before.lat
        self.window.waypoints_model.invert_direction()
        wp_local_before = self.window.waypoints_model.waypoint_data(0)
        assert wp_server_before.lat != wp_local_before.lat

        def handle_merge_dialog():
            QtTest.QTest.mouseClick(self.window.merge_dialog.keepServerBtn,
                                    QtCore.Qt.LeftButton)
            QtWidgets.QApplication.processEvents()
            QtTest.QTest.qWait(100)

        QtCore.QTimer.singleShot(3000, handle_merge_dialog)
        QtTest.QTest.mouseClick(self.window.fetch_ft,
                                QtCore.Qt.LeftButton,
                                delay=1)
        QtWidgets.QApplication.processEvents()
        # get the updated waypoints model from the server
        # ToDo understand why requesting in follow up test of self.window.waypoints_model not working
        server_xml = self.window.request_wps_from_server()
        server_waypoints_model = ft.WaypointsTableModel(xml_content=server_xml)
        new_local_wp = server_waypoints_model
        assert len(new_local_wp.waypoints) == 2
        assert new_local_wp.waypoint_data(0).lat == wp_server_before.lat
        self.window.workLocallyCheckBox.setChecked(False)
        QtWidgets.QApplication.processEvents()
        QtTest.QTest.qWait(100)
        assert self.window.waypoints_model.waypoint_data(
            0).lat == wp_server_before.lat
Exemplo n.º 17
0
 def reload_local_wp(self):
     self.waypoints_model = ft.WaypointsTableModel(filename=self.local_ftml_file, data_dir=self.data_dir)
     self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)
     self.reload_view_windows()
Exemplo n.º 18
0
 def load_wps_from_server(self):
     if self.workLocallyCheckBox.isChecked():
         return
     xml_content = self.request_wps_from_server()
     self.waypoints_model = ft.WaypointsTableModel(xml_content=xml_content)
     self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed)