def gui(dev_mode=False): """Run the QAX gui""" # temporary fix for CORS warning (QTBUG-70228) sys.argv.append("--disable-web-security") # stop auto scaling on windows # os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" # stop auto scaling on windows - part 2 # app.setAttribute(QtCore.Qt.AA_DisableHighDpiScaling) # app.setStyleSheet(AppStyle.load_stylesheet()) cfg_dir = GuiSettings.config() # setup user editable config directory if not os.path.isdir(cfg_dir): # config does not exist, so copy out default settings logger.info("Copying default config to {}".format(cfg_dir)) import shutil shutil.copytree(GuiSettings.config_default(), cfg_dir) else: logger.info("Using existing config {}".format(cfg_dir)) config = QaxConfig(Path(cfg_dir)) config.load() plugins = QaxPlugins() plugins.load(config) main_win = MainWin() main_win.initialize() sys.excepthook = main_win.exception_hook # install the exception hook main_win.show() if dev_mode: main_win.do() sys.exit(app.exec_())
def _click_open_spatial_export_folder(self): output_folder = QFileDialog.getExistingDirectory( self, f"Select folder for spatial outputs", GuiSettings.settings().value("spatial_outputs"), QFileDialog.ShowDirsOnly) if os.path.exists(output_folder): GuiSettings.settings().setValue("spatial_outputs", output_folder) self.output_folder_input.setText(output_folder)
def _click_open_output(self): filters = ("GeoTIFF (*.tif *.tiff)") filename, _ = QFileDialog.getSaveFileName( self, f"Select output file", GuiSettings.settings().value(output_folder_settings), filters) if filename is None: return last_open_folder = os.path.dirname(filename) if os.path.exists(last_open_folder): GuiSettings.settings().setValue(output_folder_settings, last_open_folder) self._set_output_filename(filename)
def _click_open(self): filters = ("GeoTIFF (*.tif *.tiff);;" "Bathymetry Attributed Grid BAG (*.bag);;" "All files (*.*)") selections, _ = QFileDialog.getOpenFileNames( self, f"Open {self.band_name} file", GuiSettings.settings().value(input_folder_settings), filters) if len(selections) == 0: return last_open_folder = os.path.dirname(selections[0]) if os.path.exists(last_open_folder): GuiSettings.settings().setValue(input_folder_settings, last_open_folder) self._set_filename(selections[0])
def update_plugin_tabs(self): """ Updates what plugins are shown in the bottom tabs """ for plugin_tab in self.plugin_tabs: plugin_tab.setParent(None) self.plugin_tabs.clear() if self.profile is None: return # get plugin instances for current profile from singleton plugins = (QaxPlugins.instance().get_profile_plugins( self.profile).plugins) for plugin in plugins: plugin_tab = PluginTab(parent_win=self, prj=self.prj, plugin=plugin) plugin_tab.plugin_changed.connect(self._on_plugin_changed) self.plugin_tabs.append(plugin_tab) icon_path = GuiSettings.icon_path(plugin.icon) if icon_path is not None: tab_index = self.tabs.addTab(plugin_tab, QtGui.QIcon(icon_path), "") else: tab_index = self.tabs.addTab(plugin_tab, plugin.name) self.tabs.setTabToolTip(tab_index, plugin.name)
def gui(dev_mode=False): """Run the QAX gui""" # temporary fix for CORS warning (QTBUG-70228) sys.argv.append("--disable-web-security") # stop auto scaling on windows # os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" # stop auto scaling on windows - part 2 # app.setAttribute(QtCore.Qt.AA_DisableHighDpiScaling) # app.setStyleSheet(AppStyle.load_stylesheet()) cfg_dir = GuiSettings.config_default() logger.info("Using config {}".format(cfg_dir)) config = QaxConfig(Path(cfg_dir)) config.load() plugins = QaxPlugins() plugins.load(config) main_win = MainWin() main_win.initialize() sys.excepthook = main_win.exception_hook # install the exception hook main_win.show() if dev_mode: main_win.do() sys.exit(app.exec_())
def _update_file_list(self) -> NoReturn: self.file_list.clear() for selected_file in self.selected_files: file_item = QtWidgets.QListWidgetItem() file_item.setText(selected_file) file_item.setFont(GuiSettings.console_font()) # file_item.setForeground(GuiSettings.console_fg_color()) path = Path(selected_file) matching_file_type = self.file_group.matching_file_type(path) if ((matching_file_type is not None) and (matching_file_type.icon is not None)): file_type_icon = QtGui.QIcon( GuiSettings.icon_path(matching_file_type.icon)) file_item.setIcon(file_type_icon) self.file_list.addItem(file_item)
def initialize(self): self.qax_widget.initialize() self.settings = GuiSettings.settings() self.resize( QtCore.QSize( int(self.settings.value("qax_app_width", defaultValue=920)), int(self.settings.value("qax_app_height", defaultValue=840)), ))
def __init__(self, param: QajsonParam, parent=None): super().__init__(param, parent=parent) hbox = QtWidgets.QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) self.setLayout(hbox) label_name = QtWidgets.QLabel( "Unknown param type: {}".format(self._param.name)) label_name.setMinimumWidth(self.label_min_width) label_name.setStyleSheet(GuiSettings.stylesheet_check_param_name()) hbox.addWidget(label_name)
def _click_add(self): """ Add files selected by user. Opens file selection dialog """ import_folder_name = "{}_import_folder".format( self.file_group.clean_name()) filters = [] if len(self.file_group.file_types) > 0: all_ext = [ "*.{}".format(ft.extension) for ft in self.file_group.file_types ] all_formats = "Supported formats ({})".format(" ".join(all_ext)) filters.append(all_formats) for ft in self.file_group.file_types: filters.append("{} (*.{})".format(ft.name, ft.extension)) filters.append("All files (*.*)") # ask the file path to the user # noinspection PyCallByClass selections, _ = QtWidgets.QFileDialog.getOpenFileNames( self, "Add {} file".format(self.file_group.name.lower()), GuiSettings.settings().value(import_folder_name), ";; ".join(filters)) if len(selections) == 0: logger.debug('adding raw: aborted') return last_open_folder = os.path.dirname(selections[0]) if os.path.exists(last_open_folder): GuiSettings.settings().setValue(import_folder_name, last_open_folder) new_selected_files = [ os.path.abspath(selection).replace("\\", "/") for selection in selections ] self.selected_files.extend(new_selected_files) self._update_file_list() self.files_added.emit(self.file_group)
def __init__(self, parent_win, prj, plugin: QaxCheckToolPlugin): QtWidgets.QWidget.__init__(self) # store a project reference self.prj = prj self.parent_win = parent_win # self.media = self.parent_win.media self.plugin = plugin self.check_widgets = [] self.vbox = QtWidgets.QVBoxLayout() self.setLayout(self.vbox) # title label_name = QtWidgets.QLabel(plugin.name) label_name.setStyleSheet(GuiSettings.stylesheet_plugin_tab_titles()) self.vbox.addWidget(label_name) # description (if one is include in config) if plugin.description is not None: label_desc = QtWidgets.QLabel(plugin.description) self.vbox.addWidget(label_desc) self.groupbox_checks = QtWidgets.QGroupBox("Checks") self.groupbox_checks.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.vbox.addWidget(self.groupbox_checks) layout_gb_checks = QtWidgets.QVBoxLayout() layout_gb_checks.setContentsMargins(0, 8, 0, 0) self.groupbox_checks.setLayout(layout_gb_checks) self.scrollarea_checks = QtWidgets.QScrollArea() self.scrollarea_checks.setWidgetResizable(True) self.scrollarea_checks.setHorizontalScrollBarPolicy( QtCore.Qt.ScrollBarAlwaysOff) self.scrollarea_checks.setStyleSheet("QScrollArea { border: none;}") layout_gb_checks.addWidget(self.scrollarea_checks) self.widget_checks = QtWidgets.QWidget() self.layout_checks = QtWidgets.QVBoxLayout(self.widget_checks) for check in self.plugin.checks(): check_widget = CheckWidget(check) check_widget.check_changed.connect(self._on_check_changed) self.layout_checks.addWidget(check_widget) self.check_widgets.append(check_widget) self.layout_checks.addStretch(1) self.scrollarea_checks.setWidget(self.widget_checks)
def _add_check_outputs(self): co_groupbox = QGroupBox("Check outputs") co_groupbox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) co_layout = QVBoxLayout() co_layout.setSpacing(16) co_groupbox.setLayout(co_layout) self.qajson_spatial_checkbox = QCheckBox( "Include summary spatial output in QAJSON. " "Supports QAX visualisation.") self.qajson_spatial_checkbox.setCheckState( QtCore.Qt.CheckState.Checked) co_layout.addWidget(self.qajson_spatial_checkbox) export_layout = QVBoxLayout() export_layout.setSpacing(4) self.export_spatial_checkbox = QCheckBox( "Export detailed spatial outputs to file. " "Supports visualisation in other geospatial applications.") self.export_spatial_checkbox.stateChanged.connect( self._on_export_spatial_changed) export_layout.addWidget(self.export_spatial_checkbox) output_folder_layout = QHBoxLayout() output_folder_layout.setSpacing(4) output_folder_layout.addSpacerItem(QtWidgets.QSpacerItem(37, 20)) self.output_folder_label = QLabel( "Detailed spatial output folder location:") output_folder_layout.addWidget(self.output_folder_label) self.output_folder_input = QLineEdit() self.output_folder_input.setText( GuiSettings.settings().value("spatial_outputs")) self.output_folder_input.setMinimumWidth(300) self.output_folder_input.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) output_folder_layout.addWidget(self.output_folder_input) self.open_output_folder_button = QPushButton() output_folder_layout.addWidget(self.open_output_folder_button) self.open_output_folder_button.setIcon(qta.icon('fa.folder-open')) self.open_output_folder_button.setToolTip( f"Select file containing data") self.open_output_folder_button.clicked.connect( self._click_open_spatial_export_folder) export_layout.addLayout(output_folder_layout) co_layout.addLayout(export_layout) self._on_export_spatial_changed() self.vbox.addWidget(co_groupbox)
def __init__(self, check_reference: QaxCheckReference, parent=None): QtWidgets.QWidget.__init__(self, parent=parent) self.check_reference = check_reference self.param_widgets = [] vbox = QtWidgets.QVBoxLayout() vbox.setContentsMargins(0, 4, 0, 4) self.setLayout(vbox) label_name = QtWidgets.QLabel("{}".format(self.check_reference.name)) label_name.setStyleSheet(GuiSettings.stylesheet_check_titles()) vbox.addWidget(label_name) if self.check_reference.description is not None: label_description = QtWidgets.QLabel("{}".format( self.check_reference.description)) vbox.addWidget(label_description) if ((self.check_reference.default_input_params is None) or (len(self.check_reference.default_input_params) == 0)): hbox = QtWidgets.QHBoxLayout() hbox.addStretch() label_no_params = QtWidgets.QLabel( "Check accepts no input parameters") hbox.addWidget(label_no_params) hbox.addStretch() vbox.addLayout(hbox) else: hbox = QtWidgets.QHBoxLayout() hbox.addSpacing(30) vbox.addLayout(hbox) params_layout = QtWidgets.QVBoxLayout() params_label = QtWidgets.QLabel("Parameters") params_layout.addWidget(params_label) params_label.setStyleSheet("QLabel { font-weight: bold; " "padding: 0px 0px 0px 0px;}") hbox.addLayout(params_layout) for check_param in self.check_reference.default_input_params: widget_param = get_param_widget(check_param) widget_param.value_changed.connect(self._param_value_changed) params_layout.addWidget(widget_param) self.param_widgets.append(widget_param) hbox.addSpacing(10) vbox.addWidget(QHLine())
def __init__(self, param: QajsonParam, parent=None): super().__init__(param, parent=parent) hbox = QtWidgets.QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) self.setLayout(hbox) label_name = QtWidgets.QLabel("{}".format(self._param.name)) label_name.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) label_name.setMinimumWidth(self.label_min_width) label_name.setStyleSheet(GuiSettings.stylesheet_check_param_name()) hbox.addWidget(label_name) self.lineedit_value = QtWidgets.QLineEdit() self.lineedit_value.setText(self._param.value) self.lineedit_value.textEdited.connect(self._on_edited) hbox.addWidget(self.lineedit_value)
def __init__(self, param: QajsonParam, parent=None): super().__init__(param, parent=parent) hbox = QtWidgets.QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) hbox.setAlignment(QtCore.Qt.AlignLeft) self.setLayout(hbox) label_name = QtWidgets.QLabel(f"{self._param.name}") label_name.setMinimumWidth(self.label_min_width) label_name.setStyleSheet(GuiSettings.stylesheet_check_param_name()) hbox.addWidget(label_name) self.checkbox = QtWidgets.QCheckBox() self.checkbox.setChecked(self._param.value) self.checkbox.stateChanged.connect(self._on_edited) hbox.addWidget(self.checkbox)
def __init__(self, parent_win, prj): QtWidgets.QWidget.__init__(self) self.prj = prj self.vbox = QtWidgets.QVBoxLayout() self.setLayout(self.vbox) lab = QtWidgets.QLabel("Plugins") lab.setStyleSheet(GuiSettings.stylesheet_plugin_tab_titles()) self.vbox.addWidget(lab) self.tabs = QtWidgets.QTabWidget() self.vbox.addWidget(self.tabs) self.profile = None # QaxConfigProfile # includes only the PluginTab instances, one per plugin self.plugin_tabs = []