예제 #1
0
    def __init__(self):
        super().__init__()
        self._web = WebRenderer()
        self._check_web_page()
        self._check_latest_release()

        # set the application name and the version
        self.name = app_info.app_name
        self.version = app_info.app_version
        self.setWindowTitle('%s v.%s' % (self.name, self.version))
        # noinspection PyArgumentList
        _app = QtCore.QCoreApplication.instance()
        _app.setApplicationName('%s' % self.name)
        _app.setOrganizationName("HydrOffice")
        _app.setOrganizationDomain("hydroffice.org")

        # set the minimum and the initial size
        # noinspection PyArgumentList
        self.setMinimumSize(240, 320)
        # noinspection PyArgumentList
        self.resize(320, 460)

        # set icons
        self.setWindowIcon(QtGui.QIcon(app_info.app_icon_path))

        self.panel = ControlPanel()
        self.setCentralWidget(self.panel)
예제 #2
0
 def run(self):
     self._web = WebRenderer(make_app=True)
     args = self.parser.parse_args()
     try:
         args.func(args)
     except AttributeError as e:
         if "'Namespace' object" not in str(e):
             logger.info(e)
         self.parser.print_help()
         self.parser.exit()
예제 #3
0
class MainWin(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self._web = WebRenderer()
        self._check_web_page()
        self._check_latest_release()

        # set the application name and the version
        self.name = app_info.app_name
        self.version = app_info.app_version
        self.setWindowTitle('%s v.%s' % (self.name, self.version))
        # noinspection PyArgumentList
        _app = QtCore.QCoreApplication.instance()
        _app.setApplicationName('%s' % self.name)
        _app.setOrganizationName("HydrOffice")
        _app.setOrganizationDomain("hydroffice.org")

        # set the minimum and the initial size
        # noinspection PyArgumentList
        self.setMinimumSize(240, 320)
        # noinspection PyArgumentList
        self.resize(320, 460)

        # set icons
        self.setWindowIcon(QtGui.QIcon(app_info.app_icon_path))

        self.panel = ControlPanel()
        self.setCentralWidget(self.panel)

    def _check_web_page(self, token: str = ""):
        try:
            if len(token) > 0:
                url = "%s_%s" % (Helper(lib_info=lib_info).web_url(), token)
            else:
                url = "%s" % Helper(lib_info=lib_info).web_url()
            self._web.open(url=url)
            logger.debug('check %s' % url)

        except Exception as e:
            logger.warning(e)

    @classmethod
    def _check_latest_release(cls):
        try:
            response = urlopen(lib_info.lib_latest_url, timeout=1)
            latest_version = response.read().split()[0].decode()
            cur_maj, cur_min, cur_fix = app_info.app_version.split('.')
            lat_maj, lat_min, lat_fix = latest_version.split('.')

            if int(lat_maj) > int(cur_maj):
                logger.info("new release available: %s" % latest_version)

            elif (int(lat_maj)
                  == int(cur_maj)) and (int(lat_min) > int(cur_min)):
                logger.info("new release available: %s" % latest_version)

            elif (int(lat_maj)
                  == int(cur_maj)) and (int(lat_min) == int(cur_min)) and (
                      int(lat_fix) > int(cur_fix)):
                logger.info("new bugfix available: %s" % latest_version)

        except Exception as e:
            logger.warning(e)

    def _do_you_really_want(self, title="Quit", text="quit"):
        """helper function that show to the user a message windows asking to confirm an action"""
        msg_box = QtWidgets.QMessageBox(self)
        msg_box.setWindowTitle(title)
        msg_box.setIconPixmap(
            QtGui.QPixmap(app_info.app_icon_path).scaled(QtCore.QSize(36, 36)))
        msg_box.setText('Do you really want to %s?' % text)
        msg_box.setStandardButtons(QtWidgets.QMessageBox.Yes
                                   | QtWidgets.QMessageBox.No)
        msg_box.setDefaultButton(QtWidgets.QMessageBox.No)
        return msg_box.exec_()

    def closeEvent(self, event):
        """ actions to be done before close the app """
        reply = self._do_you_really_want("Quit", "quit %s" % self.name)

        if reply == QtWidgets.QMessageBox.Yes:

            event.accept()
            self.panel.stop_listening()
            super().closeEvent(event)

        else:
            event.ignore()
예제 #4
0
 def test_init(self):
     # noinspection PyArgumentList
     if not QtWidgets.QApplication.instance():
         QtWidgets.QApplication([])
     wr = WebRenderer(make_app=False)
     wr.open("https://www.hydroffice.org")
예제 #5
0
from hyo2.abc.app.web_renderer import WebRenderer

wr = WebRenderer(make_app=True)
wr.open("https://www.hydroffice.org")
예제 #6
0
class QCToolsParser:
    def __init__(self):
        self._check_latest_release()

        self.parser = argparse.ArgumentParser(
            formatter_class=argparse.ArgumentDefaultsHelpFormatter)
        self.parser.add_argument('--version',
                                 action='version',
                                 version=__version__)
        subparsers = self.parser.add_subparsers()

        ff_parser = subparsers.add_parser(
            'FindFliers',
            help='Identify potential fliers in gridded bathymetry',
            formatter_class=argparse.ArgumentDefaultsHelpFormatter)
        ff_parser.add_argument(
            'input_dtm',
            type=str,
            help='The input DTM file to be searched for potential fliers.')
        ff_parser.add_argument(
            'output_folder',
            type=str,
            help='The output folder for the results of the search.')
        ff_parser.add_argument(
            '-enforce_height',
            required=False,
            type=float,
            default=None,
            help=
            'Pass a value in meters (e.g., 1.0) to enforce a specific height value. '
            'Otherwise, the height value will be automatically estimated.')
        ff_parser.add_argument(
            '-check_laplacian',
            required=False,
            type=bool,
            default=False,
            help='True to enable the Laplacian Operator Check.')
        ff_parser.add_argument(
            '-check_curv',
            required=False,
            type=bool,
            default=True,
            help='True to enable the Gaussian Curvature Check.')
        ff_parser.add_argument('-check_adjacent',
                               required=False,
                               type=bool,
                               default=True,
                               help='True to enable the Adjacent Cell Check.')
        ff_parser.add_argument('-check_isolated',
                               required=False,
                               type=bool,
                               default=True,
                               help='True to enable the Isolated Nodes Check.')
        ff_parser.add_argument('-check_slivers',
                               required=False,
                               type=bool,
                               default=True,
                               help='True to enable the Edge Slivers Check.')
        ff_parser.add_argument('-check_edges',
                               required=False,
                               type=bool,
                               default=False,
                               help='True to enable the Noisy Edges Check.')
        ff_parser.add_argument(
            '-filter_designated',
            required=False,
            type=bool,
            default=False,
            help='True to enable filtering of designated soundings.')
        ff_parser.add_argument(
            '-filter_fff',
            required=False,
            type=bool,
            default=False,
            help='True to enable filtering of S57 features.')
        ff_parser.add_argument(
            '-s57_path',
            required=False,
            type=str,
            default=None,
            help="Path to the S57 file used by '-filter_fff True'.")
        ff_parser.set_defaults(func=self.run_find_fliers)

        self._loading = False
        self._web = None

    def run(self):
        self._web = WebRenderer(make_app=True)
        args = self.parser.parse_args()
        try:
            args.func(args)
        except AttributeError as e:
            if "'Namespace' object" not in str(e):
                logger.info(e)
            self.parser.print_help()
            self.parser.exit()

    def _check_web_page(self, token: str = ""):
        try:
            if len(token) > 0:
                url = "%s_cli_%s" % (Helper(lib_info=lib_info).web_url(),
                                     token)
            else:
                url = "%s_cli" % Helper(lib_info=lib_info).web_url()
            self._web.open(url=url)
            logger.debug('check %s' % url)

        except Exception as e:
            logger.warning(e)

    @classmethod
    def _check_latest_release(cls):
        try:
            url = "https://www.hydroffice.org/latest/qctools.txt"
            response = urlopen(url, timeout=1)
            latest_version = response.read().split()[0].decode()
            cur_maj, cur_min, cur_fix = app_info.app_version.split('.')
            lat_maj, lat_min, lat_fix = latest_version.split('.')

            if int(lat_maj) > int(cur_maj):
                logger.info("new release available: %s" % latest_version)

            elif (int(lat_maj)
                  == int(cur_maj)) and (int(lat_min) > int(cur_min)):
                logger.info("new release available: %s" % latest_version)

            elif (int(lat_maj)
                  == int(cur_maj)) and (int(lat_min) == int(cur_min)) and (
                      int(lat_fix) > int(cur_fix)):
                logger.info("new bugfix available: %s" % latest_version)

        except Exception as e:
            logger.warning(e)

    def run_find_fliers(self, args):

        if not os.path.exists(args.output_folder):
            raise RuntimeError('Unable to locate output folder: %s' %
                               args.output_folder)
        out_folder = args.output_folder
        logger.debug('output folder: %s' % out_folder)
        # create the project
        prj = SurveyProject(output_folder=out_folder)

        if not os.path.exists(args.input_dtm):
            raise RuntimeError('Unable to locate input DTM: %s' %
                               args.input_dtm)
        dtm_file = args.input_dtm
        logger.debug('input DTM: %s' % dtm_file)
        prj.add_to_grid_list(dtm_file)

        if args.s57_path is not None:
            if not os.path.exists(args.s57_path):
                raise RuntimeError('Unable to locate input S57: %s' %
                                   args.s57_path)
            s57_file = args.s57_path
            logger.debug('input S57: %s' % s57_file)
            prj.add_to_s57_list(s57_file)

        if args.enforce_height is not None:
            if args.enforce_height <= 0.0:
                raise RuntimeError('Invalid height: %s' % args.enforce_height)
        height_value = args.enforce_height
        # logger.debug('height: %s' % height_value)

        check_laplacian = args.check_laplacian
        check_curv = args.check_curv
        check_adjacent = args.check_adjacent
        check_slivers = args.check_slivers
        check_isolated = args.check_isolated
        check_edges = args.check_edges

        filter_designated = args.filter_designated
        filter_fff = args.filter_fff

        self._check_web_page(
            token='FFv8_%d%d%d%d%d%d_%d%d' %
            (check_laplacian, check_curv, check_adjacent, check_slivers,
             check_isolated, check_edges, filter_designated, filter_fff))

        # actual execution
        for i, grid_path in enumerate(prj.grid_list):
            logger.debug(">>> #%d (%s)" % (i, grid_path))

            prj.clear_survey_label()
            prj.set_cur_grid(path=grid_path)
            prj.open_to_read_cur_grid(chunk_size=4294967296)

            prj.find_fliers_v8(height=height_value,
                               check_laplacian=check_laplacian,
                               check_curv=check_curv,
                               check_adjacent=check_adjacent,
                               check_slivers=check_slivers,
                               check_isolated=check_isolated,
                               check_edges=check_edges,
                               filter_fff=filter_fff,
                               filter_designated=filter_designated)
            prj.close_cur_grid()

            prj.set_cur_grid(path=grid_path)
            prj.open_to_read_cur_grid(chunk_size=4294967296)
            prj.find_fliers_v8_apply_filters()

            saved = prj.save_fliers()
            if saved:
                logger.debug('Fliers saved')